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#Single Player Party Select 20import GemRB 21from GameCheck import MAX_PARTY_SIZE 22from GUIDefines import * 23 24PartySelectWindow = 0 25TextArea = 0 26PartyCount = 0 27ScrollBar = 0 28 29def OnLoad(): 30 global PartySelectWindow, TextArea, PartyCount, ScrollBar 31 32 PartyCount = GemRB.GetINIPartyCount() 33 34 PartySelectWindow = GemRB.LoadWindow(10, "GUISP") 35 TextArea = PartySelectWindow.GetControl(6) 36 37 ModifyButton = PartySelectWindow.GetControl(12) 38 ModifyButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ModifyPress) 39 ModifyButton.SetText(10316) 40 41 CancelButton = PartySelectWindow.GetControl(11) 42 CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, lambda: PartySelectWindow.Close()) 43 CancelButton.SetText(13727) 44 CancelButton.MakeEscape() 45 46 DoneButton = PartySelectWindow.GetControl(10) 47 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DonePress) 48 DoneButton.SetText(11973) 49 DoneButton.MakeDefault() 50 51 GemRB.SetVar("PartyIdx",0) 52 GemRB.SetVar("TopIndex",0) 53 54 for i in range(0, min(6, MAX_PARTY_SIZE)): 55 Button = PartySelectWindow.GetControl(i) 56 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON, OP_OR) 57 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, PartyButtonPress) 58 59 ScrollBarPress() 60 PartyButtonPress() 61 62 PartySelectWindow.Focus() 63 64 return 65 66def ScrollBarPress(): 67 global PartySelectWindow, PartyCount 68 Pos = GemRB.GetVar("TopIndex") 69 for i in range(0, min(6, MAX_PARTY_SIZE)): 70 ActPos = Pos + i 71 Button = PartySelectWindow.GetControl(i) 72 Button.SetText("") 73 Button.SetVarAssoc("PartyIdx",-1) 74 if ActPos<PartyCount: 75 Button.SetState(IE_GUI_BUTTON_ENABLED) 76 else: 77 Button.SetState(IE_GUI_BUTTON_DISABLED) 78 79 for i in range(0, min(6, MAX_PARTY_SIZE)): 80 ActPos = Pos + i 81 Button = PartySelectWindow.GetControl(i) 82 if ActPos<PartyCount: 83 Button.SetVarAssoc("PartyIdx",ActPos) 84 Tag = "Party " + str(ActPos) 85 PartyDesc = GemRB.GetINIPartyKey(Tag, "Name", "") 86 Button.SetText(PartyDesc) 87 return 88 89def ModifyPress(): 90 Pos = GemRB.GetVar("PartyIdx") 91 if Pos == 0: # first entry - behaves same as pressing on done 92 if PartySelectWindow: 93 PartySelectWindow.Unload() 94 GemRB.LoadGame(None, 22) 95 GemRB.SetNextScript("SPPartyFormation") 96 #else: # here come the real modifications 97 98def DonePress(): 99 global PartySelectWindow 100 Pos = GemRB.GetVar("PartyIdx") 101 if Pos == 0: 102 if PartySelectWindow: 103 PartySelectWindow.Unload() 104 GemRB.LoadGame(None, 22) 105 GemRB.SetNextScript("SPPartyFormation") 106 else: 107 if PartySelectWindow: 108 PartySelectWindow.Unload() 109 GemRB.LoadGame(None, 22) 110 #here we should load the party characters 111 #but gemrb engine limitations require us to 112 #return to the main engine (loadscreen) 113 GemRB.SetNextScript("SPParty2") 114 return 115 116def PartyButtonPress(): 117 global PartySelectWindow, TextArea 118 i = GemRB.GetVar("PartyIdx") 119 Tag = "Party " + str(i) 120 PartyDesc = "" 121 for j in range(1, 9): 122 Key = "Descr" + str(j) 123 NewString = GemRB.GetINIPartyKey(Tag, Key, "") 124 if NewString != "": 125 NewString = NewString + "\n\n" 126 PartyDesc = PartyDesc + NewString 127 128 TextArea.SetText(PartyDesc) 129 return 130 131#loading characters from party.ini 132def LoadPartyCharacters(): 133 i = GemRB.GetVar("PartyIdx") 134 Tag = "Party " + str(i) 135 for j in range(1, min(6, MAX_PARTY_SIZE)+1): 136 Key = "Char"+str(j) 137 CharName = GemRB.GetINIPartyKey(Tag, Key, "") 138 if CharName !="": 139 GemRB.CreatePlayer(CharName, j, 1) 140 return 141