1# GemRB - Infinity Engine Emulator
2# Copyright (C) 2003 The GemRB Project
3#
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.
8#
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.
13#
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.
17#
18#
19#character generation, race (GUICG2)
20import GemRB
21import CommonTables
22from ie_stats import IE_RACE
23from GUIDefines import *
24
25import CharGenCommon
26
27RaceWindow = 0
28TextAreaControl = 0
29DoneButton = 0
30MyChar = 0
31
32def OnLoad():
33	global RaceWindow, TextAreaControl, DoneButton, MyChar
34
35	RaceWindow = GemRB.LoadWindow(8, "GUICG")
36	CharGenCommon.PositionCharGenWin(RaceWindow)
37
38	MyChar = GemRB.GetVar ("Slot")
39	RaceCount = CommonTables.Races.GetRowCount()
40
41	for i in range(2,RaceCount+2):
42		#hack to stop if the race table has more entries than the gui resource
43		#this needs to be done because the race table has non-selectable entries
44		Button = RaceWindow.GetControl(i)
45		if not Button:
46			RaceCount = i-2
47			break
48		Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
49
50	GemRB.SetVar ("Race", -1)
51	for i in range(2, RaceCount+2):
52		Button = RaceWindow.GetControl(i)
53		Button.SetText(CommonTables.Races.GetValue(i-2,0) )
54		Button.SetState(IE_GUI_BUTTON_ENABLED)
55		Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, RacePress)
56		Button.SetVarAssoc("Race", i-2 )
57
58	BackButton = RaceWindow.GetControl(i+2)  #i=8 now (when race count is 7)
59	BackButton.SetText(15416)
60	BackButton.MakeEscape()
61	DoneButton = RaceWindow.GetControl(0)
62	DoneButton.SetText(11973)
63	DoneButton.MakeDefault()
64	DoneButton.SetDisabled(True)
65
66	TextAreaControl = RaceWindow.GetControl(12)
67	TextAreaControl.SetText(17237)
68
69	DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
70	BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
71	RaceWindow.Focus()
72	return
73
74def RacePress():
75	Race = GemRB.GetVar("Race")
76	TextAreaControl.SetText(CommonTables.Races.GetValue(Race,1) )
77	DoneButton.SetDisabled(False)
78	return
79
80def BackPress():
81	if RaceWindow:
82		RaceWindow.Unload()
83	GemRB.SetNextScript("CharGen2")
84	GemRB.SetVar("Race",0)  #scrapping the race value
85	return
86
87def NextPress():
88	if RaceWindow:
89		RaceWindow.Unload()
90
91	Race = GemRB.GetVar ("Race")
92	GemRB.SetPlayerStat (MyChar, IE_RACE, CommonTables.Races.GetValue(Race,3) )
93
94	GemRB.SetNextScript("CharGen3") #class
95	return
96