2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2007 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #character generation, class kit (GUICG22)
23 from ie_stats
import *
24 from GUIDefines
import *
36 KitSelected
= 0 #store clicked kit on redraw as number within RowCount
37 EnhanceGUI
= GemRB
.GetVar("GUIEnhancements") #extra kit button and scroll bar toggle
40 global KitWindow
, TextAreaControl
, DoneButton
41 global SchoolList
, ClassID
42 global RowCount
, TopIndex
, KitTable
, Init
, MyChar
44 GemRB
.LoadWindowPack("GUICG", 640, 480)
45 MyChar
= GemRB
.GetVar ("Slot")
46 Race
= GemRB
.GetPlayerStat (MyChar
, IE_RACE
)
47 RaceName
= CommonTables
.Races
.GetRowName(CommonTables
.Races
.FindValue (3, Race
) )
49 ClassID
= GemRB
.GetPlayerStat (MyChar
, IE_CLASS
)
50 ClassName
= CommonTables
.Classes
.GetRowName (GemRB
.GetPlayerStat (MyChar
, IE_HITPOINTS
)) # barbarian hack
52 KitTable
= GemRB
.LoadTable("kittable")
53 KitTableName
= KitTable
.GetValue(ClassName
, RaceName
)
54 KitTable
= GemRB
.LoadTable(KitTableName
,1)
56 SchoolList
= GemRB
.LoadTable("magesch")
58 #there is a specialist mage window, but it is easier to use
59 #the class kit window for both
60 KitWindow
= GemRB
.LoadWindow(22)
62 Label
= KitWindow
.GetControl(0xfffffff)
67 Button
= KitWindow
.GetControl(i
+1)
69 Button
= KitWindow
.GetControl(i
+5)
70 Button
.SetState(IE_GUI_BUTTON_DISABLED
)
71 Button
.SetFlags(IE_GUI_BUTTON_RADIOBUTTON
, OP_OR
)
73 if not KitTable
: # sorcerer or monk
76 if ClassID
== 1: # mages
77 RowCount
= SchoolList
.GetRowCount()
79 RowCount
= KitTable
.GetRowCount()
82 GemRB
.SetVar("TopIndex", 0)
84 tmpRowCount
= RowCount
85 if RowCount
>10: #create 11 kit button
86 KitWindow
.CreateButton (15, 18, 250, 271, 20)
87 extrakit
= KitWindow
.GetControl(15)
88 extrakit
.SetState(IE_GUI_BUTTON_DISABLED
)
89 extrakit
.SetFlags(IE_GUI_BUTTON_RADIOBUTTON
, OP_OR
)
90 extrakit
.SetSprites("GUICGBC",0, 0,1,2,3)
92 if tmpRowCount
>11: #create scroll bar
93 KitWindow
.CreateScrollBar(1000, 290, 50, 16, 220)
94 ScrollBar
= KitWindow
.GetControl (1000)
95 ScrollBar
.SetSprites("GUISCRCW", 0, 0,1,2,3,5,4)
96 ScrollBar
.SetVarAssoc("TopIndex",tmpRowCount
-10)
97 ScrollBar
.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE
, RedrawKits
)
98 ScrollBar
.SetDefaultScrollBar()
99 elif not EnhanceGUI
and RowCount
>10:
102 for i
in range(RowCount
):
104 Button
= KitWindow
.GetControl(i
+1)
106 Button
= KitWindow
.GetControl(i
+5)
107 Button
.SetVarAssoc("ButtonPressed", i
)
108 Button
.SetEvent(IE_GUI_BUTTON_ON_PRESS
, KitPress
)
110 BackButton
= KitWindow
.GetControl(8)
111 BackButton
.SetText(15416)
112 BackButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
113 DoneButton
= KitWindow
.GetControl(7)
114 DoneButton
.SetText(11973)
115 DoneButton
.SetFlags(IE_GUI_BUTTON_DEFAULT
,OP_OR
)
117 TextAreaControl
= KitWindow
.GetControl(5)
118 TextAreaControl
.SetText(17247)
120 DoneButton
.SetEvent(IE_GUI_BUTTON_ON_PRESS
, NextPress
)
121 BackButton
.SetEvent(IE_GUI_BUTTON_ON_PRESS
, BackPress
)
125 KitWindow
.SetVisible(WINDOW_VISIBLE
)
129 global TopIndex
, Init
, KitSelected
131 TopIndex
=GemRB
.GetVar("TopIndex")
133 for i
in range(RowCount
):
135 Button
= KitWindow
.GetControl(i
+1)
137 Button
= KitWindow
.GetControl(i
+5)
138 Button
.SetState(IE_GUI_BUTTON_DISABLED
)
141 # TODO: check if this is ever reached
142 Kit
= GemRB
.GetVar("MAGESCHOOL")
143 KitName
= SchoolList
.GetValue(i
+TopIndex
, 0)
144 Kit
= SchoolList
.GetValue (Kit
, 3)
147 KitName
= CommonTables
.Classes
.GetValue(GemRB
.GetVar("Class")-1, 0)
149 Kit
= KitTable
.GetValue (i
+TopIndex
,0)
151 KitName
= SchoolList
.GetValue (i
+TopIndex
, 0)
153 KitName
= SchoolList
.GetValue (0, 0)
154 Button
.SetState(IE_GUI_BUTTON_ENABLED
)
155 if Init
: #preselection of mage plain kit
156 Button
.SetState(IE_GUI_BUTTON_SELECTED
)
157 KitSelected
= i
+TopIndex
160 EnabledButtons
.append(Kit
-21)
163 KitName
= CommonTables
.KitList
.GetValue(Kit
, 1)
165 KitName
= CommonTables
.Classes
.GetValue(GemRB
.GetVar("Class")-1, 0)
166 Button
.SetText(KitName
)
167 if not EnabledButtons
or i
+TopIndex
in EnabledButtons
:
168 Button
.SetState(IE_GUI_BUTTON_ENABLED
)
169 if Init
and i
+TopIndex
>0:
170 Button
.SetState(IE_GUI_BUTTON_SELECTED
)
171 KitSelected
= i
+TopIndex
175 if Init
and i
+TopIndex
==0:
177 GemRB
.SetVar("ButtonPressed", EnabledButtons
[0]) #but leave Init==1
179 GemRB
.SetVar("ButtonPressed", 0)
180 Button
.SetState(IE_GUI_BUTTON_SELECTED
)
181 KitSelected
= i
+TopIndex
183 if not Init
and i
+TopIndex
== KitSelected
: #remark selection state on redraw
184 Button
.SetState(IE_GUI_BUTTON_SELECTED
)
190 ButtonPressed
=GemRB
.GetVar("ButtonPressed")
191 KitSelected
= ButtonPressed
+ TopIndex
194 # TODO: this seems to be never reached
195 Kit
= GemRB
.GetVar("MAGESCHOOL")
196 Kit
= SchoolList
.GetValue (Kit
, 3)
200 Kit
= KitTable
.GetValue (ButtonPressed
+TopIndex
, 0)
202 if ButtonPressed
+ TopIndex
== 0:
205 Kit
= ButtonPressed
+ TopIndex
+ 21
207 if ClassID
== 1 and Kit
!= 0:
208 GemRB
.SetVar("MAGESCHOOL", Kit
-21) # hack: -21 to make the generalist 0
210 GemRB
.SetVar("MAGESCHOOL", 0) # so bards don't get schools
213 KitDescription
= CommonTables
.Classes
.GetValue(GemRB
.GetVar("Class")-1, 1)
215 KitDescription
= CommonTables
.KitList
.GetValue(Kit
, 3)
217 TextAreaControl
.SetText(KitDescription
)
218 DoneButton
.SetState(IE_GUI_BUTTON_ENABLED
)
220 GemRB
.SetVar("Class Kit", Kit
)
225 GemRB
.SetVar("Class Kit", 0) # reverting the value so we are idempotent
226 GemRB
.SetVar("MAGESCHOOL", 0)
229 GemRB
.SetNextScript("GUICG2")
236 #make gnomes always kitted
237 KitIndex
= GemRB
.GetVar ("Class Kit")
238 MageSchool
= GemRB
.GetVar ("MAGESCHOOL")
239 if MageSchool
and not KitIndex
:
240 SchoolTable
= GemRB
.LoadTable ("magesch")
241 KitIndex
= CommonTables
.KitList
.FindValue (6, SchoolTable
.GetValue (MageSchool
, 3) )
244 KitValue
= (0x4000 + KitIndex
)
245 KitName
= CommonTables
.KitList
.GetValue (KitIndex
, 0)
246 GemRB
.SetPlayerStat (MyChar
, IE_KIT
, KitValue
)
248 GemRB
.SetNextScript("CharGen4") #abilities