diff --git a/lib/dialogs/name_prompt_dialog.rb b/lib/dialogs/name_prompt_dialog.rb index 1b81ca1..ede5efe 100644 --- a/lib/dialogs/name_prompt_dialog.rb +++ b/lib/dialogs/name_prompt_dialog.rb @@ -7,15 +7,24 @@ module TAC label "Name", width: 0.25, text_size: 18 @name = edit_line @options[:renaming] ? @options[:renaming].name : "", width: 0.70, text_size: 18 end + @name_error = label "", text_size: 18, color: TAC::Palette::TACNET_CONNECTION_ERROR + @name_error.hide flow width: 1.0 do button "Cancel", width: 0.475, text_size: 18 do close end - button @options[:renaming] ? "Update" : "Add", width: 0.475, text_size: 18 do + accept_label = @options[:renaming] ? "Update" : "Add" + accept_label = @options[:accept_label] if @options[:accept_label] + + button accept_label, width: 0.475, text_size: 18 do if @name.value.strip.empty? - push_state(TAC::Dialog::AlertDialog, title: "Error", message: "Name cannot be blank.\nName cannot only be whitespace.") + @name_error.value = "Name cannot be blank.\nName cannot only be whitespace." + @name_error.show + elsif @options[:list] && @options[:list].find { |i| i.name == @name.value.strip } + @name_error.value = "Name is not unique!" + @name_error.show else if @options[:renaming] @options[:callback_method].call(@options[:renaming], @name.value.strip) diff --git a/lib/simulator/robot.rb b/lib/simulator/robot.rb index b1989a9..69b5622 100644 --- a/lib/simulator/robot.rb +++ b/lib/simulator/robot.rb @@ -2,6 +2,7 @@ module TAC class Simulator class Robot attr_accessor :position, :angle + attr_reader :width, :depth def initialize(width:, depth:) @width, @depth = width, depth diff --git a/lib/simulator/simulation.rb b/lib/simulator/simulation.rb index 6515fd7..c87d534 100644 --- a/lib/simulator/simulation.rb +++ b/lib/simulator/simulation.rb @@ -119,8 +119,8 @@ module TAC end def draw - Gosu.draw_line(@robot.position.x, @robot.position.y, Gosu::Color::GREEN, @goal.x, @goal.y, Gosu::Color::GREEN) - Gosu.draw_rect(@goal.x, @goal.y, 16, 16, Gosu::Color::RED) + Gosu.draw_line(@robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2, Gosu::Color::GREEN, @goal.x + @robot.width / 2, @goal.y + @robot.depth / 2, Gosu::Color::GREEN) + Gosu.draw_rect(@goal.x + (@robot.width / 2 - 2), @goal.y + (@robot.depth / 2 - 2), 4, 4, Gosu::Color::RED) end def update(dt) diff --git a/lib/states/boot.rb b/lib/states/boot.rb index 247327e..e188bfb 100644 --- a/lib/states/boot.rb +++ b/lib/states/boot.rb @@ -31,6 +31,12 @@ module TAC push_state(Editor) if @transition_color.alpha >= 255 end + + def button_up(id) + super + + push_state(Editor) + end end end end \ No newline at end of file diff --git a/lib/states/editor.rb b/lib/states/editor.rb index 9752994..5e1dd6b 100644 --- a/lib/states/editor.rb +++ b/lib/states/editor.rb @@ -8,7 +8,7 @@ module TAC theme(THEME) stack width: 1.0, height: 1.0 do - stack width: 1.0, height: 0.1 do + stack width: 1.0, height: 0.1, border_thickness: 1, border_color: [0, 0, Gosu::Color::BLACK, 0] do background [TAC::Palette::TIMECRAFTERS_PRIMARY, TAC::Palette::TIMECRAFTERS_SECONDARY] flow width: 1.0, height: 1.0 do @@ -86,45 +86,76 @@ module TAC end flow width: 1.0, height: 0.9 do - stack width: 0.333, height: 1.0 do + stack width: 0.333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do background TAC::Palette::GROUPS_PRIMARY flow do label "Groups" button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 18, tip: "Add group" do - push_state(TAC::Dialog::NamePromptDialog, title: "Create Group", callback_method: method(:create_group)) + 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: 18, 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! + + populate_groups_list + }) + end end - button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: 18, tip: "Clone currently selected group" button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: 18, tip: "Save group as preset" end @groups_list = stack width: 1.0 do end end - stack width: 0.333, height: 1.0 do + stack width: 0.333, height: 1.0, border_thickness: 1, border_color: [0, Gosu::Color::BLACK, 0, 0] do background TAC::Palette::ACTIONS_PRIMARY flow do label "Actions" button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 18, tip: "Add action" do if @active_group - push_state(TAC::Dialog::NamePromptDialog, title: "Create Action", callback_method: method(:create_action)) + push_state(TAC::Dialog::NamePromptDialog, 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: 18, tip: "Clone currently selected action" + button get_image("#{TAC::ROOT_PATH}/media/icons/button2.png"), image_width: 18, tip: "Clone currently selected action" do + if @active_action + clone = TAC::Config::Action.from_json( JSON.parse( @active_action.to_json, symbolize_names: true )) + clone.name = "#{clone.name}_copy" + @active_group.actions << clone + window.backend.config_changed! + + populate_actions_list(@active_group) + end + + if @active_group + push_state(Dialog::NamePromptDialog, title: "Clone Action", renaming: @active_action, accept_label: "Clone", list: @active_group.actions, callback_method: proc { |action, name| + clone = TAC::Config::Action.from_json( JSON.parse( @active_action.to_json, symbolize_names: true )) + clone.name = name + @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: 18, tip: "Save action as preset" end @actions_list = stack width: 1.0 do end end - stack width: 0.333, height: 1.0 do + stack width: 0.331, height: 1.0 do background TAC::Palette::VARIABLES_PRIMARY flow do - label "Values" + label "Variables" button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_width: 18, tip: "Add variable" do if @active_action - push_state(TAC::Dialog::VariableDialog, title: "Create Value", callback_method: method(:create_variable)) + 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 @@ -265,7 +296,7 @@ module TAC end button get_image("#{TAC::ROOT_PATH}/media/icons/wrench.png"), image_width: 18, tip: "Edit group" do - push_state(Dialog::NamePromptDialog, title: "Rename Group", renaming: group, callback_method: method(:update_group)) + 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: 18, tip: "Delete group" 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) }) @@ -289,7 +320,7 @@ module TAC end button get_image("#{TAC::ROOT_PATH}/media/icons/wrench.png"), image_width: 18, tip: "Edit action" do - push_state(Dialog::NamePromptDialog, title: "Rename Action", renaming: action, callback_method: method(:update_action)) + push_state(Dialog::NamePromptDialog, title: "Rename Action", renaming: action, list: @active_group.actions, callback_method: method(:update_action)) end button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: 18, tip: "Delete action" do push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete action and all\nof its variables?", callback_method: proc { delete_action(action) }) @@ -304,17 +335,22 @@ module TAC @variables_list.clear do variables.each_with_index do |variable, i| - flow width: 1.0 do + stack width: 1.0 do + background TAC::Palette::VARIABLES_PRIMARY if i.even? background TAC::Palette::VARIABLES_SECONDARY if i.odd? - label variable.name, text_size: 18, width: 0.855 + flow width: 1.0 do + label variable.name, text_size: 18, width: 0.855 - button get_image("#{TAC::ROOT_PATH}/media/icons/wrench.png"), image_width: 18, 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: 18, tip: "Delete variable" do - push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete variable?", callback_method: proc { delete_variable(variable) }) + button get_image("#{TAC::ROOT_PATH}/media/icons/wrench.png"), image_width: 18, 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: 18, tip: "Delete variable" do + push_state(Dialog::ConfirmDialog, title: "Are you sure?", message: "Delete variable?", callback_method: proc { delete_variable(variable) }) + end end + + label "Type: #{variable.type}, Value: #{variable.value}", text_size: 18 end end end