mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Added Redmew Debugger and Debugged Checkboxs
This commit is contained in:
@@ -23,12 +23,13 @@ function Button.new_button(name)
|
||||
local uid = Gui.uid_name()
|
||||
local self = setmetatable({
|
||||
name=uid,
|
||||
clean_name=name
|
||||
clean_name=name,
|
||||
_draw={
|
||||
name=uid,
|
||||
style=mod_gui.button_style,
|
||||
type='button'
|
||||
}
|
||||
},{__index=Button._prototype})
|
||||
|
||||
self._draw.name = uid
|
||||
self._draw.style = mod_gui.button_style
|
||||
self._draw.type = 'button'
|
||||
Button.config[uid] = self
|
||||
|
||||
if name then
|
||||
|
||||
@@ -30,9 +30,10 @@ end
|
||||
|
||||
local function get_instances(checkbox,category)
|
||||
if not Checkbox.instances[checkbox.name] then return end
|
||||
local instances = Checkbox.instances
|
||||
local instances = Checkbox.instances[checkbox.name]
|
||||
if checkbox.categorize then
|
||||
instances = instances[category]
|
||||
if not instances[category] then instances[category] = {} end
|
||||
return instances[category]
|
||||
end
|
||||
return instances
|
||||
end
|
||||
@@ -43,9 +44,12 @@ function Checkbox.new_checkbox(name)
|
||||
local self = setmetatable({
|
||||
name=uid,
|
||||
clean_name=name,
|
||||
_draw={
|
||||
name=uid,
|
||||
type='checkbox',
|
||||
state=false
|
||||
}
|
||||
},{__index=Checkbox._prototype_checkbox})
|
||||
self._draw.name = uid
|
||||
self._draw.type = 'checkbox'
|
||||
|
||||
self._post_draw = function(element)
|
||||
local category = self.categorize and self.categorize(element) or nil
|
||||
@@ -53,6 +57,8 @@ function Checkbox.new_checkbox(name)
|
||||
if instances then
|
||||
table.insert(instances,element)
|
||||
end
|
||||
local state = self:get_store_state(category)
|
||||
if state then element.state = true end
|
||||
end
|
||||
|
||||
Checkbox.config[uid] = self
|
||||
@@ -66,7 +72,7 @@ function Checkbox.new_checkbox(name)
|
||||
local element = event.element
|
||||
if self.store then
|
||||
if self.categorize then
|
||||
Store.set_chlid(self.store,self.categorize(element),element.state)
|
||||
Store.set_child(self.store,self.categorize(element),element.state)
|
||||
else
|
||||
Store.set(self.store,element.state)
|
||||
end
|
||||
@@ -87,11 +93,12 @@ function Checkbox._prototype_checkbox:add_store(categorize)
|
||||
if self.store then return end
|
||||
self.store = get_store_location(self)
|
||||
self.categorize = categorize
|
||||
Checkbox.instances[self.name]={}
|
||||
Store.register(self.store,function(value,category)
|
||||
local instances = get_instances(self,category)
|
||||
if instances then
|
||||
for k,element in pairs(instances) do
|
||||
if element.valid then
|
||||
if element and element.valid then
|
||||
element.state = value
|
||||
if self._on_state_change then
|
||||
local player = Game.get_player_by_index(element.player_index)
|
||||
@@ -109,7 +116,7 @@ end
|
||||
function Checkbox._prototype_checkbox:get_store_state(category)
|
||||
if not self.store then return end
|
||||
if self.categorize then
|
||||
return Store.get_chlid(self.store,category)
|
||||
return Store.get_child(self.store,category)
|
||||
else
|
||||
return Store.get(self.store)
|
||||
end
|
||||
@@ -119,9 +126,9 @@ function Checkbox._prototype_checkbox:set_store_state(category,state)
|
||||
if not self.store then return end
|
||||
state = not not state
|
||||
if self.categorize then
|
||||
return Store.set_chlid(self.store,category,state)
|
||||
return Store.set_child(self.store,category,state)
|
||||
else
|
||||
return Store.set(self.store,state)
|
||||
return Store.set(self.store,category)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -151,11 +158,11 @@ function Checkbox._prototype_radiobutton:add_store(categorize)
|
||||
|
||||
end
|
||||
|
||||
function Checkbox._prototype_radiobutton:get_store_value(category)
|
||||
function Checkbox._prototype_radiobutton:get_store_state(category)
|
||||
|
||||
end
|
||||
|
||||
function Checkbox._prototype_radiobutton:set_store_value(category,value)
|
||||
function Checkbox._prototype_radiobutton:set_store_state(category,value)
|
||||
|
||||
end
|
||||
|
||||
@@ -171,12 +178,14 @@ function Checkbox._prototype_radiobutton:on_state_change(callback)
|
||||
|
||||
end
|
||||
|
||||
function Checkbox.get_stored_value(name,category)
|
||||
|
||||
function Checkbox.get_stored_state(name,category)
|
||||
local checkbox = get_config(name)
|
||||
return checkbox:get_store_state(category)
|
||||
end
|
||||
|
||||
function Checkbox.set_stored_value(name,category,value)
|
||||
|
||||
function Checkbox.set_stored_state(name,category,value)
|
||||
local checkbox = get_config(name)
|
||||
return checkbox:set_store_state(category,value)
|
||||
end
|
||||
|
||||
return Checkbox
|
||||
@@ -1,26 +1,27 @@
|
||||
local Gui = require 'utils.gui'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
Gui._prototype = {_draw={}}
|
||||
Gui._prototype = {}
|
||||
Gui.inputs = {}
|
||||
Gui.structure = {}
|
||||
Gui.outputs = {}
|
||||
|
||||
function Gui._extend_prototype(tbl)
|
||||
for k,v in pairs(Gui._prototype) do
|
||||
if not tbl[k] then tbl[k] = table.deep_copy(v) end
|
||||
if not tbl[k] then tbl[k] = v end
|
||||
end
|
||||
return tbl
|
||||
end
|
||||
|
||||
--- Sets the caption for the element config
|
||||
function Gui._prototype:set_caption(caption)
|
||||
self.caption = caption
|
||||
self._draw.caption = caption
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the tooltip for the element config
|
||||
function Gui._prototype:set_tooltip(tooltip)
|
||||
self.tooltip = tooltip
|
||||
self._draw.tooltip = tooltip
|
||||
return self
|
||||
end
|
||||
|
||||
@@ -44,13 +45,14 @@ end
|
||||
|
||||
--- Draws the element using what is in the _draw table, allows use of authenticator if present
|
||||
function Gui._prototype:draw_to(element)
|
||||
if element.children[self.name] then return end
|
||||
if element[self.name] then return end
|
||||
local player = Game.get_player_by_index(element.player_index)
|
||||
if self.pre_authenticator then
|
||||
if not self.pre_authenticator(element.player,self.clean_name or self.name) then return end
|
||||
if not self.pre_authenticator(player,self.clean_name or self.name) then return end
|
||||
end
|
||||
local _element = element.add(self._draw)
|
||||
if self.authenticator then
|
||||
_element.enabled = not not self.authenticator(element.player,self.clean_name or self.name)
|
||||
_element.enabled = not not self.authenticator(player,self.clean_name or self.name)
|
||||
end
|
||||
if self._post_draw then self._post_draw(_element) end
|
||||
return _element
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
local Gui = require 'expcore.gui'
|
||||
local format_chat_colour = ext_require('expcore.common','format_chat_colour')
|
||||
local Colors = require 'resources.color_presets'
|
||||
local Game = require 'utils.game'
|
||||
local clean_stack_trace = ext_require('modules.commands.interface','clean_stack_trace')
|
||||
|
||||
local tests = {}
|
||||
|
||||
Gui.new_toolbar_button('click-1')
|
||||
:set_authenticator(function(player,button_name)
|
||||
@@ -24,4 +30,83 @@ Gui.new_toolbar_button('click-3')
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
player.print('CLICK 3')
|
||||
end)
|
||||
|
||||
Gui.new_toolbar_button('gui-test-open')
|
||||
:set_caption('Open Test Gui')
|
||||
:set_authenticator(function(player,button_name)
|
||||
return global.show_test_gui
|
||||
end)
|
||||
:on_click(function(player,_element,event)
|
||||
if player.gui.center.TestGui then player.gui.center.TestGui.destroy() return end
|
||||
local frame = player.gui.center.add{type='frame',caption='Gui Test',name='TestGui'}
|
||||
frame = frame.add{type='table',column_count=5}
|
||||
for key,element in pairs(tests) do
|
||||
local success,err = pcall(element.draw_to,element,frame)
|
||||
if success then
|
||||
player.print('Drawing: '..key..format_chat_colour(' SUCCESS',Colors.green))
|
||||
else
|
||||
player.print('Drawing: '..key..format_chat_colour(' FAIL',Colors.red)..' '..clean_stack_trace(err))
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
tests['Button no display'] = Gui.new_button('test button no display')
|
||||
:on_click(function(player,element,event)
|
||||
player.print('Button no display')
|
||||
global.test_auth_button = not global.test_auth_button
|
||||
player.print('Auth Button auth state: '..tostring(global.test_auth_button))
|
||||
end)
|
||||
|
||||
tests['Button caption'] = Gui.new_button('test button caption')
|
||||
:set_caption('Button Caption')
|
||||
:on_click(function(player,element,event)
|
||||
player.print('Button caption')
|
||||
end)
|
||||
|
||||
tests['Button icon'] = Gui.new_button('test Bbutton icon')
|
||||
:set_sprites('utility/warning_icon','utility/warning','utility/warning_white')
|
||||
:on_click(function(player,element,event)
|
||||
player.print('Button icon')
|
||||
end)
|
||||
|
||||
tests['Button auth'] = Gui.new_button('test button auth')
|
||||
:set_authenticator(function(player,button_name)
|
||||
return global.test_auth_button
|
||||
end)
|
||||
:on_click(function(player,element,event)
|
||||
player.print('Button auth')
|
||||
end)
|
||||
|
||||
tests['Checkbox local'] = Gui.new_checkbox('test checkbox local')
|
||||
:set_caption('Checkbox Local')
|
||||
:on_state_change(function(player,element)
|
||||
player.print('Checkbox local: '..tostring(element.state))
|
||||
end)
|
||||
|
||||
tests['Checkbox store game'] = Gui.new_checkbox('test checkbox store game')
|
||||
:set_caption('Checkbox Store Game')
|
||||
:add_store()
|
||||
:on_state_change(function(player,element)
|
||||
player.print('Checkbox store game: '..tostring(element.state))
|
||||
end)
|
||||
|
||||
tests['Checkbox store player'] = Gui.new_checkbox('test checkbox store player')
|
||||
:set_caption('Checkbox Store Player')
|
||||
:add_store(function(element)
|
||||
local player = Game.get_player_by_index(element.player_index)
|
||||
return player.name
|
||||
end)
|
||||
:on_state_change(function(player,element)
|
||||
player.print('Checkbox store player: '..tostring(element.state))
|
||||
end)
|
||||
|
||||
tests['Checkbox store force'] = Gui.new_checkbox('test checkbox store force')
|
||||
:set_caption('Checkbox Store Force')
|
||||
:add_store(function(element)
|
||||
local player = Game.get_player_by_index(element.player_index)
|
||||
return player.force.name
|
||||
end)
|
||||
:on_state_change(function(player,element)
|
||||
player.print('Checkbox store force: '..tostring(element.state))
|
||||
end)
|
||||
@@ -1,6 +1,4 @@
|
||||
-- This file is used to require all the different elements of the gui module
|
||||
local opt_require = ext_require('expcore.common','opt_require')
|
||||
|
||||
local Gui = require('./gui/core')
|
||||
|
||||
local Buttons = require('./gui/buttons')
|
||||
@@ -12,13 +10,8 @@ Gui.new_toolbar_button = Toolbar.new_button
|
||||
Gui.add_button_to_toolbar = Toolbar.add_button
|
||||
Gui.structure.toolbar = Toolbar
|
||||
|
||||
--[[local Checkboxs = opt_require('./gui/checkboxs')
|
||||
local Checkboxs = require('./gui/checkboxs')
|
||||
Gui.new_checkbox = Checkboxs.new_checkbox
|
||||
Gui.new_radiobutton = Checkboxs.new_radiobutton
|
||||
Gui.inputs.checkboxs = Checkboxs
|
||||
|
||||
local TextEntry = opt_require('./gui/text')
|
||||
Gui.new_text_entry = TextEntry.new_text_entry
|
||||
Gui.inputs.text_entrys = TextEntry
|
||||
]]
|
||||
return Gui
|
||||
@@ -24,4 +24,9 @@ error-log-format-promote=[ERROR] rolePromote/__1__ :: __2__
|
||||
game-message-assign=__1__ has been assigned to __2__ by __3__
|
||||
game-message-unassign=__1__ has been unassigned from __2__ by __3__
|
||||
reject-role=Invalid Role Name.
|
||||
reject-player-role=Player has a higher role.
|
||||
reject-player-role=Player has a higher role.
|
||||
|
||||
[gui_util]
|
||||
button_tooltip=Shows / hides the Toolbar Gui buttons.
|
||||
|
||||
[expcore-gui]
|
||||
|
||||
@@ -76,8 +76,8 @@
|
||||
end)
|
||||
]]
|
||||
|
||||
local Global = require 'util.global'
|
||||
local Event = require 'util.event'
|
||||
local Global = require 'utils.global'
|
||||
local Event = require 'utils.event'
|
||||
local write_json = ext_require('expcore.common','write_json','table_keys')
|
||||
|
||||
local Store = {
|
||||
@@ -169,7 +169,7 @@ end
|
||||
-- @tparam value any the new value to set at the location, value may be reverted if there is a watch callback
|
||||
-- @treturn boolean true if it was successful
|
||||
function Store.set(location,value)
|
||||
if not Store.callbacks[location] and not no_error then
|
||||
if not Store.callbacks[location] then
|
||||
return error('Location is not registered', 2)
|
||||
end
|
||||
|
||||
@@ -193,7 +193,7 @@ end
|
||||
function Store.get_children(location)
|
||||
local store = Store.get(location)
|
||||
|
||||
if type(store) ~= 'table' and table ~= nil then
|
||||
if type(store) ~= 'table' and store ~= nil then
|
||||
return error('Location has a non table value', 2)
|
||||
end
|
||||
|
||||
@@ -207,11 +207,11 @@ end
|
||||
function Store.get_child(location,child)
|
||||
local store = Store.get(location)
|
||||
|
||||
if type(store) ~= 'table' and table ~= nil then
|
||||
if type(store) ~= 'table' and store ~= nil then
|
||||
return error('Location has a non table value', 2)
|
||||
end
|
||||
|
||||
return store[child]
|
||||
return store and store[child]
|
||||
end
|
||||
|
||||
--- Sets the value of the chlid to a location, children can be added and removed during runtime
|
||||
@@ -224,7 +224,7 @@ end
|
||||
function Store.set_child(location,child,value)
|
||||
local store = Store.get(location)
|
||||
|
||||
if type(store) ~= 'table' and table ~= nil then
|
||||
if type(store) ~= 'table' and store ~= nil then
|
||||
return error('Location has a non table value', 2)
|
||||
end
|
||||
|
||||
@@ -257,14 +257,18 @@ Event.add(defines.events.on_tick,function()
|
||||
if not success then
|
||||
table.insert(errors,store_new)
|
||||
else
|
||||
if store_old ~= store_new then
|
||||
if type(store_old) ~= type(store_new)
|
||||
or type(store_old) == 'table' and not table.compare(store_new,store_new)
|
||||
or store_old ~= store_new then
|
||||
Store.data[location] = store_new
|
||||
Store.callbacks[location](store_new)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
error(errors)
|
||||
if #errors > 0 then
|
||||
error(table.concat(errors,'; '))
|
||||
end
|
||||
end)
|
||||
|
||||
return Store
|
||||
Reference in New Issue
Block a user