mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Fixed stores in gui
This commit is contained in:
@@ -74,14 +74,12 @@ local Checkbox = {
|
||||
_prototype_checkbox=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
},
|
||||
_prototype_radiobutton=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +94,7 @@ function Checkbox.new_checkbox(name)
|
||||
|
||||
self:on_draw(function(player,element)
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local state = self:get_store(category,true)
|
||||
local state = self:get_store(element,true)
|
||||
if state then element.state = true end
|
||||
end
|
||||
end)
|
||||
@@ -107,13 +104,11 @@ function Checkbox.new_checkbox(name)
|
||||
|
||||
if self.option_set then
|
||||
local value = Checkbox.option_sets[self.option_set][element.name]
|
||||
local category = self.categorize and self.categorize(element)
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
elseif self.store then
|
||||
local value = element.state
|
||||
local category = self.categorize and self.categorize(element)
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
else
|
||||
self:raise_event('on_element_update',event.player,element,element.state)
|
||||
@@ -175,15 +170,15 @@ function Checkbox._prototype_radiobutton:set_store(category,value,internal)
|
||||
end
|
||||
|
||||
--- Registers a new option set that can be linked to radiobuttons (only one can be true at a time)
|
||||
-- @tparam string name the name of the option set, must be unique
|
||||
-- @tparam function callback the update callback when the value of the option set changes
|
||||
-- callback param - value string - the new selected option for this option set
|
||||
-- callback param - category string - the category that updated if categorize was used
|
||||
-- @tparam function categorize the function used to convert an element into a string
|
||||
-- @treturn string the name of this option set to be passed to add_as_option
|
||||
function Checkbox.new_option_set(name,callback,categorize)
|
||||
function Checkbox.new_option_set(callback,categorize)
|
||||
local name = Store.register(categorize)
|
||||
|
||||
Store.register(name,function(value,category)
|
||||
Store.watch(name,function(value,category)
|
||||
local options = Checkbox.option_sets[name]
|
||||
for opt_name,define_name in pairs(options) do
|
||||
if Gui.defines[define_name] then
|
||||
|
||||
@@ -47,8 +47,7 @@ local Dropdown = {
|
||||
_prototype=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +70,7 @@ function Dropdown.new_dropdown(name)
|
||||
end
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local value = self:get_store(category)
|
||||
local value = self:get_store(element)
|
||||
if value then Dropdown.select_value(element,value) end
|
||||
end
|
||||
end)
|
||||
@@ -82,8 +80,7 @@ function Dropdown.new_dropdown(name)
|
||||
local value = Dropdown.get_selected_value(element)
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
else
|
||||
local player = event.player
|
||||
|
||||
@@ -37,8 +37,7 @@ local ElemButton = {
|
||||
_prototype=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,8 +55,7 @@ function ElemButton.new_elem_button(name)
|
||||
end
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local value = self:get_store(category)
|
||||
local value = self:get_store(element)
|
||||
if value then element.elem_value = value end
|
||||
end
|
||||
end)
|
||||
@@ -67,8 +65,7 @@ function ElemButton.new_elem_button(name)
|
||||
local value = element.elem_value
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
else
|
||||
self:raise_event('on_element_update',event.player,element,value)
|
||||
|
||||
@@ -64,8 +64,7 @@ local ProgressBar = {
|
||||
_prototype=Prototype.extend{
|
||||
on_complete = Prototype.event,
|
||||
on_store_complete = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,11 +193,10 @@ function ProgressBar.new_progressbar(name)
|
||||
|
||||
self:on_draw(function(player,element,maximum)
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local value = self:get_store(category)
|
||||
local value = self:get_store(element)
|
||||
if not value then
|
||||
value = self.count_down and 1 or 0
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
end
|
||||
element.value = value
|
||||
|
||||
@@ -350,8 +348,7 @@ function ProgressBar._prototype:reset_element(element)
|
||||
if not element or not element.valid then return end
|
||||
local value = self.count_down and 1 or 0
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
else
|
||||
element.value = value
|
||||
end
|
||||
|
||||
@@ -61,8 +61,7 @@ local Slider = {
|
||||
_prototype=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,8 +87,7 @@ function Slider.new_slider(name)
|
||||
element.set_slider_minimum_maximum(min,max)
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local value = self:get_store(category)
|
||||
local value = self:get_store(element)
|
||||
if value then element.slider_value = value end
|
||||
end
|
||||
|
||||
@@ -103,8 +101,7 @@ function Slider.new_slider(name)
|
||||
local value = element.slider_value
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
else
|
||||
event_call(self,element,value)
|
||||
@@ -144,8 +141,7 @@ function Slider._prototype:draw_label(element)
|
||||
|
||||
local value = 0
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
value = self:get_store(category) or 0
|
||||
value = self:get_store(element) or 0
|
||||
end
|
||||
|
||||
local new_element = element.add{
|
||||
|
||||
@@ -40,14 +40,12 @@ local Text = {
|
||||
_prototype_field=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
},
|
||||
_prototype_box=Prototype.extend{
|
||||
on_element_update = Prototype.event,
|
||||
on_store_update = Prototype.event,
|
||||
add_store = Prototype.store(false,store_update),
|
||||
add_sync_store = Prototype.store(true,store_update)
|
||||
add_store = Prototype.store(store_update)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +71,7 @@ function Text.new_text_field(name)
|
||||
end
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
local value = self:get_store(category)
|
||||
local value = self:get_store(element)
|
||||
if value then element.text = value end
|
||||
end
|
||||
end)
|
||||
@@ -84,8 +81,7 @@ function Text.new_text_field(name)
|
||||
local value = element.text
|
||||
|
||||
if self.store then
|
||||
local category = self.categorize and self.categorize(element) or value
|
||||
self:set_store(category,value)
|
||||
self:set_store(element,value)
|
||||
|
||||
else
|
||||
self:raise_event('on_element_update',event.player,element,value)
|
||||
|
||||
Reference in New Issue
Block a user