mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 21:32:35 +00:00
Stubbed preset manager state, added confirm and variable dialogs, variables can now be created, everything is now mutatable
This commit is contained in:
21
lib/dialogs/confirm_dialog.rb
Normal file
21
lib/dialogs/confirm_dialog.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
module TAC
|
||||
class Dialog
|
||||
class ConfirmDialog < Dialog
|
||||
def build
|
||||
background Gosu::Color::GRAY
|
||||
label @options[:message], text_size: 18
|
||||
|
||||
flow width: 1.0 do
|
||||
button "Cancel", width: 0.475, text_size: 18 do
|
||||
close
|
||||
end
|
||||
button "Okay", width: 0.475, text_size: 18 do
|
||||
@options[:callback_method].call
|
||||
|
||||
close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -5,7 +5,7 @@ module TAC
|
||||
background Gosu::Color::GRAY
|
||||
flow width: 1.0 do
|
||||
label "Name", width: 0.25, text_size: 18
|
||||
@name = edit_line "", width: 0.70, text_size: 18
|
||||
@name = edit_line @options[:renaming] ? @options[:renaming].name : "", width: 0.70, text_size: 18
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
@@ -13,11 +13,15 @@ module TAC
|
||||
close
|
||||
end
|
||||
|
||||
button @options[:submit_label], width: 0.475, text_size: 18 do
|
||||
button @options[:renaming] ? "Update" : "Add", 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.")
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip)
|
||||
if @options[:renaming]
|
||||
@options[:callback_method].call(@options[:renaming], @name.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
|
||||
119
lib/dialogs/variable_dialog.rb
Normal file
119
lib/dialogs/variable_dialog.rb
Normal file
@@ -0,0 +1,119 @@
|
||||
module TAC
|
||||
class Dialog
|
||||
class VariableDialog < Dialog
|
||||
def build
|
||||
background Gosu::Color::GRAY
|
||||
|
||||
@type = @options[:value].type if @options[:value]
|
||||
|
||||
label "Name"
|
||||
@name_error = label "Error", text_size: 18, color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
@name_error.hide
|
||||
@name = edit_line @options[:value] ? @options[:value].name : "", text_size: 18
|
||||
|
||||
label "Type"
|
||||
@type_error = label "Error", text_size: 18, color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
@type_error.hide
|
||||
# TODO: Add dropdown menus to CyberarmEngine
|
||||
flow width: 1.0 do
|
||||
[:float, :double, :integer, :long, :string, :boolean].each do |btn|
|
||||
button btn, text_size: 18 do
|
||||
@type = btn
|
||||
@value_container.show
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@value_container = stack width: 1.0 do
|
||||
label "Value"
|
||||
@value_error = label "Error", text_size: 18, color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||
@value_error.hide
|
||||
@value = edit_line @options[:value] ? @options[:value].value : "", text_size: 18
|
||||
end
|
||||
|
||||
flow width: 1.0 do
|
||||
button "Cancel", width: 0.475, text_size: 18 do
|
||||
close
|
||||
end
|
||||
|
||||
button @options[:value] ? "Update" : "Add", width: 0.475, text_size: 18 do |b|
|
||||
if valid?
|
||||
if @options[:value]
|
||||
@options[:callback_method].call(@options[:value], @name.value.strip, @type, @value.value.strip)
|
||||
else
|
||||
@options[:callback_method].call(@name.value.strip, @type, @value.value.strip)
|
||||
end
|
||||
|
||||
close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def valid?
|
||||
valid = true
|
||||
|
||||
if @name.value.strip.empty?
|
||||
@name_error.value = "Error: Name cannot be blank\n or only whitespace."
|
||||
@name_error.show
|
||||
valid = false
|
||||
else
|
||||
@name_error.value = ""
|
||||
@name_error.hide
|
||||
end
|
||||
|
||||
if not @type
|
||||
@type_error.value = "Error: Type not set."
|
||||
@type_error.show
|
||||
valid = false
|
||||
else
|
||||
@type_error.value = ""
|
||||
@type_error.hide
|
||||
end
|
||||
|
||||
if [:integer, :float, :double, :long].include?(@type)
|
||||
if @value.value.strip.empty?
|
||||
@value_error.value = "Error: Value cannot be blank\n or only whitespace."
|
||||
@value_error.show
|
||||
valid = false
|
||||
elsif [:integer, :long].include?(@type)
|
||||
begin
|
||||
Integer(@value.value.strip)
|
||||
rescue
|
||||
@value_error.value = "Error: Invalid value,\nexpected whole number."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
elsif [:float, :double].include?(@type)
|
||||
begin
|
||||
Float(@value.value.strip)
|
||||
rescue
|
||||
@value_error.value = "Error: Invalid value,\nexpected decimal number."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
else
|
||||
@value_error.value = ""
|
||||
@value_error.hide
|
||||
end
|
||||
elsif @type == :string
|
||||
if @value.value.strip.empty?
|
||||
@value_error.value = "Error: Value cannot be blank\n or only whitespace."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
elsif @type == :boolean
|
||||
@value_error.value = "Error: Boolean not yet supported."
|
||||
@value_error.show
|
||||
valid = false
|
||||
else
|
||||
@value_error.value = "Error: Type not set."
|
||||
@value_error.show
|
||||
valid = false
|
||||
end
|
||||
|
||||
return valid
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user