TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG10.py
blob130474a5cfd433d5fdf22a18fbb6cb8aeff4a8c2
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, multi-class (GUICG10)
20 import GemRB
21 import CommonTables
22 from ie_stats import *
23 from GUIDefines import *
24 import GUICG2
26 ClassWindow = 0
27 TextAreaControl = 0
28 DoneButton = 0
29 MyChar = 0
31 def OnLoad():
32 global ClassWindow, TextAreaControl, DoneButton, MyChar
34 GemRB.LoadWindowPack("GUICG", 640, 480)
35 ClassWindow = GemRB.LoadWindow(10)
37 MyChar = GemRB.GetVar ("Slot")
38 ClassCount = CommonTables.Classes.GetRowCount()+1
39 Race = GemRB.GetPlayerStat (MyChar, IE_RACE)
40 RaceName = CommonTables.Races.GetRowName(CommonTables.Races.FindValue (3, Race) )
42 j=0
43 for i in range(1,ClassCount):
44 if CommonTables.Classes.GetValue(i-1,4)==0:
45 continue
46 if j>11:
47 Button = ClassWindow.GetControl(j+7)
48 else:
49 Button = ClassWindow.GetControl(j+2)
50 Button.SetState(IE_GUI_BUTTON_DISABLED)
51 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
52 j = j + 1
53 j=0
54 for i in range(1,ClassCount):
55 ClassName = CommonTables.Classes.GetRowName(i-1)
56 Allowed = CommonTables.Classes.GetValue(ClassName, RaceName)
57 if CommonTables.Classes.GetValue(i-1,4)==0:
58 continue
59 if j>11:
60 Button = ClassWindow.GetControl(j+7)
61 else:
62 Button = ClassWindow.GetControl(j+2)
64 t = CommonTables.Classes.GetValue(i-1, 0)
65 Button.SetText(t )
66 j=j+1
67 if Allowed ==0:
68 continue
69 Button.SetState(IE_GUI_BUTTON_ENABLED)
70 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ClassPress)
71 Button.SetVarAssoc("Class", i) #multiclass, actually
73 BackButton = ClassWindow.GetControl(14)
74 BackButton.SetText(15416)
75 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
76 DoneButton = ClassWindow.GetControl(0)
77 DoneButton.SetText(11973)
78 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
80 TextAreaControl = ClassWindow.GetControl(12)
81 TextAreaControl.SetText(17244)
83 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
84 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
85 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
86 ClassWindow.SetVisible(WINDOW_VISIBLE)
87 return
89 def ClassPress():
90 GUICG2.SetClass()
91 Class = GemRB.GetVar("Class")-1
92 TextAreaControl.SetText(CommonTables.Classes.GetValue(Class,1) )
93 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
94 return
96 def BackPress():
97 GemRB.SetVar("Class",0) # scrapping it
98 if ClassWindow:
99 ClassWindow.Unload()
100 GemRB.SetNextScript("GUICG2")
101 return
103 def NextPress():
104 GUICG2.SetClass()
105 if ClassWindow:
106 ClassWindow.Unload()
108 # find the class from the class table
109 ClassIndex = GemRB.GetVar ("Class") - 1
110 Class = CommonTables.Classes.GetValue (ClassIndex, 5)
111 #protect against barbarians
112 ClassName = CommonTables.Classes.GetRowName (CommonTables.Classes.FindValue (5, Class) )
113 GemRB.SetPlayerStat (MyChar, IE_CLASS, Class)
115 GemRB.SetNextScript("CharGen4") #alignment
116 return