mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 13:52:34 +00:00
Redesigning TCT
This commit is contained in:
92
lib/pages/configurations.rb
Normal file
92
lib/pages/configurations.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Configurations < Page
|
||||
def setup
|
||||
header_bar("Manage Configurations")
|
||||
|
||||
menu_bar.clear do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/plus.png"), image_height: 1.0, 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
|
||||
|
||||
# label "Manage Configurations", text_size: 36
|
||||
end
|
||||
|
||||
status_bar.clear do
|
||||
label "Current Configuration: "
|
||||
@config_label = label window.backend.settings.config
|
||||
end
|
||||
|
||||
body.clear do
|
||||
@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
|
||||
window.backend.load_config(name)
|
||||
|
||||
@config_label.value = name.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
23
lib/pages/editor.rb
Normal file
23
lib/pages/editor.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Editor < Page
|
||||
def setup
|
||||
header_bar("Editor")
|
||||
|
||||
body.clear do
|
||||
flow(width: 1.0, height: 1.0) do
|
||||
stack(width: 0.3333, height: 1.0) do
|
||||
background 0xff_550055
|
||||
end
|
||||
stack(width: 0.3333, height: 1.0) do
|
||||
background 0xff_555555
|
||||
end
|
||||
stack(width: 0.3333, height: 1.0) do
|
||||
background 0xff_55ff55
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
42
lib/pages/home.rb
Normal file
42
lib/pages/home.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Home < Page
|
||||
def setup
|
||||
header_bar(TAC::NAME)
|
||||
|
||||
body.clear do
|
||||
stack(width: 1.0, height: 1.0) do
|
||||
label TAC::NAME, width: 1.0, text_size: 48, text_align: :center
|
||||
|
||||
stack(width: 1.0, height: 8) do
|
||||
background 0xff_006000
|
||||
end
|
||||
|
||||
if window.backend.settings.config.empty?
|
||||
label "TODO: Introduction"
|
||||
label "Get Started", text_size: 28
|
||||
button "1. Create a configuration" do
|
||||
page(TAC::Pages::Configurations)
|
||||
end
|
||||
label "2. Add a group"
|
||||
label "3. Add an action"
|
||||
label "4. Add a variable"
|
||||
label "5. Profit?"
|
||||
else
|
||||
label "Display config stats or something?"
|
||||
|
||||
config = window.backend.config
|
||||
groups = config.groups
|
||||
actions = config.groups.map { |g| g.actions }.flatten
|
||||
variables = actions.map { |a| a.variables }.flatten
|
||||
|
||||
label "Total groups: #{groups.size}"
|
||||
label "Total actions: #{actions.size}"
|
||||
label "Total variables: #{variables.size}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
13
lib/pages/presets.rb
Normal file
13
lib/pages/presets.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Presets < Page
|
||||
def setup
|
||||
header_bar("Manage Presets")
|
||||
|
||||
body.clear do
|
||||
label "Not Yet Implemented"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
20
lib/pages/search.rb
Normal file
20
lib/pages/search.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Search < Page
|
||||
def setup
|
||||
header_bar("Search")
|
||||
|
||||
menu_bar.clear do
|
||||
search = edit_line "", width: 0.9, height: 1.0
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/zoom.png"), image_height: 1.0 do
|
||||
# do search
|
||||
body.clear do
|
||||
label "Search results for: #{search.value.strip}"
|
||||
label "TODO: Search Results."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
79
lib/pages/simulator.rb
Normal file
79
lib/pages/simulator.rb
Normal file
@@ -0,0 +1,79 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class Simulator < Page
|
||||
SOURCE_FILE_PATH = "#{TAC::ROOT_PATH}/data/simulator.rb"
|
||||
def setup
|
||||
header_bar("Simulator")
|
||||
|
||||
menu_bar.clear do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), tip: "Run Simulation", image_height: 1.0 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"), tip: "Stop Simulation", image_height: 1.0 do
|
||||
@simulation.robots.each { |robot| robot.queue.clear } if @simulation
|
||||
end
|
||||
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), tip: "Save", image_height: 1.0 do
|
||||
File.open(SOURCE_FILE_PATH, "w") { |f| f.write @source_code.value }
|
||||
@simulation_status.value = "Saved source to #{SOURCE_FILE_PATH}"
|
||||
end
|
||||
end
|
||||
|
||||
status_bar.clear do
|
||||
@simulation_status = label ""
|
||||
end
|
||||
|
||||
body.clear do
|
||||
flow(width: 1.0, height: 1.0) do
|
||||
@field_container = stack width: 0.4, height: 1.0 do
|
||||
background 0xff_111111
|
||||
end
|
||||
|
||||
stack(width: 0.6, height: 1.0) do
|
||||
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"
|
||||
|
||||
source_code = File.read(SOURCE_FILE_PATH) if File.exists?(SOURCE_FILE_PATH)
|
||||
|
||||
@source_code = edit_box source_code, width: 1.0, height: 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def blur
|
||||
@simulation.robots.each { |robot| robot.queue.clear } if @simulation
|
||||
end
|
||||
|
||||
def draw
|
||||
@simulation.draw if @simulation
|
||||
end
|
||||
|
||||
def update
|
||||
return unless @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
|
||||
26
lib/pages/tacnet.rb
Normal file
26
lib/pages/tacnet.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
module TAC
|
||||
class Pages
|
||||
class TACNET < Page
|
||||
def setup
|
||||
header_bar("TimeCrafters Auxiliary Configuration Network")
|
||||
|
||||
menu_bar.clear do
|
||||
label "Hostname"
|
||||
hostname = edit_line "192.168.49.1", width: 0.33, height: 1.0
|
||||
label "Port"
|
||||
port = edit_line "192.168.49.1", width: 0.33, height: 1.0
|
||||
button "Connect", height: 1.0 do
|
||||
status_bar.clear do
|
||||
label "Connecting to #{hostname.value}:#{port.value}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
status_bar.clear do
|
||||
image "#{TAC::ROOT_PATH}/media/icons/signal3.png", height: 1.0
|
||||
label "TACNET: Connected Pkt Sent: 00314 Pkt Received: 00313", text_size: 26
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user