mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-16 05:42:35 +00:00
Enable action enabled toggle button, refactored how Variable value is stored
This commit is contained in:
@@ -130,21 +130,57 @@ module TAC
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Variable
|
class Variable
|
||||||
attr_accessor :name, :type, :value
|
attr_accessor :name, :value
|
||||||
def initialize(name:, type:, value:)
|
def initialize(name:, value:)
|
||||||
@name, @type, @value = name, type, value
|
@name, @value = name, value
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_type
|
||||||
|
case @value.split("x").first.upcase
|
||||||
|
when "I"
|
||||||
|
:integer
|
||||||
|
when "F"
|
||||||
|
:float
|
||||||
|
when "D"
|
||||||
|
:double
|
||||||
|
when "L"
|
||||||
|
:long
|
||||||
|
when "S"
|
||||||
|
:string
|
||||||
|
when "B"
|
||||||
|
:boolean
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw_value
|
||||||
|
split = @value.split("x")
|
||||||
|
v = split.last
|
||||||
|
|
||||||
|
case split.first
|
||||||
|
when "I", "L"
|
||||||
|
Integer(v)
|
||||||
|
when "F", "D"
|
||||||
|
Float(v)
|
||||||
|
when "S"
|
||||||
|
v
|
||||||
|
when "B"
|
||||||
|
v.downcase == "true"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_json(*args)
|
def to_json(*args)
|
||||||
{
|
{
|
||||||
name: @name,
|
name: @name,
|
||||||
type: @type,
|
|
||||||
value: @value
|
value: @value
|
||||||
}.to_json(*args)
|
}.to_json(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_json(hash)
|
def self.from_json(hash)
|
||||||
Variable.new(name: hash[:name], type: hash[:type].to_sym, value: hash[:value])
|
Variable.new(name: hash[:name], value: hash[:value])
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.encode_type(symbol)
|
||||||
|
symbol.to_s.chars.first.upcase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ module TAC
|
|||||||
def build
|
def build
|
||||||
background Gosu::Color::GRAY
|
background Gosu::Color::GRAY
|
||||||
|
|
||||||
@type = @options[:variable].type if @options[:variable]
|
@type = @options[:variable].raw_type if @options[:variable]
|
||||||
|
|
||||||
label "Name"
|
label "Name"
|
||||||
@name_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
@name_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||||
@@ -28,7 +28,7 @@ module TAC
|
|||||||
label "Value"
|
label "Value"
|
||||||
@value_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
@value_error = label "Error", color: TAC::Palette::TACNET_CONNECTION_ERROR
|
||||||
@value_error.hide
|
@value_error.hide
|
||||||
@value = edit_line @options[:variable] ? @options[:variable].value : ""
|
@value = edit_line @options[:variable] ? @options[:variable].raw_value : ""
|
||||||
end
|
end
|
||||||
|
|
||||||
flow width: 1.0 do
|
flow width: 1.0 do
|
||||||
@@ -39,9 +39,9 @@ module TAC
|
|||||||
button @options[:variable] ? "Update" : "Add", width: 0.475 do |b|
|
button @options[:variable] ? "Update" : "Add", width: 0.475 do |b|
|
||||||
if valid?
|
if valid?
|
||||||
if @options[:variable]
|
if @options[:variable]
|
||||||
@options[:callback_method].call(@options[:variable], @name.value.strip, @type, @value.value.strip)
|
@options[:callback_method].call(@options[:variable], @name.value.strip, "#{TAC::Config::Variable.encode_type(@type)}x#{@value.value.strip}")
|
||||||
else
|
else
|
||||||
@options[:callback_method].call(@name.value.strip, @type, @value.value.strip)
|
@options[:callback_method].call(@name.value.strip, "#{TAC::Config::Variable.encode_type(@type)}x#{@value.value.strip}")
|
||||||
end
|
end
|
||||||
|
|
||||||
close
|
close
|
||||||
|
|||||||
@@ -269,9 +269,8 @@ module TAC
|
|||||||
populate_variables_list(@active_action)
|
populate_variables_list(@active_action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_variable(variable, name, type, value)
|
def update_variable(variable, name, value)
|
||||||
variable.name = name
|
variable.name = name
|
||||||
variable.type = type
|
|
||||||
variable.value = value
|
variable.value = value
|
||||||
|
|
||||||
window.backend.config_changed!
|
window.backend.config_changed!
|
||||||
@@ -330,7 +329,11 @@ module TAC
|
|||||||
populate_variables_list(action)
|
populate_variables_list(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
toggle_button tip: "Enable action"
|
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
|
button get_image("#{TAC::ROOT_PATH}/media/icons/gear.png"), image_width: THEME_ICON_SIZE, tip: "Edit action" do
|
||||||
push_state(Dialog::NamePromptDialog, title: "Rename Action", renaming: action, list: @active_group.actions, callback_method: method(:update_action))
|
push_state(Dialog::NamePromptDialog, title: "Rename Action", renaming: action, list: @active_group.actions, callback_method: method(:update_action))
|
||||||
@@ -351,7 +354,7 @@ module TAC
|
|||||||
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
flow width: 1.0, **THEME_ITEM_CONTAINER_PADDING do
|
||||||
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
background i.even? ? THEME_EVEN_COLOR : THEME_ODD_COLOR
|
||||||
|
|
||||||
button "#{variable.name} [Type: #{variable.type}, Value: #{variable.value}]", width: 0.925, tip: "Edit variable" do
|
button "#{variable.name} [Type: #{variable.raw_type}, Value: #{variable.raw_value}]", width: 0.925, tip: "Edit variable" do
|
||||||
push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, callback_method: method(:update_variable))
|
push_state(Dialog::VariableDialog, title: "Edit Variable", variable: variable, callback_method: method(:update_variable))
|
||||||
end
|
end
|
||||||
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete variable", **THEME_DANGER_BUTTON do
|
button get_image("#{TAC::ROOT_PATH}/media/icons/trashcan.png"), image_width: THEME_ICON_SIZE, tip: "Delete variable", **THEME_DANGER_BUTTON do
|
||||||
|
|||||||
Reference in New Issue
Block a user