Example #1
0
def CloseStoreWindow ():
	import GUIINV
	global StoreWindow, ActionWindow, PortraitWindow
	global OldPortraitWindow

	GemRB.SetVar ("Inventory", 0)
	CloseWindows ()
	if StoreWindow:
		StoreWindow.Unload ()
	if ActionWindow:
		ActionWindow.Unload ()
	if not GUICommon.GameIsBG1():
		if PortraitWindow:
			PortraitWindow.Unload ()
	StoreWindow = None
	GemRB.LeaveStore ()
	if not GUICommon.GameIsBG1():
		GUICommonWindows.PortraitWindow = OldPortraitWindow
	if Inventory:
		GUIINV.OpenInventoryWindow ()
	else:
		GemRB.GamePause (0, 1)
		GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE) #enabling the game control screen
		GemRB.UnhideGUI () #enabling the other windows
		GUICommonWindows.SetSelectionChangeHandler( None )
	return
Example #2
0
def ProfsLeftPress():
	"""Increases the current proficiency by one."""

	global ProfsPointsLeft

	Pos = GemRB.GetVar("Prof")+ProfsTopIndex
	ProfsTextArea.SetText(ProfsTable.GetValue(Pos+ProfsTableOffset, 2) )
	if ProfsPointsLeft == 0:
		return
	if GUICommon.GameIsIWD1() or GUICommon.GameIsBG1():
		ProfMaxTable = GemRB.LoadTable ("profsmax")
		if ProfsType == LUPROFS_TYPE_CHARGEN:
			MaxProf = ProfMaxTable.GetValue(ClassNameSave, "FIRST_LEVEL")
		else:
			MaxProf = ProfMaxTable.GetValue(ClassNameSave, "OTHER_LEVELS")
	else:
		MaxProf = ProfsTable.GetValue(Pos+ProfsTableOffset, ProfsColumn)
	if MaxProf>5:
		MaxProf = 5

	ActPoint = GemRB.GetVar("Prof "+str(Pos) )
	if ActPoint >= MaxProf:
		return
	GemRB.SetVar("Prof "+str(Pos),ActPoint+1)
	ProfsPointsLeft -= 1
	GemRB.SetVar ("ProfsPointsLeft", ProfsPointsLeft)
	ProfsRedraw ()
	ProfsCallback ()
	return
Example #3
0
def ProfsLeftPress():
	"""Increases the current proficiency by one."""

	global ProfsPointsLeft

	Pos = GemRB.GetVar("Prof")+ProfsTopIndex
	ProfsTextArea.SetText(ProfsTable.GetValue(Pos+ProfsTableOffset, 2) )
	if ProfsPointsLeft == 0:
		return
	if GUICommon.GameIsIWD1() or GUICommon.GameIsBG1():
		ProfMaxTable = GemRB.LoadTable ("profsmax")
		MaxProf = ProfMaxTable.GetValue(ClassNameSave, "OTHER_LEVELS")
	else:
		MaxProf = ProfsTable.GetValue(Pos+ProfsTableOffset, ProfsColumn)
	if MaxProf>5:
		MaxProf = 5
	# FIXME: use profsmax.2da (in all games? could be problematic for weapon styles)
	#if (MaxProf>2) and GUICommon.GameIsBG1():
	#	MaxProf = 2

	ActPoint = GemRB.GetVar("Prof "+str(Pos) )
	if ActPoint >= MaxProf:
		return
	GemRB.SetVar("Prof "+str(Pos),ActPoint+1)
	ProfsPointsLeft -= 1
	GemRB.SetVar ("ProfsPointsLeft", ProfsPointsLeft)
	ProfsRedraw ()
	ProfsCallback ()
	return
Example #4
0
def OpenStoreRumourWindow ():
	global StoreRumourWindow

	GemRB.SetVar ("TopIndex", 0)
	CloseWindows()

	StoreRumourWindow = Window = GemRB.LoadWindow (8)

	#removing those pesky labels
	for i in range (5):
		Window.DeleteControl (0x10000005+i)

	TextArea = Window.GetControl (11)
	TextArea.SetText (14144)

	#tavern quality image
	if GUICommon.GameIsBG1() or GUICommon.GameIsBG2():
		BAM = "TVRNQUL%d"% ((Store['StoreFlags']>>9)&3)
		Button = Window.GetControl (12)
		Button.SetSprites (BAM, 0, 0, 0, 0, 0)
		Button.SetState (IE_GUI_BUTTON_LOCKED)

	ScrollBar = Window.GetControl (5)
	ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, UpdateStoreRumourWindow)
	Count = Store['StoreDrinkCount']
	if Count>4:
		Count = Count-4
	else:
		Count = 0
	ScrollBar.SetVarAssoc ("TopIndex", Count+1)

	GUICommonWindows.SetSelectionChangeHandler( UpdateStoreRumourWindow )
	UpdateStoreRumourWindow ()
	Window.SetVisible (WINDOW_VISIBLE)
	return
Example #5
0
def CloseOptionsWindow():
    global GameOptionsWindow, OptionsWindow, PortraitWindow
    global OldPortraitWindow, OldOptionsWindow

    if GameOptionsWindow == None:
        return

    if GameOptionsWindow:
        GameOptionsWindow.Unload()
    if OptionsWindow:
        OptionsWindow.Unload()
    if PortraitWindow:
        PortraitWindow.Unload()

    GameOptionsWindow = None
    GemRB.SetVar("OtherWindow", -1)
    GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
    GemRB.UnhideGUI()
    GUICommonWindows.OptionsWindow = OldOptionsWindow
    OldOptionsWindow = None
    if not GUICommon.GameIsBG1():
        GUICommonWindows.PortraitWindow = OldPortraitWindow
        OldPortraitWindow = None

    GemRB.GamePause(0, 3)
    return
Example #6
0
def ProfsSave (pc, type=LUPROFS_TYPE_LEVELUP):
	"""Updates the actor with the new proficiencies."""

	ProfCount = ProfsTable.GetRowCount () - ProfsTableOffset
	for i in range(ProfCount): # skip bg1 weapprof.2da proficiencies
		ProfID = ProfsTable.GetValue (i+ProfsTableOffset, 0)
		if GUICommon.GameIsBG1():
			ProfID = ProfID + IE_PROFICIENCYBASTARDSWORD
		SaveProf = GemRB.GetVar ("Prof "+str(i))

		if type == LUPROFS_TYPE_CHARGEN and GUICommon.GameIsBG2():
			GemRB.DispelEffect (pc, "Proficiency", ProfID)
		else:
			if type != LUPROFS_TYPE_DUALCLASS:
				OldProf = GemRB.GetPlayerStat (pc, ProfID) & 0x38
				SaveProf = OldProf | SaveProf
			else: # gotta move the old prof to the back for dual class
				OldProf = GemRB.GetPlayerStat (pc, ProfID) & 0x07
				SaveProf = (OldProf << 3) | SaveProf

		GemRB.SetPlayerStat (pc, ProfID, SaveProf)
		if GUICommon.GameIsBG2() and (type == LUPROFS_TYPE_LEVELUP or type == LUPROFS_TYPE_CHARGEN):
			if SaveProf:
				GemRB.ApplyEffect (pc, "Proficiency", SaveProf, ProfID)
	return
Example #7
0
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
Example #8
0
def RemovePlayerConfirm():
    slot = GemRB.GetVar("Selected")
    if GUICommon.GameIsBG2():
        GemRB.LeaveParty(slot, 2)
    elif GUICommon.GameIsBG1():
        GemRB.LeaveParty(slot, 1)
    else:
        GemRB.LeaveParty(slot)
    OpenReformPartyWindow()
    return
Example #9
0
def OptRadio (action, window, button_id, label_id, variable, value):
	"""Standard radio button for option windows"""

	button = window.GetControl (button_id)
	button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
	button.SetEvent (IE_GUI_BUTTON_ON_PRESS, action)
	button.SetVarAssoc (variable, value)
	if GUICommon.GameIsIWD2():
		button.SetSprites("GBTNOPT4", 0, 0, 1, 2, 3)
	elif GUICommon.GameIsIWD1() or GUICommon.GameIsBG1():
		button.SetSprites ("TOGGLE", 0, 0, 1, 3, 2)

	OptBuddyLabel (window, label_id)

	return button
Example #10
0
def OpenStoreIdentifyWindow ():
	global StoreIdentifyWindow
	global LeftButton

	GemRB.SetVar ("Index", -1)
	GemRB.SetVar ("TopIndex", 0)
	CloseWindows()

	StoreIdentifyWindow = Window = GemRB.LoadWindow (4)

	ScrollBar = Window.GetControl (7)
	ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RedrawStoreIdentifyWindow)

	TextArea = Window.GetControl (23)
	TextArea.SetFlags (IE_GUI_TEXTAREA_AUTOSCROLL)

	# Identify
	LeftButton = Button = Window.GetControl (5)
	Button.SetText (14133)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, IdentifyPressed)
	Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, InfoIdentifyWindow)

	# price ...
	Label = Window.GetControl (0x10000003)
	Label.SetText ("0")

	# 8-11 item slots, 0x1000000c-f labels
	for i in range (ItemButtonCount):
		Button = Window.GetControl (i+8)
		Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
		if GUICommon.GameIsIWD1() or GUICommon.GameIsIWD2():
			Button.SetSprites ("GUISTMSC", 0, 1,2,0,3)
			Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
		elif GUICommon.GameIsBG1():
			Button.SetBorder (0,0,0,0,0,32,32,192,128,0,1)
		else:
			Button.SetBorder (0,0,0,0,0,0,0,128,160,0,1)
		Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, SelectID)
		Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, InfoIdentifyWindow)
		Button.SetFont ("NUMBER")
		Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT|IE_GUI_BUTTON_ALIGN_TOP, OP_OR)
		Button.AttachScrollBar (ScrollBar)

	GUICommonWindows.SetSelectionChangeHandler( UpdateStoreIdentifyWindow )
	UpdateStoreIdentifyWindow ()
	Window.SetVisible (WINDOW_VISIBLE)
	return
Example #11
0
def InfoWindow (Slot, Item):
	global MessageWindow

	Identify = Slot['Flags'] & IE_INV_ITEM_IDENTIFIED

	MessageWindow = Window = GemRB.LoadWindow (12)

	# TODO: check non-bg2 games to see which label is which
	if GUICommon.GameIsBG2():
		NameLabel = Window.GetControl (0x10000000)
		FakeLabel = Window.GetControl (0x10000007)
	else:
		NameLabel = Window.GetControl (0x10000007)
		FakeLabel = Window.GetControl (0x10000000)

	#fake label
	FakeLabel.SetText ("")

	#description bam
	if GUICommon.GameIsBG1() or GUICommon.GameIsBG2():
		Button = Window.GetControl (7)
		Button.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_CENTER_PICTURES | IE_GUI_BUTTON_NO_IMAGE, OP_OR)
		Button.SetItemIcon (Slot['ItemResRef'], 2)

	#slot bam
	Button = Window.GetControl (2)
	Button.SetItemIcon (Slot['ItemResRef'], 0)

	TextArea = Window.GetControl (5)
	if Identify:
		NameLabel.SetText (Item['ItemNameIdentified'])
		TextArea.SetText (Item['ItemDescIdentified'])
	else:
		NameLabel.SetText (Item['ItemName'])
		TextArea.SetText (Item['ItemDesc'])

	#Done
	Button = Window.GetControl (4)
	Button.SetText (11973)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ErrorDone)

	# hide the empty button
	if GUICommon.GameIsBG2() or GUICommon.GameIsIWD2():
		Window.DeleteControl (9)

	Window.ShowModal (MODAL_SHADOW_GRAY)
	return
Example #12
0
def SpellsCancelPress():
    """Removes all known spells and close the window.

	This is only callable within character generation."""

    # remove all learned spells
    GUICommon.RemoveKnownSpells(pc, IE_SPELL_TYPE_WIZARD, 1, 9, 1)

    if GUICommon.GameIsBG2():
        # unload teh window and go back
        if SpellsWindow:
            SpellsWindow.Unload()
        GemRB.SetNextScript("CharGen6")  #haterace
    elif GUICommon.GameIsBG1():
        import CharGenCommon
        CharGenCommon.BackPress()
    else:
        print "Uh-oh in SpellsCancelPress in", GemRB.GameType
    return
Example #13
0
def OpenStoreRentWindow ():
	global StoreRentWindow, RentIndex

	CloseWindows()

	StoreRentWindow = Window = GemRB.LoadWindow (7)

	# room types
	RentIndex = -1
	for i in range (4):
		ok = Store['StoreRoomPrices'][i]
		Button = Window.GetControl (i)
		Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateStoreRentWindow)
		if ok<0:
			Button.SetState (IE_GUI_BUTTON_DISABLED) #disabled room icons are selected, not disabled
		else:
			Button.SetVarAssoc ("RentIndex", i)
			if RentIndex==-1:
				RentIndex = i

		Button = Window.GetControl (i+4)
		Button.SetText (14294+i)
		Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateStoreRentWindow)
		Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
		Button.SetVarAssoc ("RentIndex", i)
		if GUICommon.GameIsBG1():
			#these bioware guys screw up everything possible
			#remove this line if you fixed guistore
			Button.SetSprites ("GUISTROC",0, 1,2,0,3)
		if ok<0:
			Button.SetState (IE_GUI_BUTTON_DISABLED)

	# Rent
	Button = Window.GetControl (11)
	Button.SetText (14293)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, RentRoom)

	GemRB.SetVar ("RentIndex", RentIndex)

	GUICommonWindows.SetSelectionChangeHandler( UpdateStoreRentWindow )
	UpdateStoreRentWindow ()
	Window.SetVisible (WINDOW_VISIBLE)
	return
Example #14
0
def OptCheckbox (winhelp, ctlhelp, help_ta, window, button_id, label_id, label_strref, variable, handler=None, value=1):
	"""Standard checkbox for option windows"""

	button = window.GetControl (button_id)
	button.SetFlags (IE_GUI_BUTTON_CHECKBOX, OP_OR)
	if variable:
		button.SetVarAssoc (variable, value)

	if GUICommon.GameIsIWD2():
		button.SetSprites("GBTNOPT4", 0, 0, 1, 2, 3)
	elif GUICommon.GameIsIWD1() or GUICommon.GameIsBG1():
		button.SetSprites ("GMPPARBC", 3, 1, 2, 3, 5)

	if handler:
		button.SetEvent (IE_GUI_BUTTON_ON_PRESS, handler)
	else:
		# create an anonymous callback, so we don't need to create a separate function for each string
		# FIXME: IE_GUI_MOUSE_ENTER_BUTTON would be more UX-sensible, but interferes with toggling
		button.SetEvent (IE_GUI_BUTTON_ON_PRESS, lambda s=ctlhelp, ta=help_ta: ta.SetText (s))

	OptBuddyLabel (window, label_id, label_strref, help_ta, ctlhelp, winhelp)

	return button
Example #15
0
def FeedScroll ():
	global TextArea, Position

	Table = GemRB.LoadTable (TableName)
	if GUICommon.GameIsBG2():
		#this is a rather primitive selection but works for the games
		Value = Table.GetValue (0, 1)
		if Value == "REPUTATION":
			line = 2
		else:
			line = 1
		Value = Table.GetValue (line, 1)
	elif GUICommon.GameIsBG1():
		Value = Table.GetValue (Row, Position)
		if Value == 'NONE':
			Position = 1
		else:
			Position = Position + 1
	else:
		Value = Table.GetValue (Chapter, 1)

	TextArea.Append (Value, -1, 6)
	return
Example #16
0
def UpdateActionsWindow():
    """Redraws the actions section of the window."""

    global ActionsWindow, PortraitWindow, OptionsWindow
    global level, TopIndex

    if GUICommon.GameIsIWD2():
        Window = PortraitWindow
    else:
        Window = ActionsWindow

    if Window == -1:
        return

    if Window == None:
        return

    #fully redraw the side panes to cover the actions window
    #do this only when there is no 'otherwindow'
    if GUICommon.GameIsIWD2():
        if GemRB.GetVar("OtherWindow") != -1:
            return
    else:
        GUICommon.SetGamedaysAndHourToken()
        if OptionsWindow and OptionsWindow.HasControl(9):
            Button = OptionsWindow.GetControl(9)
            Button.SetTooltip(GemRB.GetString(
                16041))  # refetch the string, since the tokens changed
        elif ActionsWindow and ActionsWindow.HasControl(62):
            Button = ActionsWindow.GetControl(62)
            Button.SetTooltip(GemRB.GetString(16041))

        if GemRB.GetVar("OtherWindow") == -1:
            if PortraitWindow:
                PortraitWindow.Invalidate()
            if OptionsWindow:
                OptionsWindow.Invalidate()

    Selected = GemRB.GetSelectedSize()

    #setting up the disabled button overlay (using the second border slot)
    if not GUICommon.GameIsIWD2():
        for i in range(12):
            Button = Window.GetControl(i)
            if GUICommon.GameIsBG1():
                Button.SetBorder(0, 6, 6, 4, 4, 0, 254, 0, 255)
            Button.SetBorder(1, 0, 0, 0, 0, 50, 30, 10, 120, 0, 1)
            Button.SetFont("NUMBER")
            Button.SetText("")

    if Selected == 0:
        EmptyControls()
        return
    if Selected > 1:
        GroupControls()
        return

    #we are sure there is only one actor selected
    pc = GemRB.GameGetFirstSelectedActor()

    level = GemRB.GetVar("ActionLevel")
    TopIndex = GemRB.GetVar("TopIndex")
    if level == 0:
        #this is based on class
        Window.SetupControls(globals(), pc, ActionBarControlOffset)
    elif level == 1:
        Window.SetupEquipmentIcons(globals(), pc, TopIndex,
                                   ActionBarControlOffset)
    elif level == 2:  #spells
        GemRB.SetVar("Type", 3)
        Spellbook.SetupSpellIcons(Window, 3, TopIndex, ActionBarControlOffset)
    elif level == 3:  #innates
        GemRB.SetVar("Type", 4)
        Spellbook.SetupSpellIcons(Window, 4, TopIndex, ActionBarControlOffset)
    elif level == 4:  #quick weapon/item ability selection
        SetupItemAbilities(pc, GemRB.GetVar("Slot"))
    elif level == 5:  #all known mage spells
        GemRB.SetVar("Type", -1)
        Spellbook.SetupSpellIcons(Window, -1, TopIndex, ActionBarControlOffset)
    elif level == 6:  # iwd2 skills
        print "IWD2 skill selection is not implemented yet, ignoring!\n\n"
    elif level == 7:  # quickspells, but with innates too
        GemRB.SetVar("Type", 7)
        Spellbook.SetupSpellIcons(Window, 7, TopIndex, ActionBarControlOffset)
    return
Example #17
0
def GetStatOverview (pc, LevelDiff=[0,0,0]):
	StateTable = GemRB.LoadTable ("statdesc")

	GS = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s)
	GB = lambda s, pc=pc: GemRB.GetPlayerStat (pc, s, 1)
	GA = lambda s, col, pc=pc: GemRB.GetAbilityBonus (s, col, GS (s) )

	# everyone but bg1 has it somewhere
	if GUICommon.GameIsBG2():
		str_None = GemRB.GetString (61560)
	elif GUICommon.GameIsBG1():
		str_None = -1
	elif GUICommon.GameIsPST():
		str_None = GemRB.GetString (41275)
	else:
		str_None = GemRB.GetString (17093)

	stats = []
	# class levels
	# 16480 <CLASS>: Level <LEVEL>
	# Experience: <EXPERIENCE>
	# Next Level: <NEXTLEVEL>

	# collecting tokens for stat overview
	ClassTitle = GUICommon.GetActorClassTitle (pc)
	GemRB.SetToken ("CLASS", ClassTitle)
	Class = GemRB.GetPlayerStat (pc, IE_CLASS)
	Class = CommonTables.Classes.FindValue (5, Class)
	Class = CommonTables.Classes.GetRowName (Class)
	Dual = GUICommon.IsDualClassed (pc, 1)
	Multi = GUICommon.IsMultiClassed (pc, 1)
	XP = GemRB.GetPlayerStat (pc, IE_XP)
	LevelDrain = GS (IE_LEVELDRAIN)

	if GS (IE_STATE_ID) & STATE_DEAD:
		stats.append ( (11829,1,'c') ) # DEAD
		stats.append (None)

	if Multi[0] > 1: # we're multiclassed
		print "\tMulticlassed"
		Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]

		stats.append ( (19721,1,'c') )
		stats.append (None)
		for i in range (Multi[0]):
			ClassIndex = CommonTables.Classes.FindValue (5, Multi[i+1])
			ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (ClassIndex, 2))
			GemRB.SetToken ("CLASS", ClassTitle)
			Class = CommonTables.Classes.GetRowName (ClassIndex)
			GemRB.SetToken ("LEVEL", str (Levels[i]+LevelDiff[i]-int(LevelDrain/Multi[0])) )
			GemRB.SetToken ("EXPERIENCE", str (XP/Multi[0]) )
			if LevelDrain:
				stats.append ( (GemRB.GetString (19720),1,'d') )
				stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
			else:
				GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Levels[i]+LevelDiff[i], Class) )
				stats.append ( (GemRB.GetString (16480),"",'d') )
			stats.append (None)
			print "\t\tClass (Level):",Class,"(",Levels[i],")"

	elif Dual[0] > 0: # dual classed; first show the new class
		print "\tDual classed"
		stats.append ( (19722,1,'c') )
		stats.append (None)

		Levels = [GemRB.GetPlayerStat (pc, IE_LEVEL), GemRB.GetPlayerStat (pc, IE_LEVEL2), GemRB.GetPlayerStat (pc, IE_LEVEL3)]

		# the levels are stored in the class order (eg. FIGHTER_MAGE)
		# the current active class does not matter!
		if GUICommon.IsDualSwap (pc):
			Levels = [Levels[1], Levels[0], Levels[2]]

		Levels[0] += LevelDiff[0]

		ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (Dual[2], 2))
		GemRB.SetToken ("CLASS", ClassTitle)
		GemRB.SetToken ("LEVEL", str (Levels[0]-LevelDrain))
		Class = CommonTables.Classes.GetRowName (Dual[2])
		XP2 = GemRB.GetPlayerStat (pc, IE_XP)
		GemRB.SetToken ("EXPERIENCE", str (XP2) )
		if LevelDrain:
			stats.append ( (GemRB.GetString (19720),1,'d') )
			stats.append ( (GemRB.GetString (57435),1,'d') ) # LEVEL DRAINED
		else:
			GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Levels[0], Class) )
			stats.append ( (GemRB.GetString (16480),"",'d') )
		stats.append (None)

		# the first class (shown second)
		if Dual[0] == 1:
			ClassTitle = GemRB.GetString (CommonTables.KitList.GetValue (Dual[1], 2))
		elif Dual[0] == 2:
			ClassTitle = GemRB.GetString (CommonTables.Classes.GetValue (Dual[1], 2))
		GemRB.SetToken ("CLASS", ClassTitle)
		GemRB.SetToken ("LEVEL", str (Levels[1]) )

		# the xp table contains only classes, so we have to determine the base class for kits
		if Dual[0] == 2:
			BaseClass = CommonTables.Classes.GetRowName (Dual[1])
		else:
			BaseClass = GUICommon.GetKitIndex (pc)
			BaseClass = CommonTables.KitList.GetValue (BaseClass, 7)
			BaseClass = CommonTables.Classes.FindValue (5, BaseClass)
			BaseClass = CommonTables.Classes.GetRowName (BaseClass)
		# the first class' XP is discarded and set to the minimum level
		# requirement, so if you don't dual class right after a levelup,
		# the game would eat some of your XP
		XP1 = CommonTables.NextLevel.GetValue (BaseClass, str (Levels[1]))
		GemRB.SetToken ("EXPERIENCE", str (XP1) )

		# inactive until the new class SURPASSES the former
		if Levels[0] <= Levels[1]:
			# inactive
			stats.append ( (19719,1,'c') )
		else:
			stats.append ( (19720,1,'c') )
		stats.append (None)
	else: # single classed
		print "\tSingle classed"
		Level = GemRB.GetPlayerStat (pc, IE_LEVEL) + LevelDiff[0]
		GemRB.SetToken ("LEVEL", str (Level-LevelDrain))
		GemRB.SetToken ("EXPERIENCE", str (XP) )
		if LevelDrain:
			stats.append ( (19720,1,'c') )
			stats.append ( (57435,1,'c') ) # LEVEL DRAINED
		else:
			GemRB.SetToken ("NEXTLEVEL", LUCommon.GetNextLevelExp (Level, Class) )
			stats.append ( (16480,1,'c') )
		stats.append (None)
		print "\t\tClass (Level):",Class,"(",Level,")"

	# check to see if we have a level diff anywhere
	if sum (LevelDiff) == 0:
		effects = GemRB.GetPlayerStates (pc)
		if len (effects):
			for c in effects:
				tmp = StateTable.GetValue (ord(c)-66, 0)
				stats.append ( (tmp,c,'a') )
			stats.append (None)

	#proficiencies
	stats.append ( (8442,1,'c') )

	# look ma, I can use both hands
	if GUICommon.GameIsBG2():
		stats.append ( (61932, GS (IE_TOHIT), '0') )
		if (GemRB.IsDualWielding(pc)):
			stats.append ( (56911, GemRB.GetCombatDetails(pc, 0)["ToHit"], '0') )
			stats.append ( (56910, GemRB.GetCombatDetails(pc, 1)["ToHit"], '0') )
		else:
			stats.append ( (9457, GemRB.GetCombatDetails(pc, 0)["ToHit"], '0') )
	else:
		stats.append ( (9457, str(GS (IE_TOHIT))+" ("+str(GemRB.GetCombatDetails(pc, 0)["ToHit"])+")", '0') )
	tmp = GS (IE_NUMBEROFATTACKS)
	if (tmp&1):
		tmp2 = str (tmp/2) + chr (188)
	else:
		tmp2 = str (tmp/2)
	stats.append ( (9458, tmp2, '') )
	stats.append ( (9459, GSNN (pc, IE_LORE), '0') )
	if GUICommon.GameIsBG1() or GUICommon.GameIsIWD1():
		stats.append ( (19224, GS (IE_RESISTMAGIC), '') )

	# party's reputation
	reptxt = GetReputation (GemRB.GameGetReputation ()/10)
	stats.append ( (9465, reptxt, '') )
	stats.append ( (9460, GSNN (pc, IE_LOCKPICKING), '') )
	stats.append ( (9462, GSNN (pc, IE_TRAPS), '') )
	stats.append ( (9463, GSNN (pc, IE_PICKPOCKET), '') )
	stats.append ( (9461, GSNN (pc, IE_STEALTH), '') )
	HatedRace = GS (IE_HATEDRACE)
	if HatedRace:
		HateTable = GemRB.LoadTable ("haterace")
		Racist = HateTable.FindValue (1, HatedRace)
		if Racist != -1:
			HatedRace = HateTable.GetValue (Racist, 0)
			stats.append ( (15982, GemRB.GetString (HatedRace), '') )

	# these skills were new in bg2
	if GUICommon.GameIsBG2() or GUICommon.GameIsIWD1():
		stats.append ( (34120, GSNN (pc, IE_HIDEINSHADOWS), '') )
		stats.append ( (34121, GSNN (pc, IE_DETECTILLUSIONS), '') )
		stats.append ( (34122, GSNN (pc, IE_SETTRAPS), '') )
	stats.append ( (12128, GS (IE_BACKSTABDAMAGEMULTIPLIER), 'x') )
	stats.append ( (12126, GS (IE_TURNUNDEADLEVEL), '') )

	#this hack only displays LOH if we know the spell
	#TODO: the core should just not set LOH if the paladin can't learn it
	if (Spellbook.HasSpell (pc, IE_SPELL_TYPE_INNATE, 0, "SPCL211") >= 0):
		stats.append ( (12127, GS (IE_LAYONHANDSAMOUNT), '') )

	#script
	aiscript = GemRB.GetPlayerScript (pc )
	stats.append ( (2078, aiscript, '') )
	stats.append (None)

	# 17379 Saving throws
	stats.append (17379)
	# 17380 Paralyze/Poison/Death
	stats.append ( (17380, IE_SAVEVSDEATH, 's') )
	# 17381 Rod/Staff/Wand
	stats.append ( (17381, IE_SAVEVSWANDS, 's') )
	# 17382 Petrify/Polymorph
	stats.append ( (17382, IE_SAVEVSPOLY, 's') )
	# 17383 Breath weapon
	stats.append ( (17383, IE_SAVEVSBREATH, 's') )
	# 17384 Spells
	stats.append ( (17384, IE_SAVEVSSPELL, 's') )
	stats.append (None)

	# 9466 Weapon proficiencies
	stats.append (9466)
	table = GemRB.LoadTable ("weapprof")
	RowCount = table.GetRowCount ()
	# the first 7 profs are foobared (bg1 style)
	if GUICommon.GameIsBG2():
		offset = 8
	else:
		offset = 0
	for i in range (offset, RowCount):
		# iwd displays capitalised strings
		# FIXME: ignore it and do the capitalisation manually, so it works for everyone
		if GUICommon.GameIsIWD1():
			text = table.GetValue (i, 3)
		else:
			text = table.GetValue (i, 1)
		stat = table.GetValue (i, 0)
		if not offset and not GUICommon.GameIsIWD1(): # TODO: fishy, recheck
			stat = stat + IE_PROFICIENCYBASTARDSWORD
		stats.append ( (text, GS (stat)&0x07, '+') )
	stats.append (None)

	# 11766 AC Bonuses
	stats.append (11766)
	# 11770 AC vs. Crushing
	stats.append ((11770, GS (IE_ACCRUSHINGMOD), 'p'))
	# 11767 AC vs. Missile
	stats.append ((11767, GS (IE_ACMISSILEMOD), 'p'))
	# 11769 AC vs. Piercing
	stats.append ((11769, GS (IE_ACPIERCINGMOD), 'p'))
	# 11768 AC vs. Slashing
	stats.append ((11768, GS (IE_ACSLASHINGMOD), 'p'))
	stats.append (None)

	# 10315 Ability bonuses
	stats.append (10315)
	value = GemRB.GetPlayerStat (pc, IE_STR)
	ex = GemRB.GetPlayerStat (pc, IE_STREXTRA)
	# 10332 to hit
	stats.append ( (10332, GemRB.GetAbilityBonus (IE_STR,0,value,ex), 'p') )
	# 10336 damage
	stats.append ( (10336, GemRB.GetAbilityBonus (IE_STR,1,value,ex), 'p') )
	# 10337 open doors (bend bars lift gates)
	stats.append ( (10337, GemRB.GetAbilityBonus (IE_STR,2,value,ex), '0') )
	# 10338 weight allowance
	stats.append ( (10338, GemRB.GetAbilityBonus (IE_STR,3,value,ex), '0') )
	# 10339 AC
	stats.append ( (10339, GA (IE_DEX,2), '0') )
	# 10340 Missile adjustment
	stats.append ( (10340, GA (IE_DEX,1), 'p') )
	# 10341 Reaction adjustment
	stats.append ( (10341, GA (IE_DEX,0), 'p') )
	# 10342 CON HP Bonus/Level
	# dual-classed chars get no bonus while the primary class is inactive
	# and the new class' bonus afterwards
	# single- and multi-classed chars are straightforward - the highest class bonus counts
	if GUICommon.IsWarrior (pc):
		stats.append ( (10342, GA (IE_CON, 1), 'p') )
	else:
		stats.append ( (10342, GA (IE_CON, 0), 'p') )
	# 10343 Chance To Learn spell
	if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_WIZARD, 0, 0)>0:
		stats.append ( (10343, GA (IE_INT,0), '%' ) )
	# 10347 Reaction
	stats.append ( (10347, GA (IE_REPUTATION,0), '0') )
	stats.append (None)

	# 10344 Bonus Priest spells
	if GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, 0, 0)>0:
		stats.append (10344)
		for level in range (7):
			GemRB.SetToken ("SPELLLEVEL", str (level+1) )
			#get the bonus spell count
			base = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level, 0)
			if base:
				count = GemRB.GetMemorizableSpellsCount (pc, IE_SPELL_TYPE_PRIEST, level)
				stats.append ( (GemRB.GetString (10345), count-base, 'r') )
		stats.append (None)

	# only bg2 displayed all the resistances, but it is useful information
	# Resistances
	if GUICommon.GameIsIWD1():
		stats.append (15544)
	else:
		stats.append (32204)
	# 32213 Normal Fire
	stats.append ((32213, GS (IE_RESISTFIRE), '%'))
	# 32222 Magic Fire
	stats.append ((32222, GS (IE_RESISTMAGICFIRE), '%'))
	# 32214 Normal Cold
	stats.append ((32214, GS (IE_RESISTCOLD), '%'))
	# 32223 Magic Cold
	stats.append ((32223, GS (IE_RESISTMAGICCOLD), '%'))
	# 32220 Electricity
	stats.append ((32220, GS (IE_RESISTELECTRICITY), '%'))
	# 32221 Acid
	stats.append ((32221, GS (IE_RESISTACID), '%'))
	if GUICommon.GameIsBG2():
		# Magic (others show it higher up)
		stats.append ((62146, GS (IE_RESISTMAGIC), '%'))
	# Magic Damage
	stats.append ((32233, GS (IE_MAGICDAMAGERESISTANCE), '%'))
	# Missile
	stats.append ((11767, GS (IE_RESISTMISSILE), '%'))
	# Slashing
	stats.append ((11768, GS (IE_RESISTSLASHING), '%'))
	# Piercing
	stats.append ((11769, GS (IE_RESISTPIERCING), '%'))
	# Crushing
	stats.append ((11770, GS (IE_RESISTCRUSHING), '%'))
	# Poison
	stats.append ((14017, GS (IE_RESISTPOISON), '%'))
	stats.append (None)

	if GUICommon.GameIsBG2():
		# Weapon Style bonuses
		stats.append (32131)
		wstyle = GemRB.GetCombatDetails (pc, 0)["Style"] # equipped weapon style + 1000 * proficiency level
		profcount = wstyle / 1000
		if profcount:
			wstyletables = { IE_PROFICIENCY2WEAPON:"wstwowpn", IE_PROFICIENCY2HANDED:"wstwohnd", IE_PROFICIENCYSINGLEWEAPON:"wssingle", IE_PROFICIENCYSWORDANDSHIELD:"wsshield" }
			bonusrefs = { "THAC0BONUSRIGHT":56911, "THAC0BONUSLEFT":56910, "DAMAGEBONUS":10336, "CRITICALHITBONUS":32140, "PHYSICALSPEED":32141, "AC":10339, "ACVSMISSLE":10340 }
			WStyleTable = GemRB.LoadTable (wstyletables[wstyle%1000])
			for col in range(WStyleTable.GetColumnCount()):
				value = WStyleTable.GetValue (profcount, col)
				stats.append ((bonusrefs[WStyleTable.GetColumnName(col)], value, ''))
		stats.append (None)

	res = []
	lines = 0
	for s in stats:
		try:
			strref, val, type = s
			if val == 0 and type != '0':
				continue
			if type == '+': #pluses
				res.append ("[capital=0]"+GemRB.GetString (strref) + ' '+ '+' * val)
			elif type == 'p': #a plus prefix if positive
				if val > 0:
					res.append ("[capital=0]" + GemRB.GetString (strref) + ' +' + str (val) )
				else:
					res.append ("[capital=0]" + GemRB.GetString (strref) + ' ' + str (val) )
			elif type == 'r': #a plus prefix if positive, strref is an already resolved string
				if val > 0:
					res.append ("[capital=0]" + strref + ' +' + str (val) )
				else:
					res.append ("[capital=0]" + strref + ' ' + str (val) )
			elif type == 's': #both base and (modified) stat, but only if they differ
				base = GB (val)
				stat = GS (val)
				base_str = "[capital=0]" + GemRB.GetString (strref) + ': ' + str(stat)
				if base == stat:
					res.append (base_str)
				else:
					res.append (base_str + " (" + str(stat-base) + ")")
			elif type == 'x': #x character before value
				res.append ("[capital=0]"+GemRB.GetString (strref) +': x' + str (val) )
			elif type == 'a': #value (portrait icon) + string
				res.append ("[capital=2]"+val+" "+GemRB.GetString (strref))
			elif type == 'b': #strref is an already resolved string
				res.append ("[capital=0]"+strref+": "+str (val))
			elif type == 'c': #normal string
				res.append ("[capital=0]"+GemRB.GetString (strref))
			elif type == 'd': #strref is an already resolved string
				res.append ("[capital=0]"+strref)
			elif type == '0': #normal value
				res.append (GemRB.GetString (strref) + ': ' + str (val))
			else: #normal value + type character, for example percent sign
				res.append ("[capital=0]"+GemRB.GetString (strref) + ': ' + str (val) + type)
			lines = 1
		except:
			if s != None:
				res.append ("[capital=0]"+ GemRB.GetString (s) )
				lines = 0
			else:
				if not lines and str_None != -1:
					res.append (str_None)
				res.append ("")
				lines = 0

	return "\n".join (res)
Example #18
0
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 GUICommon.GameIsBG1()):
                    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 GUICommon.GameIsBG1() 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 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
Example #19
0
def SetupMenuWindowControls(Window, Gears, ReturnToGame):
    """Sets up all of the basic control windows."""

    global OptionsWindow, ActionBarControlOffset

    OptionsWindow = Window
    # FIXME: add "(key)" to tooltips!

    if GUICommon.GameIsIWD2():
        ActionBarControlOffset = 6
        SetupIWD2WindowControls(Window, Gears, ReturnToGame)
        return

    # Return to Game
    Button = Window.GetControl(0)
    Button.SetTooltip(16313)
    Button.SetVarAssoc("SelectedWindow", 0)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)
    if GUICommon.GameIsBG1():
        # enabled BAM isn't present in .chu, defining it here
        Button.SetSprites("GUILSOP", 0, 16, 17, 28, 16)

    # Map
    Button = Window.GetControl(1)
    Button.SetTooltip(16310)
    Button.SetVarAssoc("SelectedWindow", 1)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIMA.OpenMapWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 0, 1, 20, 0)

    # Journal
    Button = Window.GetControl(2)
    Button.SetTooltip(16308)
    Button.SetVarAssoc("SelectedWindow", 2)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIJRNL.OpenJournalWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 4, 5, 22, 4)

    # Inventory
    Button = Window.GetControl(3)
    Button.SetTooltip(16307)
    Button.SetVarAssoc("SelectedWindow", 3)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIINV.OpenInventoryWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 2, 3, 21, 2)

    # Records
    Button = Window.GetControl(4)
    Button.SetTooltip(16306)
    Button.SetVarAssoc("SelectedWindow", 4)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIREC.OpenRecordsWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 6, 7, 23, 6)

    # Mage
    Button = Window.GetControl(5)
    Button.SetTooltip(16309)
    Button.SetVarAssoc("SelectedWindow", 5)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIMG.OpenMageWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 8, 9, 24, 8)

    # Priest
    Button = Window.GetControl(6)
    Button.SetTooltip(14930)
    Button.SetVarAssoc("SelectedWindow", 6)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIPR.OpenPriestWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 10, 11, 25, 10)

    # Options
    Button = Window.GetControl(7)
    Button.SetTooltip(16311)
    Button.SetVarAssoc("SelectedWindow", 7)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIOPT.OpenOptionsWindow)
    if GUICommon.GameIsBG1():
        Button.SetSprites("GUILSOP", 0, 12, 13, 26, 12)

    # Party mgmt
    Button = Window.GetControl(8)
    Button.SetTooltip(16312)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None)  #TODO: OpenPartyWindow

    # pause button
    if Gears:
        # Pendulum, gears, sun/moon dial (time)
        # FIXME: display all animations: CPEN, CGEAR, CDIAL
        if GUICommon.HasHOW():  # how doesn't have this in the right place
            pos = GemRB.GetSystemVariable(SV_HEIGHT) - 71
            Window.CreateButton(9, 6, pos, 64, 71)
        Button = Window.GetControl(9)
        if GUICommon.GameIsBG2():
            Label = Button.CreateLabelOnButton(0x10000009, "NORMAL", 0)
            Label.SetAnimation("CPEN")

        Button.SetAnimation("CGEAR")
        if GUICommon.GameIsBG2():
            Button.SetBAM("CDIAL", 0, 0)
        Button.SetState(IE_GUI_BUTTON_ENABLED)
        Button.SetFlags(
            IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_ANIMATED
            | IE_GUI_BUTTON_NORMAL, OP_SET)
        Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.GearsClicked)
        GUICommon.SetGamedaysAndHourToken()
        Button.SetTooltip(GemRB.GetString(16041))
        rb = 11
    else:
        rb = 9

    # Rest
    if Window.HasControl(rb):
        Button = Window.GetControl(rb)
        Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommon.RestPress)
        Button.SetTooltip(11942)

    MarkMenuButton(Window)

    if PortraitWindow:
        UpdatePortraitWindow()
    return
Example #20
0
def OpenLevelUpWindow():
    """Sets up the level up window."""
    import GUIREC

    global LevelUpWindow, TextAreaControl, NewProfPoints, actor
    global DoneButton
    global NewSkillPoints, KitName, LevelDiff
    global Level, Classes, NumClasses, DualSwap, IsMulti
    global OldHPMax, OldSaves, OldLore, OldThaco, DeltaDSpells, DeltaWSpells
    global NewDSpells, NewWSpells, OldDSpells, OldWSpells, pc, HLACount, ClassName, IsDual

    LevelUpWindow = GemRB.LoadWindow(3)

    if GUICommon.GameIsBG2():
        InfoButton = LevelUpWindow.GetControl(125)
        InfoButton.SetText(13707)
        InfoButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpInfoPress)

    DoneButton = LevelUpWindow.GetControl(0)
    DoneButton.SetText(11962)
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpDonePress)
    DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
    DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # hide "Character Generation"
    Label = LevelUpWindow.CreateLabel(0x1000007e, 0, 0, 0, 0, "NUMBER", "", 1)

    # name
    pc = GemRB.GameGetSelectedPCSingle()
    actor = Actor.Actor(pc)
    Label = LevelUpWindow.GetControl(0x10000000 + 90)
    Label.SetText(GemRB.GetPlayerName(pc))

    if GUICommon.GameIsBG1() or GUICommon.GameIsIWD1():
        # armorclass
        Label = LevelUpWindow.GetControl(0x10000057)
        ac = GemRB.GetPlayerStat(pc, IE_ARMORCLASS)
        #This is a temporary solution, the core engine should set the stat correctly!
        ac += GemRB.GetAbilityBonus(IE_DEX, 2, GemRB.GetPlayerStat(pc, IE_DEX))
        Label.SetText(str(ac))
        Label.SetTooltip(17183)

        # hp now
        Label = LevelUpWindow.GetControl(0x10000058)
        Label.SetText(str(GemRB.GetPlayerStat(pc, IE_HITPOINTS)))
        Label.SetTooltip(17184)

        # hp max
        Label = LevelUpWindow.GetControl(0x10000059)
        Label.SetText(str(GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS)))
        Label.SetTooltip(17378)

    # some current values
    OldHPMax = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS, 1)
    OldThaco = GemRB.GetPlayerStat(pc, IE_TOHIT, 1)
    OldLore = GemRB.GetPlayerStat(pc, IE_LORE, 1)
    for i in range(5):
        OldSaves[i] = GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH + i, 1)

    # class
    Label = LevelUpWindow.GetControl(0x10000000 + 106)
    Label.SetText(GUICommon.GetActorClassTitle(pc))
    print "Title:", GUICommon.GetActorClassTitle(
        pc), "\tActor Title:", actor.ClassTitle()

    Class = GemRB.GetPlayerStat(pc, IE_CLASS)
    print "Class:", Class, "\tActor Class:", actor.classid
    SkillTable = GemRB.LoadTable("skills")

    # kit
    ClassName = GUICommon.GetClassRowName(Class, "class")
    Kit = GUICommon.GetKitIndex(pc)
    print "Kit:", Kit, "\tActor Kit:", actor.KitIndex()
    print "ClassName:", ClassName, "\tActor ClassNames:", actor.ClassNames()

    # need this for checking gnomes
    RaceName = GemRB.GetPlayerStat(pc, IE_RACE, 1)
    RaceName = CommonTables.Races.FindValue(3, RaceName)
    RaceName = CommonTables.Races.GetRowName(RaceName)

    # figure our our proficiency table and index
    if Kit == 0:
        KitName = ClassName
    else:
        #rowname is just a number, the kitname is the first data column
        KitName = CommonTables.KitList.GetValue(Kit, 0)

    # our multiclass variables
    IsMulti = GUICommon.IsMultiClassed(pc, 1)
    Classes = [IsMulti[1], IsMulti[2], IsMulti[3]]
    NumClasses = IsMulti[0]  # 2 or 3 if IsMulti; 0 otherwise
    IsMulti = NumClasses > 1
    IsDual = 0
    DualSwap = 0

    # not multi, check dual
    if not IsMulti:
        # check if we're dual classed
        IsDual = GUICommon.IsDualClassed(pc, 1)
        Classes = [IsDual[2], IsDual[1]]  # make sure the new class is first

        # either dual or single only care about 1 class
        NumClasses = 1

        # not dual, must be single
        if IsDual[0] == 0:
            Classes = [Class]
        else:  # make sure Classes[1] is a class, not a kit
            if IsDual[0] == 1:  # kit
                Classes[1] = CommonTables.KitList.GetValue(IsDual[1], 7)
            else:  # class
                TmpClassName = GUICommon.GetClassRowName(Classes[1], "class")
                Classes[1] = CommonTables.Classes.GetValue(TmpClassName, "ID")

        # store a boolean for IsDual
        IsDual = IsDual[0] > 0

    print "NumClasses:", NumClasses, "\tActor NumClasses:", actor.NumClasses()

    Level = [0] * 3
    LevelDiff = [0] * 3

    # reorganize the leves if we're dc so the one we want to use is in Level[0]
    # and the old one is in Level[1] (used to regain old class abilities)
    if IsDual:
        # convert the classes from indicies to class id's
        DualSwap = GUICommon.IsDualSwap(pc)
        ClassName = GUICommon.GetClassRowName(Classes[0], "class")
        KitName = ClassName  # for simplicity throughout the code
        Classes[0] = CommonTables.Classes.GetValue(ClassName, "ID")
        # Class[1] is taken care of above

        # we need the old level as well
        if DualSwap:
            Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL)
        else:
            Level[1] = GemRB.GetPlayerStat(pc, IE_LEVEL2)

    print "Classes:", Classes, "\tActor Classes:", actor.Classes()
    print "IsDual:", IsDual > 0, "\tActor IsDual", actor.isdual

    hp = 0
    HaveCleric = 0
    # clear some globals, since we may get called multiple times with different classes
    DeltaWSpells = 0
    DeltaDSpells = 0
    OldDSpells = [0] * 7
    OldWSpells = [0] * 9
    NewDSpells = [0] * 7
    NewWSpells = [0] * 9

    # get a bunch of different things each level
    for i in range(NumClasses):
        #		print "Class:",Classes[i]
        # we don't care about the current level, but about the to-be-achieved one
        # get the next level
        Level[i] = LUCommon.GetNextLevelFromExp(
            GemRB.GetPlayerStat(pc, IE_XP) / NumClasses, Classes[i])
        TmpClassName = GUICommon.GetClassRowName(Classes[i], "class")

        # find the level diff for each classes (3 max, obviously)
        if i == 0:
            if DualSwap:
                LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2)
            else:
                LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL)
        elif i == 1:
            LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL2)
        elif i == 2:
            LevelDiff[i] = Level[i] - GemRB.GetPlayerStat(pc, IE_LEVEL3)


#		print "Level (",i,"):",Level[i]
#		print "Level Diff (",i,"):",LevelDiff[i]

# save our current and next spell amounts
        StartLevel = Level[i] - LevelDiff[i]
        DruidTable = CommonTables.ClassSkills.GetValue(TmpClassName,
                                                       "DRUIDSPELL", 0)
        ClericTable = CommonTables.ClassSkills.GetValue(
            TmpClassName, "CLERICSPELL", 0)
        MageTable = CommonTables.ClassSkills.GetValue(TmpClassName,
                                                      "MAGESPELL", 0)

        # see if we have mage spells
        if MageTable != "*":
            # we get 1 extra spell per level if we're a specialist
            Specialist = 0
            if CommonTables.KitList.GetValue(
                    Kit, 7) == 1:  # see if we're a kitted mage
                Specialist = 1
            MageTable = GemRB.LoadTable(MageTable)
            # loop through each spell level and save the amount possible to cast (current)
            for j in range(MageTable.GetColumnCount()):
                NewWSpells[j] = MageTable.GetValue(str(Level[i]), str(j + 1),
                                                   1)
                OldWSpells[j] = MageTable.GetValue(str(StartLevel), str(j + 1),
                                                   1)
                if NewWSpells[
                        j] > 0:  # don't want specialist to get 1 in levels they should have 0
                    NewWSpells[j] += Specialist
                if OldWSpells[j] > 0:
                    OldWSpells[j] += Specialist
            DeltaWSpells = sum(NewWSpells) - sum(OldWSpells)
        elif ClericTable != "*":
            # check for cleric spells
            if not GemRB.HasResource(ClericTable, RES_2DA, 1):
                ClericTable = "MXSPLPRS"  # iwd1 doesn't have a DRUIDSPELL column in the table
            ClericTable = GemRB.LoadTable(ClericTable)
            HaveCleric = 1
            # same as above
            for j in range(ClericTable.GetColumnCount()):
                NewDSpells[j] = ClericTable.GetValue(str(Level[i]), str(j + 1),
                                                     1)
                OldDSpells[j] = ClericTable.GetValue(str(StartLevel),
                                                     str(j + 1), 1)
            DeltaDSpells = sum(NewDSpells) - sum(OldDSpells)
        elif DruidTable != "*":
            # clerics have precedence in multis (ranger/cleric)
            if HaveCleric == 0:
                #use MXSPLPRS if we can't find the resource (SoA fix)
                if not GemRB.HasResource(DruidTable, RES_2DA):
                    DruidTable = "MXSPLPRS"

                # check druid spells
                DruidTable = GemRB.LoadTable(DruidTable)
                # same as above
                for j in range(DruidTable.GetColumnCount()):
                    NewDSpells[j] = DruidTable.GetValue(
                        str(Level[i]), str(j + 1), 1)
                    OldDSpells[j] = DruidTable.GetValue(
                        str(StartLevel), str(j + 1), 1)
                DeltaDSpells = sum(NewDSpells) - sum(OldDSpells)

        # setup class bonuses for this class
        if IsMulti or IsDual or Kit == 0:
            ABTable = CommonTables.ClassSkills.GetValue(
                TmpClassName, "ABILITIES")
        else:  # single-classed with a kit
            ABTable = CommonTables.KitList.GetValue(str(Kit), "ABILITIES")

        # add the abilites if we have a table to ref
        if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1):
            GUICommon.AddClassAbilities(pc, ABTable, Level[i], LevelDiff[i])

    print "Actor CurrentLevels:", actor.Levels()
    print "Levels:", Level, "Actor NextLevels:", actor.NextLevels()
    print "LevelDiffs:", LevelDiff, "Actor LevelDiffs:", actor.LevelDiffs()

    #update our saves, thaco, hp and lore
    LUCommon.SetupSavingThrows(pc, Level)
    LUCommon.SetupThaco(pc, Level)
    LUCommon.SetupLore(pc, LevelDiff)
    LUCommon.SetupHP(pc, Level, LevelDiff)

    # use total levels for HLAs
    HLACount = 0
    if GUICommon.HasTOB():  # make sure SoA doesn't try to get it
        HLATable = GemRB.LoadTable("lunumab")
        # we need to check each level against a multi value (this is kinda screwy)
        if actor.multiclass:
            print "Actor HLA Names:",["MULTI"+str(actor.NumClasses())+name \
             for name in actor.ClassNames()]
        else:
            print "Actor HLA Names:", actor.ClassNames()

        for i in range(NumClasses):
            if IsMulti:
                # get the row name for lookup ex. MULTI2FIGHTER, MULTI3THIEF
                MultiName = GUICommon.GetClassRowName(Classes[i], "class")
                MultiName = "MULTI" + str(NumClasses) + MultiName
            else:
                MultiName = ClassName

            # if we can't learn for this class, we can't learn at all
            FirstLevel = HLATable.GetValue(MultiName, "FIRST_LEVEL", 1)
            if Level[i] < FirstLevel:
                HLACount = 0
                break

            if (Level[i] - LevelDiff[i]) < FirstLevel:
                # count only from FirstLevel up
                HLACount += (Level[i] - FirstLevel + 1)
            else:
                HLACount += LevelDiff[i]

        # set values required by the hla level up code
        HLACount = HLACount / HLATable.GetValue(ClassName, "RATE", 1)
        GemRB.SetVar("HLACount", HLACount)
    if GUICommon.GameIsBG2():
        HLAButton = LevelUpWindow.GetControl(126)
        if HLACount:
            HLAButton.SetText(4954)
            HLAButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUpHLAPress)
        else:
            HLAButton.SetFlags(IE_GUI_BUTTON_DISABLED, OP_OR)

    # setup our profs
    Level1 = []
    for i in range(len(Level)):
        Level1.append(Level[i] - LevelDiff[i])
    if GUICommon.GameIsBG2():
        LUProfsSelection.SetupProfsWindow(
            pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow,
            RedrawSkills, Level1, Level)
    else:
        LUProfsSelection.SetupProfsWindow(
            pc, LUProfsSelection.LUPROFS_TYPE_LEVELUP, LevelUpWindow,
            RedrawSkills, Level1, Level, 0, False, 0)
    NewProfPoints = GemRB.GetVar("ProfsPointsLeft")

    #we autohide the skills and let SetupSkillsWindow show them if needbe
    for i in range(4):
        HideSkills(i)
    if GUICommon.GameIsBG2():
        LUSkillsSelection.SetupSkillsWindow(
            pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow,
            RedrawSkills, Level1, Level)
    else:
        LUSkillsSelection.SetupSkillsWindow(
            pc, LUSkillsSelection.LUSKILLS_TYPE_LEVELUP, LevelUpWindow,
            RedrawSkills, Level1, Level, 0, False)
    NewSkillPoints = GemRB.GetVar("SkillPointsLeft")

    if GUICommon.GameIsBG2():
        TextAreaControl = LevelUpWindow.GetControl(110)
        TextAreaControl.SetText(GetLevelUpNews())
    else:
        TextAreaControl = LevelUpWindow.GetControl(42)
        TextAreaControl.SetText(GUIREC.GetStatOverview(pc, LevelDiff))

    RedrawSkills()
    GemRB.SetRepeatClickFlags(GEM_RK_DISABLE, OP_NAND)
    LevelUpWindow.ShowModal(MODAL_SHADOW_GRAY)

    # if we have a sorcerer who can learn spells, we need to do spell selection
    if (Classes[0] == 19) and (DeltaWSpells >
                               0):  # open our sorc spell selection window
        LUSpellSelection.OpenSpellsWindow(pc, "SPLSRCKN", Level[0],
                                          LevelDiff[0])
Example #21
0
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",
                            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
Example #22
0
def OpenOptionsWindow():
    """Open main options window"""

    global GameOptionsWindow, OptionsWindow, PortraitWindow
    global OldPortraitWindow, OldOptionsWindow

    if GUICommon.CloseOtherWindow(OpenOptionsWindow):
        CloseOptionsWindow()
        return

    GemRB.GamePause(1, 3)

    CommonWindow.CloseContainerWindow()
    GemRB.HideGUI()
    GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
    if GUICommon.GameIsBG1():
        GUICommonWindows.SetSelectionChangeHandler(None)

    GemRB.LoadWindowPack("GUIOPT", WIDTH, HEIGHT)
    GameOptionsWindow = Window = GemRB.LoadWindow(2)
    GemRB.SetVar("OtherWindow", GameOptionsWindow.ID)

    if OldOptionsWindow == None:
        # OptionsWindow is the leftmost menu bar window present in most of the games
        OldOptionsWindow = GUICommonWindows.OptionsWindow
        OptionsWindow = GemRB.LoadWindow(0)
        if GUICommon.GameIsBG2():
            GUICommonWindows.MarkMenuButton(OptionsWindow)
        GUICommonWindows.SetupMenuWindowControls(OptionsWindow, 0,
                                                 OpenOptionsWindow)
        OptionsWindow.SetFrame()
        if not GUICommon.GameIsBG1(
        ):  #not in PST either, but it has its own OpenOptionsWindow()
            OptionsWindow.SetFrame()
            #saving the original portrait window
            OldPortraitWindow = GUICommonWindows.PortraitWindow
            PortraitWindow = GUICommonWindows.OpenPortraitWindow(0)

    # Return to Game
    Button = Window.GetControl(11)
    Button.SetText(10308)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenOptionsWindow)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    # Quit Game
    Button = Window.GetControl(10)
    Button.SetText(13731)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenQuitMsgWindow)

    # Load Game
    Button = Window.GetControl(5)
    Button.SetText(13729)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenLoadMsgWindow)

    # Save Game
    Button = Window.GetControl(6)
    Button.SetText(13730)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenSaveMsgWindow)

    # Video Options
    Button = Window.GetControl(7)
    Button.SetText(17162)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenVideoOptionsWindow)

    # Audio Options
    Button = Window.GetControl(8)
    Button.SetText(17164)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenAudioOptionsWindow)

    # Gameplay Options
    Button = Window.GetControl(9)
    Button.SetText(17165)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenGameplayOptionsWindow)

    # game version, e.g. v1.1.0000
    VersionLabel = Window.GetControl(0x1000000b)
    VersionLabel.SetText(GEMRB_VERSION)

    if GUICommon.GameIsIWD2():
        # Keyboard shortcuts
        KeyboardButton = Window.GetControl(13)
        KeyboardButton.SetText(33468)
        KeyboardButton.SetEvent(IE_GUI_BUTTON_ON_PRESS,
                                OpenHotkeyOptionsWindow)

        # Movies
        MoviesButton = Window.GetControl(14)
        MoviesButton.SetText(15415)
        MoviesButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenMovieWindow)

    RestoreWinVisibility()

    return
Example #23
0
def ReactivateBaseClass():
    """Regains all abilities of the base dual-class.

	Proficiencies, THACO, saves, spells, and innate abilites,
	most noteably."""

    # we construct the Classes array, so that the active class is always first and the base is second
    ClassName = GUICommon.GetClassRowName(Classes[1], "class")
    KitIndex = GUICommon.GetKitIndex(pc)

    # reactivate all our proficiencies
    TmpTable = GemRB.LoadTable("weapprof")
    ProfsTableOffset = 0
    if GUICommon.GameIsBG2():
        ProfsTableOffset = 8  # skip bg1 weapprof.2da proficiencies
    ProfCount = TmpTable.GetRowCount() - ProfsTableOffset
    for i in range(ProfCount):
        ProfID = TmpTable.GetValue(i + ProfsTableOffset, 0)
        if GUICommon.GameIsBG1():
            ProfID = ProfID + IE_PROFICIENCYBASTARDSWORD
        Value = GemRB.GetPlayerStat(pc, ProfID)
        OldProf = (Value & 0x38) >> 3
        NewProf = Value & 0x07
        if OldProf > NewProf:
            Value = (OldProf << 3) | OldProf
            print "Value:", Value
            if GUICommon.GameIsBG2():
                GemRB.ApplyEffect(pc, "Proficiency", Value, ProfID)
            else:
                GemRB.SetPlayerStat(pc, ProfID, Value)

    # see if this thac0 is lower than our current thac0
    ThacoTable = GemRB.LoadTable("THAC0")
    TmpThaco = ThacoTable.GetValue(Classes[1] - 1, Level[1] - 1, 1)
    if TmpThaco < GemRB.GetPlayerStat(pc, IE_TOHIT, 1):
        GemRB.SetPlayerStat(pc, IE_TOHIT, TmpThaco)

    # see if all our saves are lower than our current saves
    SavesTable = CommonTables.Classes.GetValue(ClassName, "SAVE", 0)
    SavesTable = GemRB.LoadTable(SavesTable)
    for i in range(5):
        # see if this save is lower than our old save
        TmpSave = SavesTable.GetValue(i, Level[1] - 1)
        if TmpSave < GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH + i, 1):
            GemRB.SetPlayerStat(pc, IE_SAVEVSDEATH + i, TmpSave)

    # see if we're a caster
    SpellTables = [
        CommonTables.ClassSkills.GetValue(ClassName, "DRUIDSPELL", 0),
        CommonTables.ClassSkills.GetValue(ClassName, "CLERICSPELL", 0),
        CommonTables.ClassSkills.GetValue(ClassName, "MAGESPELL", 0)
    ]
    if SpellTables[2] != "*":  # casts mage spells
        # set up our memorizations
        SpellTable = GemRB.LoadTable(SpellTables[2])
        for i in range(9):
            # if we can cast more spells at this level (should be always), then update
            NumSpells = SpellTable.GetValue(Level[1] - 1, i)
            if NumSpells > GemRB.GetMemorizableSpellsCount(
                    pc, IE_SPELL_TYPE_WIZARD, i, 1):
                GemRB.SetMemorizableSpellsCount(pc, NumSpells,
                                                IE_SPELL_TYPE_WIZARD, i)
    elif SpellTables[1] != "*" or SpellTables[0] != "*":  # casts priest spells
        # get the correct table and mask
        if SpellTables[1] != "*":  # clerical spells
            SpellTable = GemRB.LoadTable(SpellTables[1])
            ClassMask = 0x4000
        else:  # druidic spells
            if not GemRB.HasResource(SpellTables[0], RES_2DA):
                SpellTables[0] = "MXSPLPRS"
            SpellTable = GemRB.LoadTable(SpellTables[0])
            ClassMask = 0x8000

        # loop through each spell level
        for i in range(7):
            # update if we can cast more spells at this level
            NumSpells = SpellTable.GetValue(str(Level[1]), str(i + 1), 1)
            if not NumSpells:
                continue
            if NumSpells > GemRB.GetMemorizableSpellsCount(
                    pc, IE_SPELL_TYPE_PRIEST, i, 1):
                GemRB.SetMemorizableSpellsCount(pc, NumSpells,
                                                IE_SPELL_TYPE_PRIEST, i)

            # also re-learn the spells if we have to
            # WARNING: this fixes the error whereby rangers dualed to clerics still got all druid spells
            #	they will now only get druid spells up to the level they could cast
            #	this should probably be noted somewhere (ranger/cleric multis still function the same,
            #	but that could be remedied if desired)
            Learnable = Spellbook.GetLearnablePriestSpells(
                ClassMask, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1)
            for k in range(
                    len(Learnable)):  # loop through all the learnable spells
                if Spellbook.HasSpell(
                        pc, IE_SPELL_TYPE_PRIEST, i, Learnable[k]
                ) < 0:  # only write it if we don't yet know it
                    GemRB.LearnSpell(pc, Learnable[k])

    # setup class bonuses for this class
    if KitIndex == 0:  # no kit
        ABTable = CommonTables.ClassSkills.GetValue(ClassName, "ABILITIES")
    else:  # kit
        ABTable = CommonTables.KitList.GetValue(KitIndex, 4, 0)
    print "ABTable:", ABTable

    # add the abilites if we have a table to ref
    if ABTable != "*" and GemRB.HasResource(ABTable, RES_2DA, 1):
        GUICommon.AddClassAbilities(pc, ABTable, Level[1],
                                    Level[1])  # relearn class abilites
Example #24
0
from GUIDefines import *

###################################################
GameOptionsWindow = None  # not in PST
PortraitWindow = None  # not in BG1 or PST
OldPortraitWindow = None  #not in BG1 or PST
OptionsWindow = None
OldOptionsWindow = None
HelpTextArea = None

LoadMsgWindow = None
QuitMsgWindow = None
SubOptionsWindow = None
SubSubOptionsWindow = None

if GUICommon.GameIsBG1():
    HelpTextArea2 = None
else:
    # just an alias to keep our logic from being plagued by too many GUICommon.GameIsBG1() checks
    HelpTextArea2 = HelpTextArea

if GUICommon.GameIsIWD2():
    WIDTH = 800
    HEIGHT = 600
else:
    WIDTH = 640
    HEIGHT = 480


###################################################
def CloseOptionsWindow():
Example #25
0
def StartTextScreen():
    global TextScreen, TextArea, Chapter, TableName, Row, Ticks

    if GUICommon.GameIsIWD2():
        GemRB.LoadWindowPack("GUICHAP", 800, 600)
    else:
        GemRB.LoadWindowPack("GUICHAP", 640, 480)
        if GUICommon.GameIsBG1() or GUICommon.GameIsBG2():
            Ticks = BGTICKS

    LoadPic = TableName = GemRB.GetGameString(STR_LOADMOS)
    #if there is no preset loadpic, try to determine it from the chapter
    #fixme: we always assume there isn't for non-bg2
    if GUICommon.GameIsBG2():
        if TableName == "":
            Chapter = GemRB.GetGameVar("CHAPTER") & 0x7fffffff
            TableName = "CHPTXT" + str(Chapter)
        ID = 62
    else:
        ID = GemRB.GetGameVar("CHAPTER") & 0x7fffffff
        Chapter = ID + 1

    #iwd2/bg2 has no separate music
    if GUICommon.GameIsIWD1():
        if LoadPic == "":
            GemRB.LoadMusicPL("chap0.mus")
        else:
            GemRB.LoadMusicPL("chap1.mus")
        TableName = "chapters"
    elif GUICommon.GameIsIWD2():
        GemRB.HardEndPL()
        TableName = "chapters"
    elif GUICommon.GameIsBG1() and TableName[:6] == "chptxt":
        GemRB.LoadMusicPL("chapter.mus")
    else:
        GemRB.HardEndPL()

    TextScreen = GemRB.LoadWindow(ID)
    TextScreen.SetFrame()

    TextArea = TextScreen.GetControl(2)
    TextArea.SetFlags(IE_GUI_TEXTAREA_SMOOTHSCROLL)
    TextArea.SetEvent(IE_GUI_TEXTAREA_OUT_OF_TEXT, FeedScroll)

    #caption
    Table = GemRB.LoadTable(TableName)
    if GUICommon.GameIsBG1():
        #these suckers couldn't use a fix row
        FindTextRow(Table)
    elif GUICommon.GameIsBG2():
        LoadPic = Table.GetValue(-1, -1)
        if LoadPic != "":
            TextScreen.SetPicture(LoadPic)
        FindTextRow(Table)
    else:
        Row = Chapter

    Value = Table.GetValue(Row, 0)
    #don't display the fake -1 string (No caption in toscst.2da)
    if Value != "NONE" and Value > 0 and TextScreen.HasControl(0x10000000):
        Label = TextScreen.GetControl(0x10000000)
        Label.SetText(Value)

    #done
    Button = TextScreen.GetControl(0)
    Button.SetText(11973)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, EndTextScreen)
    Button.SetFlags(IE_GUI_BUTTON_DEFAULT | IE_GUI_BUTTON_CANCEL, OP_OR)

    #replay
    Button = TextScreen.GetControl(3)
    Button.SetText(16510)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReplayTextScreen)

    GemRB.HideGUI()
    GUICommon.GameWindow.SetVisible(
        WINDOW_INVISIBLE)  #removing the gamecontrol screen
    TextScreen.SetVisible(WINDOW_VISIBLE)

    TextArea.Rewind(Ticks)
    GemRB.DisplayString(17556, 0xff0000)  #Paused for chapter text
    GemRB.GamePause(1, 1)
    return
Example #26
0
def SetupHP(pc, Level=None, LevelDiff=None):
    """Updates an actors hp based upon level.

	Level should contain the actors current level.
	LevelDiff should contain the change in levels.
	Level and LevelDiff must be of the same length.
	If either are None, they are filled with the actors current level."""

    Levels, NumClasses, Class = _SetupLevels(pc, Level, noclass=1)
    LevelDiffs, NumClasses, Class = _SetupLevels(pc, LevelDiff, noclass=1)
    if len(Levels) != len(LevelDiffs):
        return

    #adjust the class for multi/dual chars
    Class = [GemRB.GetPlayerStat(pc, IE_CLASS)]
    Multi = GUICommon.IsMultiClassed(pc, 1)
    Dual = GUICommon.IsDualClassed(pc, 1)
    NumClasses = 1
    if Multi[0] > 1:  #get each of the multi-classes
        NumClasses = Multi[0]
        Class = [Multi[1], Multi[2], Multi[3]]
    elif Dual[0]:  #only worry about the newer class
        #we only get the hp bonus if the old class is reactivated
        if (Levels[0] <= Levels[1]):
            return
        Class = GUICommon.GetClassRowName(Dual[2], "index")
        Class = [CommonTables.Classes.GetValue(Class, "ID")]
        #if Level and LevelDiff are passed, we assume it is correct
        if GUICommon.IsDualSwap(pc) and not Level and not LevelDiff:
            LevelDiffs = [LevelDiffs[1], LevelDiffs[0], LevelDiffs[2]]
    if NumClasses > len(Levels):
        return

    #get the correct hp for barbarians
    Kit = GUICommon.GetKitIndex(pc)
    ClassName = None
    if Kit and not Dual[0] and Multi[0] < 2:
        KitName = CommonTables.KitList.GetValue(Kit, 0, 0)
        if CommonTables.Classes.GetRowIndex(KitName) >= 0:
            ClassName = KitName

    # determine the minimum hp roll
    ConBonTable = GemRB.LoadTable("hpconbon")
    MinRoll = ConBonTable.GetValue(GemRB.GetPlayerStat(pc, IE_CON) - 1,
                                   2)  # MIN_ROLL column

    #loop through each class and update the hp
    OldHP = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS, 1)
    CurrentHP = 0
    Divisor = float(NumClasses)
    for i in range(NumClasses):
        #check this classes hp table for any gain
        if not ClassName or NumClasses > 1:
            ClassName = GUICommon.GetClassRowName(Class[i], "class")
        HPTable = CommonTables.Classes.GetValue(ClassName, "HP")
        HPTable = GemRB.LoadTable(HPTable)

        #make sure we are within table ranges
        MaxLevel = HPTable.GetRowCount() - 1
        LowLevel = Levels[i] - LevelDiffs[i]
        HiLevel = Levels[i]
        if LowLevel >= HiLevel:
            continue
        if LowLevel < 0:
            LowLevel = 0
        elif LowLevel > MaxLevel:
            LowLevel = MaxLevel
        if HiLevel < 0:
            HiLevel = 0
        elif HiLevel > MaxLevel:
            HiLevel = MaxLevel

        #add all the hp for the given level
        #we use ceil to ensure each class gets hp
        for level in range(LowLevel, HiLevel):
            sides = HPTable.GetValue(level, 0)
            rolls = HPTable.GetValue(level, 1)
            bonus = HPTable.GetValue(level, 2)

            # we only do a roll on core difficulty or higher
            # and if maximum HP rolls (bg2 and later) are disabled
            # and/or if it is bg1 chargen (I guess too many testers got annoyed)
            # BUT when we do roll, constitution gives a kind of a luck bonus to the roll
            if rolls:
                if GemRB.GetVar ("Difficulty Level") >= 3 and not GemRB.GetVar ("Maximum HP") \
                and not (GUICommon.GameIsBG1() and LowLevel == 0) and MinRoll < sides:
                    if MinRoll > 1:
                        roll = GemRB.Roll(rolls, sides, bonus)
                        if roll - bonus < MinRoll:
                            roll = MinRoll + bonus
                        AddedHP = int(roll / Divisor + 0.5)
                    else:
                        AddedHP = int(
                            GemRB.Roll(rolls, sides, bonus) / Divisor + 0.5)
                else:
                    AddedHP = int((rolls * sides + bonus) / Divisor + 0.5)
            else:
                AddedHP = int(bonus / Divisor + 0.5)
            # ensure atleast 1hp is given
            # this is safe for inactive dualclass levels too (handled above)
            if AddedHP == 0:
                AddedHP = 1
            CurrentHP += AddedHP

    #update our hp values
    GemRB.SetPlayerStat(pc, IE_MAXHITPOINTS, CurrentHP + OldHP)
    # HACK: account also for the new constitution bonus for the current hitpoints
    GemRB.SetPlayerStat(
        pc, IE_HITPOINTS,
        GemRB.GetPlayerStat(pc, IE_HITPOINTS, 1) + CurrentHP + 5)
    return
Example #27
0
def SetupProfsWindow (pc, type, window, callback, level1=[0,0,0], level2=[1,1,1], classid=0, scroll=True, profTableOffset=8):
	"""Opens the proficiency selection window.

	type specifies the type of selection we are doing; choices are above.
	window specifies the window to be updated.
	callback specifies the function to call on changes.
	classid is sent only during dualclassing to specify the new class."""

	global ProfsOffsetSum, ProfsOffsetButton1, ProfsOffsetLabel, ProfsOffsetStar, OddIDs
	global ProfsOffsetPress, ProfsPointsLeft, ProfsNumButtons, ProfsTopIndex
	global ProfsScrollBar, ProfsTableOffset, ProfsType
	global ProfsWindow, ProfsCallback, ProfsTextArea, ProfsColumn, ProfsTable, ProfCount
	global Profs2ndOffsetButton1, Profs2ndOffsetStar, Profs2ndOffsetLabel, ClassNameSave, ClassWeaponsTable

	# make sure we're within ranges
	GemRB.SetVar ("ProfsPointsLeft", 0)
	if not window or not callback or len(level1)!=len(level2):
		return

	# save the values we'll point to
	ProfsWindow = window
	ProfsCallback = callback
	ProfsTableOffset = profTableOffset
	ProfsType = type

	if type == LUPROFS_TYPE_CHARGEN and GUICommon.GameIsBG2(): #chargen
		ProfsOffsetSum = 9
		ProfsOffsetButton1 = 11
		ProfsOffsetStar = 27
		ProfsOffsetLabel = 1
		ProfsOffsetPress = 69
		ProfsNumButtons = 8
		ProfsTextArea = ProfsWindow.GetControl (68)
		ProfsTextArea.SetText (9588)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (78)
	elif type == LUPROFS_TYPE_CHARGEN and GUICommon.GameIsBG1(): #chargen
		ProfsOffsetSum = 9
		ProfsOffsetButton1 = 11
		ProfsOffsetStar = 27
		ProfsOffsetLabel = 1
		ProfsOffsetPress = 69
		ProfsNumButtons = 8
		ProfsTextArea = ProfsWindow.GetControl (68)
		ProfsTextArea.SetText (9588)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (78)
	elif type == LUPROFS_TYPE_LEVELUP and GUICommon.GameIsBG2(): #levelup
		ProfsOffsetSum = 36
		ProfsOffsetButton1 = 1
		ProfsOffsetStar = 48
		ProfsOffsetLabel = 24
		ProfsOffsetPress = 112
		ProfsNumButtons = 7
		ProfsTextArea = ProfsWindow.GetControl (110)
		ProfsScrollBar = ProfsWindow.GetControl (108)
	elif type == LUPROFS_TYPE_LEVELUP and GUICommon.GameIsBG1(): #levelup
		ProfsOffsetSum = 36
		ProfsOffsetButton1 = 1
		ProfsOffsetStar = 48
		ProfsOffsetLabel = 24
		ProfsOffsetPress = 17
		ProfsNumButtons = 8
		ProfsTextArea = ProfsWindow.GetControl (42)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (108)
	elif type == LUPROFS_TYPE_LEVELUP and GUICommon.GameIsIWD1(): #levelup
		ProfsOffsetSum = 36
		ProfsOffsetButton1 = 1
		ProfsOffsetStar = 48
		ProfsOffsetLabel = 24
		ProfsOffsetPress = -1
		ProfsNumButtons = 15 # 8+7, the 7 are done with the following vars
		Profs2ndOffsetButton1 = 150
		Profs2ndOffsetStar = 115
		Profs2ndOffsetLabel = 108
		ProfsTextArea = ProfsWindow.GetControl (42)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (108)
		OddIDs = 0
	elif type == LUPROFS_TYPE_DUALCLASS and GUICommon.GameIsIWD1(): #dualclass
		ProfsOffsetSum = 40
		ProfsOffsetButton1 = 50
		ProfsOffsetStar = 0
		ProfsOffsetLabel = 41
		ProfsOffsetPress = -1 #66
		ProfsNumButtons = 15
		Profs2ndOffsetButton1 = 78
		Profs2ndOffsetStar = 92
		Profs2ndOffsetLabel = 126
		ProfsTextArea = ProfsWindow.GetControl (74)
		ProfsTextArea.SetText (9588)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (None)
		OddIDs = 1
	elif type == LUPROFS_TYPE_DUALCLASS and GUICommon.GameIsBG1(): #dualclass
		ProfsOffsetSum = 40
		ProfsOffsetButton1 = 50
		ProfsOffsetStar = 0
		ProfsOffsetLabel = 41
		ProfsOffsetPress = -1 #FIXME
		ProfsNumButtons = 8
		ProfsTextArea = ProfsWindow.GetControl (74)
		ProfsTextArea.SetText (9588)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (None)
	elif type == LUPROFS_TYPE_DUALCLASS: #dualclass
		ProfsOffsetSum = 40
		ProfsOffsetButton1 = 50
		ProfsOffsetStar = 0
		ProfsOffsetLabel = 41
		ProfsOffsetPress = 66
		ProfsNumButtons = 8
		ProfsTextArea = ProfsWindow.GetControl (74)
		ProfsTextArea.SetText (9588)
		if (scroll):
			ProfsScrollBar = ProfsWindow.GetControl (78)
	else: #unknown
		return

	#nullify internal variables
	GemRB.SetVar ("ProfsTopIndex", 0)
	ProfsPointsLeft = 0
	ProfsTopIndex = 0

	ProfsTable = GemRB.LoadTable ("profs")
	if GUICommon.GameIsIWD1() or GUICommon.GameIsBG1():
		ClassWeaponsTable = GemRB.LoadTable ("clasweap")
	else:
		ClassWeaponsTable = None

	#get the class name
	IsDual = GUICommon.IsDualClassed (pc, 1)
	if classid: #for dual classes when we can't get the class dualing to
		Class = classid
	elif IsDual[0]:
		Class = CommonTables.Classes.GetValue (IsDual[2], 5)
	else:
		Class = GemRB.GetPlayerStat (pc, IE_CLASS)
	ClassName = CommonTables.Classes.FindValue (5, Class)
	ClassName = CommonTables.Classes.GetRowName (ClassName)

	# profs.2da has entries for everyone, so no need to muck around
	ProfsRate = ProfsTable.GetValue (ClassName, "RATE")

	#figure out how many prof points we have
	if sum (level1) == 0: #character is being generated (either chargen or dual)
		ProfsPointsLeft = ProfsTable.GetValue (ClassName, "FIRST_LEVEL")

	ProfIndex = 0
	IsMulti = GUICommon.IsMultiClassed (pc, 1)
	if IsMulti[0] > 1:
		# sum the levels, since the rate is for the combined multiclass
		ProfsPointsLeft += (sum(level2) - sum(level1))/ProfsRate
	else:
		if GUICommon.IsDualSwap (pc):
			ProfIndex = 1

		#we need these 2 number to floor before subtracting
		ProfsPointsLeft += level2[ProfIndex]/ProfsRate - level1[ProfIndex]/ProfsRate

	#setup prof vars for passing between functions
	ProfsTable = GemRB.LoadTable ("weapprof")

	# weapprof has no sorcerer entry
	if ClassName == "SORCERER":
		ClassName = "MAGE"
	ClassNameSave = ClassName

	# if we have the classweapons table, use it
	if ClassWeaponsTable:
		ProfsColumn = ClassWeaponsTable.GetRowIndex (ClassName)
	else:
		Kit = GUICommon.GetKitIndex (pc)
		if Kit and type != LUPROFS_TYPE_DUALCLASS and IsMulti[0]<2 and not IsDual[0]:
			#if we do kit with dualclass, we'll get the old kit
			#also don't want to worry about kitted multis
			ProfsColumn = CommonTables.KitList.GetValue (Kit, 5)
		else:
			ProfsColumn = ProfsTable.GetColumnIndex (ClassName)

	#setup some basic counts
	RowCount = ProfsTable.GetRowCount () - ProfsTableOffset + 1
	ProfCount = RowCount-ProfsNumButtons #decrease it with the number of controls

	ProfsAssignable = 0
	TwoWeapIndex = ProfsTable.GetRowIndex ("2WEAPON")
	for i in range(RowCount):
		ProfName = ProfsTable.GetValue (i+ProfsTableOffset, 1)
		#decrease it with the number of invalid proficiencies
		if ProfName > 0x1000000 or ProfName < 0:
			ProfCount -= 1

		#we only need the low 3 bits for profeciencies on levelup; otherwise
		#we just set them all to 0
		currentprof = 0
		if type == LUPROFS_TYPE_LEVELUP:
			stat = ProfsTable.GetValue (i+ProfsTableOffset, 0)
			if GUICommon.GameIsBG1():
				stat = stat + IE_PROFICIENCYBASTARDSWORD
			currentprof = GemRB.GetPlayerStat (pc, stat)&0x07
		else:
			#rangers always get 2 points in 2 weapons style
			if (i+ProfsTableOffset) == TwoWeapIndex and "RANGER" in ClassName.split("_"):
				currentprof = 2
		GemRB.SetVar ("Prof "+str(i), currentprof)
		GemRB.SetVar ("ProfBase "+str(i), currentprof)

		#see if we can assign to this prof
		if ClassWeaponsTable:
			maxprof = ClassWeaponsTable.GetValue (ProfsColumn, i) # this table has profs as rows
		else:
			maxprof = ProfsTable.GetValue(i+ProfsTableOffset, ProfsColumn)
		if maxprof > currentprof:
			ProfsAssignable += maxprof-currentprof

	#correct the profs left if we can't assign that much
	if ProfsPointsLeft > ProfsAssignable:
		ProfsPointsLeft = ProfsAssignable
	GemRB.SetVar ("ProfsPointsLeft", ProfsPointsLeft)

	# setup the +/- and info controls
	for i in range (ProfsNumButtons):
		if ProfsOffsetPress != -1:
			Button=ProfsWindow.GetControl(i+ProfsOffsetPress)
			Button.SetVarAssoc("Prof", i)
			Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ProfsJustPress)

		cid = i*2+ProfsOffsetButton1
		if Profs2ndOffsetButton1 != -1 and i > 7:
			cid = (i-8)*2+Profs2ndOffsetButton1

		Button=ProfsWindow.GetControl(cid)
		Button.SetVarAssoc("Prof", i)
		Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ProfsLeftPress)

		Button=ProfsWindow.GetControl(cid+1)
		Button.SetVarAssoc("Prof", i)
		Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ProfsRightPress)

	if(ProfsScrollBar):
		# proficiencies scrollbar
		ProfsScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, ProfsScrollBarPress)
		ProfsScrollBar.SetDefaultScrollBar ()
		ProfsScrollBar.SetVarAssoc ("ProfsTopIndex", ProfCount)
	ProfsRedraw (1)
	return
Example #28
0
def OpenStoreWindow ():
	global Store
	global StoreWindow, ActionWindow, PortraitWindow
	global OldPortraitWindow
	global store_funcs
	global Inventory, RepModTable, BarteringPC

	#these are function pointers, not strings
	#can't put this in global init, doh!
	store_funcs = (OpenStoreShoppingWindow,
	OpenStoreIdentifyWindow,OpenStoreStealWindow,
	OpenStoreHealWindow, OpenStoreDonateWindow,
	OpenStoreRumourWindow,OpenStoreRentWindow )

	RepModTable = GemRB.LoadTable ("repmodst")

	GemRB.HideGUI ()
	GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE) #removing the game control screen

	if GemRB.GetVar ("Inventory"):
		Inventory = 1
	else:
		Inventory = None
		# pause the game, so we don't get interrupted
		GemRB.GamePause (1, 1)

	GemRB.SetVar ("Action", 0)
	if GUICommon.GameIsIWD2():
		GemRB.LoadWindowPack ("GUISTORE", 800, 600)
	else:
		GemRB.LoadWindowPack ("GUISTORE", 640, 480)
	StoreWindow = Window = GemRB.LoadWindow (3)
	#saving the original portrait window
	OldPortraitWindow = GUICommonWindows.PortraitWindow
	if GUICommon.GameIsIWD2() or GUICommon.GameIsBG1():
		#PortraitWindow = GUICommonWindows.OpenPortraitWindow ()
		pass
	else:
		PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
	ActionWindow = GemRB.LoadWindow (0)
	#this window is static and grey, but good to stick the frame onto
	ActionWindow.SetFrame ()

	Store = GemRB.GetStore ()
	BarteringPC = GemRB.GameGetFirstSelectedPC ()

	# Done
	Button = Window.GetControl (0)
	Button.SetText (11973)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseStoreWindow)

	#Store type icon
	if not GUICommon.GameIsIWD2():
		Button = Window.GetControl (5)
		Button.SetSprites (storebams[Store['StoreType']],0,0,0,0,0)

	#based on shop type, these buttons will change
	store_type = Store['StoreType']
	store_buttons = Store['StoreButtons']
	for i in range (4):
		Buttons[i] = Button = Window.GetControl (i+1)
		Action = store_buttons[i]
		Button.SetVarAssoc ("Action", i)
		if Action>=0:
			Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
			if GUICommon.GameIsIWD1() or GUICommon.GameIsIWD2():
				Button.SetSprites ("GUISTBBC", Action, 1,2,0,0)
			else:
				Button.SetSprites ("GUISTBBC", Action, 0,1,2,0)
			Button.SetTooltip (storetips[Action])
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, store_funcs[Action])
			Button.SetState (IE_GUI_BUTTON_ENABLED)
		else:
			Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
			Button.SetTooltip ("")
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
			Button.SetState (IE_GUI_BUTTON_DISABLED)

	ActionWindow.SetVisible (WINDOW_VISIBLE)
	Window.SetVisible (WINDOW_VISIBLE)
	store_funcs[store_buttons[0]] ()
	if not GUICommon.GameIsIWD2():
		if GUICommon.GameIsBG1():
			GUICommonWindows.PortraitWindow.SetVisible (WINDOW_VISIBLE)
		else:
			PortraitWindow.SetVisible (WINDOW_VISIBLE)
	return
Example #29
0
def StartTextScreen():
    global TextScreen, TextArea, TableName, Row

    GemRB.GamePause(1, 3)

    ID = -1
    MusicName = "*"
    Message = 17556  # default: Paused for chapter text
    TableName = GemRB.GetGameString(STR_TEXTSCREEN)

    #iwd2/bg2 has no separate music
    if GUICommon.GameIsIWD1():
        if TableName == "":
            MusicName = "chap0"
        else:
            MusicName = "chap1"
        TableName = "chapters"
    elif GUICommon.GameIsIWD2():
        TableName = "chapters"

    if TableName == "":
        EndTextScreen()
        return
    else:
        TextTable = GemRB.LoadTable("textscrn", 1)
        if TextTable != None:
            TxtRow = TextTable.GetRowIndex(TableName)
            if TxtRow >= 0:
                ID = TextTable.GetValue(TxtRow, 0)
                MusicName = TextTable.GetValue(TxtRow, 1)
                Message = TextTable.GetValue(TxtRow, 2)

    if Message != "*":
        GemRB.DisplayString(Message, 0xff0000)

    if GUICommon.GameIsIWD2():
        GemRB.LoadWindowPack("GUICHAP", 800, 600)
    else:
        GemRB.LoadWindowPack("GUICHAP", 640, 480)

    if GUICommon.GameIsBG2():
        ID = 62
    elif ID == -1:
        #default: try to determine ID from current chapter
        ID = GemRB.GetGameVar("CHAPTER") & 0x7fffffff
        Chapter = ID + 1

    if MusicName != "*":
        GemRB.LoadMusicPL(MusicName + ".mus")
    else:
        GemRB.HardEndPL()

    TextScreen = GemRB.LoadWindow(ID)
    TextScreen.SetFrame()

    TextArea = TextScreen.GetControl(2)
    TextArea.SetFlags(IE_GUI_TEXTAREA_SMOOTHSCROLL)

    Table = GemRB.LoadTable(TableName)
    if GUICommon.GameIsBG1():
        #these suckers couldn't use a fix row
        FindTextRow(Table)
    elif GUICommon.GameIsBG2():
        LoadPic = Table.GetValue(-1, -1)
        if LoadPic != "":
            TextScreen.SetPicture(LoadPic)
        FindTextRow(Table)
    else:
        Row = Chapter

    #caption
    Value = Table.GetValue(Row, 0)
    #don't display the fake -1 string (No caption in toscst.2da)
    if Value != "NONE" and Value > 0 and TextScreen.HasControl(0x10000000):
        Label = TextScreen.GetControl(0x10000000)
        Label.SetText(Value)

    #done
    Button = TextScreen.GetControl(0)
    Button.SetText(11973)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, EndTextScreen)
    Button.SetFlags(IE_GUI_BUTTON_DEFAULT | IE_GUI_BUTTON_CANCEL, OP_OR)

    #replay
    Button = TextScreen.GetControl(3)
    Button.SetText(16510)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReplayTextScreen)

    #if this was opened from somewhere other than game control close that window
    GUICommon.CloseOtherWindow(None)
    GemRB.HideGUI()
    GUICommon.GameWindow.SetVisible(
        WINDOW_INVISIBLE)  #removing the gamecontrol screen
    TextScreen.SetVisible(WINDOW_VISIBLE)

    ReplayTextScreen()
    return
Example #30
0
def OpenCustomizeWindow():
    import GUIREC
    global CustomizeWindow, ScriptsTable, Gender

    pc = GemRB.GameGetSelectedPCSingle()
    if GemRB.GetPlayerStat(pc, IE_MC_FLAGS) & MC_EXPORTABLE:
        Exportable = 1
    else:
        Exportable = 0

    ScriptsTable = GemRB.LoadTable("SCRPDESC")
    GUIREC.ColorTable = GemRB.LoadTable("CLOWNCOL")
    Gender = GemRB.GetPlayerStat(pc, IE_SEX)
    CustomizeWindow = GemRB.LoadWindow(17)

    PortraitSelectButton = CustomizeWindow.GetControl(0)
    PortraitSelectButton.SetText(11961)
    if not Exportable:
        PortraitSelectButton.SetState(IE_GUI_BUTTON_DISABLED)

    SoundButton = CustomizeWindow.GetControl(1)
    SoundButton.SetText(10647)
    if not Exportable:
        SoundButton.SetState(IE_GUI_BUTTON_DISABLED)

    if not GUICommon.GameIsIWD2():
        ColorButton = CustomizeWindow.GetControl(2)
        ColorButton.SetText(10646)
        ColorButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIREC.OpenColorWindow)
        if not Exportable:
            ColorButton.SetState(IE_GUI_BUTTON_DISABLED)

    ScriptButton = CustomizeWindow.GetControl(3)
    ScriptButton.SetText(17111)

    #This button does not exist in bg1 and pst, but theoretically we could create it here
    if not (GUICommon.GameIsBG1() or GUICommon.GameIsPST()):
        BiographyButton = CustomizeWindow.GetControl(9)
        BiographyButton.SetText(18003)
        BiographyButton.SetEvent(IE_GUI_BUTTON_ON_PRESS,
                                 OpenBiographyEditWindow)
        if not Exportable:
            BiographyButton.SetState(IE_GUI_BUTTON_DISABLED)

    TextArea = CustomizeWindow.GetControl(5)
    TextArea.SetText(11327)

    CustomizeDoneButton = CustomizeWindow.GetControl(7)
    CustomizeDoneButton.SetText(11973)
    CustomizeDoneButton.SetState(IE_GUI_BUTTON_ENABLED)

    CancelButton = CustomizeWindow.GetControl(8)
    CancelButton.SetText(13727)
    CancelButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    PortraitSelectButton.SetEvent(IE_GUI_BUTTON_ON_PRESS,
                                  OpenPortraitSelectWindow)
    SoundButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenSoundWindow)
    ScriptButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenScriptWindow)
    CustomizeDoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CustomizeDonePress)
    CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CustomizeCancelPress)

    CustomizeWindow.ShowModal(MODAL_SHADOW_GRAY)
    return