do the bashing via the BashDoor action
[gemrb.git] / gemrb / GUIScripts / iwd2 / Class.py
blob4eeae5cc3795f12b572d6990486944aca568b84e
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, class (GUICG2)
20 import GemRB
21 from GUIDefines import *
22 import CommonTables
24 ClassWindow = 0
25 TextAreaControl = 0
26 DoneButton = 0
27 BackButton = 0
28 ClassCount = 0
29 HasSubClass = 0
30 ClassID = 0
32 def AdjustTextArea():
33 global HasSubClass, ClassID
35 Class = GemRB.GetVar("Class")-1
36 TextAreaControl.SetText(CommonTables.Classes.GetValue(Class,1) )
37 ClassName = CommonTables.Classes.GetRowName(Class)
38 ClassID = CommonTables.Classes.GetValue(ClassName, "ID")
39 #determining if this class has any subclasses
40 HasSubClass = 0
41 for i in range(1, ClassCount):
42 ClassName = CommonTables.Classes.GetRowName(i-1)
43 #determining if this is a kit or class
44 Allowed = CommonTables.Classes.GetValue(ClassName, "CLASS")
45 if Allowed != ClassID:
46 continue
47 HasSubClass = 1
48 break
50 if HasSubClass == 0:
51 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
52 else:
53 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
54 return
56 def OnLoad():
57 global ClassWindow, TextAreaControl, DoneButton, BackButton
58 global ClassCount
60 GemRB.LoadWindowPack("GUICG", 800, 600)
61 #this replaces help02.2da for class restrictions
62 ClassCount = CommonTables.Classes.GetRowCount()+1
63 ClassWindow = GemRB.LoadWindow(2)
64 rid = CommonTables.Races.FindValue(3, GemRB.GetVar('BaseRace'))
65 RaceName = CommonTables.Races.GetRowName(rid)
67 #radiobutton groups must be set up before doing anything else to them
68 j = 0
69 for i in range(1,ClassCount):
70 ClassName = CommonTables.Classes.GetRowName(i-1)
71 Allowed = CommonTables.Classes.GetValue(ClassName, "CLASS")
72 if Allowed > 0:
73 continue
74 Button = ClassWindow.GetControl(j+2)
75 j = j+1
76 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET)
77 Button.SetState(IE_GUI_BUTTON_DISABLED)
79 j = 0
80 for i in range(1,ClassCount):
81 ClassName = CommonTables.Classes.GetRowName(i-1)
82 #determining if this is a kit or class
83 Allowed = CommonTables.Classes.GetValue(ClassName, "CLASS")
84 if Allowed > 0:
85 continue
86 Allowed = CommonTables.Classes.GetValue(ClassName, RaceName)
87 Button = ClassWindow.GetControl(j+2)
88 j = j+1
89 t = CommonTables.Classes.GetValue(ClassName, "NAME_REF")
90 Button.SetText(t )
92 if Allowed==0:
93 continue
94 Button.SetState(IE_GUI_BUTTON_ENABLED)
95 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ClassPress)
96 Button.SetVarAssoc("Class", i)
98 BackButton = ClassWindow.GetControl(17)
99 BackButton.SetText(15416)
100 BackButton.SetFlags(IE_GUI_BUTTON_CANCEL,OP_OR)
102 DoneButton = ClassWindow.GetControl(0)
103 DoneButton.SetText(36789)
104 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
106 ScrollBarControl = ClassWindow.GetControl(15)
108 TextAreaControl = ClassWindow.GetControl(16)
110 Class = GemRB.GetVar("Class")-1
111 if Class<0:
112 TextAreaControl.SetText(17242)
113 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
114 else:
115 AdjustTextArea()
117 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
118 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
119 ClassWindow.SetVisible(WINDOW_VISIBLE)
120 return
122 def ClassPress():
123 global HasSubClass
125 AdjustTextArea()
126 if HasSubClass == 0:
127 return
129 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
130 j = 0
131 for i in range(1,ClassCount):
132 ClassName = CommonTables.Classes.GetRowName(i-1)
133 Allowed = CommonTables.Classes.GetValue(ClassName, "CLASS")
134 if Allowed > 0:
135 continue
136 Button = ClassWindow.GetControl(j+2)
137 j = j+1
138 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_SET)
139 Button.SetState(IE_GUI_BUTTON_DISABLED)
140 Button.SetText("")
143 for i in range(1, ClassCount):
144 ClassName = CommonTables.Classes.GetRowName(i-1)
145 #determining if this is a kit or class
146 Allowed = CommonTables.Classes.GetValue(ClassName, "CLASS")
147 if Allowed != ClassID:
148 continue
149 Button = ClassWindow.GetControl(j+2)
150 j = j+1
151 t = CommonTables.Classes.GetValue(ClassName, "NAME_REF")
152 Button.SetText(t )
153 Button.SetState(IE_GUI_BUTTON_ENABLED)
154 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ClassPress2)
155 Button.SetVarAssoc("Class", i)
157 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress2)
158 return
160 def ClassPress2():
161 Class = GemRB.GetVar("Class")-1
162 TextAreaControl.SetText(CommonTables.Classes.GetValue(Class,1) )
163 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
164 return
166 def BackPress2():
167 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
168 if ClassWindow:
169 ClassWindow.Unload()
170 OnLoad()
171 return
173 def BackPress():
174 if ClassWindow:
175 ClassWindow.Unload()
176 GemRB.SetNextScript("CharGen3")
177 GemRB.SetVar("Class",0) #scrapping the class value
178 MyChar = GemRB.GetVar("Slot")
179 GemRB.SetPlayerStat (IE_CLASS, 0)
180 return
182 def NextPress():
183 #classcolumn is base class
184 Class = GemRB.GetVar("Class")
185 ClassColumn = CommonTables.Classes.GetValue(Class - 1, 3)
186 if ClassColumn <= 0: #it was already a base class
187 ClassColumn = Class
188 GemRB.SetVar("BaseClass", ClassColumn)
189 if ClassWindow:
190 ClassWindow.Unload()
191 GemRB.SetNextScript("CharGen4") #alignment
192 return