|
You last visited: Today at 18:10
Advertisement
[Python] Extend modules of ScriptWindow
Discussion on [Python] Extend modules of ScriptWindow within the Metin2 PServer Guides & Strategies forum part of the Metin2 Private Server category.
11/18/2017, 17:54
|
#1
|
elite*gold: 10
Join Date: Jul 2013
Posts: 93
Received Thanks: 416
|
[Python] Extend modules of ScriptWindow
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. - 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)
How to use self.Realloc(int, list()):
Code:
def OnClickHideButton(self):
self.Realloc(self.STATE_HIDE, self.GetChildList(["GuildNameValue", "GuildMasterNameValue", "CurrentExperienceValue", "LastExperienceValue", "GuildMemberCountValue", "DeclareWarButton"]))
How you can play with GetChildList, another example:
Code:
for (key, object) in enumerate(self.GetChildList(["TextLineA", "TextLineB", "TextLineC"])):
object.SetText("Format line: {0}".format(key))
Code isn't so wow, because i was write on some minutes for test something and i don't use it so, enjoy.
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)]]
English isn't my first language, so please excuse any mistakes.
|
|
|
11/20/2017, 14:55
|
#2
|
elite*gold: 10
Join Date: Jul 2013
Posts: 93
Received Thanks: 416
|
[Python] Extend modules of ScriptWindow
Quote:
|
Probably changing the way it indexes the data does the deal, using strings instead of numbers sounds good to me.
|
Now you can use it more easy, have fun.
Code:
#root/ui.py
def GetChildDictionary(self, received_objects):
if isinstance(received_objects, (list, tuple)):
return {item : self.ElementDictionary.get(item, None) for item in received_objects}
return dict()
def Realloc(self, state, received_objects, allowed_type = [self.STATE_HIDE, self.STATE_SHOW]):
if (not state in allowed_type or not isinstance(received_objects, dict)):
import dbg
dbg.TraceError(
"<ScriptWindow> Failed to change state.\n{0}\n{1}".format(
"<state '{0}'> Allowed states: {1}.".format(state, allowed_type),
"{0} Allowed type: {1}.".format(type(received_objects), type(dict()))))
return
for item in [zip for zip in received_objects.values() if (zip is not None)]:
if state is self.STATE_HIDE:
item.Hide()
else:
item.Show()
#main.py (example):
self.childrenDict = self.GetChildDictionary(["LoginButton", "LoginExitButton"])
self.childrenDict["LoginButton"].SetPosition(20, 500)
self.childrenDict["LoginExitButton"].SetPosition(-300, 800)
self.Realloc(self.STATE_SHOW, childrenDict) # Use Realloc(state, object_dictionary) for a action as Hide() or Show() by state.
Small test board.
Code:
import ui, exception, dbg
class MainWindow(ui.ScriptWindow):
def __init__(self):
ui.ScriptWindow.__init__(self)
self.LoadWindow()
def __del__(self):
ui.ScriptWindow.__del__(self)
def Destroy(self):
self.ClearDictionary()
def LoadWindow(self):
try:
ui.PythonScriptLoader().LoadScriptFile(self, "uiScript/main_window.py")
except:
exception.Abort("MainWindow.LoadWindow.LoadWindow")
self.childrenDict = self.GetChildDictionary(["MatchingButton", "RefreshButton", "SelectButton", "HideButtons"])
self.childrenDict["RefreshButton"].SAFE_SetEvent(self.OnToggleRefreshButton)
self.childrenDict["MatchingButton"].SAFE_SetEvent(self.OnToggleMatchingButton)
self.childrenDict["SelectButton"].SAFE_SetEvent(self.OnToggleSelectButton)
self.childrenDict["HideButtons"].SAFE_SetEvent(self.OnToggleHideButtons)
self.Show()
def OnToggleRefreshButton(self):
dbg.LogBox("OnClickRefreshButton")
def OnToggleMatchingButton(self):
dbg.LogBox("OnClickToggleMatchingButton")
def OnToggleSelectButton(self):
dbg.LogBox("OnClickToggleSelectButton")
def OnToggleHideButtons(self):
self.SetChildDictionaryState(self.STATE_HIDE, self.childrenDict)
Code:
import uiScriptLocale
UI_WIDTH = 115
UI_HEIGHT = 160
window = {
"name" : "MainWindow",
"style" : ("movable", "float",),
"x" : SCREEN_WIDTH / 2 - UI_WIDTH / 2,
"y" : SCREEN_HEIGHT / 2 - UI_HEIGHT / 2,
"width" : UI_WIDTH,
"height" : UI_HEIGHT,
"children" :
(
{
"name" : "Board",
"type" : "board_with_titlebar",
"x" : 0,
"y" : 0,
"width" : UI_WIDTH,
"height" : UI_HEIGHT,
"title" : "Window",
"children" :
(
{
"name" : "MatchingButton",
"type" : "button",
"x" : 15,
"y" : 40,
"text" : "MatchingButton",
"default_image" : "d:/ymir work/ui/public/large_button_01.sub",
"over_image" : "d:/ymir work/ui/public/large_button_02.sub",
"down_image" : "d:/ymir work/ui/public/large_button_03.sub",
},
{
"name" : "RefreshButton",
"type" : "button",
"x" : 15,
"y" : 40 + (30 * 1),
"text" : "RefreshButton",
"default_image" : "d:/ymir work/ui/public/large_button_01.sub",
"over_image" : "d:/ymir work/ui/public/large_button_02.sub",
"down_image" : "d:/ymir work/ui/public/large_button_03.sub",
},
{
"name" : "SelectButton",
"type" : "button",
"x" : 15,
"y" : 40 + (30 * 2),
"text" : "SelectButton",
"default_image" : "d:/ymir work/ui/public/large_button_01.sub",
"over_image" : "d:/ymir work/ui/public/large_button_02.sub",
"down_image" : "d:/ymir work/ui/public/large_button_03.sub",
},
{
"name" : "HideButtons",
"type" : "button",
"x" : 15,
"y" : 40 + (30 * 3),
"text" : "HideButtons",
"default_image" : "d:/ymir work/ui/public/large_button_01.sub",
"over_image" : "d:/ymir work/ui/public/large_button_02.sub",
"down_image" : "d:/ymir work/ui/public/large_button_03.sub",
},
),
},
),
}
|
|
|
12/12/2017, 16:28
|
#3
|
elite*gold: 191
Join Date: May 2009
Posts: 1,214
Received Thanks: 2,597
|
Quote:
Originally Posted by VegaS ♆
Code:
[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)]]
|
Well, this is quite bad code style.
Try to stay to the pythonic way, list comprehensions should only be used for simple list-related methods (and only for one line, mostly) and here you could easily use a normal loop and a if, this would make your code much more readable.
Best regards
|
|
|
12/30/2019, 22:41
|
#4
|
elite*gold: 0
Join Date: Apr 2009
Posts: 2
Received Thanks: 0
|
did somebody managed to put it in use?
|
|
|
 |
Similar Threads
|
[Python] Modules after GameForge-Update (01.10.2013)
05/23/2015 - Metin2 Guides & Templates - 21 Replies
Good afternoon Elitepvpers.
The update from the 01.10.2013 has changed a few things in the Metin2Client concerning Python.
Some Pythonmodules have been removed from the Root-Eterpack and were moved directly into the client-executable.
Dump:
Module: background
004511C0 IsSoftwareTiling
004511E0 EnableSoftwareTiling
00451240 EnableSnow
00451970 GlobalPositionToLocalPosition
|
Fatal errror: failed to load platform modules
05/02/2011 - Counter-Strike - 9 Replies
ja ich kann kein CS:S mehr spielen/starten denn bei steam is irgendetwas kaputt, naja immer kommt die fehler meldung "Fatal errror: failed to load platform modules" kann mir da jemand weiter helfen?
mfg
|
BotResourcePack (VB.net modules)
05/04/2009 - CO2 Bots & Macros - 58 Replies
I was bored so I decided to try the level-bot for taos in BanditL97 cave.
I noticed it lagged the system alot and didnt sit/meditate or auto-disconnect when attacked so thought "I should make a better one!" ...which I did.
The bot was almost finished when I decided to change what it did... modularisation was then needed so I spilt functions off into their own self-contained modules.
This download is what resulted.
These modules can be used with any Bot-making in VB.net so far and I...
|
Question about modules
10/13/2007 - Conquer Online 2 - 0 Replies
This might not be the right part of the forum to ask, But i tried search so dont say use search =P
I was wondering if theres a VB module around to allow editting memory adresses, this is to make a trainer in VB for SV :)
So if anyone can point me to the right direction it would be very apreciated.
|
All times are GMT +1. The time now is 18:10.
|
|