TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG5.py
blob0388a5066a38c52591b26334466ffe4773616303
1 # GemRB - Infinity Engine Emulator
2 # Copyright (C) 2003 The GemRB Project
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #character generation, name (GUICG5)
20 import GemRB
22 NameWindow = 0
23 NameField = 0
24 DoneButton = 0
26 def OnLoad():
27 global NameWindow, NameField, DoneButton
29 GemRB.LoadWindowPack("GUICG", 640, 480)
30 NameWindow = GemRB.LoadWindow(5)
32 BackButton = NameWindow.GetControl(3)
33 BackButton.SetText(15416)
34 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
36 DoneButton = NameWindow.GetControl(0)
37 DoneButton.SetText(11973)
38 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
39 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
41 NameField = NameWindow.GetControl(2)
43 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
44 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
45 NameField.SetEvent(IE_GUI_EDIT_ON_CHANGE, EditChange)
46 NameWindow.SetVisible(WINDOW_VISIBLE)
47 NameField.SetStatus(IE_GUI_CONTROL_FOCUSED)
48 return
50 def BackPress():
51 if NameWindow:
52 NameWindow.Unload()
53 GemRB.SetNextScript("CharGen8")
54 return
56 def NextPress():
57 Name = NameField.QueryText()
58 #check length?
59 #seems like a good idea to store it here for the time being
60 GemRB.SetToken("CHARNAME",Name)
61 if NameWindow:
62 NameWindow.Unload()
63 GemRB.SetNextScript("CharGen9")
64 return
66 def EditChange():
67 Name = NameField.QueryText()
68 if len(Name)==0:
69 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
70 else:
71 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
72 return