Page 1 of 1

[solved] GUI elements - how to determine type?

Posted: Sat Aug 27, 2016 11:23 am
by aubergine18
UPDATE: .type property now available on gui elements since 0.13.20

If I've got a GUI with a bunch of GUI elements in it, I can get a list of the elements and inspect their various properties, but there doesn't seem to be any quick way to determine the type of the elements... I'm trying to avoid having yet another custom lookup list to manage my GUI... Any ideas?

Re: GUI elements - how to determine type?

Posted: Sat Aug 27, 2016 4:23 pm
by Nexela
LuiGuiElement seems to not have a .type property read. I wonder if this is something that the dev's might be interested in adding for us modders :)

Re: GUI elements - how to determine type?

Posted: Sat Aug 27, 2016 10:51 pm
by aubergine18
I'll put in a request if there isn't already one.

viewtopic.php?f=28&t=31724

Re: GUI elements - how to determine type?

Posted: Mon Aug 29, 2016 11:53 am
by Helfima
i use string.find AND regex pattern on the GuiElement name, my MOD have a big dynamic UI

https://github.com/Helfima/helmod/blob/ ... Dialog.lua

Code: Select all

function PlannerDialog.methods:on_gui_click(event)
	if event.element.valid and string.find(event.element.name, self:classname()) then
		local player = game.players[event.player_index]
		
		local patternAction = self:classname().."=([^=]*)"
		local patternItem = self:classname()..".*=ID=([^=]*)"
		local patternItem2 = self:classname()..".*=ID=[^=]*=([^=]*)"
		local patternItem3 = self:classname()..".*=ID=[^=]*=[^=]*=([^=]*)"
		local action = string.match(event.element.name,patternAction,1)
		local item = string.match(event.element.name,patternItem,1)
		local item2 = string.match(event.element.name,patternItem2,1)
		local item3 = string.match(event.element.name,patternItem3,1)

		self:send_event(player, event.element, action, item, item2, item3)
	end
end

Re: GUI elements - how to determine type?

Posted: Mon Aug 29, 2016 12:16 pm
by aubergine18
For now I've resorted to using serpent to serialise tables in to element names, and then deserialise when a gui event is triggered. A new .type property has been implemented for next release so that will make type checking much more reliable.