This module was not designed for people who don't know nothing about python.
Here is a simple functions which gives you the chance to be able to turn all objects of script loader (uiScript) into a a simple list and control all very simple.
This is more easy if you have a lot a objects and want to do some actions with them like set multiples text, load images etc. do a simple loop by range start:end and you can play with it.
How to use GetChildList(list()):
How to use self.Realloc(int, list()):
How you can play with GetChildList, another example:
Code isn't so wow, because i was write on some minutes for test something and i don't use it so, enjoy.
English isn't my first language, so please excuse any mistakes.
Here is a simple functions which gives you the chance to be able to turn all objects of script loader (uiScript) into a a simple list and control all very simple.
This is more easy if you have a lot a objects and want to do some actions with them like set multiples text, load images etc. do a simple loop by range start:end and you can play with it.
- self.OBJECT_MAX_NUM = 25 | You can change how many max objects you can send into list.
- self.Realloc(state, objectList) | You can run a action (Hide() / Show()) for all objects what you sended on list.
How to use GetChildList(list()):
Code:
class TestWindow(ui.ScriptWindow):
def __init__(self):
ui.ScriptWindow.__init__(self)
ui.PythonScriptLoader().LoadScriptFile(self, "uiscript/guildwindow.py")
self.childrenList = self.GetChildList(["GuildNameValue", "DeclareWarButton", "Board"])
def Reference(self):
self.childrenList[0].SetText("GUARDIANS")
self.childrenList[1].SetPosition(100, 200)
self.childrenList[2].SetSize(500, 1000)
Code:
def OnClickHideButton(self): self.Realloc(self.STATE_HIDE, self.GetChildList(["GuildNameValue", "GuildMasterNameValue", "CurrentExperienceValue", "LastExperienceValue", "GuildMemberCountValue", "DeclareWarButton"]))
Code:
for (key, object) in enumerate(self.GetChildList(["TextLineA", "TextLineB", "TextLineC"])):
object.SetText("Format line: {0}".format(key))
Code:
#root/ui.py
#1.) Search for:
class ScriptWindow(Window):
def __init__(self, layer = "UI"):
Window.__init__(self, layer)
self.Children = []
self.ElementDictionary = {}
#2.) Add after:
self.STATE_HIDE = 1
self.STATE_SHOW = 2
self.OBJECT_MAX_NUM = 25
#1.) Search for:
def GetChild(self, name):
return self.ElementDictionary[name]
#2.) Add after:
def GetChildList(self, received_objects):
return [self.ElementDictionary.get(item, None) for item in received_objects] if (isinstance(received_objects, (list, tuple))) else list()
def Realloc(self, state, received_objects, state_alowed = [self.STATE_HIDE, self.STATE_SHOW]):
if (not state in state_alowed or not isinstance(received_objects, (list, tuple))):
import dbg
dbg.TraceError(
"<ScriptWindow> Failed to change state.\n{0}\n{1}".format(
"<state '{0}'> Allowed states: {1}.".format(state, state_alowed),
"{0} Allowed type: tuple or a list.".format(type(received_objects))
))
return
[item.Hide() if (state is self.STATE_HIDE) else item.Show()
for item in [object for object in (received_objects
if len(received_objects) < self.OBJECT_MAX_NUM else
received_objects[:self.OBJECT_MAX_NUM])
if (object is not None)]]