def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow # save all the spells for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) if len(Spells[i]) > (24 + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 24), 6) + 1) else: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 25), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells() DoneButton.SetState(IE_GUI_BUTTON_DISABLED) return # close our window and update our records if SpellsWindow and (not chargen or GUICommon.GameIsBG2()): SpellsWindow.Unload() SpellsWindow = None # move to the next script if this is chargen if chargen: if GUICommon.GameIsBG2(): # HACK GemRB.SetNextScript("GUICG6") elif GUICommon.GameIsBG1(): # HACK from CharGenCommon import next next() return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow # save all the spells for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i SpellBook = [0] * len(Spells[i]) if EnhanceGUI: # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) if len(Spells[i]) > (24 + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc("SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 24), 6) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 25), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells() DoneButton.SetState(IE_GUI_BUTTON_DISABLED) return # close our window and update our records if SpellsWindow and (not chargen or GUICommon.GameIsBG2()): SpellsWindow.Unload() SpellsWindow = None # move to the next script if this is chargen if chargen: if GUICommon.GameIsBG2(): # HACK GemRB.SetNextScript("GUICG6") elif GUICommon.GameIsBG1(): # HACK from CharGenCommon import next next() return
def OpenSpellsWindow(actor, table, level, diff, kit=0, gen=0, recommend=True): """Opens the spells selection window. table should refer to the name of the classes MXSPLxxx.2da. level contains the current level of the actor. diff contains the difference from the old level. kit should always be GetKitIndex except when dualclassing. gen is true if this is for character generation. recommend is used in bg2 for spell recommendation / autopick.""" global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel global SpellsTextArea, SpellsKnownTable, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart global KitMask, EnhanceGUI, Memorization #enhance GUI? if (GemRB.GetVar("GUIEnhancements") & GE_SCROLLBARS): EnhanceGUI = 1 # save our pc pc = actor chargen = gen # this ensures compatibility with chargen, sorc, and dual-classing if kit == 0: KitMask = 0x4000 else: # need to implement this if converted to CharGen KitMask = kit # make sure there is an entry at the given level (bard) SpellsKnownTable = GemRB.LoadTable(table) if not SpellsKnownTable.GetValue(str(level), str(1), 1): if chargen: if GameCheck.IsBG2(): # HACK GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() return # load our window if chargen: GemRB.LoadWindowPack("GUICG", 640, 480) SpellsWindow = GemRB.LoadWindow(7) if not recommend: GUICommon.CloseOtherWindow(SpellsWindow.Unload) DoneButton = SpellsWindow.GetControl(0) SpellsTextArea = SpellsWindow.GetControl(27) SpellPointsLeftLabel = SpellsWindow.GetControl(0x1000001b) if (EnhanceGUI): SpellsWindow.CreateScrollBar(1000, 325, 42, 16, 252) HideUnhideScrollBar(1) SpellStart = 2 # cancel button only applicable for chargen SpellsCancelButton = SpellsWindow.GetControl(29) SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress) SpellsCancelButton.SetText(13727) SpellsCancelButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR) if (recommend): # recommended spell picks SpellsPickButton = SpellsWindow.GetControl(30) SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress) SpellsPickButton.SetText(34210) else: SpellsWindow = GemRB.LoadWindow(8) DoneButton = SpellsWindow.GetControl(28) SpellsTextArea = SpellsWindow.GetControl(26) SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000018) if (EnhanceGUI): SpellsWindow.CreateScrollBar(1000, 290, 142, 16, 252) HideUnhideScrollBar(1) #25th spell button for sorcerers SpellsWindow.CreateButton(24, 231, 345, 42, 42) SpellStart = 0 # setup our variables GemRB.SetVar("SpellTopIndex", 0) Memorization = 0 # the done button also doubles as a next button DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) AlreadyShown = 0 for i in range(9): # make sure we always have a value to minus (bards) SecondPoints = SpellsKnownTable.GetValue(str(level - diff), str(i + 1), 1) if not SecondPoints: SecondPoints = 0 # make sure we get more spells of each class before continuing SpellsSelectPointsLeft[i] = SpellsKnownTable.GetValue( str(level), str(i + 1), 1) - SecondPoints if SpellsSelectPointsLeft[i] <= 0: continue elif chargen and KitMask != 0x4000: # specialists get an extra spell per level SpellsSelectPointsLeft[i] += 1 # chargen character seem to get more spells per level (this is kinda dirty hack) # except sorcerers if chargen and GemRB.GetPlayerStat(pc, IE_CLASS) != 19: SpellsSelectPointsLeft[i] += 1 # get all the spells of the given level Spells[i] = Spellbook.GetMageSpells( KitMask, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1) # dump all the spells we already know NumDeleted = 0 for j in range(len(Spells[i])): CurrentIndex = j - NumDeleted # this ensure we don't go out of range if Spellbook.HasSpell(pc, IE_SPELL_TYPE_WIZARD, i, Spells[i][CurrentIndex][0]) >= 0: del Spells[i][CurrentIndex] NumDeleted += 1 # display these spells if it's the first non-zero level if AlreadyShown == 0: # save the level and spellbook data SpellLevel = i SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells) ScrollBar.SetDefaultScrollBar() # only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp if len(Spells[i]) > (24 + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 24), 6) + 1) else: #there are five rows of 5 spells in level up of sorcs ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv((len(Spells[i]) - 25), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show our spells ShowSpells() AlreadyShown = 1 # show the selection window if chargen: if recommend: SpellsWindow.SetVisible(WINDOW_VISIBLE) else: SpellsWindow.ShowModal(MODAL_SHADOW_NONE) else: SpellsWindow.ShowModal(MODAL_SHADOW_GRAY) return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, IE_SPELL_TYPE_WIZARD, SpellLevel, i - 1, 1) SpellBook = [] MemoBook = [0] * 24 # save all the spells if not Memorization: for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) if len(Spells[i]) > (24 + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - 24), 6) + 1) else: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - 25), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells() DoneButton.SetState(IE_GUI_BUTTON_DISABLED) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) # TODO: check iwd2, which is currently lacking all spell handling if chargen and GameCheck.IsBG1() and sum(MemoBook) == 0: SpellLevel = 0 SpellsSelectPointsLeft[SpellLevel] = 1 if KitMask != 0x4000: # specialists get an extra spell per level SpellsSelectPointsLeft[SpellLevel] += 1 DoneButton.SetState(IE_GUI_BUTTON_DISABLED) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2()): SpellsWindow.Unload() SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): # HACK GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() return
def OpenSpellsWindow (actor, table, level, diff, kit=0, gen=0, recommend=True, booktype=0): """Opens the spells selection window. table should refer to the name of the classes MXSPLxxx.2da. level contains the current level of the actor. diff contains the difference from the old level. kit should always be GetKitIndex except when dualclassing. gen is true if this is for character generation. recommend is used in bg2 for spell recommendation / autopick.""" global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel global SpellsTextArea, SpellsKnownTable, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart global KitMask, EnhanceGUI, Memorization, SpellBookType, SpellsPickButton, ButtonCount, Class #enhance GUI? if (GemRB.GetVar("GUIEnhancements")&GE_SCROLLBARS) and not IWD2: EnhanceGUI = 1 # save our pc pc = actor chargen = gen # this ensures compatibility with chargen, sorc, and dual-classing if kit == 0: KitMask = 0x4000 else: # need to implement this if converted to CharGen KitMask = kit if IWD2: # save the spellbook type (class) that corresponds to our table SpellBookType = booktype if not chargen: ButtonCount = 30 # make sure there is an entry at the given level (bard) SpellsKnownTable = GemRB.LoadTable (table) if not SpellsKnownTable.GetValue (str(level), str(1), GTV_INT): if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript ("CharGen7") return # load our window if chargen: GemRB.LoadWindowPack("GUICG", WIDTH, HEIGHT) SpellsWindow = GemRB.LoadWindow (7) if not recommend: GUICommon.CloseOtherWindow (SpellsWindow.Unload) DoneButton = SpellsWindow.GetControl (0) SpellsTextArea = SpellsWindow.GetControl (27) SpellPointsLeftLabel = SpellsWindow.GetControl (0x1000001b) if (EnhanceGUI): SpellsWindow.CreateScrollBar (1000, 325,42, 16,252) HideUnhideScrollBar(1) SpellStart = 2 # cancel button only applicable for chargen SpellsCancelButton = SpellsWindow.GetControl(29) SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress) SpellsCancelButton.SetText(13727) SpellsCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR) if (recommend): # recommended spell picks SpellsPickButton = SpellsWindow.GetControl(30) SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress) SpellsPickButton.SetText(34210) else: SpellsWindow = GemRB.LoadWindow (8) if IWD2: DoneButton = SpellsWindow.GetControl (33) SpellsTextArea = SpellsWindow.GetControl(30) SpellPointsLeftLabel = SpellsWindow.GetControl (0x10000022) else: DoneButton = SpellsWindow.GetControl (28) SpellsTextArea = SpellsWindow.GetControl(26) SpellPointsLeftLabel = SpellsWindow.GetControl (0x10000018) if(EnhanceGUI): SpellsWindow.CreateScrollBar (1000, 290,142, 16,252) HideUnhideScrollBar(1) #25th spell button for sorcerers SpellsWindow.CreateButton (24, 231, 345, 42, 42) SpellStart = 0 # setup our variables GemRB.SetVar ("SpellTopIndex", 0) Memorization = 0 Class = GemRB.GetPlayerStat (pc, IE_CLASS) if IWD2 and not chargen: LUClass = GemRB.GetVar ("LUClass") LUClassName = CommonTables.Classes.GetRowName (LUClass) LUClassID = CommonTables.Classes.GetValue (LUClassName, "ID") Class = LUClassID # the done button also doubles as a next button DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) AlreadyShown = 0 for i in range (9): # make sure we always have a value to minus (bards) SecondPoints = SpellsKnownTable.GetValue (str(level-diff), str(i+1), GTV_INT) if not SecondPoints: SecondPoints = 0 # make sure we get more spells of each class before continuing SpellsSelectPointsLeft[i] = SpellsKnownTable.GetValue (str(level), str(i+1), GTV_INT) - SecondPoints if SpellsSelectPointsLeft[i] <= 0: continue elif chargen and KitMask != 0x4000 and (not IWD2 or Class == 11): # specialists get an extra spell per level SpellsSelectPointsLeft[i] += 1 # chargen character seem to get more spells per level (this is kinda dirty hack) # except sorcerers if chargen and Class != 19 and not IWD2: SpellsSelectPointsLeft[i] += 1 # get all the spells of the given level Spells[i] = Spellbook.GetMageSpells (KitMask, GemRB.GetPlayerStat (pc, IE_ALIGNMENT), i+1, Class) # dump all the spells we already know NumDeleted = 0 for j in range (len (Spells[i])): CurrentIndex = j - NumDeleted # this ensure we don't go out of range if Spellbook.HasSpell (pc, SpellBookType, i, Spells[i][CurrentIndex][0]) >= 0: del Spells[i][CurrentIndex] NumDeleted += 1 # display these spells if it's the first non-zero level if AlreadyShown == 0: # save the level and spellbook data SpellLevel = i SpellBook = [0]*len(Spells[i]) if(EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl (1000) # ScrollBar.SetDefaultScrollBar () # only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp if len (Spells[i]) > ( ButtonCount + ExtraSpellButtons() ): ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells) HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount ) , 6 ) + 1 ) else: #there are five rows of 5 spells in level up of sorcs ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount-1 ) , 5 ) + 1 ) else: ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, None) ScrollBar.SetVarAssoc ("SpellTopIndex", 0) HideUnhideScrollBar(1) # show our spells ShowSpells () AlreadyShown = 1 # show the selection window if chargen: if recommend: SpellsWindow.SetVisible (WINDOW_VISIBLE) else: SpellsWindow.ShowModal (MODAL_SHADOW_NONE) else: SpellsWindow.ShowModal (MODAL_SHADOW_GRAY) return
def SpellsDonePress (): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, SpellBookType, SpellLevel, i-1, 1) SpellBook = [] MemoBook = [0]*ButtonCount # save all the spells if not Memorization: for i in range (len (Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell if IWD2: GemRB.LearnSpell (pc, Spells[SpellLevel][i][0], 0, 1<<SpellBookType) else: GemRB.LearnSpell (pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range (SpellLevel+1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar ("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0]*len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl (1000) if len (Spells[i]) > ( ButtonCount + ExtraSpellButtons() ): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount ) , 6 ) + 1 ) else: ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount-1 ) , 5 ) + 1 ) else: ScrollBar.SetVarAssoc ("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells () DoneButton.SetState (IE_GUI_BUTTON_DISABLED) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) if chargen and sum(MemoBook) == 0 and \ (GameCheck.IsBG1() or (IWD2 and SpellBookType != IE_IWD2_SPELL_SORCERER)): SpellLevel = 0 SpellsSelectPointsLeft[SpellLevel] = 1 if KitMask != 0x4000: # specialists get an extra spell per level SpellsSelectPointsLeft[SpellLevel] += 1 DoneButton.SetState (IE_GUI_BUTTON_DISABLED) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2): SpellsWindow.Unload () SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") elif IWD2: import GUIREC GUIREC.FinishLevelUp () return
def OpenSpellsWindow(actor, table, level, diff, kit=0, gen=0, recommend=True, booktype=0): """Opens the spells selection window. table should refer to the name of the classes MXSPLxxx.2da. level contains the current level of the actor. diff contains the difference from the old level. kit should always be GetKitIndex except when dualclassing. gen is true if this is for character generation. recommend is used in bg2 for spell recommendation / autopick.""" global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel global SpellsTextArea, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart, BonusPoints global KitMask, EnhanceGUI, Memorization, SpellBookType, SpellsPickButton, ButtonCount, Class #enhance GUI? if (GemRB.GetVar("GUIEnhancements") & GE_SCROLLBARS) and not IWD2: EnhanceGUI = 1 # save our pc pc = actor chargen = gen # this ensures compatibility with chargen, sorc, and dual-classing if kit == 0: KitMask = 0x4000 else: # need to implement this if converted to CharGen KitMask = kit if IWD2: # save the spellbook type (class) that corresponds to our table SpellBookType = booktype if not chargen: ButtonCount = 30 # make sure there is an entry at the given level (bard) SpellLearnTable = table SpellsToMemoTable = GemRB.LoadTable(table) if not SpellsToMemoTable.GetValue(str(level), str(1), GTV_INT): if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") return # load our window if chargen: SpellsWindow = GemRB.LoadWindow(7, "GUICG") if GameCheck.IsBG2(): import CharGenCommon CharGenCommon.PositionCharGenWin(SpellsWindow) elif GameCheck.IsIWD2(): import CharOverview CharOverview.PositionCharGenWin(SpellsWindow) DoneButton = SpellsWindow.GetControl(0) SpellsTextArea = SpellsWindow.GetControl(27) SpellPointsLeftLabel = SpellsWindow.GetControl(0x1000001b) if (EnhanceGUI): sb = SpellsWindow.CreateScrollBar(NewScrollBarID, { 'x': 325, 'y': 42, 'w': 16, 'h': 252 }) sb.SetVisible(False) SpellStart = 2 # cancel button only applicable for chargen SpellsCancelButton = SpellsWindow.GetControl(29) SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsCancelButton.OnPress(SpellsCancelPress) SpellsCancelButton.SetText(13727) SpellsCancelButton.MakeEscape() if (recommend): # recommended spell picks SpellsPickButton = SpellsWindow.GetControl(30) SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsPickButton.OnPress(SpellsPickPress) SpellsPickButton.SetText(34210) else: SpellsWindow = GemRB.LoadWindow(8) if IWD2: DoneButton = SpellsWindow.GetControl(33) SpellsTextArea = SpellsWindow.GetControl(30) SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000022) else: DoneButton = SpellsWindow.GetControl(28) SpellsTextArea = SpellsWindow.GetControl(26) SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000018) if (EnhanceGUI): sb = SpellsWindow.CreateScrollBar(NewScrollBarID, { 'x': 290, 'y': 142, 'w': 16, 'h': 252 }) sb.SetVisible(False) #25th spell button for sorcerers SpellsWindow.CreateButton(24, 231, 345, 42, 42) SpellStart = 0 # setup our variables GemRB.SetVar("SpellTopIndex", 0) Memorization = 0 Class = GemRB.GetPlayerStat(pc, IE_CLASS) if IWD2 and not chargen: LUClass = GemRB.GetVar("LUClass") LUClassName = CommonTables.Classes.GetRowName(LUClass) LUClassID = CommonTables.Classes.GetValue(LUClassName, "ID") Class = LUClassID # the done button also doubles as a next button DoneButton.SetDisabled(True) DoneButton.OnPress(SpellsDonePress) DoneButton.SetText(11973) DoneButton.MakeDefault() # adjust the table for the amount of spells available for learning for free # bg2 had SPLSRCKN, iwd2 also SPLBRDKN, but all the others lacked the tables if SpellLearnTable == "MXSPLSOR" or SpellLearnTable == "MXSPLSRC": SpellLearnTable = "SPLSRCKN" elif SpellLearnTable == "MXSPLBRD": SpellLearnTable = "SPLBRDKN" # ... which is also important for mages during chargen and then never again elif SpellLearnTable == "MXSPLWIZ": SpellLearnTable = "SPLWIZKN" else: print( "OpenSpellsWindow: unhandled spell learning type encountered, falling back to memo table:", table) SpellLearnTable = GemRB.LoadTable(SpellLearnTable) CastingStatValue = 0 if IWD2: # mxsplbon.2da is handled in core, but does also affect learning, at least in chargen BonusSpellTable = GemRB.LoadTable("mxsplbon") ClassRowName = GUICommon.GetClassRowName(pc) CastingStat = CommonTables.ClassSkills.GetValue( ClassRowName, "CASTING", GTV_INT) CastingStatValue = GemRB.GetPlayerStat(pc, CastingStat) AlreadyShown = 0 for i in range(9): # make sure we always have a value to minus (bards) SecondPoints = SpellsToMemoTable.GetValue(str(level - diff), str(i + 1), GTV_INT) # make sure we get more spells of each class before continuing SpellsSelectPointsLeft[i] = SpellsToMemoTable.GetValue( str(level), str(i + 1), GTV_INT) - SecondPoints if SpellsSelectPointsLeft[i] <= 0: continue SpellsSelectPointsLeft[i] = SpellLearnTable.GetValue( str(level), str(i + 1), GTV_INT) # luckily the bonus applies both to learning and memorization if IWD2 and chargen: BonusPoints[i] = BonusSpellTable.GetValue(str(CastingStatValue), str(i + 1), GTV_INT) SpellsSelectPointsLeft[i] += BonusPoints[i] if SpellsSelectPointsLeft[i] <= 0: continue elif chargen and KitMask != 0x4000 and (not IWD2 or SpellBookType == IE_IWD2_SPELL_WIZARD): # specialists get an extra spell per level SpellsSelectPointsLeft[i] += 1 BonusPoints[i] += 1 # get all the spells of the given level Spells[i] = Spellbook.GetMageSpells( KitMask, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1, Class) # dump all the spells we already know NumDeleted = 0 for j in range(len(Spells[i])): CurrentIndex = j - NumDeleted # this ensure we don't go out of range if Spellbook.HasSpell(pc, SpellBookType, i, Spells[i][CurrentIndex][0]) >= 0: del Spells[i][CurrentIndex] NumDeleted += 1 # display these spells if it's the first non-zero level if AlreadyShown == 0: # save the level and spellbook data SpellLevel = i SpellBook = [0] * len(Spells[i]) ScrollBar = SpellsWindow.GetControl(NewScrollBarID) UpdateScrollBar(ScrollBar, len(Spells[i])) # show our spells ShowSpells() AlreadyShown = 1 # show the selection window if chargen: if recommend: SpellsWindow.Focus() else: SpellsWindow.ShowModal(MODAL_SHADOW_NONE) else: SpellsWindow.ShowModal(MODAL_SHADOW_GRAY) return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, SpellBookType, SpellLevel, i - 1, 1) SpellBook = [] MemoBook = [0] * ButtonCount # save all the spells if not Memorization: for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell if IWD2: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0], 0, 1 << SpellBookType) else: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0] * len(Spells[i]) ScrollBar = SpellsWindow.GetControl(NewScrollBarID) UpdateScrollBar(ScrollBar, len(Spells[i])) # show the spells and set the done button to off ShowSpells() DoneButton.SetDisabled(True) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) if chargen and sum(MemoBook) == 0 and \ (GameCheck.IsBG1() or (IWD2 and SpellBookType == IE_IWD2_SPELL_WIZARD)): SpellLevel = 0 # bump it for specialists and iwd2 casters with high stats SpellsSelectPointsLeft[SpellLevel] = 1 + BonusPoints[SpellLevel] # FIXME: setting the proper count here breaks original characters, see #680 #GemRB.SetMemorizableSpellsCount (pc, SpellsSelectPointsLeft[SpellLevel], SpellBookType, SpellLevel) DoneButton.SetDisabled(True) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2): SpellsWindow.Close() SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): SpellsWindow.Close() # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") elif IWD2: import GUIREC GUIREC.FinishLevelUp() return
def SpellsDonePress(): """Move to the next assignable level. If there is not another assignable level, then save all the new spells and close the window.""" global SpellBook, SpellLevel, SpellsWindow, MemoBook, Memorization # oops, we were here before, just memorise the spells and exit if sum(MemoBook) > 0: for i in MemoBook: if i: GemRB.MemorizeSpell(pc, SpellBookType, SpellLevel, i - 1, 1) SpellBook = [] MemoBook = [0] * ButtonCount # save all the spells if not Memorization: for i in range(len(Spells[SpellLevel])): if SpellBook[i]: # we need to learn this spell if IWD2: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0], 0, 1 << SpellBookType) else: GemRB.LearnSpell(pc, Spells[SpellLevel][i][0]) # check to see if we need to update again for i in range(SpellLevel + 1, 9): if SpellsSelectPointsLeft[i] > 0: # reset the variables GemRB.SetVar("SpellTopIndex", 0) SpellLevel = i if not (chargen and GameCheck.IsBG1()): SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) if len(Spells[i]) > (ButtonCount + ExtraSpellButtons()): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount), 6) + 1) else: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount - 1), 5) + 1) else: ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show the spells and set the done button to off ShowSpells() DoneButton.SetState(IE_GUI_BUTTON_DISABLED) return # bg1 lets you memorize spells too (iwd too, but it does it by itself) if chargen and sum(MemoBook) == 0 and \ (GameCheck.IsBG1() or (IWD2 and SpellBookType == IE_IWD2_SPELL_WIZARD)): SpellLevel = 0 # bump it for specialists and iwd2 casters with high stats SpellsSelectPointsLeft[SpellLevel] = 1 + BonusPoints[SpellLevel] DoneButton.SetState(IE_GUI_BUTTON_DISABLED) Memorization = 1 ShowKnownSpells() return # close our window and update our records if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2): SpellsWindow.Unload() SpellsWindow = None # move to the next script if this is chargen if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") elif IWD2: import GUIREC GUIREC.FinishLevelUp() return
def OpenSpellsWindow (actor, table, level, diff, kit=0, gen=0, recommend=True): """Opens the spells selection window. table should refer to the name of the classes MXSPLxxx.2da. level contains the current level of the actor. diff contains the difference from the old level. kit should always be GetKitIndex except when dualclassing. gen is true if this is for character generation. recommend is used in bg2 for spell recommendation / autopick.""" global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel global SpellsTextArea, SpellsKnownTable, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart global KitMask, EnhanceGUI #enhance GUI? if (GemRB.GetVar("GUIEnhancements")): EnhanceGUI = 1 # save our pc pc = actor chargen = gen # this ensures compatibility with chargen, sorc, and dual-classing if kit == 0: KitMask = 0x4000 else: # need to implement this if converted to CharGen KitMask = kit # make sure there is an entry at the given level (bard) SpellsKnownTable = GemRB.LoadTable (table) if not SpellsKnownTable.GetValue (str(level), str(1), 1): if chargen: if GUICommon.GameIsBG2(): # HACK GemRB.SetNextScript("GUICG6") elif GUICommon.GameIsBG1(): # HACK from CharGenCommon import next next() return # load our window if chargen: GemRB.LoadWindowPack("GUICG", 640, 480) SpellsWindow = GemRB.LoadWindow (7) if not recommend: GUICommon.CloseOtherWindow (SpellsWindow.Unload) DoneButton = SpellsWindow.GetControl (0) SpellsTextArea = SpellsWindow.GetControl (27) SpellPointsLeftLabel = SpellsWindow.GetControl (0x1000001b) if (EnhanceGUI): SpellsWindow.CreateScrollBar (1000, 325,42, 16,252) HideUnhideScrollBar(1) SpellStart = 2 # cancel button only applicable for chargen SpellsCancelButton = SpellsWindow.GetControl(29) SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress) SpellsCancelButton.SetText(13727) SpellsCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR) if (recommend): # recommended spell picks SpellsPickButton = SpellsWindow.GetControl(30) SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress) SpellsPickButton.SetText(34210) else: SpellsWindow = GemRB.LoadWindow (8) DoneButton = SpellsWindow.GetControl (28) SpellsTextArea = SpellsWindow.GetControl(26) SpellPointsLeftLabel = SpellsWindow.GetControl (0x10000018) if(EnhanceGUI): SpellsWindow.CreateScrollBar (1000, 290,142, 16,252) HideUnhideScrollBar(1) #25th spell button for sorcerers SpellsWindow.CreateButton (24, 231, 345, 42, 42) SpellStart = 0 # setup our variables GemRB.SetVar ("SpellTopIndex", 0) # the done button also doubles as a next button DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) AlreadyShown = 0 for i in range (9): # make sure we always have a value to minus (bards) SecondPoints = SpellsKnownTable.GetValue (str(level-diff), str(i+1), 1) if not SecondPoints: SecondPoints = 0 # make sure we get more spells of each class before continuing SpellsSelectPointsLeft[i] = SpellsKnownTable.GetValue (str(level), str(i+1), 1) - SecondPoints if SpellsSelectPointsLeft[i] <= 0: continue elif chargen and KitMask != 0x4000: # specialists get an extra spell per level SpellsSelectPointsLeft[i] += 1 # chargen character seem to get more spells per level (this is kinda dirty hack) # except sorcerers if chargen and GemRB.GetPlayerStat (pc, IE_CLASS) != 19: SpellsSelectPointsLeft[i] += 1 # get all the spells of the given level Spells[i] = GUICommon.GetMageSpells (KitMask, GemRB.GetPlayerStat (pc, IE_ALIGNMENT), i+1) # dump all the spells we already know NumDeleted = 0 for j in range (len (Spells[i])): CurrentIndex = j - NumDeleted # this ensure we don't go out of range if GUICommon.HasSpell (pc, IE_SPELL_TYPE_WIZARD, i, Spells[i][CurrentIndex][0]) >= 0: del Spells[i][CurrentIndex] NumDeleted += 1 # display these spells if it's the first non-zero level if AlreadyShown == 0: # save the level and spellbook data SpellLevel = i SpellBook = [0]*len(Spells[i]) if(EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl (1000) #FIXME: use other resources instead, this one is bg2-only if GemRB.HasResource ("GUISCRCW", RES_BAM): ScrollBar.SetSprites ("GUISCRCW", 0, 0,1,2,3,5,4) ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells) ScrollBar.SetDefaultScrollBar () # only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp if len (Spells[i]) > ( 24 + ExtraSpellButtons() ): HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc ("SpellTopIndex", int ( ceil ( ( len (Spells[i])-24 ) / 6.0 ) ) + 1 ) else: #there are five rows of 5 spells in level up of sorcs ScrollBar.SetVarAssoc ("SpellTopIndex", int ( ceil ( ( len (Spells[i])-25 ) / 5.0 ) ) + 1 ) else: ScrollBar.SetVarAssoc ("SpellTopIndex", 0) HideUnhideScrollBar(1) # show our spells ShowSpells () AlreadyShown = 1 # show the selection window if chargen: if recommend: SpellsWindow.SetVisible (WINDOW_VISIBLE) else: SpellsWindow.ShowModal (MODAL_SHADOW_NONE) else: SpellsWindow.ShowModal (MODAL_SHADOW_GRAY) return
def OpenSpellsWindow(actor, table, level, diff, kit=0, gen=0, recommend=True, booktype=0): """Opens the spells selection window. table should refer to the name of the classes MXSPLxxx.2da. level contains the current level of the actor. diff contains the difference from the old level. kit should always be GetKitIndex except when dualclassing. gen is true if this is for character generation. recommend is used in bg2 for spell recommendation / autopick.""" global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel global SpellsTextArea, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart global KitMask, EnhanceGUI, Memorization, SpellBookType, SpellsPickButton, ButtonCount, Class #enhance GUI? if (GemRB.GetVar("GUIEnhancements") & GE_SCROLLBARS) and not IWD2: EnhanceGUI = 1 # save our pc pc = actor chargen = gen # this ensures compatibility with chargen, sorc, and dual-classing if kit == 0: KitMask = 0x4000 else: # need to implement this if converted to CharGen KitMask = kit if IWD2: # save the spellbook type (class) that corresponds to our table SpellBookType = booktype if not chargen: ButtonCount = 30 # make sure there is an entry at the given level (bard) SpellLearnTable = table SpellsToMemoTable = GemRB.LoadTable(table) if not SpellsToMemoTable.GetValue(str(level), str(1), GTV_INT): if chargen: if GameCheck.IsBG2(): GemRB.SetNextScript("GUICG6") elif GameCheck.IsBG1(): # HACK from CharGenCommon import next next() elif IWD2: GemRB.SetNextScript("CharGen7") return # load our window if chargen: GemRB.LoadWindowPack("GUICG", WIDTH, HEIGHT) SpellsWindow = GemRB.LoadWindow(7) if not recommend: GUICommon.CloseOtherWindow(SpellsWindow.Unload) DoneButton = SpellsWindow.GetControl(0) SpellsTextArea = SpellsWindow.GetControl(27) SpellPointsLeftLabel = SpellsWindow.GetControl(0x1000001b) if (EnhanceGUI): SpellsWindow.CreateScrollBar(1000, 325, 42, 16, 252) HideUnhideScrollBar(1) SpellStart = 2 # cancel button only applicable for chargen SpellsCancelButton = SpellsWindow.GetControl(29) SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress) SpellsCancelButton.SetText(13727) SpellsCancelButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR) if (recommend): # recommended spell picks SpellsPickButton = SpellsWindow.GetControl(30) SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED) SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress) SpellsPickButton.SetText(34210) else: SpellsWindow = GemRB.LoadWindow(8) if IWD2: DoneButton = SpellsWindow.GetControl(33) SpellsTextArea = SpellsWindow.GetControl(30) SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000022) else: DoneButton = SpellsWindow.GetControl(28) SpellsTextArea = SpellsWindow.GetControl(26) SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000018) if (EnhanceGUI): SpellsWindow.CreateScrollBar(1000, 290, 142, 16, 252) HideUnhideScrollBar(1) #25th spell button for sorcerers SpellsWindow.CreateButton(24, 231, 345, 42, 42) SpellStart = 0 # setup our variables GemRB.SetVar("SpellTopIndex", 0) Memorization = 0 Class = GemRB.GetPlayerStat(pc, IE_CLASS) if IWD2 and not chargen: LUClass = GemRB.GetVar("LUClass") LUClassName = CommonTables.Classes.GetRowName(LUClass) LUClassID = CommonTables.Classes.GetValue(LUClassName, "ID") Class = LUClassID # the done button also doubles as a next button DoneButton.SetState(IE_GUI_BUTTON_DISABLED) DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress) DoneButton.SetText(11973) DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR) # adjust the table for the amount of spells available for learning for free # bg2 had SPLSRCKN, iwd2 also SPLBRDKN, but all the others lacked the tables if SpellLearnTable == "MXSPLSOR": SpellLearnTable = "SPLSRCKN" elif SpellLearnTable == "MXSPLBRD": SpellLearnTable = "SPLBRDKN" # ... which is also important for mages during chargen and then never again elif SpellLearnTable == "MXSPLWIZ": SpellLearnTable = "SPLWIZKN" else: print "OpenSpellsWindow: unhandled spell learning type encountered, falling back to memo table:", table SpellLearnTable = GemRB.LoadTable(SpellLearnTable) AlreadyShown = 0 for i in range(9): # make sure we always have a value to minus (bards) SecondPoints = SpellsToMemoTable.GetValue(str(level - diff), str(i + 1), GTV_INT) # make sure we get more spells of each class before continuing SpellsSelectPointsLeft[i] = SpellsToMemoTable.GetValue( str(level), str(i + 1), GTV_INT) - SecondPoints if SpellsSelectPointsLeft[i] <= 0: continue SpellsSelectPointsLeft[i] = SpellLearnTable.GetValue( str(level), str(i + 1), GTV_INT) if SpellsSelectPointsLeft[i] <= 0: continue elif chargen and KitMask != 0x4000 and (not IWD2 or Class == 11): # specialists get an extra spell per level SpellsSelectPointsLeft[i] += 1 # get all the spells of the given level Spells[i] = Spellbook.GetMageSpells( KitMask, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1, Class) # dump all the spells we already know NumDeleted = 0 for j in range(len(Spells[i])): CurrentIndex = j - NumDeleted # this ensure we don't go out of range if Spellbook.HasSpell(pc, SpellBookType, i, Spells[i][CurrentIndex][0]) >= 0: del Spells[i][CurrentIndex] NumDeleted += 1 # display these spells if it's the first non-zero level if AlreadyShown == 0: # save the level and spellbook data SpellLevel = i SpellBook = [0] * len(Spells[i]) if (EnhanceGUI): # setup the scrollbar ScrollBar = SpellsWindow.GetControl(1000) # ScrollBar.SetDefaultScrollBar () # only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp if len(Spells[i]) > (ButtonCount + ExtraSpellButtons()): ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells) HideUnhideScrollBar(0) if chargen: ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount), 6) + 1) else: #there are five rows of 5 spells in level up of sorcs ScrollBar.SetVarAssoc( "SpellTopIndex", GUICommon.ceildiv( (len(Spells[i]) - ButtonCount - 1), 5) + 1) else: ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, None) ScrollBar.SetVarAssoc("SpellTopIndex", 0) HideUnhideScrollBar(1) # show our spells ShowSpells() AlreadyShown = 1 # show the selection window if chargen: if recommend: SpellsWindow.SetVisible(WINDOW_VISIBLE) else: SpellsWindow.ShowModal(MODAL_SHADOW_NONE) else: SpellsWindow.ShowModal(MODAL_SHADOW_GRAY) return