iwd: more gcw syncing with bg2 - actonpc and dragging
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG2.py
blob5f529743bbcb7e47cad42a2a10e2cb45b9d345a1
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 import GUICommon
22 import LUCommon
23 from ie_stats import *
24 from GUIDefines import *
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(2)
37 MyChar = GemRB.GetVar ("Slot")
38 Race = GUICommon.RaceTable.FindValue (3, GemRB.GetPlayerStat (MyChar, IE_RACE) )
39 RaceName = GUICommon.RaceTable.GetRowName(Race)
41 ClassCount = GUICommon.ClassTable.GetRowCount()+1
43 j = 0
44 #radiobutton groups must be set up before doing anything else to them
45 for i in range(1,ClassCount):
46 if GUICommon.ClassTable.GetValue(i-1,4):
47 continue
48 if j>7:
49 Button = ClassWindow.GetControl(j+7)
50 else:
51 Button = ClassWindow.GetControl(j+2)
52 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
53 Button.SetState(IE_GUI_BUTTON_DISABLED)
54 j = j+1
56 j = 0
57 GemRB.SetVar("MAGESCHOOL",0)
58 HasMulti = 0
59 for i in range(1,ClassCount):
60 ClassName = GUICommon.ClassTable.GetRowName(i-1)
61 Allowed = GUICommon.ClassTable.GetValue(ClassName, RaceName)
62 if GUICommon.ClassTable.GetValue(i-1,4):
63 if Allowed!=0:
64 HasMulti = 1
65 continue
66 if j>7:
67 Button = ClassWindow.GetControl(j+7)
68 else:
69 Button = ClassWindow.GetControl(j+2)
70 j = j+1
71 t = GUICommon.ClassTable.GetValue(i-1, 0)
72 Button.SetText(t )
74 if Allowed==0:
75 continue
76 if Allowed==2:
77 GemRB.SetVar("MAGESCHOOL",5) #illusionist
78 Button.SetState(IE_GUI_BUTTON_ENABLED)
79 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ClassPress)
80 Button.SetVarAssoc("Class", i)
82 MultiClassButton = ClassWindow.GetControl(10)
83 MultiClassButton.SetText(11993)
84 if HasMulti == 0:
85 MultiClassButton.SetState(IE_GUI_BUTTON_DISABLED)
87 BackButton = ClassWindow.GetControl(14)
88 BackButton.SetText(15416)
89 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
90 DoneButton = ClassWindow.GetControl(0)
91 DoneButton.SetText(11973)
92 DoneButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
94 TextAreaControl = ClassWindow.GetControl(13)
96 Class = GemRB.GetVar("Class")-1
97 if Class<0:
98 TextAreaControl.SetText(17242)
99 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
100 else:
101 TextAreaControl.SetText(GUICommon.ClassTable.GetValue(Class,1) )
102 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
104 MultiClassButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, MultiClassPress)
105 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
106 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
107 ClassWindow.SetVisible(WINDOW_VISIBLE)
108 return
110 def BackPress():
111 if ClassWindow:
112 ClassWindow.Unload()
113 GemRB.SetNextScript("CharGen3")
114 GemRB.SetVar("Class",0) #scrapping the class value
115 return
117 def SetClass():
118 # find the class from the class table
119 ClassIndex = GemRB.GetVar ("Class") - 1
120 Class = GUICommon.ClassTable.GetValue (ClassIndex, 5)
121 GemRB.SetPlayerStat (MyChar, IE_CLASS, Class)
122 ClassName = GUICommon.ClassTable.GetRowName (GUICommon.ClassTable.FindValue (5, Class))
123 # protect against barbarians; this stat will be overwritten later
124 GemRB.SetPlayerStat (MyChar, IE_HITPOINTS, ClassIndex)
126 #assign the correct XP
127 if GUICommon.GameIsTOB():
128 GemRB.SetPlayerStat (MyChar, IE_XP, GUICommon.ClassSkillsTable.GetValue (ClassName, "STARTXP2"))
129 else:
130 GemRB.SetPlayerStat (MyChar, IE_XP, GUICommon.ClassSkillsTable.GetValue (ClassName, "STARTXP"))
132 #create an array to get all the classes from
133 NumClasses = 1
134 IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
135 if IsMulti[0] > 1:
136 NumClasses = IsMulti[0]
137 Classes = [IsMulti[1], IsMulti[2], IsMulti[3]]
138 else:
139 Classes = [GemRB.GetPlayerStat (MyChar, IE_CLASS)]
141 #loop through each class and update it's level
142 xp = GemRB.GetPlayerStat (MyChar, IE_XP)/NumClasses
143 for i in range (NumClasses):
144 CurrentLevel = LUCommon.GetNextLevelFromExp (xp, Classes[i])
145 if i == 0:
146 GemRB.SetPlayerStat (MyChar, IE_LEVEL, CurrentLevel)
147 elif i <= 2:
148 GemRB.SetPlayerStat (MyChar, IE_LEVEL2+i-1, CurrentLevel)
150 def MultiClassPress():
151 GemRB.SetVar("Class Kit",0)
152 if ClassWindow:
153 ClassWindow.Unload()
154 GemRB.SetNextScript("GUICG10")
155 return
157 def ClassPress():
158 SetClass()
159 if ClassWindow:
160 ClassWindow.Unload()
161 GemRB.SetNextScript("GUICG22")
162 return
164 def NextPress ():
165 SetClass()
166 if ClassWindow:
167 ClassWindow.Unload()
168 GemRB.SetNextScript("CharGen4") #alignment
169 return