mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 05:42:35 +00:00
Fixed Variable dialog erroneously saying that a valid type was invalid, removed old states and renamed NewEditor to Editor, updated dialogs with 2 side-by-side buttons to use 0.5 instead of 0.475 dynamic width, removed manual newlines in dialogs since TextBlock now supports word wrap.
This commit is contained in:
@@ -15,7 +15,7 @@ module TAC
|
||||
|
||||
# title
|
||||
flow width: 0.9 do
|
||||
label @title, text_size: THEME_SUBHEADING_TEXT_SIZE, width: 1.0, text_align: :center, text_shadow: true, text_shadow_color: 0xff_222222, text_shadow_size: 1
|
||||
label @title, text_size: THEME_SUBHEADING_TEXT_SIZE, width: 1.0, text_align: :center, text_border: true, text_border_color: 0xff_222222, text_border_size: 1
|
||||
end
|
||||
|
||||
# Buttons
|
||||
|
||||
@@ -16,11 +16,11 @@ module TAC
|
||||
@comment = edit_line @options[:action] ? @options[:action].comment : "", width: 1.0
|
||||
|
||||
flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
button "Cancel", width: 0.475 do
|
||||
button "Cancel", width: 0.5 do
|
||||
close
|
||||
end
|
||||
|
||||
button @options[:action] ? @options[:accept_label] ? @options[:accept_label] : "Update" : "Add", width: 0.475 do |b|
|
||||
button @options[:action] ? @options[:accept_label] ? @options[:accept_label] : "Update" : "Add", width: 0.5 do |b|
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,11 +15,11 @@ module TAC
|
||||
label @options[:message]
|
||||
|
||||
flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
button "Cancel", width: 0.475 do
|
||||
button "Cancel", width: 0.5 do
|
||||
close
|
||||
end
|
||||
|
||||
button "Proceed", width: 0.475, **TAC::THEME_DANGER_BUTTON do
|
||||
button "Proceed", width: 0.5, **TAC::THEME_DANGER_BUTTON do
|
||||
try_commit(true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,14 +15,14 @@ module TAC
|
||||
end
|
||||
|
||||
flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
button "Cancel", width: 0.475 do
|
||||
button "Cancel", width: 0.5 do
|
||||
close
|
||||
end
|
||||
|
||||
accept_label = @options[:renaming] ? "Update" : "Add"
|
||||
accept_label = @options[:accept_label] if @options[:accept_label]
|
||||
|
||||
button accept_label, width: 0.475 do
|
||||
button accept_label, width: 0.5 do
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
@@ -44,7 +44,7 @@ module TAC
|
||||
name = @name.value.strip
|
||||
|
||||
if @name.value.strip.empty?
|
||||
@name_error.value = "Name cannot be blank.\nName cannot only be whitespace."
|
||||
@name_error.value = "Name cannot be blank. Name cannot only be whitespace."
|
||||
@name_error.show
|
||||
|
||||
return false
|
||||
|
||||
@@ -19,7 +19,8 @@ module TAC
|
||||
@type_error.hide
|
||||
|
||||
@var_type = list_box items: [:float, :double, :integer, :long, :string, :boolean], choose: @type ? @type : :double, width: 1.0 do |item|
|
||||
@type = item
|
||||
@type = item.value.to_sym
|
||||
|
||||
if @type == :boolean
|
||||
@value.hide
|
||||
@value_boolean.show
|
||||
@@ -52,11 +53,11 @@ module TAC
|
||||
end
|
||||
|
||||
flow width: 1.0, margin_top: THEME_DIALOG_BUTTON_PADDING do
|
||||
button "Cancel", width: 0.475 do
|
||||
button "Cancel", width: 0.5 do
|
||||
close
|
||||
end
|
||||
|
||||
button @options[:variable] ? "Update" : "Add", width: 0.475 do |b|
|
||||
button @options[:variable] ? "Update" : "Add", width: 0.5 do |b|
|
||||
try_commit
|
||||
end
|
||||
end
|
||||
@@ -80,7 +81,7 @@ module TAC
|
||||
valid = true
|
||||
|
||||
if @name.value.strip.empty?
|
||||
@name_error.value = "Error: Name cannot be blank\n or only whitespace."
|
||||
@name_error.value = "Error: Name cannot be blank or only whitespace."
|
||||
@name_error.show
|
||||
valid = false
|
||||
else
|
||||
@@ -99,7 +100,7 @@ module TAC
|
||||
|
||||
if [:integer, :float, :double, :long].include?(@type)
|
||||
if @value.value.strip.empty?
|
||||
@value_error.value = "Error: Numeric value cannot be\nblank or only whitespace."
|
||||
@value_error.value = "Error: Numeric value cannot be blank or only whitespace."
|
||||
@value_error.show
|
||||
valid = false
|
||||
|
||||
@@ -107,7 +108,7 @@ module TAC
|
||||
begin
|
||||
Integer(@value.value.strip)
|
||||
rescue
|
||||
@value_error.value = "Error: Invalid value,\nexpected whole number."
|
||||
@value_error.value = "Error: Invalid value, expected whole number."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
@@ -116,7 +117,7 @@ module TAC
|
||||
begin
|
||||
Float(@value.value.strip)
|
||||
rescue
|
||||
@value_error.value = "Error: Invalid value,\nexpected decimal number."
|
||||
@value_error.value = "Error: Invalid value, expected decimal number."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
@@ -127,7 +128,7 @@ module TAC
|
||||
|
||||
elsif @type == :string
|
||||
if @value.value.strip.empty?
|
||||
@value_error.value = "Error: Value cannot be blank\n or only whitespace."
|
||||
@value_error.value = "Error: Value cannot be blank or only whitespace."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
@@ -135,7 +136,7 @@ module TAC
|
||||
elsif @type == :boolean
|
||||
|
||||
else
|
||||
@value_error.value = "Error: Type not set or\ntype #{@var_type.value.inspect} is not valid."
|
||||
@value_error.value = "Error: Type not set or type #{@type.inspect} is not valid."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ module TAC
|
||||
|
||||
populate_configs
|
||||
else
|
||||
push_state(Dialog::AlertDialog, title: "Config Rename Failed", message: "File already exists at\n#{TAC::CONFIGS_PATH}/#{new_name}.json}")
|
||||
push_state(Dialog::AlertDialog, title: "Config Rename Failed", message: "File already exists at #{TAC::CONFIGS_PATH}/#{new_name}.json}")
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
@@ -162,7 +162,7 @@ module TAC
|
||||
if @active_action
|
||||
push_state(TAC::Dialog::VariableDialog, title: "Create Variable", callback_method: method(:create_variable))
|
||||
else
|
||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create variable,\nno action selected.")
|
||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create variable, no action selected.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,7 +6,7 @@ module TAC
|
||||
background [TAC::Palette::TIMECRAFTERS_PRIMARY, TAC::Palette::TIMECRAFTERS_SECONDARY, TAC::Palette::TIMECRAFTERS_TERTIARY, TAC::Palette::TIMECRAFTERS_PRIMARY]
|
||||
end
|
||||
|
||||
@title_font = CyberarmEngine::Text.new(TAC::NAME, z: 100, size: 72, shadow: true, shadow_size: 3, font: THEME[:Label][:font])
|
||||
@title_font = CyberarmEngine::Text.new(TAC::NAME, z: 100, size: 72, border: true, border_size: 3, font: THEME[:Label][:font])
|
||||
@logo = Gosu::Image.new("#{TAC::ROOT_PATH}/media/logo.png")
|
||||
|
||||
@title_animator = CyberarmEngine::Animator.new(start_time: 0, duration: 750, from: 0.0, to: 1.0, tween: :swing_from_to)
|
||||
@@ -14,7 +14,7 @@ module TAC
|
||||
@transition_animator = CyberarmEngine::Animator.new(start_time: 2_250, duration: 750, from: 0, to: 255, tween: :ease_out)
|
||||
@transition_color = Gosu::Color.new(0x00_111111)
|
||||
|
||||
@next_state = NewEditor
|
||||
@next_state = Editor
|
||||
end
|
||||
|
||||
def draw
|
||||
|
||||
@@ -1,394 +1,174 @@
|
||||
module TAC
|
||||
class States
|
||||
class Editor < CyberarmEngine::GuiState
|
||||
class Editor < CyberarmEngine::GuiState
|
||||
include CyberarmEngine::Theme # get access to deep_merge method
|
||||
attr_reader :header_bar, :header_bar_label, :navigation, :content, :menu_bar, :status_bar, :body
|
||||
|
||||
def setup
|
||||
@active_group = nil
|
||||
@active_action = nil
|
||||
@window_width = 0
|
||||
@window_height = 0
|
||||
|
||||
theme(THEME)
|
||||
@pages = {}
|
||||
@page = nil
|
||||
|
||||
stack width: 1.0, height: 1.0 do
|
||||
stack width: 1.0, height: 0.1, border_thickness: 1, border_color: [0, 0, Gosu::Color::BLACK, 0] do
|
||||
background THEME_HEADER_BACKGROUND
|
||||
# TODO: Use these colors for buttons
|
||||
_theme = {
|
||||
Button: {
|
||||
background: 0xff_006000,
|
||||
border_color: 0x88_111111,
|
||||
hover: {
|
||||
color: 0xff_ffffff,
|
||||
background: 0xff_00d000,
|
||||
border_color: 0x88_111111
|
||||
},
|
||||
active: {
|
||||
color: 0xff_ffffff,
|
||||
background: 0xff_004000,
|
||||
border_color: 0x88_111111
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flow width: 1.0, height: 1.0 do
|
||||
stack width: 0.60 do
|
||||
label TAC::NAME, bold: true, text_size: THEME_HEADING_TEXT_SIZE
|
||||
flow width: 1.0 do
|
||||
flow width: 0.3 do
|
||||
label "Group: "
|
||||
@active_group_label = label ""
|
||||
theme(deep_merge(TAC::THEME, _theme))
|
||||
|
||||
@header_bar = flow(width: 1.0, height: 36) do
|
||||
background 0xff_006000
|
||||
|
||||
@header_bar_label = label TAC::NAME, width: 1.0, text_align: :center, text_size: 32
|
||||
|
||||
@window_controls = flow(x: window.width - 36 * 2, y: 0, height: 1.0) do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/minus.png"), tip: "Minimize", image_height: 1.0 do
|
||||
window.minimize if window.respond_to?(:minimize)
|
||||
end
|
||||
|
||||
flow width: 0.3 do
|
||||
label "Action: "
|
||||
@active_action_label = label ""
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/larger.png"), tip: "Maximize", image_height: 1.0 do |btn|
|
||||
window.maximize if window.respond_to?(:maximize)
|
||||
end
|
||||
|
||||
flow width: 0.395 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Simulator" do
|
||||
push_state(Simulator)
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/menuList.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Manage presets" do
|
||||
push_state(ManagePresets)
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/wrench.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Manage configurations" do
|
||||
push_state(ManageConfigurations)
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Save config and settings to disk" do
|
||||
window.backend.save_config
|
||||
window.backend.save_settings
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/export.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Upload local config to remote, if connected." do
|
||||
window.backend.upload_config(window.backend.settings.config)
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/import.png"), image_width: THEME_ICON_SIZE, margin_left: 10, tip: "Download remote config, if connected." do
|
||||
window.backend.download_config(window.backend.settings.config)
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/cross.png"), tip: "Exit", image_height: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
flow width: 0.399 do
|
||||
stack width: 0.5 do
|
||||
label "TACNET v#{TACNET::Packet::PROTOCOL_VERSION}", color: TAC::Palette::TACNET_PRIMARY, text_shadow: true, text_shadow_size: 1, text_shadow_color: Gosu::Color::BLACK
|
||||
flow width: 1.0 do
|
||||
@tacnet_hostname = edit_line "#{window.backend.settings.hostname}", width: 0.5, margin_right: 0
|
||||
@tacnet_hostname.subscribe(:changed) do |caller, value|
|
||||
window.backend.settings.hostname = value
|
||||
window.backend.settings_changed!
|
||||
@container = flow(width: 1.0, height: 1.0) do
|
||||
@navigation = stack(width: 64, height: 1.0) do
|
||||
background 0xff_333333
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/home.png"), margin: 4, tip: "Home", image_width: 1.0 do
|
||||
page(TAC::Pages::Home)
|
||||
end
|
||||
|
||||
label ":", margin: 0, padding: 0, padding_top: 3
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/menuList.png"), margin: 4, tip: "Editor", image_width: 1.0 do
|
||||
page(TAC::Pages::Editor)
|
||||
end
|
||||
|
||||
@tacnet_port = edit_line "#{window.backend.settings.port}", width: 0.2, margin_left: 0
|
||||
@tacnet_port.subscribe(:changed) do |caller, value|
|
||||
window.backend.settings.port = Integer(value)
|
||||
window.backend.settings_changed!
|
||||
@tacnet_button = button get_image("#{TAC::ROOT_PATH}/media/icons/signal3.png"), margin: 4, tip: "TACNET", image_width: 1.0 do
|
||||
page(TAC::Pages::TACNET)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), margin: 4, tip: "Simulator", image_width: 1.0 do
|
||||
page(TAC::Pages::Simulator)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), margin: 4, tip: "Configurations", image_width: 1.0 do
|
||||
page(TAC::Pages::Configurations)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/menuGrid.png"), margin: 4, tip: "Presets", image_width: 1.0 do
|
||||
page(TAC::Pages::Presets)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/zoom.png"), margin: 4, tip: "Search", image_width: 1.0 do
|
||||
page(TAC::Pages::Search)
|
||||
end
|
||||
end
|
||||
|
||||
@content = stack(width: window.width - @navigation.style.width, height: 1.0) do
|
||||
@chrome = stack(width: 1.0, height: 96) do
|
||||
@menu_bar = flow(width: 1.0, height: 48, padding: 8) do
|
||||
background 0xff_008000
|
||||
end
|
||||
|
||||
@status_bar = flow(width: 1.0, height: 96 - 48, padding: 2) do
|
||||
background 0xff_006000
|
||||
end
|
||||
end
|
||||
|
||||
@body = stack(width: 1.0, height: 1.0) do
|
||||
background 0xff_707070
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 0.499 do
|
||||
@tacnet_status = label "Not Connected", background: TAC::Palette::TACNET_NOT_CONNECTED, width: 1.0, padding: 5, margin_top: 2, border_thickness: 1, border_color: Gosu::Color::GRAY
|
||||
flow width: 1.0 do
|
||||
@tacnet_connection_button = button "Connect", width: 0.475 do
|
||||
case window.backend.tacnet.status
|
||||
when :connected, :connecting
|
||||
window.backend.tacnet.close
|
||||
when :not_connected, :connection_error
|
||||
window.backend.tacnet.connect(@tacnet_hostname.value, @tacnet_port.value)
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/information.png"), image_width: THEME_ICON_SIZE, width: 0.475 do
|
||||
push_state(Dialog::TACNETStatusDialog, title: "TACNET Status", message: window.backend.tacnet.full_status)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@window_controls.hide unless BORDERLESS
|
||||
|
||||
page(TAC::Pages::Home)
|
||||
end
|
||||
|
||||
@content = flow width: 1.0, height: 0.9 do
|
||||
background THEME_CONTENT_BACKGROUND
|
||||
stack width: 0.333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do
|
||||
flow do
|
||||
label "Groups", text_size: THEME_SUBHEADING_TEXT_SIZE
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add group" do
|
||||
push_state(TAC::Dialog::NamePromptDialog, title: "Create Group", list: window.backend.config.groups, callback_method: method(:create_group))
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: THEME_ICON_SIZE, tip: "Clone currently selected group" do
|
||||
if @active_group
|
||||
push_state(Dialog::NamePromptDialog, title: "Clone Group", renaming: @active_group, accept_label: "Clone", list: window.backend.config.groups, callback_method: proc { |group, name|
|
||||
clone = TAC::Config::Group.from_json( JSON.parse( @active_group.to_json, symbolize_names: true ))
|
||||
clone.name = "#{name}"
|
||||
window.backend.config.groups << clone
|
||||
window.backend.config_changed!
|
||||
def draw
|
||||
super
|
||||
|
||||
populate_groups_list
|
||||
})
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, tip: "Save group as preset" do
|
||||
if @active_group
|
||||
push_state(Dialog::NamePromptDialog, title: "Save Group Preset", renaming: @active_group, accept_label: "Save", list: window.backend.config.presets.actions, callback_method: proc { |action, name|
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@groups_list = stack width: 1.0 do
|
||||
end
|
||||
end
|
||||
stack width: 0.333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do
|
||||
flow do
|
||||
label "Actions", text_size: THEME_SUBHEADING_TEXT_SIZE
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add action" do
|
||||
if @active_group
|
||||
push_state(TAC::Dialog::ActionDialog, title: "Create Action", list: @active_group.actions, callback_method: method(:create_action))
|
||||
else
|
||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create action,\nno group selected.")
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: THEME_ICON_SIZE, tip: "Clone currently selected action" do
|
||||
if @active_group && @active_action
|
||||
push_state(Dialog::ActionDialog, title: "Clone Action", action: @active_action, accept_label: "Clone", list: @active_group.actions, callback_method: proc { |action, name, comment|
|
||||
clone = TAC::Config::Action.from_json( JSON.parse( @active_action.to_json, symbolize_names: true ))
|
||||
clone.name = name
|
||||
clone.comment = comment
|
||||
@active_group.actions << clone
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_actions_list(@active_group)
|
||||
})
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, tip: "Save action as preset" do
|
||||
if @active_action
|
||||
push_state(Dialog::NamePromptDialog, title: "Save Action Preset", renaming: @active_action, accept_label: "Save", list: window.backend.config.presets.actions, callback_method: proc { |action, name|
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@actions_list = stack width: 1.0 do
|
||||
end
|
||||
end
|
||||
stack width: 0.331, height: 1.0 do
|
||||
flow do
|
||||
label "Variables", text_size: THEME_SUBHEADING_TEXT_SIZE
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: THEME_ICON_SIZE, tip: "Add variable" do
|
||||
if @active_action
|
||||
push_state(TAC::Dialog::VariableDialog, title: "Create Variable", callback_method: method(:create_variable))
|
||||
else
|
||||
push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Unable to create variable,\nno action selected.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@variables_list = stack width: 1.0 do
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if window.backend.settings.config == nil || window.backend.config == nil
|
||||
push_state(ManageConfigurations)
|
||||
else
|
||||
populate_groups_list
|
||||
end
|
||||
|
||||
@tacnet_status_monitor = CyberarmEngine::Timer.new(250) do
|
||||
case window.backend.tacnet.status
|
||||
when :connected
|
||||
@tacnet_status.value = "Connected"
|
||||
@tacnet_status.background = TAC::Palette::TACNET_CONNECTED
|
||||
|
||||
@tacnet_connection_button.value = "Disconnect"
|
||||
when :connecting
|
||||
@tacnet_status.value = "Connecting..."
|
||||
@tacnet_status.background = TAC::Palette::TACNET_CONNECTING
|
||||
|
||||
@tacnet_connection_button.value = "Disconnect"
|
||||
when :connection_error
|
||||
@tacnet_status.value = "Connection Error"
|
||||
@tacnet_status.background = TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
|
||||
if @tacnet_connection_button.value != "Connect"
|
||||
push_state(Dialog::TACNETDialog, title: "TACNET Error", message: window.backend.tacnet.full_status)
|
||||
end
|
||||
|
||||
@tacnet_connection_button.value = "Connect"
|
||||
when :not_connected
|
||||
@tacnet_status.value = "Not Connected"
|
||||
@tacnet_status.background = TAC::Palette::TACNET_NOT_CONNECTED
|
||||
|
||||
@tacnet_connection_button.value = "Connect"
|
||||
end
|
||||
end
|
||||
@page.draw if @page
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@tacnet_status_monitor.update
|
||||
@page.update if @page
|
||||
|
||||
case window.backend.tacnet.status
|
||||
when :not_connected
|
||||
@tacnet_button.style.color = Gosu::Color::WHITE
|
||||
when :connecting
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTING
|
||||
when :connected
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTED
|
||||
when :connection_error
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
end
|
||||
|
||||
def create_group(name)
|
||||
window.backend.config.groups << TAC::Config::Group.new(name: name, actions: [])
|
||||
window.backend.config_changed!
|
||||
window.width = Gosu.available_width / 2 if window.width < Gosu.available_width / 2
|
||||
window.height = Gosu.available_height / 2 if window.height < Gosu.available_height / 2
|
||||
|
||||
populate_groups_list
|
||||
end
|
||||
if window.width != @window_width || window.height != @window_height
|
||||
@window_width = window.width
|
||||
@window_height = window.height
|
||||
|
||||
def update_group(group, name)
|
||||
group.name = name
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_groups_list
|
||||
end
|
||||
|
||||
def delete_group(group)
|
||||
window.backend.config.groups.delete(group)
|
||||
window.backend.config_changed!
|
||||
|
||||
@active_group = nil
|
||||
@active_group_label.value = ""
|
||||
@active_action = nil
|
||||
@active_action_label.value = ""
|
||||
@actions_list.clear
|
||||
@variables_list.clear
|
||||
|
||||
populate_groups_list
|
||||
end
|
||||
|
||||
def create_action(name, comment)
|
||||
@active_group.actions << TAC::Config::Action.new(name: name, comment: comment, enabled: true, variables: [])
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_actions_list(@active_group)
|
||||
end
|
||||
|
||||
def update_action(action, name, comment)
|
||||
action.name = name
|
||||
action.comment = comment
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_actions_list(@active_group)
|
||||
end
|
||||
|
||||
def delete_action(action)
|
||||
@active_group.actions.delete(action)
|
||||
window.backend.config_changed!
|
||||
|
||||
@active_action = nil
|
||||
@active_action_label.value = ""
|
||||
@variables_list.clear
|
||||
|
||||
populate_actions_list(@active_group)
|
||||
end
|
||||
|
||||
def create_variable(name, type, value)
|
||||
@active_action.variables << TAC::Config::Variable.new(name: name, type: type, value: value)
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_variables_list(@active_action)
|
||||
end
|
||||
|
||||
def update_variable(variable, name, type, value)
|
||||
variable.name = name
|
||||
variable.type = type
|
||||
variable.value = value
|
||||
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_variables_list(@active_action)
|
||||
end
|
||||
|
||||
def delete_variable(variable)
|
||||
@active_action.variables.delete(variable)
|
||||
window.backend.config_changed!
|
||||
|
||||
populate_variables_list(@active_action)
|
||||
end
|
||||
|
||||
def populate_groups_list
|
||||
groups = window.backend.config.groups
|
||||
|
||||
@groups_list.clear do
|
||||
groups.each_with_index do |group, i|
|
||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||
|
||||
button group.name, width: 0.855 do
|
||||
@active_group = group
|
||||
@active_group_label.value = group.name
|
||||
@active_action = nil
|
||||
@active_action_label.value = ""
|
||||
|
||||
populate_actions_list(group)
|
||||
@variables_list.clear
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit group" do
|
||||
push_state(Dialog::NamePromptDialog, title: "Rename Group", renaming: group, list: window.backend.config.groups, callback_method: method(:update_group))
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete group", **THEME_DANGER_BUTTON do
|
||||
push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete group and all\nof its actions and variables?", callback_method: proc { delete_group(group) })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def populate_actions_list(group)
|
||||
actions = group.actions
|
||||
|
||||
@actions_list.clear do
|
||||
actions.each_with_index do |action, i|
|
||||
stack width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||
|
||||
flow width: 1.0 do
|
||||
button action.name, width: 0.8 do
|
||||
@active_action = action
|
||||
@active_action_label.value = action.name
|
||||
|
||||
populate_variables_list(action)
|
||||
end
|
||||
|
||||
action_enabled_toggle = toggle_button tip: "Enable action", checked: action.enabled
|
||||
action_enabled_toggle.subscribe(:changed) do |sender, value|
|
||||
action.enabled = value
|
||||
window.backend.config_changed!
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit action" do
|
||||
push_state(Dialog::ActionDialog, title: "Rename Action", action: action, list: @active_group.actions, callback_method: method(:update_action))
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete action", **THEME_DANGER_BUTTON do
|
||||
push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete action and all\nof its variables?", callback_method: proc { delete_action(action) })
|
||||
recalc
|
||||
end
|
||||
end
|
||||
|
||||
label "#{action.comment}" unless action.comment.empty?
|
||||
end
|
||||
def recalc
|
||||
@window_controls.style.x = window.width - @window_controls.width
|
||||
@container.style.height = window.height - @header_bar.height
|
||||
@content.style.width = window.width - @navigation.width
|
||||
@body.style.height = window.height - (@chrome.height + @header_bar.height)
|
||||
|
||||
|
||||
request_recalculate
|
||||
end
|
||||
|
||||
def page(klass, options = {})
|
||||
@menu_bar.clear
|
||||
@status_bar.clear
|
||||
@body.clear
|
||||
|
||||
if window.backend.settings.config.empty?
|
||||
if [TAC::Pages::Home, TAC::Pages::TACNET, TAC::Pages::Simulator, TAC::Pages::Configurations].include?(klass)
|
||||
else
|
||||
push_state(TAC::Dialog::AlertDialog, title: "No Config Loaded", message: "A config must be loaded.")
|
||||
page(TAC::Pages::Configurations)
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def populate_variables_list(action)
|
||||
variables = action.variables
|
||||
@page.blur if @page
|
||||
|
||||
@variables_list.clear do
|
||||
variables.each_with_index do |variable, i|
|
||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||
@pages[klass] = klass.new(host: self) unless @pages[klass]
|
||||
@page = @pages[klass]
|
||||
|
||||
button "#{variable.name} [Type: #{variable.type}, Value: #{variable.value}]", width: 0.925, tip: "Edit variable" do
|
||||
push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, callback_method: method(:update_variable))
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete variable", **THEME_DANGER_BUTTON do
|
||||
push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete variable?", callback_method: proc { delete_variable(variable) })
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_config
|
||||
@active_group = nil
|
||||
@active_group_label.value = ""
|
||||
@active_action = nil
|
||||
@active_action_label.value = ""
|
||||
|
||||
@groups_list.clear
|
||||
@actions_list.clear
|
||||
@variables_list.clear
|
||||
|
||||
populate_groups_list
|
||||
end
|
||||
end
|
||||
@page.options = options
|
||||
@page.setup
|
||||
@page.focus
|
||||
end
|
||||
end
|
||||
@@ -1,106 +0,0 @@
|
||||
module TAC
|
||||
class States
|
||||
class ManageConfigurations < CyberarmEngine::GuiState
|
||||
def setup
|
||||
theme(THEME)
|
||||
stack width: 1.0, height: 0.1 do
|
||||
background THEME_HEADER_BACKGROUND
|
||||
label "#{TAC::NAME} ― Manage Configurations", bold: true, text_size: THEME_HEADING_TEXT_SIZE
|
||||
flow do
|
||||
button "Close" do
|
||||
if window.backend.settings.config
|
||||
window.backend.load_config(window.backend.settings.config)
|
||||
|
||||
pop_state
|
||||
|
||||
window.current_state.refresh_config
|
||||
else
|
||||
push_state(Dialog::AlertDialog, title: "No Config Loaded", message: "A config must be loaded.")
|
||||
end
|
||||
end
|
||||
|
||||
label "Current Configuration: "
|
||||
@config_label = label window.backend.settings.config
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 1.0, height: 0.9 do
|
||||
background THEME_CONTENT_BACKGROUND
|
||||
flow do
|
||||
label "Configurations", text_size: THEME_SUBHEADING_TEXT_SIZE
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 18, tip: "Add configuration" do
|
||||
push_state(Dialog::NamePromptDialog, title: "Config Name", callback_method: proc { |name|
|
||||
window.backend.write_new_config(name)
|
||||
|
||||
change_config(name)
|
||||
populate_configs
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
@configs_list = stack width: 1.0 do
|
||||
end
|
||||
end
|
||||
|
||||
populate_configs
|
||||
end
|
||||
|
||||
def populate_configs
|
||||
@config_files = Dir.glob("#{TAC::CONFIGS_PATH}/*.json")
|
||||
@config_files_list = @config_files.map { |file| Dialog::NamePromptDialog::NameStub.new(File.basename(file, ".json")) }
|
||||
|
||||
@configs_list.clear do
|
||||
@config_files.each_with_index do |config_file, i|
|
||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||
|
||||
name = File.basename(config_file, ".json")
|
||||
|
||||
button "#{name}", width: 0.94 do
|
||||
change_config(name)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Rename configuration" do
|
||||
push_state(Dialog::NamePromptDialog, title: "Rename Config", renaming: @config_files_list.find { |c| c.name == name }, list: @config_files_list, accept_label: "Update", callback_method: proc { |old_name, new_name|
|
||||
if not File.exist?("#{TAC::CONFIGS_PATH}/#{new_name}.json")
|
||||
FileUtils.mv(
|
||||
"#{TAC::CONFIGS_PATH}/#{name}.json",
|
||||
"#{TAC::CONFIGS_PATH}/#{new_name}.json"
|
||||
)
|
||||
|
||||
if window.backend.settings.config == name
|
||||
change_config(new_name)
|
||||
end
|
||||
|
||||
populate_configs
|
||||
else
|
||||
push_state(Dialog::AlertDialog, title: "Config Rename Failed", message: "File already exists at\n#{TAC::CONFIGS_PATH}/#{new_name}.json}")
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, **THEME_DANGER_BUTTON, tip: "Delete configuration" do
|
||||
push_state(Dialog::ConfirmDialog, title: "Delete Config?", callback_method: proc {
|
||||
File.delete("#{TAC::CONFIGS_PATH}/#{name}.json")
|
||||
|
||||
if window.backend.settings.config == name
|
||||
change_config(nil)
|
||||
end
|
||||
|
||||
populate_configs
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def change_config(name)
|
||||
window.backend.settings.config = name
|
||||
window.backend.save_settings
|
||||
|
||||
@config_label.value = name.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,45 +0,0 @@
|
||||
module TAC
|
||||
class States
|
||||
class ManagePresets < CyberarmEngine::GuiState
|
||||
def setup
|
||||
theme(THEME)
|
||||
|
||||
stack width: 1.0, height: 0.1 do
|
||||
background THEME_HEADER_BACKGROUND
|
||||
label "#{TAC::NAME} ― Manage Presets", bold: true, text_size: THEME_HEADING_TEXT_SIZE
|
||||
button "Close" do
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
flow width: 1.0, height: 0.9 do
|
||||
stack width: 0.33, height: 1.0 do
|
||||
background TAC::Palette::GROUPS_PRIMARY
|
||||
|
||||
label "Group Presets"
|
||||
# TAC::Storage.group_presets.each do |preset|
|
||||
%w{ Hello World How Are You }.each do |preset|
|
||||
button preset, width:1.0
|
||||
end
|
||||
|
||||
label "Action Presets"
|
||||
# TAC::Storage.action_presets.each do |preset|
|
||||
%w{ Hello World How Are You }.each do |preset|
|
||||
button preset, width:1.0
|
||||
end
|
||||
end
|
||||
|
||||
stack width: 0.6698, height: 1.0 do
|
||||
background TAC::Palette::EDITOR_PRIMARY
|
||||
|
||||
label "Editor"
|
||||
|
||||
@editor = stack width: 1.0, height: 1.0, margin: 10 do
|
||||
background TAC::Palette::EDITOR_SECONDARY
|
||||
label "HELLO WORLD"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,174 +0,0 @@
|
||||
class NewEditor < CyberarmEngine::GuiState
|
||||
include CyberarmEngine::Theme # get access to deep_merge method
|
||||
attr_reader :header_bar, :header_bar_label, :navigation, :content, :menu_bar, :status_bar, :body
|
||||
|
||||
def setup
|
||||
@window_width = 0
|
||||
@window_height = 0
|
||||
|
||||
@pages = {}
|
||||
@page = nil
|
||||
|
||||
# TODO: Use these colors for buttons
|
||||
_theme = {
|
||||
Button: {
|
||||
background: 0xff_006000,
|
||||
border_color: 0x88_111111,
|
||||
hover: {
|
||||
color: 0xff_ffffff,
|
||||
background: 0xff_00d000,
|
||||
border_color: 0x88_111111
|
||||
},
|
||||
active: {
|
||||
color: 0xff_ffffff,
|
||||
background: 0xff_004000,
|
||||
border_color: 0x88_111111
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
theme(deep_merge(TAC::THEME, _theme))
|
||||
|
||||
@header_bar = flow(width: 1.0, height: 36) do
|
||||
background 0xff_006000
|
||||
|
||||
@header_bar_label = label TAC::NAME, width: 1.0, text_align: :center, text_size: 32
|
||||
|
||||
@window_controls = flow(x: window.width - 36 * 2, y: 0, height: 1.0) do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/minus.png"), tip: "Minimize", image_height: 1.0 do
|
||||
window.minimize if window.respond_to?(:minimize)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/larger.png"), tip: "Maximize", image_height: 1.0 do |btn|
|
||||
window.maximize if window.respond_to?(:maximize)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/cross.png"), tip: "Exit", image_height: 1.0, **TAC::THEME_DANGER_BUTTON do
|
||||
window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@container = flow(width: 1.0, height: 1.0) do
|
||||
@navigation = stack(width: 64, height: 1.0) do
|
||||
background 0xff_333333
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/home.png"), margin: 4, tip: "Home", image_width: 1.0 do
|
||||
page(TAC::Pages::Home)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/menuList.png"), margin: 4, tip: "Editor", image_width: 1.0 do
|
||||
page(TAC::Pages::Editor)
|
||||
end
|
||||
|
||||
@tacnet_button = button get_image("#{TAC::ROOT_PATH}/media/icons/signal3.png"), margin: 4, tip: "TACNET", image_width: 1.0 do
|
||||
page(TAC::Pages::TACNET)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), margin: 4, tip: "Simulator", image_width: 1.0 do
|
||||
page(TAC::Pages::Simulator)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), margin: 4, tip: "Configurations", image_width: 1.0 do
|
||||
page(TAC::Pages::Configurations)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/menuGrid.png"), margin: 4, tip: "Presets", image_width: 1.0 do
|
||||
page(TAC::Pages::Presets)
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/zoom.png"), margin: 4, tip: "Search", image_width: 1.0 do
|
||||
page(TAC::Pages::Search)
|
||||
end
|
||||
end
|
||||
|
||||
@content = stack(width: window.width - @navigation.style.width, height: 1.0) do
|
||||
@chrome = stack(width: 1.0, height: 96) do
|
||||
@menu_bar = flow(width: 1.0, height: 48, padding: 8) do
|
||||
background 0xff_008000
|
||||
end
|
||||
|
||||
@status_bar = flow(width: 1.0, height: 96 - 48, padding: 2) do
|
||||
background 0xff_006000
|
||||
end
|
||||
end
|
||||
|
||||
@body = stack(width: 1.0, height: 1.0) do
|
||||
background 0xff_707070
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@window_controls.hide unless BORDERLESS
|
||||
|
||||
page(TAC::Pages::Home)
|
||||
end
|
||||
|
||||
def draw
|
||||
super
|
||||
|
||||
@page.draw if @page
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
@page.update if @page
|
||||
|
||||
case window.backend.tacnet.status
|
||||
when :not_connected
|
||||
@tacnet_button.style.color = Gosu::Color::WHITE
|
||||
when :connecting
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTING
|
||||
when :connected
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTED
|
||||
when :connection_error
|
||||
@tacnet_button.style.color = TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
end
|
||||
|
||||
window.width = Gosu.available_width / 2 if window.width < Gosu.available_width / 2
|
||||
window.height = Gosu.available_height / 2 if window.height < Gosu.available_height / 2
|
||||
|
||||
if window.width != @window_width || window.height != @window_height
|
||||
@window_width = window.width
|
||||
@window_height = window.height
|
||||
|
||||
recalc
|
||||
end
|
||||
end
|
||||
|
||||
def recalc
|
||||
@window_controls.style.x = window.width - @window_controls.width
|
||||
@container.style.height = window.height - @header_bar.height
|
||||
@content.style.width = window.width - @navigation.width
|
||||
@body.style.height = window.height - (@chrome.height + @header_bar.height)
|
||||
|
||||
|
||||
request_recalculate
|
||||
end
|
||||
|
||||
def page(klass, options = {})
|
||||
@menu_bar.clear
|
||||
@status_bar.clear
|
||||
@body.clear
|
||||
|
||||
if window.backend.settings.config.empty?
|
||||
if [TAC::Pages::Home, TAC::Pages::TACNET, TAC::Pages::Simulator, TAC::Pages::Configurations].include?(klass)
|
||||
else
|
||||
push_state(TAC::Dialog::AlertDialog, title: "No Config Loaded", message: "A config must be loaded.")
|
||||
page(TAC::Pages::Configurations)
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
@page.blur if @page
|
||||
|
||||
@pages[klass] = klass.new(host: self) unless @pages[klass]
|
||||
@page = @pages[klass]
|
||||
|
||||
@page.options = options
|
||||
@page.setup
|
||||
@page.focus
|
||||
end
|
||||
end
|
||||
@@ -1,86 +0,0 @@
|
||||
module TAC
|
||||
class States
|
||||
class Simulator < CyberarmEngine::GuiState
|
||||
def setup
|
||||
theme(THEME)
|
||||
|
||||
stack width: 1.0, height: 0.1 do
|
||||
background THEME_HEADER_BACKGROUND
|
||||
label "#{TAC::NAME} ― Simulator", bold: true, text_size: THEME_HEADING_TEXT_SIZE
|
||||
button "Close" do
|
||||
pop_state
|
||||
end
|
||||
end
|
||||
|
||||
flow width: 1.0, height: 0.9 do
|
||||
@field_container = stack width: 0.4, height: 1.0 do
|
||||
background Gosu::Color.new(0xff_333333)..Gosu::Color::BLACK
|
||||
end
|
||||
|
||||
stack width: 0.6, height: 1.0 do
|
||||
background Gosu::Color.new(0x88_ff8800)
|
||||
|
||||
flow width: 1.0, height: 0.05 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Run simulation" do
|
||||
begin
|
||||
@simulation_start_time = Gosu.milliseconds
|
||||
@simulation = TAC::Simulator::Simulation.new(source_code: @source_code.value, field_container: @field_container)
|
||||
@simulation.start
|
||||
rescue SyntaxError, NameError, NoMethodError, TypeError, ArgumentError => e
|
||||
puts e.backtrace.reverse.join("\n")
|
||||
puts e
|
||||
push_state(Dialog::AlertDialog, title: "#{e.class}", message: e)
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Stop simulation" do
|
||||
@simulation.robots.each { |robot| robot.queue.clear } if @simulation
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Save source code" do
|
||||
File.open("#{TAC::ROOT_PATH}/data/simulator.rb", "w") { |f| f.write @source_code.value }
|
||||
end
|
||||
|
||||
@simulation_status = label ""
|
||||
end
|
||||
|
||||
stack width: 1.0, height: 0.95 do
|
||||
source_code = ""
|
||||
if File.exist?("#{TAC::ROOT_PATH}/data/simulator.rb")
|
||||
source_code = File.read("#{TAC::ROOT_PATH}/data/simulator.rb")
|
||||
else
|
||||
source_code =
|
||||
"robot = create_robot(alliance: :blue, width: 18, depth: 18)
|
||||
robot.backward 100
|
||||
robot.turn 90
|
||||
robot.forward 100
|
||||
robot.turn -90
|
||||
robot.forward 100
|
||||
robot.turn -90
|
||||
robot.forward 100"
|
||||
end
|
||||
@source_code = edit_box source_code, width: 1.0, height: 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def draw
|
||||
super
|
||||
|
||||
Gosu.flush
|
||||
@simulation.draw if @simulation
|
||||
end
|
||||
|
||||
def update
|
||||
super
|
||||
|
||||
if @simulation
|
||||
@simulation.update
|
||||
|
||||
unless @simulation.robots.all? { |robot| robot.queue.empty? } # Only update clock if simulation is running
|
||||
@simulation_status.value = "Time: #{((Gosu.milliseconds - @simulation_start_time) / 1000.0).round(1)} seconds" if @simulation_start_time
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -17,11 +17,7 @@ require_relative "lib/backend"
|
||||
require_relative "lib/config"
|
||||
require_relative "lib/settings"
|
||||
require_relative "lib/states/boot"
|
||||
require_relative "lib/states/new_editor"
|
||||
# require_relative "lib/states/editor"
|
||||
# require_relative "lib/states/simulator"
|
||||
# require_relative "lib/states/manage_presets"
|
||||
# require_relative "lib/states/manage_configurations"
|
||||
require_relative "lib/states/editor"
|
||||
require_relative "lib/page"
|
||||
require_relative "lib/pages/home"
|
||||
require_relative "lib/pages/editor"
|
||||
|
||||
Reference in New Issue
Block a user