예제 #1
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
예제 #2
0
def OpenHLAWindow (actor, numclasses, classes, levels):
	"""Opens the HLA selection window."""

	global HLAWindow, HLADoneButton, HLATextArea, HLACount, NumClasses, pc, Classes, Level
	global EnhanceGUI

	#enhance GUI?
	if (GemRB.GetVar("GUIEnhancements")&GE_SCROLLBARS):
		EnhanceGUI = 1

	# save our variables 
	pc = actor
	NumClasses = numclasses
	Classes = classes
	Level = levels
	HLACount = GemRB.GetVar ("HLACount")

	# we use the same window as sorcerer spell selection
	HLAWindow = GemRB.LoadWindow (8)

	# get all our HLAs (stored in HLAAbilities)
	GetHLAs ()

	# change the title to ABILITIES
	TitleLabel = HLAWindow.GetControl (0x10000017)
	TitleLabel.SetText (63818)

	# create the done button
	HLADoneButton = HLAWindow.GetControl (28)
	HLADoneButton.SetState(IE_GUI_BUTTON_DISABLED)
	HLADoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, HLADonePress)
	HLADoneButton.SetText(11973)
	HLADoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

	# setup our text area
	HLATextArea = HLAWindow.GetControl(26)

	print "Number of HLAs:",len (HLAAbilities)

	# create a scrollbar if need-be
	if ( len (HLAAbilities) >= 25 ) and EnhanceGUI:
		# setup extra 25th HLA slot:
		HLAWindow.CreateButton (24, 231, 345, 42, 42)
		if ( len (HLAAbilities) > 25):
			# setup our scroll index
			GemRB.SetVar("HLATopIndex", 0)
			# setup scrollbar
			HLAWindow.CreateScrollBar (1000, 290,142, 16,252)
			ScrollBar = HLAWindow.GetControl (1000)
			ScrollBar.SetSprites ("GUISCRCW", 0, 0,1,2,3,5,4)
			ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, HLAShowAbilities)
			#with enhanced GUI we have 5 rows of 5 abilities (the last one is 'the extra slot')
			ScrollBar.SetVarAssoc ("HLATopIndex", GUICommon.ceildiv ( ( len (HLAAbilities)-25 ) , 5 ) + 1 )
			ScrollBar.SetDefaultScrollBar ()

	# draw our HLAs and show the window
	HLAShowAbilities ()
	HLAWindow.ShowModal (MODAL_SHADOW_GRAY)

	return
예제 #3
0
def UpdateRecordsWindow():
    global stats_overview, faction_help, alignment_help

    Window = RecordsWindow
    if not RecordsWindow:
        print "SelectionChange handler points to non existing window\n"
        return

    pc = GemRB.GameGetSelectedPCSingle()

    # Setting up the character information
    GetCharacterHeader(pc)

    # Checking whether character has leveled up.
    Button = Window.GetControl(9)
    if avatar_header['SecoLevel'] == 0:
        if avatar_header['XP'] >= avatar_header['PrimNextLevXP']:
            Button.SetState(IE_GUI_BUTTON_ENABLED)
        else:
            Button.SetState(IE_GUI_BUTTON_DISABLED)
    else:
        # Character is Multi-Class
        if avatar_header['XP'] >= avatar_header[
                'PrimNextLevXP'] or avatar_header['XP'] >= avatar_header[
                    'SecoNextLevXP']:
            Button.SetState(IE_GUI_BUTTON_ENABLED)
        else:
            Button.SetState(IE_GUI_BUTTON_DISABLED)

    # name
    Label = Window.GetControl(0x1000000a)
    Label.SetText(GemRB.GetPlayerName(pc, 1))

    # portrait
    Image = Window.GetControl(2)
    Image.SetState(IE_GUI_BUTTON_LOCKED)
    Image.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
    Image.SetPicture(GUICommonWindows.GetActorPortrait(pc, 'STATS'))

    # armorclass
    Label = Window.GetControl(0x1000000b)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_ARMORCLASS)))
    Label.SetTooltip(4197)

    # hp now
    Label = Window.GetControl(0x1000000c)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_HITPOINTS)))
    Label.SetTooltip(4198)

    # hp max
    Label = Window.GetControl(0x1000000d)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS)))
    Label.SetTooltip(4199)

    # stats

    sstr = GemRB.GetPlayerStat(pc, IE_STR)
    bstr = GemRB.GetPlayerStat(pc, IE_STR, 1)
    sstrx = GemRB.GetPlayerStat(pc, IE_STREXTRA)
    bstrx = GemRB.GetPlayerStat(pc, IE_STREXTRA, 1)
    if (sstrx > 0) and (sstr == 18):
        sstr = "%d/%02d" % (sstr, sstrx % 100)
    if (bstrx > 0) and (bstr == 18):
        bstr = "%d/%02d" % (bstr, bstrx % 100)
    sint = GemRB.GetPlayerStat(pc, IE_INT)
    bint = GemRB.GetPlayerStat(pc, IE_INT, 1)
    swis = GemRB.GetPlayerStat(pc, IE_WIS)
    bwis = GemRB.GetPlayerStat(pc, IE_WIS, 1)
    sdex = GemRB.GetPlayerStat(pc, IE_DEX)
    bdex = GemRB.GetPlayerStat(pc, IE_DEX, 1)
    scon = GemRB.GetPlayerStat(pc, IE_CON)
    bcon = GemRB.GetPlayerStat(pc, IE_CON, 1)
    schr = GemRB.GetPlayerStat(pc, IE_CHR)
    bchr = GemRB.GetPlayerStat(pc, IE_CHR, 1)

    stats = (sstr, sint, swis, sdex, scon, schr)
    basestats = (bstr, bint, bwis, bdex, bcon, bchr)
    for i in range(6):
        Label = Window.GetControl(0x1000000e + i)
        if stats[i] != basestats[i]:
            Label.SetTextColor(255, 0, 0)
        else:
            Label.SetTextColor(255, 255, 255)
        Label.SetText(str(stats[i]))

    # race
    # HACK: for some strange reason, Morte's race is 1 (Human), instead of 45 (Morte)
    print "species: %d  race: %d" % (GemRB.GetPlayerStat(
        pc, IE_SPECIES), GemRB.GetPlayerStat(pc, IE_RACE))
    #be careful, some saves got this field corrupted
    race = GemRB.GetPlayerStat(pc, IE_SPECIES) - 1

    text = CommonTables.Races.GetValue(race, 0)

    Label = Window.GetControl(0x10000014)
    Label.SetText(text)

    # sex
    GenderTable = GemRB.LoadTable("GENDERS")
    text = GenderTable.GetValue(GemRB.GetPlayerStat(pc, IE_SEX) - 1, GTV_STR)

    Label = Window.GetControl(0x10000015)
    Label.SetText(text)

    # class
    text = CommonTables.Classes.GetValue(GUICommon.GetClassRowName(pc),
                                         "NAME_REF")

    Label = Window.GetControl(0x10000016)
    Label.SetText(text)

    # alignment
    align = GemRB.GetPlayerStat(pc, IE_ALIGNMENT)
    ss = GemRB.LoadSymbol("ALIGN")
    sym = ss.GetValue(align)

    AlignmentTable = GemRB.LoadTable("ALIGNS")
    alignment_help = AlignmentTable.GetValue(sym, 'DESC_REF', GTV_REF)
    frame = (3 * int(align / 16) + align % 16) - 4

    Button = Window.GetControl(5)
    Button.SetState(IE_GUI_BUTTON_LOCKED)
    Button.SetSprites('STALIGN', 0, frame, 0, 0, 0)
    Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, OnRecordsHelpAlignment)
    Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, OnRecordsButtonLeave)

    # faction
    faction = GemRB.GetPlayerStat(pc, IE_FACTION)
    FactionTable = GemRB.LoadTable("FACTIONS")
    faction_help = FactionTable.GetValue(faction, 0, GTV_REF)
    frame = FactionTable.GetValue(faction, 1)

    Button = Window.GetControl(6)
    Button.SetState(IE_GUI_BUTTON_LOCKED)
    Button.SetSprites('STFCTION', 0, frame, 0, 0, 0)
    Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, OnRecordsHelpFaction)
    Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, OnRecordsButtonLeave)

    # help, info textarea
    stats_overview = GetStatOverview(pc)
    Text = Window.GetControl(0)
    Text.SetText(stats_overview)
    return
예제 #4
0
def OnLoad():
	# Lay on hands, turn undead and backstab multiplier get set by the core
	# set my character up
	MyChar = GemRB.GetVar ("Slot")
	ClassName = GUICommon.GetClassRowName (MyChar)
	IsMulti = GUICommon.IsMultiClassed (MyChar, 1)
	Levels = [GemRB.GetPlayerStat (MyChar, IE_LEVEL), GemRB.GetPlayerStat (MyChar, IE_LEVEL2), \
			GemRB.GetPlayerStat (MyChar, IE_LEVEL3)]

	# weapon proficiencies
	# set the base number of attacks; effects will add the proficiency bonus
	# 2 means 1 attack, because this is the number of attacks in 2 rounds
	GemRB.SetPlayerStat (MyChar, IE_NUMBEROFATTACKS, 2)

	#lore, thac0, hp, and saves
	GemRB.SetPlayerStat (MyChar, IE_MAXHITPOINTS, 0)
	GemRB.SetPlayerStat (MyChar, IE_HITPOINTS, 0)
	LUCommon.SetupSavingThrows (MyChar)
	LUCommon.SetupThaco (MyChar)
	LUCommon.SetupLore (MyChar)
	LUCommon.SetupHP (MyChar)

	# mage spells
	TableName = CommonTables.ClassSkills.GetValue (ClassName, "MAGESPELL", GTV_STR)
	if TableName != "*":
		index = 0
		if IsMulti[0]>1:
			#find out which class gets mage spells
			for i in range (IsMulti[0]):
				TmpClassName = GUICommon.GetClassRowName (IsMulti[i+1], "class")
				if CommonTables.ClassSkills.GetValue (TmpClassName, "MAGESPELL", GTV_STR) != "*":
					index = i
					break
		Spellbook.SetupSpellLevels(MyChar, TableName, IE_SPELL_TYPE_WIZARD, Levels[index])

	# apply class/kit abilities
	GUICommon.ResolveClassAbilities (MyChar, ClassName)

	# alignment based bhaal powers are added in FixInnates later
	# unless we're starting with SoA
	if GemRB.GetVar("oldgame") == 1:
		AlignmentAbbrev = CommonTables.Aligns.FindValue ("VALUE", GemRB.GetPlayerStat (MyChar, IE_ALIGNMENT))
		GUICommon.AddClassAbilities (MyChar, "abstart", 6,6, AlignmentAbbrev)

	# setup starting gold (uses a roll dictated by class
	TmpTable = GemRB.LoadTable ("strtgold")
	temp = GemRB.Roll (TmpTable.GetValue (ClassName, "ROLLS"), TmpTable.GetValue (ClassName, "SIDES"), TmpTable.GetValue (ClassName, "MODIFIER"))
	GemRB.SetPlayerStat (MyChar, IE_GOLD, temp * TmpTable.GetValue (ClassName, "MULTIPLIER"))

	# save the appearance
	GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, GemRB.GetVar ("HairColor") )
	GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, GemRB.GetVar ("SkinColor") )
	GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, GemRB.GetVar ("MajorColor") )
	GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, GemRB.GetVar ("MinorColor") )
	#GUICommon.SetColorStat (MyChar, IE_METAL_COLOR, 0x1B )
	#GUICommon.SetColorStat (MyChar, IE_LEATHER_COLOR, 0x16 )
	#GUICommon.SetColorStat (MyChar, IE_ARMOR_COLOR, 0x17 )
	GemRB.SetPlayerStat (MyChar, IE_EA, 2 )

	# save the name and starting xp (can level right away in game)
	GemRB.SetPlayerName (MyChar, GemRB.GetToken ("CHARNAME"), 0)

	# does all the rest
	LargePortrait = GemRB.GetToken ("LargePortrait")
	SmallPortrait = GemRB.GetToken ("SmallPortrait")
	GemRB.FillPlayerInfo (MyChar, LargePortrait, SmallPortrait)

	# biography
	Bio = GemRB.GetToken("BIO")
	BioStrRef = 33347
	if Bio:
		BioStrRef = 62016
		GemRB.CreateString (BioStrRef, Bio)
	GemRB.SetPlayerString (MyChar, 74, BioStrRef)

	if GameCheck.IsTOB():
		# will also add the starting inventory for tob
		GemRB.GameSetExpansion (4)
		# no torture, let's refresh all the spells, at least for sorcerers
		# TODO: autopick memorisations for mages? Did they have a memorisation choice step like in bg1?
		GemRB.ChargeSpells (MyChar)

	playmode = GemRB.GetVar ("PlayMode")
	if playmode >=0:
		GemRB.SaveCharacter (MyChar, "gembak")
		#LETS PLAY!!
		import CharGenCommon, CommonWindow
		CharGenCommon.CharGenWindow.Close ()

		CommonWindow.SetGameGUIHidden(True)
		# fade with some number longer than it takes to get everything setup and running
		# eventually another fade call is executed which will cancel the remaining time
		GemRB.ExecuteString ("FadeFromColor([1000.0],0)", MyChar)
		GemRB.EnterGame()
		GemRB.ExecuteString ("EquipMostDamagingMelee()", MyChar)
		if GameCheck.IsTOB ():
			# delay for sorcerers, since their class pcf needs to run first to set up their spellbook properly
			GemRB.SetTimedEvent (lambda: GemRB.ChargeSpells (MyChar), 1)
	else:
		#when export is done, go to start
		if GameCheck.HasTOB():
			GemRB.SetToken ("NextScript","Start2")
		else:
			GemRB.SetToken ("NextScript","Start")
		GemRB.SetNextScript ("ExportFile") #export
	return
예제 #5
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, SpellBookType, SpellLevel, i-1, 1)
		SpellBook = []
		MemoBook = [0]*ButtonCount

	# save all the spells
	if not Memorization:
		for i in range (len (Spells[SpellLevel])):
			if SpellBook[i]: # we need to learn this spell
				if IWD2:
					GemRB.LearnSpell (pc, Spells[SpellLevel][i][0], 0, 1<<SpellBookType)
				else:
					GemRB.LearnSpell (pc, Spells[SpellLevel][i][0])

		# check to see if we need to update again
		for i in range (SpellLevel+1, 9):
			if SpellsSelectPointsLeft[i] > 0:
				# reset the variables
				GemRB.SetVar ("SpellTopIndex", 0)
				SpellLevel = i
				if not (chargen and GameCheck.IsBG1()):
					SpellBook = [0]*len(Spells[i])

				if (EnhanceGUI):
					# setup the scrollbar
					ScrollBar = SpellsWindow.GetControl (1000)
					if len (Spells[i]) > ( ButtonCount + ExtraSpellButtons() ):
						HideUnhideScrollBar(0)
						if chargen:
							ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount ) , 6 ) + 1 )
						else:
							ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount-1 ) , 5 ) + 1 )
					else:
						ScrollBar.SetVarAssoc ("SpellTopIndex", 0)
						HideUnhideScrollBar(1)

				# show the spells and set the done button to off
				ShowSpells ()
				DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
				return

		# bg1 lets you memorize spells too (iwd too, but it does it by itself)
		if chargen and sum(MemoBook) == 0 and \
		(GameCheck.IsBG1() or (IWD2 and SpellBookType != IE_IWD2_SPELL_SORCERER)):
			SpellLevel = 0
			SpellsSelectPointsLeft[SpellLevel] = 1
			if KitMask != 0x4000:
				# specialists get an extra spell per level
				SpellsSelectPointsLeft[SpellLevel] += 1
			DoneButton.SetState (IE_GUI_BUTTON_DISABLED)
			Memorization = 1
			ShowKnownSpells()
			return

	# close our window and update our records
	if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2):
		SpellsWindow.Unload ()
		SpellsWindow = None

	# move to the next script if this is chargen
	if chargen:
		if GameCheck.IsBG2():
			GemRB.SetNextScript("GUICG6")
		elif GameCheck.IsBG1():
			# HACK
			from CharGenCommon import next
			next()
		elif IWD2:
			GemRB.SetNextScript("CharGen7")
	elif IWD2:
		import GUIREC
		GUIREC.FinishLevelUp ()

	return
예제 #6
0
def setAccept():
    #set my character up
    MyChar = GemRB.GetVar("Slot")

    ClassName = GUICommon.GetClassRowName(MyChar)

    #reputation
    AllignID = GemRB.GetPlayerStat(MyChar, IE_ALIGNMENT)

    TmpTable = GemRB.LoadTable("repstart")
    t = TmpTable.GetValue(AllignID, 0) * 10
    GemRB.SetPlayerStat(MyChar, IE_REPUTATION, t)

    #lore, thac0, hp, and saves
    GemRB.SetPlayerStat(MyChar, IE_MAXHITPOINTS, 0)
    GemRB.SetPlayerStat(MyChar, IE_HITPOINTS, 0)
    LUCommon.SetupSavingThrows(MyChar)
    LUCommon.SetupThaco(MyChar)
    LUCommon.SetupLore(MyChar)
    LUCommon.SetupHP(MyChar)

    #slot 1 is the protagonist
    if MyChar == 1:
        GemRB.GameSetReputation(t)

    #gold
    TmpTable = GemRB.LoadTable("strtgold")
    t = GemRB.Roll(TmpTable.GetValue(ClassName, "ROLLS"),
                   TmpTable.GetValue(ClassName, "SIDES"),
                   TmpTable.GetValue(ClassName, "MODIFIER"))
    GemRB.SetPlayerStat(MyChar, IE_GOLD,
                        t * TmpTable.GetValue(ClassName, "MULTIPLIER"))

    #set the base number of attacks; effects will add the proficiency bonus
    GemRB.SetPlayerStat(MyChar, IE_NUMBEROFATTACKS, 2)

    #colors
    GUICommon.SetColorStat(MyChar, IE_METAL_COLOR, 0x1B)
    GUICommon.SetColorStat(MyChar, IE_LEATHER_COLOR, 0x16)
    GUICommon.SetColorStat(MyChar, IE_ARMOR_COLOR, 0x17)

    #does all the rest
    LargePortrait = GemRB.GetToken("LargePortrait")
    SmallPortrait = GemRB.GetToken("SmallPortrait")
    GemRB.FillPlayerInfo(MyChar, LargePortrait, SmallPortrait)
    #10 is a weapon slot (see slottype.2da row 10)
    GemRB.CreateItem(MyChar, "staf01", 10, 1, 0, 0)
    GemRB.SetEquippedQuickSlot(MyChar, 0)

    # apply class/kit abilities
    GUICommon.ResolveClassAbilities(MyChar, ClassName)

    #LETS PLAY!!
    playmode = GemRB.GetVar("PlayMode")

    GUICommon.CloseOtherWindow(None)

    if playmode >= 0:
        CharGenCommon.close()
        if GemRB.GetVar("GUIEnhancements"):
            GemRB.SaveCharacter(GemRB.GetVar("Slot"), "gembak")
        GemRB.EnterGame()
    else:
        #show the export window
        GemRB.SetToken("NextScript", "CharGen")
        GemRB.SetNextScript("ExportFile")
예제 #7
0
def OpenContainerWindow ():
	global ContainerWindow, Container

	if ContainerWindow:
		return

	hideflag = GemRB.HideGUI ()

	GemRB.LoadWindowPack (GUICommon.GetWindowPack())
	ContainerWindow = Window = GemRB.LoadWindow (8)


	#stop gears from interfering
	if GameCheck.IsPST():
		GUIWORLD.OldPortraitWindow = GUIClasses.GWindow( GemRB.GetVar ("PortraitWindow") )
		GUICommonWindows.DisableAnimatedWindows ()

	if GameCheck.IsIWD2():
		GUIWORLD.OldMessageWindow = GUIClasses.GWindow( GemRB.GetVar ("MessageWindow") )
		GemRB.SetVar ("MessageWindow", Window.ID)
	else:
		GUIWORLD.OldActionsWindow = GUIClasses.GWindow( GemRB.GetVar ("ActionsWindow") )
		GUIWORLD.OldMessageWindow = GUIClasses.GWindow( GemRB.GetVar ("MessageWindow") )
		GemRB.SetVar ("MessageWindow", -1)
		GemRB.SetVar ("ActionsWindow", Window.ID)

	Container = GemRB.GetContainer(0)

	# Gears (time) when options pane is down
	if GameCheck.IsBG2() and Window.HasControl (62):
		Button = Window.GetControl (62)
		Label = Button.CreateLabelOnButton (0x1000003e, "NORMAL", IE_FONT_SINGLE_LINE)

		Label.SetAnimation ("CPEN")
		Button.SetAnimation ("CGEAR")
		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(16041)

	# 0-5 - Ground Item
	for i in range (ground_size):
		Button = Window.GetControl (i)
		Button.SetVarAssoc ("LeftIndex", i)
		Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, TakeItemContainer)
		if GameCheck.IsPST():
			Button.SetFont ("NUMBER")
			Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_BOTTOM, OP_OR)

	# 10-13 - Personal Item
	for i in range (4):
		Button = Window.GetControl (i+10)
		Button.SetVarAssoc ("RightIndex", i)
		Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DropItemContainer)
		if GameCheck.IsPST():
			Button.SetFont ("NUMBER")
			Button.SetFlags (IE_GUI_BUTTON_ALIGN_RIGHT | IE_GUI_BUTTON_ALIGN_BOTTOM, OP_OR)

	# left scrollbar (container)
	ScrollBar = Window.GetControl (52)
	ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RedrawContainerWindow)

	# right scrollbar (inventory)
	ScrollBar = Window.GetControl (53)
	ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RedrawContainerWindow)

	# encumbrance and inventory icon
	# iwd has a handy button
	if Window.HasControl (54):
		Button = Window.GetControl (54)
		if GameCheck.IsPST():
			Button.SetFont ("NUMBER")
			Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
		Button.CreateLabelOnButton (0x10000043, "NUMBER", IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP|IE_FONT_SINGLE_LINE)
		Button.CreateLabelOnButton (0x10000044, "NUMBER", IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_BOTTOM|IE_FONT_SINGLE_LINE)
	else:
		Label = Window.CreateLabel (0x10000043, 323,14,60,15,"NUMBER","0:",IE_FONT_ALIGN_LEFT|IE_FONT_ALIGN_TOP|IE_FONT_SINGLE_LINE)
		Label = Window.CreateLabel (0x10000044, 323,20,80,15,"NUMBER","0:",IE_FONT_ALIGN_RIGHT|IE_FONT_ALIGN_TOP|IE_FONT_SINGLE_LINE)

	# container icon
	Button = Window.GetControl (50)
	if GameCheck.IsPST():
		Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
	Button.SetState (IE_GUI_BUTTON_LOCKED)

	if not GameCheck.IsPST():
		Table = GemRB.LoadTable ("containr")
		row = Container['Type']
		tmp = Table.GetValue (row, 0)
		if tmp!='*':
			GemRB.PlaySound (tmp)
		tmp = Table.GetValue (row, 1)
		if tmp!='*':
			Button.SetSprites (tmp, 0, 0, 0, 0, 0 )

	# Done
	Button = Window.GetControl (51)
	if GameCheck.IsPST():
		Button.SetText (1403)
	else:
		Button.SetText ("")
	Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LeaveContainer)

	GemRB.SetVar ("LeftTopIndex", 0)
	GemRB.SetVar ("RightTopIndex", 0)
	UpdateContainerWindow ()
	if hideflag:
		GemRB.UnhideGUI ()
예제 #8
0
def OpenOptionsWindow():
    """Open main options window (peacock tail)"""
    global OptionsWindow

    if GUICommon.CloseOtherWindow(OpenOptionsWindow):
        GemRB.HideGUI()
        if OptionsWindow:
            OptionsWindow.Unload()
        GemRB.SetVar("OtherWindow", -1)
        GUICommonWindows.EnableAnimatedWindows()
        OptionsWindow = None

        GemRB.UnhideGUI()
        return

    GemRB.GamePause(1, 1)
    TrySavingConfiguration()

    CommonWindow.CloseContainerWindow()
    GemRB.HideGUI()
    GemRB.LoadWindowPack("GUIOPT")
    OptionsWindow = Window = GemRB.LoadWindow(0)
    GemRB.SetVar("OtherWindow", OptionsWindow.ID)
    GUICommonWindows.DisableAnimatedWindows()

    def ConfigOptButton(button, strref, action):
        button.SetText(strref)
        button.SetEvent(IE_GUI_BUTTON_ON_PRESS, action)
        button.SetFlags(IE_GUI_BUTTON_MULTILINE, OP_OR)

    # Return to Game
    ConfigOptButton(Window.GetControl(0), 28638, OpenOptionsWindow)

    # Quit Game
    ConfigOptButton(Window.GetControl(1), 2595, OpenQuitMsgWindow)

    # Load Game
    ConfigOptButton(Window.GetControl(2), 2592, OpenLoadMsgWindow)

    # Save Game
    ConfigOptButton(Window.GetControl(3), 20639, GUISAVE.OpenSaveWindow)

    # Video Options
    ConfigOptButton(Window.GetControl(4), 28781, OpenVideoOptionsWindow)

    # Audio Options
    ConfigOptButton(Window.GetControl(5), 29720, OpenAudioOptionsWindow)

    # Gameplay Options
    ConfigOptButton(Window.GetControl(6), 29722, OpenGameplayOptionsWindow)

    # Keyboard Mappings
    ConfigOptButton(Window.GetControl(7), 29723, OpenKeyboardMappingsWindow)

    # Movies
    ConfigOptButton(Window.GetControl(9), 38156, OpenMoviesWindow)

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

    GemRB.UnhideGUI()
예제 #9
0
def guardMageSpells():
    MyChar = GemRB.GetVar("Slot")
    ClassName = GUICommon.GetClassRowName(MyChar)
    TableName = CommonTables.ClassSkills.GetValue(ClassName, "MAGESPELL")
    return TableName != "*"
예제 #10
0
def OpenRecordsWindow():
    import GUICommonWindows

    global RecordsWindow, OptionsWindow, PortraitWindow, PauseState
    global OldPortraitWindow, OldOptionsWindow

    if GUICommon.CloseOtherWindow(OpenRecordsWindow):
        if InformationWindow: OpenInformationWindow()

        GUIRECCommon.CloseSubSubCustomizeWindow()
        GUIRECCommon.CloseSubCustomizeWindow()
        GUIRECCommon.CloseCustomizeWindow()
        GUIRECCommon.ExportCancelPress()
        GUIRECCommon.CloseBiographyWindow()
        KitDonePress()
        CloseInformationWindow()

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

        RecordsWindow = None
        GemRB.SetVar("OtherWindow", -1)
        GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
        GemRB.UnhideGUI()
        GUICommonWindows.PortraitWindow = OldPortraitWindow
        OldPortraitWindow = None
        GUICommonWindows.UpdatePortraitWindow()
        GUICommonWindows.OptionsWindow = OldOptionsWindow
        OldOptionsWindow = None
        GUICommonWindows.SetSelectionChangeHandler(None)
        GemRB.GamePause(PauseState, 3)
        return

    PauseState = GemRB.GamePause(3, 1)
    GemRB.GamePause(1, 3)

    GemRB.HideGUI()
    GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)

    GemRB.LoadWindowPack("GUIREC", 640, 480)
    RecordsWindow = Window = GemRB.LoadWindow(2)
    GemRB.SetVar("OtherWindow", RecordsWindow.ID)
    # saving the original portrait window
    OldOptionsWindow = GUICommonWindows.OptionsWindow
    OptionsWindow = GemRB.LoadWindow(0)
    GUICommonWindows.SetupMenuWindowControls(OptionsWindow, 0,
                                             OpenRecordsWindow)
    GUICommonWindows.MarkMenuButton(OptionsWindow)
    OptionsWindow.SetFrame()
    OldPortraitWindow = GUICommonWindows.PortraitWindow
    PortraitWindow = GUICommonWindows.OpenPortraitWindow(0)

    # dual class
    Button = Window.GetControl(0)
    Button.SetText(7174)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DualClass.DualClassWindow)

    # levelup
    Button = Window.GetControl(37)
    Button.SetText(7175)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, LevelUp.OpenLevelUpWindow)

    # information
    Button = Window.GetControl(1)
    Button.SetText(11946)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenInformationWindow)

    # reform party
    Button = Window.GetControl(51)
    Button.SetText(16559)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenRecReformPartyWindow)

    # customize
    Button = Window.GetControl(50)
    Button.SetText(10645)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIRECCommon.OpenCustomizeWindow)

    # export
    Button = Window.GetControl(36)
    Button.SetText(13956)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIRECCommon.OpenExportWindow)

    # kit info
    if GameCheck.IsBG2():
        Button = Window.GetControl(52)
        Button.SetText(61265)
        Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenKitInfoWindow)

    # create a button so we can map it do ESC for quit exiting
    Button = Window.CreateButton(99, 0, 0, 1, 1)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenRecordsWindow)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    GUICommonWindows.SetSelectionChangeHandler(UpdateRecordsWindow)
    UpdateRecordsWindow()

    Window.SetKeyPressEvent(GUICommonWindows.SwitchPCByKey)

    OptionsWindow.SetVisible(WINDOW_VISIBLE)
    Window.SetVisible(WINDOW_VISIBLE)
    PortraitWindow.SetVisible(WINDOW_VISIBLE)
    return
예제 #11
0
def NextPress():
	#set my character up
	MyChar = GemRB.GetVar ("Slot")
	GemRB.SetPlayerStat (MyChar, IE_SEX, GemRB.GetVar ("Gender") )
	GemRB.SetPlayerStat (MyChar, IE_RACE, GemRB.GetVar ("BaseRace") )
	race = GemRB.GetVar ("Race")
	GemRB.SetPlayerStat (MyChar, IE_SUBRACE, race & 255 )
	row = CommonTables.Races.FindValue (3, race )
	racename = CommonTables.Races.GetRowName (row)
	if row!=-1:
		SetRaceResistances( MyChar, racename )
		SetRaceAbilities( MyChar, racename )

	#base class
	Class=GemRB.GetVar ("BaseClass")
	GemRB.SetPlayerStat (MyChar, IE_CLASS, Class)
	#kit
	GemRB.SetPlayerStat (MyChar, IE_KIT, GemRB.GetVar ("Class") )
	AlignmentTable = GemRB.LoadTable ("aligns")
	t=GemRB.GetVar ("Alignment")
	GemRB.SetPlayerStat (MyChar, IE_ALIGNMENT, AlignmentTable.GetValue (t, 3) )
	TmpTable=GemRB.LoadTable ("repstart")
	#t=AlignmentTable.FindValue (3,t)
	t=TmpTable.GetValue (t,0)
	GemRB.SetPlayerStat (MyChar, IE_REPUTATION, t)
	TmpTable=GemRB.LoadTable ("strtgold")
	a = TmpTable.GetValue (Class, 1) #number of dice
	b = TmpTable.GetValue (Class, 0) #size
	c = TmpTable.GetValue (Class, 2) #adjustment
	d = TmpTable.GetValue (Class, 3) #external multiplier
	e = TmpTable.GetValue (Class, 4) #level bonus rate
	t = GemRB.GetPlayerStat (MyChar, IE_LEVEL) 
	if t>1:
		e=e*(t-1)
	else:
		e=0
	t = GemRB.Roll(a,b,c)*d+e
	GemRB.SetPlayerStat (MyChar, IE_GOLD, t)
	GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, GemRB.GetVar ("HatedRace") )
	TmpTable = GemRB.LoadTable ("ability")
	AbilityCount = TmpTable.GetRowCount ()
	for i in range (AbilityCount):
		StatID=TmpTable.GetValue (i,4)
		GemRB.SetPlayerStat (MyChar, StatID, GemRB.GetVar ("Ability "+str(i) ) )

#	TmpTable=GemRB.LoadTable ("weapprof")
#	ProfCount = TmpTable.GetRowCount ()
#	for i in range(ProfCount):
#		StatID=TmpTable.GetValue (i, 0)
#		GemRB.SetPlayerStat (MyChar, StatID, GemRB.GetVar ("Prof "+str(i) ) )
	GUICommon.SetColorStat (MyChar, IE_HAIR_COLOR, GemRB.GetVar ("Color1") )
	GUICommon.SetColorStat (MyChar, IE_SKIN_COLOR, GemRB.GetVar ("Color2") )
	GUICommon.SetColorStat (MyChar, IE_MAJOR_COLOR, GemRB.GetVar ("Color4") )
	GUICommon.SetColorStat (MyChar, IE_MINOR_COLOR, GemRB.GetVar ("Color3") )
	GUICommon.SetColorStat (MyChar, IE_METAL_COLOR, 0x1B )
	GUICommon.SetColorStat (MyChar, IE_LEATHER_COLOR, 0x16 )
	GUICommon.SetColorStat (MyChar, IE_ARMOR_COLOR, 0x17 )
	GemRB.SetPlayerStat (MyChar, IE_EA, 2 )
	Str=GemRB.GetVar ("Ability 1")
	GemRB.SetPlayerStat (MyChar, IE_STR, Str)
	if Str==18:
		GemRB.SetPlayerStat (MyChar,IE_STREXTRA,GemRB.GetVar ("StrExtra"))
	else:
		GemRB.SetPlayerStat (MyChar, IE_STREXTRA,0)

	GemRB.SetPlayerStat (MyChar, IE_DEX, GemRB.GetVar ("Ability 2"))
	GemRB.SetPlayerStat (MyChar, IE_CON, GemRB.GetVar ("Ability 3"))
	GemRB.SetPlayerStat (MyChar, IE_INT, GemRB.GetVar ("Ability 4"))
	GemRB.SetPlayerStat (MyChar, IE_WIS, GemRB.GetVar ("Ability 5"))
	GemRB.SetPlayerStat (MyChar, IE_CHR, GemRB.GetVar ("Ability 6"))
	GemRB.SetPlayerName (MyChar, GemRB.GetToken ("CHARNAME"), 0)

	#setting skills
	TmpTable = GemRB.LoadTable ("skillsta")
	SkillCount = TmpTable.GetRowCount ()
	for i in range (SkillCount):
		StatID=TmpTable.GetValue (i, 2)
		GemRB.SetPlayerStat (MyChar, StatID, GemRB.GetVar ("Skill "+str(i) ) )

	#setting feats

	#does all the rest
	LargePortrait = GemRB.GetToken ("LargePortrait")
	SmallPortrait = GemRB.GetToken ("SmallPortrait")
	GemRB.FillPlayerInfo(MyChar, LargePortrait, SmallPortrait) 
 	GemRB.SetNextScript ("SPPartyFormation")

	TmpTable = GemRB.LoadTable ("strtxp")

	#starting xp is race dependent
	xp = TmpTable.GetValue (racename, "VALUE")
	GemRB.SetPlayerStat (MyChar, IE_XP, xp ) 

	return
예제 #12
0
def OpenSpellsWindow(actor,
                     table,
                     level,
                     diff,
                     kit=0,
                     gen=0,
                     recommend=True,
                     booktype=0):
    """Opens the spells selection window.

	table should refer to the name of the classes MXSPLxxx.2da.
	level contains the current level of the actor.
	diff contains the difference from the old level.
	kit should always be GetKitIndex except when dualclassing.
	gen is true if this is for character generation.
	recommend is used in bg2 for spell recommendation / autopick."""

    global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel
    global SpellsTextArea, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart, BonusPoints
    global KitMask, EnhanceGUI, Memorization, SpellBookType, SpellsPickButton, ButtonCount, Class

    #enhance GUI?
    if (GemRB.GetVar("GUIEnhancements") & GE_SCROLLBARS) and not IWD2:
        EnhanceGUI = 1

    # save our pc
    pc = actor
    chargen = gen

    # this ensures compatibility with chargen, sorc, and dual-classing
    if kit == 0:
        KitMask = 0x4000
    else:  # need to implement this if converted to CharGen
        KitMask = kit

    if IWD2:
        # save the spellbook type (class) that corresponds to our table
        SpellBookType = booktype
        if not chargen:
            ButtonCount = 30

    # make sure there is an entry at the given level (bard)
    SpellLearnTable = table
    SpellsToMemoTable = GemRB.LoadTable(table)
    if not SpellsToMemoTable.GetValue(str(level), str(1), GTV_INT):
        if chargen:
            if GameCheck.IsBG2():
                GemRB.SetNextScript("GUICG6")
            elif GameCheck.IsBG1():
                # HACK
                from CharGenCommon import next
                next()
            elif IWD2:
                GemRB.SetNextScript("CharGen7")
        return

    # load our window
    if chargen:
        GemRB.LoadWindowPack("GUICG", WIDTH, HEIGHT)
        SpellsWindow = GemRB.LoadWindow(7)
        if not recommend:
            GUICommon.CloseOtherWindow(SpellsWindow.Unload)
        DoneButton = SpellsWindow.GetControl(0)
        SpellsTextArea = SpellsWindow.GetControl(27)
        SpellPointsLeftLabel = SpellsWindow.GetControl(0x1000001b)
        if (EnhanceGUI):
            SpellsWindow.CreateScrollBar(1000, 325, 42, 16, 252)
            HideUnhideScrollBar(1)
        SpellStart = 2

        # cancel button only applicable for chargen
        SpellsCancelButton = SpellsWindow.GetControl(29)
        SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED)
        SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress)
        SpellsCancelButton.SetText(13727)
        SpellsCancelButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

        if (recommend):
            # recommended spell picks
            SpellsPickButton = SpellsWindow.GetControl(30)
            SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED)
            SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress)
            SpellsPickButton.SetText(34210)
    else:
        SpellsWindow = GemRB.LoadWindow(8)
        if IWD2:
            DoneButton = SpellsWindow.GetControl(33)
            SpellsTextArea = SpellsWindow.GetControl(30)
            SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000022)
        else:
            DoneButton = SpellsWindow.GetControl(28)
            SpellsTextArea = SpellsWindow.GetControl(26)
            SpellPointsLeftLabel = SpellsWindow.GetControl(0x10000018)
        if (EnhanceGUI):
            SpellsWindow.CreateScrollBar(1000, 290, 142, 16, 252)
            HideUnhideScrollBar(1)
            #25th spell button for sorcerers
            SpellsWindow.CreateButton(24, 231, 345, 42, 42)
        SpellStart = 0

    # setup our variables
    GemRB.SetVar("SpellTopIndex", 0)
    Memorization = 0
    Class = GemRB.GetPlayerStat(pc, IE_CLASS)
    if IWD2 and not chargen:
        LUClass = GemRB.GetVar("LUClass")
        LUClassName = CommonTables.Classes.GetRowName(LUClass)
        LUClassID = CommonTables.Classes.GetValue(LUClassName, "ID")
        Class = LUClassID

    # the done button also doubles as a next button
    DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress)
    DoneButton.SetText(11973)
    DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # adjust the table for the amount of spells available for learning for free
    # bg2 had SPLSRCKN, iwd2 also SPLBRDKN, but all the others lacked the tables
    if SpellLearnTable == "MXSPLSOR":
        SpellLearnTable = "SPLSRCKN"
    elif SpellLearnTable == "MXSPLBRD":
        SpellLearnTable = "SPLBRDKN"
    # ... which is also important for mages during chargen and then never again
    elif SpellLearnTable == "MXSPLWIZ":
        SpellLearnTable = "SPLWIZKN"
    else:
        print "OpenSpellsWindow: unhandled spell learning type encountered, falling back to memo table:", table
    SpellLearnTable = GemRB.LoadTable(SpellLearnTable)

    CastingStatValue = 0
    if IWD2:
        # mxsplbon.2da is handled in core, but does also affect learning, at least in chargen
        BonusSpellTable = GemRB.LoadTable("mxsplbon")
        ClassRowName = GUICommon.GetClassRowName(pc)
        CastingStat = CommonTables.ClassSkills.GetValue(
            ClassRowName, "CASTING", GTV_INT)
        CastingStatValue = GemRB.GetPlayerStat(pc, CastingStat)

    AlreadyShown = 0
    for i in range(9):
        # make sure we always have a value to minus (bards)
        SecondPoints = SpellsToMemoTable.GetValue(str(level - diff),
                                                  str(i + 1), GTV_INT)

        # make sure we get more spells of each class before continuing
        SpellsSelectPointsLeft[i] = SpellsToMemoTable.GetValue(
            str(level), str(i + 1), GTV_INT) - SecondPoints
        if SpellsSelectPointsLeft[i] <= 0:
            continue

        SpellsSelectPointsLeft[i] = SpellLearnTable.GetValue(
            str(level), str(i + 1), GTV_INT)
        # luckily the bonus applies both to learning and memorization
        if IWD2 and chargen:
            BonusPoints[i] = BonusSpellTable.GetValue(str(CastingStatValue),
                                                      str(i + 1), GTV_INT)
            SpellsSelectPointsLeft[i] += BonusPoints[i]

        if SpellsSelectPointsLeft[i] <= 0:
            continue
        elif chargen and KitMask != 0x4000 and (not IWD2 or SpellBookType
                                                == IE_IWD2_SPELL_WIZARD):
            # specialists get an extra spell per level
            SpellsSelectPointsLeft[i] += 1
            BonusPoints[i] += 1

        # get all the spells of the given level
        Spells[i] = Spellbook.GetMageSpells(
            KitMask, GemRB.GetPlayerStat(pc, IE_ALIGNMENT), i + 1, Class)

        # dump all the spells we already know
        NumDeleted = 0
        for j in range(len(Spells[i])):
            CurrentIndex = j - NumDeleted  # this ensure we don't go out of range
            if Spellbook.HasSpell(pc, SpellBookType, i,
                                  Spells[i][CurrentIndex][0]) >= 0:
                del Spells[i][CurrentIndex]
                NumDeleted += 1

        # display these spells if it's the first non-zero level
        if AlreadyShown == 0:
            # save the level and spellbook data
            SpellLevel = i
            SpellBook = [0] * len(Spells[i])

            if (EnhanceGUI):
                # setup the scrollbar
                ScrollBar = SpellsWindow.GetControl(1000)
                #				ScrollBar.SetDefaultScrollBar ()

                # only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp
                if len(Spells[i]) > (ButtonCount + ExtraSpellButtons()):
                    ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells)
                    HideUnhideScrollBar(0)
                    if chargen:
                        ScrollBar.SetVarAssoc(
                            "SpellTopIndex",
                            GUICommon.ceildiv(
                                (len(Spells[i]) - ButtonCount), 6) + 1)
                    else:  #there are five rows of 5 spells in level up of sorcs
                        ScrollBar.SetVarAssoc(
                            "SpellTopIndex",
                            GUICommon.ceildiv(
                                (len(Spells[i]) - ButtonCount - 1), 5) + 1)
                else:
                    ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, None)
                    ScrollBar.SetVarAssoc("SpellTopIndex", 0)
                    HideUnhideScrollBar(1)

            # show our spells
            ShowSpells()
            AlreadyShown = 1

    # show the selection window
    if chargen:
        if recommend:
            SpellsWindow.SetVisible(WINDOW_VISIBLE)
        else:
            SpellsWindow.ShowModal(MODAL_SHADOW_NONE)
    else:
        SpellsWindow.ShowModal(MODAL_SHADOW_GRAY)

    return
예제 #13
0
def OnLoad():
    global AppearanceWindow, PortraitButton, PortraitsTable, LastPortrait
    global Gender

    if GUICommon.CloseOtherWindow(OnLoad):
        if (AppearanceWindow):
            AppearanceWindow.Unload()
        return

    GemRB.LoadWindowPack("GUICG", 640, 480)
    AppearanceWindow = GemRB.LoadWindow(11)

    #Load the Gender
    MyChar = GemRB.GetVar("Slot")
    Gender = GemRB.GetPlayerStat(MyChar, IE_SEX)

    #Load the Portraits Table
    PortraitsTable = GemRB.LoadTable("PICTURES")
    PortraitsStart = PortraitsTable.FindValue(0, 2)
    FemaleCount = PortraitsTable.GetRowCount() - PortraitsStart + 1
    if Gender == 2:
        LastPortrait = GemRB.Roll(1, FemaleCount, PortraitsStart - 1)
    else:
        LastPortrait = GemRB.Roll(1,
                                  PortraitsTable.GetRowCount() - FemaleCount,
                                  0)

    PortraitButton = AppearanceWindow.GetControl(1)
    PortraitButton.SetFlags(IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_NO_IMAGE,
                            OP_SET)
    PortraitButton.SetState(IE_GUI_BUTTON_LOCKED)

    LeftButton = AppearanceWindow.GetControl(2)
    RightButton = AppearanceWindow.GetControl(3)

    BackButton = AppearanceWindow.GetControl(5)
    BackButton.SetText(15416)

    CustomButton = AppearanceWindow.GetControl(6)
    CustomButton.SetText(17545)

    DoneButton = AppearanceWindow.GetControl(0)
    DoneButton.SetText(11973)
    DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    RightButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, RightPress)
    LeftButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, LeftPress)
    BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CharGenCommon.BackPress)
    CustomButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CustomPress)
    DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)

    flag = False
    while True:
        if PortraitsTable.GetValue(LastPortrait, 0) == Gender:
            SetPicture()
            break
        LastPortrait = LastPortrait + 1
        if LastPortrait >= PortraitsTable.GetRowCount():
            LastPortrait = 0
            if flag:
                SetPicture()
                break
            flag = True

    AppearanceWindow.ShowModal(MODAL_SHADOW_NONE)
    return
예제 #14
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, SpellBookType, SpellLevel, i - 1, 1)
        SpellBook = []
        MemoBook = [0] * ButtonCount

    # save all the spells
    if not Memorization:
        for i in range(len(Spells[SpellLevel])):
            if SpellBook[i]:  # we need to learn this spell
                if IWD2:
                    GemRB.LearnSpell(pc, Spells[SpellLevel][i][0], 0,
                                     1 << SpellBookType)
                else:
                    GemRB.LearnSpell(pc, Spells[SpellLevel][i][0])

        # check to see if we need to update again
        for i in range(SpellLevel + 1, 9):
            if SpellsSelectPointsLeft[i] > 0:
                # reset the variables
                GemRB.SetVar("SpellTopIndex", 0)
                SpellLevel = i
                if not (chargen and GameCheck.IsBG1()):
                    SpellBook = [0] * len(Spells[i])

                if (EnhanceGUI):
                    # setup the scrollbar
                    ScrollBar = SpellsWindow.GetControl(1000)
                    if len(Spells[i]) > (ButtonCount + ExtraSpellButtons()):
                        HideUnhideScrollBar(0)
                        if chargen:
                            ScrollBar.SetVarAssoc(
                                "SpellTopIndex",
                                GUICommon.ceildiv(
                                    (len(Spells[i]) - ButtonCount), 6) + 1)
                        else:
                            ScrollBar.SetVarAssoc(
                                "SpellTopIndex",
                                GUICommon.ceildiv(
                                    (len(Spells[i]) - ButtonCount - 1), 5) + 1)
                    else:
                        ScrollBar.SetVarAssoc("SpellTopIndex", 0)
                        HideUnhideScrollBar(1)

                # show the spells and set the done button to off
                ShowSpells()
                DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
                return

        # bg1 lets you memorize spells too (iwd too, but it does it by itself)
        if chargen and sum(MemoBook) == 0 and \
        (GameCheck.IsBG1() or (IWD2 and SpellBookType == IE_IWD2_SPELL_WIZARD)):
            SpellLevel = 0
            # bump it for specialists and iwd2 casters with high stats
            SpellsSelectPointsLeft[SpellLevel] = 1 + BonusPoints[SpellLevel]
            DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
            Memorization = 1
            ShowKnownSpells()
            return

    # close our window and update our records
    if SpellsWindow and (not chargen or GameCheck.IsBG2() or IWD2):
        SpellsWindow.Unload()
        SpellsWindow = None

    # move to the next script if this is chargen
    if chargen:
        if GameCheck.IsBG2():
            GemRB.SetNextScript("GUICG6")
        elif GameCheck.IsBG1():
            # HACK
            from CharGenCommon import next
            next()
        elif IWD2:
            GemRB.SetNextScript("CharGen7")
    elif IWD2:
        import GUIREC
        GUIREC.FinishLevelUp()

    return
예제 #15
0
파일: GUIOPT.py 프로젝트: TeoTwawki/gemrb
def SaveGame():
    GemRB.SetVar("QuitAfterSave", 1)
    OpenQuitMsgWindow()
    if GUICommon.CloseOtherWindow(OpenOptionsWindow):
        OpenOptionsWindow()
    GUISAVE.OpenSaveWindow()
예제 #16
0
파일: GUIPR.py 프로젝트: scriptedfate/gemrb
def OpenPriestWindow ():
	import GUICommonWindows
	global PriestWindow, OptionsWindow, PortraitWindow
	global OldPortraitWindow, OldOptionsWindow

	if GUICommon.CloseOtherWindow (OpenPriestWindow):
		if PriestWindow:
			PriestWindow.Unload ()
		if OptionsWindow:
			OptionsWindow.Unload ()
		if PortraitWindow:
			PortraitWindow.Unload ()

		PriestWindow = None
		GemRB.SetVar ("OtherWindow", -1)
		GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
		GemRB.UnhideGUI ()
		GUICommonWindows.PortraitWindow = OldPortraitWindow
		OldPortraitWindow = None
		GUICommonWindows.OptionsWindow = OldOptionsWindow
		OldOptionsWindow = None
		GUICommonWindows.SetSelectionChangeHandler (None)
		return

	GemRB.HideGUI ()
	GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)

	GemRB.LoadWindowPack ("GUIPR", 640, 480)
	PriestWindow = Window = GemRB.LoadWindow (2)
	GemRB.SetVar ("OtherWindow", PriestWindow.ID)
	#saving the original portrait window
	OldOptionsWindow = GUICommonWindows.OptionsWindow
	OptionsWindow = GemRB.LoadWindow (0)
	GUICommonWindows.MarkMenuButton (OptionsWindow)
	GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenPriestWindow)
	OptionsWindow.SetFrame ()
	OldPortraitWindow = GUICommonWindows.PortraitWindow
	PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)

	Button = Window.GetControl (1)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestPrevLevelPress)

	Button = Window.GetControl (2)
	Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestNextLevelPress)

	# Setup memorized spells buttons
	for i in range (12):
		Button = Window.GetControl (3 + i)
		Button.SetBorder (0,0,0,0,0,0,0,0,64,0,1)
		Button.SetSprites ("SPELFRAM",0,0,0,0,0)
		Button.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_PLAYONCE, OP_OR)
		Button.SetState (IE_GUI_BUTTON_LOCKED)

	# Setup book spells buttons
	for i in range (GUICommon.GetIWDSpellButtonCount()):
		Button = Window.GetControl (27 + i)
		Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PLAYONCE, OP_OR)
		Button.SetState (IE_GUI_BUTTON_LOCKED)

	GUICommonWindows.SetSelectionChangeHandler (UpdatePriestWindow)
	UpdatePriestWindow ()
	OptionsWindow.SetVisible (WINDOW_VISIBLE)
	#bringing window front
	Window.SetVisible (WINDOW_FRONT)
	PortraitWindow.SetVisible (WINDOW_VISIBLE)
	return
예제 #17
0
파일: GUIPR.py 프로젝트: scriptedfate/gemrb
def UpdatePriestWindow ():
	global PriestMemorizedSpellList, PriestKnownSpellList

	PriestMemorizedSpellList = []
	PriestKnownSpellList = []

	Window = PriestWindow
	pc = GemRB.GameGetSelectedPCSingle ()
	type = IE_SPELL_TYPE_PRIEST
	level = PriestSpellLevel
	max_mem_cnt = GemRB.GetMemorizableSpellsCount (pc, type, level)

	Label = Window.GetControl (0x10000032)
	GemRB.SetToken ('LEVEL', str (level + 1))
	Label.SetText (12137)

	Name = GemRB.GetPlayerName (pc, 0)
	Label = Window.GetControl (0x10000035)
	Label.SetText (Name)

	mem_cnt = GemRB.GetMemorizedSpellsCount (pc, type, level, False)
	for i in range (12):
		Button = Window.GetControl (3 + i)
		if i < mem_cnt:
			ms = GemRB.GetMemorizedSpell (pc, type, level, i)
			Button.SetSpellIcon (ms['SpellResRef'], 0)
			Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_NAND)
			Button.SetFlags (IE_GUI_BUTTON_PICTURE | IE_GUI_BUTTON_PLAYONCE, OP_OR)
			if ms['Flags']:
				Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenPriestSpellUnmemorizeWindow)
			else:
				Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnPriestUnmemorizeSpell)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenPriestSpellInfoWindow)
			spell = GemRB.GetSpell (ms['SpellResRef'])
			Button.SetTooltip (spell['SpellName'])
			PriestMemorizedSpellList.append (ms['SpellResRef'])
			Button.SetVarAssoc ("SpellButton", i)
			Button.EnableBorder (0, ms['Flags'] == 0)
		else:
			if i < max_mem_cnt:
				Button.SetFlags (IE_GUI_BUTTON_NORMAL | IE_GUI_BUTTON_PLAYONCE, OP_SET)
			else:
				Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_SET)
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
			Button.SetTooltip ('')
			Button.EnableBorder (0, 0)


	known_cnt = GemRB.GetKnownSpellsCount (pc, type, level)
	for i in range (GUICommon.GetIWDSpellButtonCount()):
		Button = Window.GetControl (27 + i)
		if i < known_cnt:
			ks = GemRB.GetKnownSpell (pc, type, level, i)
			Button.SetSpellIcon (ks['SpellResRef'], 0)
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OnPriestMemorizeSpell)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, OpenPriestSpellInfoWindow)
			spell = GemRB.GetSpell (ks['SpellResRef'])
			Button.SetTooltip (spell['SpellName'])
			PriestKnownSpellList.append (ks['SpellResRef'])
			Button.SetVarAssoc ("SpellButton", 100 + i)

		else:
			Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE, OP_OR)
			Button.SetFlags (IE_GUI_BUTTON_PICTURE, OP_NAND)
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
			Button.SetTooltip ('')
			Button.EnableBorder (0, 0)

	Class = GemRB.GetPlayerStat (pc, IE_CLASS)
	DivineCaster = CommonTables.ClassSkills.GetValue (Class, 1)
	if DivineCaster == "*":
		# also check the DRUIDSPELL column
		DivineCaster = CommonTables.ClassSkills.GetValue (Class, 0)
	CantCast = DivineCaster == "*" or GemRB.GetPlayerStat(pc, IE_DISABLEDBUTTON)&(1<<ACT_CAST)
	if CantCast or GemRB.GetPlayerStat (pc, IE_STATE_ID) & STATE_DEAD:
		Window.SetVisible (WINDOW_GRAYED)
	else:
		Window.SetVisible (WINDOW_VISIBLE)
	return
예제 #18
0
def DualClassWindow():
    """Opens the dual class selection window."""

    global pc, OldClassName, NewMageSpells, NewPriestMask, NewClassId, OldKitName, DualClassTable
    global DCMainWindow, DCMainClassButton, DCMainDoneButton, DCMainSkillsButton, DCMainStep

    # get our basic globals
    pc = GemRB.GameGetSelectedPCSingle()
    DCMainStep = 1

    # make sure to nullify old values
    NewPriestMask = 0
    NewMageSpells = 0
    NewClassId = 0

    # set up our main window
    DCMainWindow = GemRB.LoadWindow(5)

    # done button (off)
    DCMainDoneButton = DCMainWindow.GetControl(2)
    DCMainDoneButton.SetText(11973)
    DCMainDoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCMainDonePress)
    DCMainDoneButton.SetState(IE_GUI_BUTTON_DISABLED)
    DCMainDoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # cancel button (on)
    DCMainCancelButton = DCMainWindow.GetControl(1)
    DCMainCancelButton.SetText(13727)
    DCMainCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCMainCancelPress)
    DCMainCancelButton.SetState(IE_GUI_BUTTON_ENABLED)
    DCMainCancelButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # class button (on)
    DCMainClassButton = DCMainWindow.GetControl(3)
    DCMainClassButton.SetText(11959)
    DCMainClassButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCMainClassPress)
    DCMainClassButton.SetState(IE_GUI_BUTTON_ENABLED)
    DCMainClassButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # skills button (off)
    DCMainSkillsButton = DCMainWindow.GetControl(4)
    DCMainSkillsButton.SetText(17372)
    DCMainSkillsButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCMainSkillsPress)
    DCMainSkillsButton.SetState(IE_GUI_BUTTON_DISABLED)
    DCMainSkillsButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # back button (on)
    DCMainBackButton = DCMainWindow.GetControl(5)
    if GameCheck.IsBG2():
        DCMainBackButton.SetText(15416)
    DCMainBackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DCMainBackPress)
    DCMainBackButton.SetState(IE_GUI_BUTTON_ENABLED)
    DCMainBackButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)

    # picture of character
    DCMainPictureButton = DCMainWindow.GetControl(6)
    DCMainPictureButton.SetState(IE_GUI_BUTTON_LOCKED)
    DCMainPictureButton.SetFlags(
        IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
    DCMainPictureButton.SetPicture(GemRB.GetPlayerPortrait(pc, 0), "NOPORTMD")

    # text area warning
    DCTextArea = DCMainWindow.GetControl(7)
    DCTextArea.SetText(10811)

    # character name
    DCLabel = DCMainWindow.GetControl(0x10000008)
    DCLabel.SetText(GemRB.GetPlayerName(pc, 0))

    # class name
    Kit = GUICommon.GetKitIndex(pc)
    OldClassName = GUICommon.GetClassRowName(pc)
    if Kit:
        OldKitName = CommonTables.KitList.GetValue(Kit, 0, GTV_STR)
    else:
        OldKitName = OldClassName
    DCLabel = DCMainWindow.GetControl(0x10000009)
    DCLabel.SetText(GUICommon.GetActorClassTitle(pc))

    # get the names of the classes we can dual to
    DualClassTable = GemRB.LoadTable("dualclas")
    for i in range(DualClassTable.GetColumnCount()):
        DCClasses.append(DualClassTable.GetColumnName(i))

    # show our window
    DCMainWindow.ShowModal(MODAL_SHADOW_GRAY)
    return
예제 #19
0
def OpenInformationWindow():
    global InformationWindow

    if InformationWindow != None:
        GUIRECCommon.CloseBiographyWindow()
        CloseInformationWindow()
        return

    InformationWindow = Window = GemRB.LoadWindow(4)

    # Biography
    Button = Window.GetControl(26)
    Button.SetText(18003)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIRECCommon.OpenBiographyWindow)

    # Done
    Button = Window.GetControl(24)
    Button.SetText(11973)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, CloseInformationWindow)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    TotalPartyExp = 0
    ChapterPartyExp = 0
    TotalPartyKills = 0
    ChapterCount = 0
    for i in range(1, GemRB.GetPartySize() + 1):
        stat = GemRB.GetPCStats(i)
        TotalPartyExp = TotalPartyExp + stat['KillsTotalXP']
        ChapterPartyExp = ChapterPartyExp + stat['KillsChapterXP']
        TotalPartyKills = TotalPartyKills + stat['KillsTotalCount']
        ChapterCount = ChapterCount + stat['KillsChapterCount']

    # These are used to get the stats
    pc = GemRB.GameGetSelectedPCSingle()
    stat = GemRB.GetPCStats(pc)

    Label = Window.GetControl(0x10000000)
    Label.SetText(GemRB.GetPlayerName(pc, 1))
    # class
    ClassTitle = GUICommon.GetActorClassTitle(pc)
    Label = Window.GetControl(0x10000018)
    Label.SetText(ClassTitle)

    #most powerful vanquished
    Label = Window.GetControl(0x10000005)
    #we need getstring, so -1 will translate to empty string
    Label.SetText(GemRB.GetString(stat['BestKilledName']))

    Label = Window.GetControl(0x10000006)
    time = GUICommon.SetCurrentDateTokens(stat)
    Label.SetText(time)

    #favourite spell
    Label = Window.GetControl(0x10000007)
    Label.SetText(stat['FavouriteSpell'])

    #favourite weapon
    Label = Window.GetControl(0x10000008)
    #actually it is 10479 <WEAPONNAME>, but weaponname is translated to
    #the real weapon name (which we should set using SetToken)
    #there are other strings like bow+wname/xbow+wname/sling+wname
    #are they used?
    Label.SetText(stat['FavouriteWeapon'])

    #total party xp
    Label = Window.GetControl(0x10000013)
    if TotalPartyExp != 0:
        PartyExp = int((stat['KillsTotalXP'] * 100) / TotalPartyExp)
        Label.SetText(str(PartyExp) + '%')
    else:
        Label.SetText("0%")

    # chapter party xp
    Label = Window.GetControl(0x1000000f)
    if ChapterPartyExp != 0:
        PartyExp = int((stat['KillsChapterXP'] * 100) / ChapterPartyExp)
        Label.SetText(str(PartyExp) + '%')
    else:
        Label.SetText("0%")

    # total kills
    Label = Window.GetControl(0x10000014)
    if TotalPartyKills != 0:
        PartyKills = int((stat['KillsTotalCount'] * 100) / TotalPartyKills)
        Label.SetText(str(PartyKills) + '%')
    else:
        Label.SetText("0%")

    # chapter kills
    Label = Window.GetControl(0x10000010)
    if ChapterCount != 0:
        PartyKills = int((stat['KillsChapterCount'] * 100) / ChapterCount)
        Label.SetText(str(PartyKills) + '%')
    else:
        Label.SetText("0%")

    Label = Window.GetControl(0x10000011)
    Label.SetText(str(stat['KillsChapterXP']))
    Label = Window.GetControl(0x10000015)
    Label.SetText(str(stat['KillsTotalXP']))

    #count of kills in chapter/game
    Label = Window.GetControl(0x10000012)
    Label.SetText(str(stat['KillsChapterCount']))
    Label = Window.GetControl(0x10000016)
    Label.SetText(str(stat['KillsTotalCount']))

    Window.ShowModal(MODAL_SHADOW_GRAY)
    return
예제 #20
0
def GetCharacterHeader(pc):
    global avatar_header

    Class = GemRB.GetPlayerStat(pc, IE_CLASS) - 1
    Multi = GUICommon.HasMultiClassBits(pc)
    Specific = "%d" % GemRB.GetPlayerStat(pc, IE_SPECIFIC)

    #Nameless is Specific == 1
    avatar_header['Specific'] = Specific

    # Nameless is a special case (dual class)
    if Specific == 1:
        avatar_header['PrimClass'] = CommonTables.Classes.GetRowName(Class)
        avatar_header['SecoClass'] = "*"

        avatar_header['SecoLevel'] = 0

        if avatar_header['PrimClass'] == "FIGHTER":
            avatar_header['PrimLevel'] = GemRB.GetPlayerStat(pc, IE_LEVEL)
            avatar_header['XP'] = GemRB.GetPlayerStat(pc, IE_XP)
        elif avatar_header['PrimClass'] == "MAGE":
            avatar_header['PrimLevel'] = GemRB.GetPlayerStat(pc, IE_LEVEL2)
            avatar_header['XP'] = GemRB.GetPlayerStat(pc, IE_XP_MAGE)
        else:
            avatar_header['PrimLevel'] = GemRB.GetPlayerStat(pc, IE_LEVEL3)
            avatar_header['XP'] = GemRB.GetPlayerStat(pc, IE_XP_THIEF)

        avatar_header['PrimNextLevXP'] = GetNextLevelExp(
            avatar_header['PrimLevel'], avatar_header['PrimClass'])
        avatar_header['SecoNextLevXP'] = 0
    else:
        # PC is not NAMELESS_ONE
        avatar_header['PrimLevel'] = GemRB.GetPlayerStat(pc, IE_LEVEL)
        avatar_header['XP'] = GemRB.GetPlayerStat(pc, IE_XP)
        if Multi:
            avatar_header['XP'] = avatar_header['XP'] / 2
            avatar_header['SecoLevel'] = GemRB.GetPlayerStat(pc, IE_LEVEL2)

            avatar_header['PrimClass'] = "FIGHTER"
            if Multi == 3:
                #fighter/mage
                Class = 0
            else:
                #fighter/thief
                Class = 3
            avatar_header['SecoClass'] = CommonTables.Classes.GetRowName(Class)

            avatar_header['PrimNextLevXP'] = GetNextLevelExp(
                avatar_header['PrimLevel'], avatar_header['PrimClass'])
            avatar_header['SecoNextLevXP'] = GetNextLevelExp(
                avatar_header['SecoLevel'], avatar_header['SecoClass'])

            # Converting to the displayable format
            avatar_header['SecoClass'] = CommonTables.Classes.GetValue(
                avatar_header['SecoClass'], "NAME_REF", GTV_REF)
        else:
            avatar_header['SecoLevel'] = 0
            avatar_header['PrimClass'] = CommonTables.Classes.GetRowName(Class)
            avatar_header['SecoClass'] = "*"
            avatar_header['PrimNextLevXP'] = GetNextLevelExp(
                avatar_header['PrimLevel'], avatar_header['PrimClass'])
            avatar_header['SecoNextLevXP'] = 0

    # Converting to the displayable format
    avatar_header['PrimClass'] = CommonTables.Classes.GetValue(
        avatar_header['PrimClass'], "NAME_REF", GTV_REF)
예제 #21
0
파일: GUISAVE.py 프로젝트: ogregoire/gemrb
def OpenSaveWindow():
    global SaveWindow, Games, ScrollBar
    global num_rows, ctrl_offset, sav_version, strs

    if GameCheck.IsIWD2():
        num_rows = 5
        ctrl_offset = (55, 60, 25, 0x10000005, 0x1000000a, 23, 22, 3,
                       0x10000004, 40, 7, 8, 2)
        sav_version = 22
    else:
        if GameCheck.IsPST():
            ctrl_offset = (14, 18, 22, 0x10000004, 0x10000008, 13, 46, 1,
                           0x10000002, 6, 4, 5, 3)
            strs = {
                'cancel': 4196,
                'save': 28645,
                'delete': 28640,
                'empty': 28647,
                'overwrite': 28644,
                'yousure': 28639
            }

    SaveWindow = Window = GemRB.LoadWindow(0, "GUISAVE")

    # Cancel button
    CancelButton = Window.GetControl(ctrl_offset[6])
    CancelButton.SetText(strs['cancel'])
    CancelButton.OnPress(CloseSaveWindow)
    CancelButton.MakeEscape()

    for i in range(num_rows):
        Button = Window.GetControl(ctrl_offset[0] + i)
        Button.SetText(strs['save'])
        Button.OnPress(OpenConfirmWindow)
        Button.SetState(IE_GUI_BUTTON_DISABLED)
        Button.SetValue(i)

        Button = Window.GetControl(ctrl_offset[1] + i)
        Button.SetText(strs['delete'])
        Button.OnPress(DeleteGamePress)
        Button.SetState(IE_GUI_BUTTON_DISABLED)
        Button.SetValue(i)

        # area previews
        Button = Window.GetControl(1 + i)
        Button.SetState(IE_GUI_BUTTON_LOCKED)
        Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)

        # PC portraits
        for j in range(min(6, MAX_PARTY_SIZE)):
            Button = Window.GetControl(ctrl_offset[2] +
                                       i * min(6, MAX_PARTY_SIZE) + j)
            Button.SetState(IE_GUI_BUTTON_LOCKED)
            Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE,
                            OP_SET)
            if GameCheck.IsIWD2():
                Button.SetSize(21, 21)

    ScrollBar = Window.GetControl(ctrl_offset[5])
    ScrollBar.OnChange(ScrollBarPress)
    GUICommon.SetSaveDir()
    Games = GemRB.GetSaveGames()
    TopIndex = max(0, len(Games) - num_rows + 1)  #one more for the 'new game'
    ScrollBar.SetVarAssoc("TopIndex", TopIndex, 0, TopIndex)
    Window.SetEventProxy(ScrollBar)
    ScrollBarPress()
    Window.Focus()
    return
예제 #22
0
def OpenInformationWindow():
    global InformationWindow

    GemRB.HideGUI()

    if InformationWindow != None:
        if BiographyWindow: OpenBiographyWindow()

        if InformationWindow:
            InformationWindow.Unload()
        InformationWindow = None
        GemRB.SetVar("FloatWindow", -1)

        GemRB.UnhideGUI()
        return

    InformationWindow = Window = GemRB.LoadWindow(5)
    GemRB.SetVar("FloatWindow", InformationWindow.ID)

    # Biography
    Button = Window.GetControl(1)
    Button.SetText(4247)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenBiographyWindow)

    # Done
    Button = Window.GetControl(0)
    Button.SetText(1403)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenInformationWindow)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    TotalPartyExp = 0
    TotalPartyKills = 0
    for i in range(1, GemRB.GetPartySize() + 1):
        stat = GemRB.GetPCStats(i)
        TotalPartyExp = TotalPartyExp + stat['KillsTotalXP']
        TotalPartyKills = TotalPartyKills + stat['KillsTotalCount']

    # These are used to get the stats
    pc = GemRB.GameGetSelectedPCSingle()
    stat = GemRB.GetPCStats(pc)

    Label = Window.GetControl(0x10000001)
    Label.SetText(GemRB.GetPlayerName(pc, 1))

    # class
    ClassTitle = GUICommon.GetActorClassTitle(pc)
    Label = Window.GetControl(0x1000000A)
    Label.SetText(ClassTitle)

    Label = Window.GetControl(0x10000002)
    if stat['BestKilledName'] == -1:
        Label.SetText(GemRB.GetString(41275))
    else:
        Label.SetText(GemRB.GetString(stat['BestKilledName']))

    Label = Window.GetControl(0x10000003)
    GUICommon.SetCurrentDateTokens(stat, True)
    Label.SetText(41277)

    Label = Window.GetControl(0x10000004)
    Label.SetText(stat['FavouriteSpell'])

    Label = Window.GetControl(0x10000005)
    Label.SetText(stat['FavouriteWeapon'])

    Label = Window.GetControl(0x10000006)
    if TotalPartyExp != 0:
        PartyExp = int((stat['KillsTotalXP'] * 100) / TotalPartyExp)
        Label.SetText(str(PartyExp) + '%')
    else:
        Label.SetText("0%")

    Label = Window.GetControl(0x10000007)
    if TotalPartyKills != 0:
        PartyKills = int((stat['KillsTotalCount'] * 100) / TotalPartyKills)
        Label.SetText(str(PartyKills) + '%')
    else:
        Label.SetText("0%")

    Label = Window.GetControl(0x10000008)
    Label.SetText(str(stat['KillsTotalXP']))

    Label = Window.GetControl(0x10000009)
    Label.SetText(str(stat['KillsTotalCount']))

    Label = Window.GetControl(0x1000000B)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x1000000C)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x1000000D)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x1000000E)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x1000000F)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x10000010)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x10000011)
    Label.SetTextColor(255, 255, 255)

    Label = Window.GetControl(0x10000012)
    Label.SetTextColor(255, 255, 255)

    GemRB.UnhideGUI()
    Window.ShowModal(MODAL_SHADOW_GRAY)
예제 #23
0
def guardHateRace():
    MyChar = GemRB.GetVar("Slot")
    ClassName = GUICommon.GetClassRowName(MyChar)
    TableName = CommonTables.ClassSkills.GetValue(ClassName, "HATERACE")
    return TableName != "*"
예제 #24
0
def OpenRecordsWindow():
    global RecordsWindow
    global StatTable

    StatTable = GemRB.LoadTable("abcomm")

    if GUICommon.CloseOtherWindow(OpenRecordsWindow):
        GemRB.HideGUI()
        if InformationWindow: OpenInformationWindow()

        if RecordsWindow:
            RecordsWindow.Unload()
        RecordsWindow = None
        GemRB.SetVar("OtherWindow", -1)
        GUICommonWindows.SetSelectionChangeHandler(None)

        GemRB.UnhideGUI()
        return

    GemRB.HideGUI()
    GemRB.LoadWindowPack("GUIREC")
    RecordsWindow = Window = GemRB.LoadWindow(3)
    GemRB.SetVar("OtherWindow", RecordsWindow.ID)

    # Information
    Button = Window.GetControl(7)
    Button.SetText(4245)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenInformationWindow)

    # Reform Party
    Button = Window.GetControl(8)
    Button.SetText(4244)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIWORLD.OpenReformPartyWindow)

    # Level Up
    Button = Window.GetControl(9)
    Button.SetText(4246)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, NewLife.OpenLUStatsWindow)

    statevents = (OnRecordsHelpStrength, OnRecordsHelpIntelligence,
                  OnRecordsHelpWisdom, OnRecordsHelpDexterity,
                  OnRecordsHelpConstitution, OnRecordsHelpCharisma)
    # stat buttons
    for i in range(6):
        Button = Window.GetControl(31 + i)
        Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_SET)
        Button.SetSprites("", 0, 0, 0, 0, 0)
        Button.SetState(IE_GUI_BUTTON_LOCKED)
        Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, statevents[i])
        Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, OnRecordsButtonLeave)

    # AC button
    Button = Window.GetControl(37)
    Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_SET)
    Button.SetSprites("", 0, 0, 0, 0, 0)
    Button.SetState(IE_GUI_BUTTON_LOCKED)
    Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, OnRecordsHelpArmorClass)
    Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, OnRecordsButtonLeave)

    # HP button
    Button = Window.GetControl(38)
    Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE, OP_SET)
    Button.SetSprites("", 0, 0, 0, 0, 0)
    Button.SetState(IE_GUI_BUTTON_LOCKED)
    Button.SetEvent(IE_GUI_MOUSE_OVER_BUTTON, OnRecordsHelpHitPoints)
    Button.SetEvent(IE_GUI_MOUSE_LEAVE_BUTTON, OnRecordsButtonLeave)

    GUICommonWindows.SetSelectionChangeHandler(UpdateRecordsWindow)
    UpdateRecordsWindow()

    GemRB.UnhideGUI()
예제 #25
0
def unsetColors():
    MyChar = GemRB.GetVar("Slot")
    GUICommon.SetColorStat(MyChar, IE_HAIR_COLOR, 0)
    GUICommon.SetColorStat(MyChar, IE_SKIN_COLOR, 0)
    GUICommon.SetColorStat(MyChar, IE_MAJOR_COLOR, 0)
    GUICommon.SetColorStat(MyChar, IE_MINOR_COLOR, 0)
예제 #26
0
def OpenLevelUpWindow():
    global LevelUpWindow
    global SavThrows
    global HPGained
    global WeapProfType, CurrWeapProf, WeapProfGained
    global NumOfPrimLevUp, NumOfSecoLevUp

    GemRB.HideGUI()

    if LevelUpWindow != None:
        if LevelUpWindow:
            LevelUpWindow.Unload()
        LevelUpWindow = None
        GemRB.SetVar("FloatWindow", -1)

        GemRB.UnhideGUI()
        return

    GemRB.LoadWindowPack("GUIREC")  # since we get called from NewLife
    LevelUpWindow = Window = GemRB.LoadWindow(4)
    GemRB.SetVar("FloatWindow", LevelUpWindow.ID)

    # Accept
    Button = Window.GetControl(0)
    Button.SetText(4192)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, AcceptLevelUp)

    pc = GemRB.GameGetSelectedPCSingle()

    # These are used to identify Nameless One
    BioTable = GemRB.LoadTable("bios")
    Specific = GemRB.GetPlayerStat(pc, IE_SPECIFIC)
    AvatarName = BioTable.GetRowName(Specific + 1)

    # These will be used for saving throws
    SavThrUpdated = False
    SavThrows = [0, 0, 0, 0, 0]
    SavThrows[0] = GemRB.GetPlayerStat(pc, IE_SAVEVSDEATH)
    SavThrows[1] = GemRB.GetPlayerStat(pc, IE_SAVEVSWANDS)
    SavThrows[2] = GemRB.GetPlayerStat(pc, IE_SAVEVSPOLY)
    SavThrows[3] = GemRB.GetPlayerStat(pc, IE_SAVEVSBREATH)
    SavThrows[4] = GemRB.GetPlayerStat(pc, IE_SAVEVSSPELL)

    HPGained = 0
    ConHPBon = 0
    Thac0Updated = False
    Thac0 = 0
    WeapProfGained = 0

    ClasWeapTable = GemRB.LoadTable("weapprof")
    WeapProfType = -1
    CurrWeapProf = -1
    #This does not apply to Nameless since he uses unused slots system
    #Nameless is Specific == 1
    if Specific != "1":
        # Searching for the column name where value is 1
        for i in range(5):
            WeapProfName = ClasWeapTable.GetRowName(i)
            value = ClasWeapTable.GetValue(AvatarName, WeapProfName)
            if value == 1:
                WeapProfType = i
                break

    if WeapProfType != -1:
        CurrWeapProf = GemRB.GetPlayerStat(pc, IE_WEAPPROF + WeapProfType)

    # Recording this avatar's current proficiency level
    # Since Nameless one is not covered, hammer and club can't occur
    # What is the avatar's class (Which we can use to lookup XP)
    Class = GUICommon.GetClassRowName(pc)

    # name
    Label = Window.GetControl(0x10000000)
    Label.SetText(GemRB.GetPlayerName(pc, 1))

    # class
    Label = Window.GetControl(0x10000001)
    Label.SetText(CommonTables.Classes.GetValue(Class, "NAME_REF"))

    # Armor Class
    Label = Window.GetControl(0x10000023)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_ARMORCLASS)))

    # Thief Skills
    # For now we shall set them to the current levels and disable the increment buttons
    # Points Left
    Label = Window.GetControl(0x10000006)
    Label.SetText('0')
    # Stealth
    Label = Window.GetControl(0x10000008)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_STEALTH)) + '%')
    # Detect Traps
    Label = Window.GetControl(0x1000000A)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_TRAPS)) + '%')
    # Pick Pockets
    Label = Window.GetControl(0x1000000C)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_PICKPOCKET)) + '%')
    # Open Doors
    Label = Window.GetControl(0x1000000E)
    Label.SetText(str(GemRB.GetPlayerStat(pc, IE_LOCKPICKING)) + '%')
    # Plus and Minus buttons
    for i in range(8):
        Button = Window.GetControl(16 + i)
        Button.SetState(IE_GUI_BUTTON_LOCKED)

    # Is avatar multi-class?
    if avatar_header['SecoLevel'] == 0:
        # avatar is single class
        # What will be avatar's next level?
        NextLevel = avatar_header['PrimLevel'] + 1
        while avatar_header['XP'] >= GetNextLevelExp(NextLevel, Class):
            NextLevel = NextLevel + 1
        NumOfPrimLevUp = NextLevel - avatar_header[
            'PrimLevel']  # How many levels did we go up?

        # Is avatar Nameless One?
        if Specific == "1":
            # Saving Throws
            # Nameless One gets the best possible throws from all the classes except Priest
            FigSavThrTable = GemRB.LoadTable("SAVEWAR")
            MagSavThrTable = GemRB.LoadTable("SAVEWIZ")
            ThiSavThrTable = GemRB.LoadTable("SAVEROG")
            # For Nameless, we also need to know his levels in every class, so that we pick
            # the right values from the corresponding tables. Also we substract one, so
            # that we may use them as column indices in tables.
            FighterLevel = GemRB.GetPlayerStat(pc, IE_LEVEL) - 1
            MageLevel = GemRB.GetPlayerStat(pc, IE_LEVEL2) - 1
            ThiefLevel = GemRB.GetPlayerStat(pc, IE_LEVEL3) - 1
            # this is the constitution bonus type for this level
            CONType = 1
            # We are leveling up one of those levels. Therefore, one of them has to be updated.
            if avatar_header['PrimClass'] == "FIGHTER":
                FighterLevel = NextLevel - 1
                CONType = 0
            elif avatar_header['PrimClass'] == "MAGE":
                MageLevel = NextLevel - 1
            else:
                ThiefLevel = NextLevel - 1

            ConHPBon = GetConHPBonus(pc, NumOfPrimLevUp, 0, CONType)
            # Now we need to update the saving throws with the best values from those tables.
            # The smaller the number, the better saving throw it is.
            # We also need to check if any of the levels are larger than 21, since
            # after that point the table runs out, and the throws remain the
            # same
            if FighterLevel < 21:
                for i in range(5):
                    Throw = FigSavThrTable.GetValue(i, FighterLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            if MageLevel < 21:
                for i in range(5):
                    Throw = MagSavThrTable.GetValue(i, MageLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            if ThiefLevel < 21:
                for i in range(5):
                    Throw = ThiSavThrTable.GetValue(i, ThiefLevel)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            # Cleaning up
        else:
            #How many weapon procifiencies we get
            for i in range(NumOfPrimLevUp):
                if HasGainedWeapProf(pc, CurrWeapProf + WeapProfGained,
                                     avatar_header['PrimLevel'] + i,
                                     avatar_header['PrimClass']):
                    WeapProfGained += 1

            # Saving Throws
            # Loading the right saving throw table
            SavThrTable = GemRB.LoadTable(
                CommonTables.Classes.GetValue(Class, "SAVE"))
            # Updating the current saving throws. They are changed only if the
            # new ones are better than current. The smaller the number, the better.
            # We need to substract one from the NextLevel, so that we get right values.
            # We also need to check if NextLevel is larger than 21, since after that point
            # the table runs out, and the throws remain the same
            if NextLevel < 22:
                for i in range(5):
                    Throw = SavThrTable.GetValue(i, NextLevel - 1)
                    if Throw < SavThrows[i]:
                        SavThrows[i] = Throw
                        SavThrUpdated = True
            # Cleaning Up

            # Hit Points Gained and Hit Points from Constitution Bonus
            for i in range(NumOfPrimLevUp):
                HPGained = HPGained + GetSingleClassHP(
                    Class, avatar_header['PrimLevel'])

            if avatar_header['PrimClass'] == "FIGHTER":
                CONType = 0
            else:
                CONType = 1
            ConHPBon = GetConHPBonus(pc, NumOfPrimLevUp, 0, CONType)

            # Thac0
            Thac0 = GetThac0(Class, NextLevel)
            # Is the new thac0 better than old? (The smaller, the better)
            if Thac0 < GemRB.GetPlayerStat(pc, IE_TOHIT, 1):
                Thac0Updated = True

    else:
        # avatar is multi class
        # we have only fighter/X multiclasses, so this
        # part is a bit hardcoded
        PrimNextLevel = 0
        SecoNextLevel = 0
        NumOfPrimLevUp = 0
        NumOfSecoLevUp = 0

        # What will be avatar's next levels?
        PrimNextLevel = avatar_header['PrimLevel']
        while avatar_header['XP'] >= GetNextLevelExp(PrimNextLevel, "FIGHTER"):
            PrimNextLevel = PrimNextLevel + 1
        # How many primary levels did we go up?
        NumOfPrimLevUp = PrimNextLevel - avatar_header['PrimLevel']

        for i in range(NumOfPrimLevUp):
            if HasGainedWeapProf(pc, CurrWeapProf + WeapProfGained,
                                 avatar_header['PrimLevel'] + i,
                                 avatar_header['PrimClass']):
                WeapProfGained += 1

        # Saving Throws
        FigSavThrTable = GemRB.LoadTable("SAVEWAR")
        if PrimNextLevel < 22:
            for i in range(5):
                Throw = FigSavThrTable.GetValue(i, PrimNextLevel - 1)
                if Throw < SavThrows[i]:
                    SavThrows[i] = Throw
                    SavThrUpdated = True
        # Which multi class is it?
        if GemRB.GetPlayerStat(pc, IE_CLASS) == 7:
            # avatar is Fighter/Mage (Dak'kon)
            Class = "MAGE"
            SavThrTable = GemRB.LoadTable("SAVEWIZ")
        else:
            # avatar is Fighter/Thief (Annah)
            Class = "THIEF"
            SavThrTable = GemRB.LoadTable("SAVEROG")

        SecoNextLevel = avatar_header['SecoLevel']
        while avatar_header['XP'] >= GetNextLevelExp(SecoNextLevel, Class):
            SecoNextLevel = SecoNextLevel + 1
        # How many secondary levels did we go up?
        NumOfSecoLevUp = SecoNextLevel - avatar_header['SecoLevel']
        if SecoNextLevel < 22:
            for i in range(5):
                Throw = SavThrTable.GetValue(i, SecoNextLevel - 1)
                if Throw < SavThrows[i]:
                    SavThrows[i] = Throw
                    SavThrUpdated = True

        # Hit Points Gained and Hit Points from Constitution Bonus (multiclass)
        for i in range(NumOfPrimLevUp):
            HPGained = HPGained + GetSingleClassHP(
                "FIGHTER", avatar_header['PrimLevel']) / 2

        for i in range(NumOfSecoLevUp):
            HPGained = HPGained + GetSingleClassHP(
                Class, avatar_header['SecoLevel']) / 2
        ConHPBon = GetConHPBonus(pc, NumOfPrimLevUp, NumOfSecoLevUp, 2)

        # Thac0
        # Multi class use the primary class level to determine Thac0
        Thac0 = GetThac0(Class, PrimNextLevel)
        # Is the new thac0 better than old? (The smaller the better)
        if Thac0 < GemRB.GetPlayerStat(pc, IE_TOHIT, 1):
            Thac0Updated = True

    # Displaying the saving throws
    # Death
    Label = Window.GetControl(0x10000019)
    Label.SetText(str(SavThrows[0]))
    # Wand
    Label = Window.GetControl(0x1000001B)
    Label.SetText(str(SavThrows[1]))
    # Polymorph
    Label = Window.GetControl(0x1000001D)
    Label.SetText(str(SavThrows[2]))
    # Breath
    Label = Window.GetControl(0x1000001F)
    Label.SetText(str(SavThrows[3]))
    # Spell
    Label = Window.GetControl(0x10000021)
    Label.SetText(str(SavThrows[4]))

    FinalCurHP = GemRB.GetPlayerStat(pc, IE_HITPOINTS) + HPGained
    FinalMaxHP = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS) + HPGained

    # Current HP
    Label = Window.GetControl(0x10000025)
    Label.SetText(str(FinalCurHP))

    # Max HP
    Label = Window.GetControl(0x10000027)
    Label.SetText(str(FinalMaxHP))

    # Displaying level up info
    overview = ""
    if CurrWeapProf != -1 and WeapProfGained > 0:
        overview = overview + '+' + str(
            WeapProfGained) + ' ' + GemRB.GetString(WeapProfDispStr) + '\n'

    overview = overview + str(HPGained) + " " + GemRB.GetString(38713) + '\n'
    overview = overview + str(ConHPBon) + " " + GemRB.GetString(38727) + '\n'

    if SavThrUpdated:
        overview = overview + GemRB.GetString(38719) + '\n'
    if Thac0Updated:
        GemRB.SetPlayerStat(pc, IE_TOHIT, Thac0)
        overview = overview + GemRB.GetString(38718) + '\n'

    Text = Window.GetControl(3)
    Text.SetText(overview)

    GemRB.UnhideGUI()
    Window.ShowModal(MODAL_SHADOW_GRAY)
예제 #27
0
파일: GUIINV.py 프로젝트: ThyWoof/gemrb
def RefreshInventoryWindow(Window):
    """Partial redraw without resetting TopIndex."""

    pc = GemRB.GameGetSelectedPCSingle()

    # name
    Label = Window.GetControl(0x10000032)
    Label.SetText(GemRB.GetPlayerName(pc, 0))

    # portrait
    Button = Window.GetControl(50)

    anim_id = GemRB.GetPlayerStat(pc, IE_ANIMATION_ID)
    row = "0x%04X" % anim_id
    size = CommonTables.Pdolls.GetValue(row, "SIZE")

    if size == "*":
        Button.SetPLT(GUICommon.GetActorPaperDoll(pc), -1, 0, 0, 0, 0, 0, 0, 0,
                      0)
    else:
        Color1 = GemRB.GetPlayerStat(pc, IE_METAL_COLOR)
        Color2 = GemRB.GetPlayerStat(pc, IE_MINOR_COLOR)
        Color3 = GemRB.GetPlayerStat(pc, IE_MAJOR_COLOR)
        Color4 = GemRB.GetPlayerStat(pc, IE_SKIN_COLOR)
        Color5 = GemRB.GetPlayerStat(pc, IE_LEATHER_COLOR)
        Color6 = GemRB.GetPlayerStat(pc, IE_ARMOR_COLOR)
        Color7 = GemRB.GetPlayerStat(pc, IE_HAIR_COLOR)
        Button.SetPLT(GUICommon.GetActorPaperDoll(pc), Color1, Color2, Color3,
                      Color4, Color5, Color6, Color7, 0, 0)

        # Weapon
        slot_item = GemRB.GetSlotItem(pc, GemRB.GetEquippedQuickSlot(pc))
        if slot_item:
            item = GemRB.GetItem(slot_item["ItemResRef"])
            if (item['AnimationType'] != ''):
                Button.SetPLT("WP" + size + item['AnimationType'] + "INV",
                              Color1, Color2, Color3, Color4, Color5, Color6,
                              Color7, 0, 1)

        # Shield
        slot_item = GemRB.GetSlotItem(pc, 3)
        if slot_item:
            itemname = slot_item["ItemResRef"]
            item = GemRB.GetItem(itemname)
            if (item['AnimationType'] != ''):
                if (GemRB.CanUseItemType(SLOT_WEAPON, itemname)):
                    #off-hand weapon
                    Button.SetPLT("WP" + size + item['AnimationType'] + "OIN",
                                  Color1, Color2, Color3, Color4, Color5,
                                  Color6, Color7, 0, 2)
                else:
                    #shield
                    Button.SetPLT("WP" + size + item['AnimationType'] + "INV",
                                  Color1, Color2, Color3, Color4, Color5,
                                  Color6, Color7, 0, 2)

        # Helmet
        slot_item = GemRB.GetSlotItem(pc, 1)
        if slot_item:
            item = GemRB.GetItem(slot_item["ItemResRef"])
            if (item['AnimationType'] != ''):
                Button.SetPLT("WP" + size + item['AnimationType'] + "INV",
                              Color1, Color2, Color3, Color4, Color5, Color6,
                              Color7, 0, 3)

    # encumbrance
    GUICommon.SetEncumbranceLabels(Window, 0x10000043, 0x10000044, pc)

    # armor class
    ac = GemRB.GetPlayerStat(pc, IE_ARMORCLASS)
    Label = Window.GetControl(0x10000038)
    Label.SetText(str(ac))

    # hp current
    hp = GemRB.GetPlayerStat(pc, IE_HITPOINTS)
    Label = Window.GetControl(0x10000039)
    Label.SetText(str(hp))

    # hp max
    hpmax = GemRB.GetPlayerStat(pc, IE_MAXHITPOINTS)
    Label = Window.GetControl(0x1000003a)
    Label.SetText(str(hpmax))

    # party gold
    Label = Window.GetControl(0x10000040)
    Label.SetText(str(GemRB.GameGetPartyGold()))

    # class
    ClassTitle = GUICommon.GetActorClassTitle(pc)
    Label = Window.GetControl(0x10000042)
    Label.SetText(ClassTitle)

    Button = Window.GetControl(62)
    Color = GemRB.GetPlayerStat(pc, IE_MAJOR_COLOR, 1) & 0xFF
    Button.SetBAM("COLGRAD", 0, 0, Color)

    Button = Window.GetControl(63)
    Color = GemRB.GetPlayerStat(pc, IE_MINOR_COLOR, 1) & 0xFF
    Button.SetBAM("COLGRAD", 0, 0, Color)

    # update ground inventory slots
    TopIndex = GemRB.GetVar("TopIndex")
    for i in range(5):
        Button = Window.GetControl(i + 68)
        if GemRB.IsDraggingItem() == 1:
            Button.SetState(IE_GUI_BUTTON_FAKEPRESSED)
        else:
            Button.SetState(IE_GUI_BUTTON_ENABLED)
        Button.SetAction(InventoryCommon.OnDragItemGround,
                         IE_ACT_DRAG_DROP_DST)
        Slot = GemRB.GetContainerItem(pc, i + TopIndex)

        if Slot == None:
            Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, None)
            Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
            Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS, None)
        else:
            Button.SetAction(InventoryCommon.OnDragItemGround,
                             IE_ACT_DRAG_DROP_CRT)
            Button.SetEvent(IE_GUI_BUTTON_ON_PRESS,
                            InventoryCommon.OnDragItemGround)
            Button.SetEvent(IE_GUI_BUTTON_ON_RIGHT_PRESS,
                            InventoryCommon.OpenGroundItemInfoWindow)
            Button.SetEvent(IE_GUI_BUTTON_ON_SHIFT_PRESS,
                            InventoryCommon.OpenGroundItemAmountWindow)

        InventoryCommon.UpdateInventorySlot(pc, Button, Slot, "ground")

    # making window visible/shaded depending on the pc's state
    GUICommon.AdjustWindowVisibility(Window, pc, False)
    return
예제 #28
0
def RefreshInventoryWindow ():
	Window = InventoryWindow

	pc = GemRB.GameGetSelectedPCSingle ()

	# name
	Label = Window.GetControl (0x10000032)
	Label.SetText (GemRB.GetPlayerName (pc, 0))

	# paperdoll
	Button = Window.GetControl (50)

	Button.SetFlags (IE_GUI_BUTTON_CENTER_PICTURES, OP_OR)
	pdoll = GUICommonWindows.GetActorPaperDoll (pc)+"WK"
	# FIXME: animation bleeds through top window
	# NOTE: regenerate invenwin.png with a transparent hole if we
	# can ever keep drawing the gamecontrol underneath ...
	# and then remove this block
	if GemRB.HasResource (pdoll, RES_BAM):
		pal = [GemRB.GetPlayerStat (pc, c) for c in range(IE_METAL_COLOR, IE_HAIR_COLOR + 1)]
		Button.SetAnimation (pdoll, 0, 0, pal)

	# portrait
	Button = Window.GetControl (84)
	# NOTE: use FillPlayerInfo or code to switch pics iff the party will grow
	#Button.SetPicture (GemRB.GetPlayerPortrait (pc,0))
	Button.SetPicture ("portr1L")

	# encumbrance
	GUICommon.SetEncumbranceLabels (Window, 0x10000042, None, pc)

	# armor class
	ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
	Label = Window.GetControl (0x10000038)
	Label.SetText (str (ac))

	# hp current
	hp = GemRB.GetPlayerStat (pc, IE_HITPOINTS)
	Label = Window.GetControl (0x10000039)
	Label.SetText (str (hp))

	# hp max
	hpmax = GemRB.GetPlayerStat (pc, IE_MAXHITPOINTS)
	Label = Window.GetControl (0x1000003a)
	Label.SetText (str (hpmax))

	# party gold
	Label = Window.GetControl (0x10000040)
	Label.SetText (str (GemRB.GameGetPartyGold ()))

	Button = Window.GetControl (62)
	Color = GemRB.GetPlayerStat (pc, IE_MAJOR_COLOR, 1) & 0xFF
	Button.SetBAM ("COLGRAD", 0, 0, Color)

	Button = Window.GetControl (63)
	Color = GemRB.GetPlayerStat (pc, IE_MINOR_COLOR, 1) & 0xFF
	Button.SetBAM ("COLGRAD", 0, 0, Color)

	Button = Window.GetControl (82)
	Color = GemRB.GetPlayerStat (pc, IE_HAIR_COLOR, 1) & 0xFF
	Button.SetBAM ("COLGRAD", 0, 0, Color)

	Button = Window.GetControl (83)
	Color = GemRB.GetPlayerStat (pc, IE_SKIN_COLOR, 1) & 0xFF
	Button.SetBAM ("COLGRAD", 0, 0, Color)

	# update ground inventory slots
	TopIndex = GemRB.GetVar ("TopIndex")
	for i in range (6):
		if i<5:
			Button = Window.GetControl (i+68)
		else:
			Button = Window.GetControl (i+76)

		if GemRB.IsDraggingItem ()==1:
			Button.SetState (IE_GUI_BUTTON_FAKEPRESSED)
		else:
			Button.SetState (IE_GUI_BUTTON_ENABLED)
		Button.SetAction (InventoryCommon.OnDragItemGround, IE_ACT_DRAG_DROP_DST)

		Slot = GemRB.GetContainerItem (pc, i+TopIndex)
		if Slot == None:
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, None)
			Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, None)
		else:
			Button.SetValue (i + TopIndex)
			Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, InventoryCommon.OnDragItemGround)
			Button.SetEvent (IE_GUI_BUTTON_ON_RIGHT_PRESS, InventoryCommon.OpenGroundItemInfoWindow)
			Button.SetEvent (IE_GUI_BUTTON_ON_SHIFT_PRESS, InventoryCommon.OpenGroundItemAmountWindow)

		InventoryCommon.UpdateInventorySlot (pc, Button, Slot, "ground")

	#if actor is uncontrollable, make this grayed
	GUICommon.AdjustWindowVisibility (Window, pc, False)
	return
예제 #29
0
def OpenReformPartyWindow():
    global ReformPartyWindow, OldActionsWindow, OldMessageWindow
    global removable_pcs

    GemRB.SetVar("Selected", 0)
    hideflag = GemRB.HideGUI()

    if ReformPartyWindow:
        ReformPartyWindow.Unload()
        GemRB.SetVar("ActionsWindow", OldActionsWindow.ID)
        GemRB.SetVar("MessageWindow", OldMessageWindow.ID)
        GemRB.SetVar("OtherWindow", -1)

        OldActionsWindow = None
        OldMessageWindow = None
        ReformPartyWindow = None
        if hideflag:
            GemRB.UnhideGUI()
        #re-enabling party size control
        GemRB.GameSetPartySize(PARTY_SIZE)
        GUICommonWindows.UpdatePortraitWindow()
        return

    GemRB.LoadWindowPack(GUICommon.GetWindowPack())
    ReformPartyWindow = Window = GemRB.LoadWindow(24)
    GemRB.SetVar("OtherWindow", Window.ID)

    # skip exportable party members (usually only the protagonist)
    removable_pcs = []
    for i in range(1, GemRB.GetPartySize() + 1):
        if not GemRB.GetPlayerStat(i, IE_MC_FLAGS) & MC_EXPORTABLE:
            removable_pcs.append(i)

    #PC portraits
    for j in range(PARTY_SIZE + 1):
        Button = Window.GetControl(j)
        Button.SetState(IE_GUI_BUTTON_LOCKED)
        Button.SetFlags(
            IE_GUI_BUTTON_RADIOBUTTON | IE_GUI_BUTTON_NO_IMAGE
            | IE_GUI_BUTTON_PICTURE, OP_SET)
        Button.SetBorder(FRAME_PC_SELECTED, 1, 1, 2, 2, 0, 255, 0, 255)
        if j < len(removable_pcs):
            Button.SetVarAssoc("Selected", removable_pcs[j])
        Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, UpdateReformWindow)

    # Remove
    Button = Window.GetControl(15)
    Button.SetText(17507)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, RemovePlayer)

    # Done
    Button = Window.GetControl(8)
    Button.SetText(11973)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, OpenReformPartyWindow)

    OldActionsWindow = GUIClasses.GWindow(GemRB.GetVar("ActionsWindow"))
    OldMessageWindow = GUIClasses.GWindow(GemRB.GetVar("MessageWindow"))
    GemRB.SetVar("ActionsWindow", -1)
    GemRB.SetVar("MessageWindow", -1)

    # if nobody can be removed, just close the window
    if not removable_pcs:
        OpenReformPartyWindow()
        if hideflag:
            GemRB.UnhideGUI()
        return

    UpdateReformWindow()
    if hideflag:
        GemRB.UnhideGUI()
    Window.ShowModal(MODAL_SHADOW_GRAY)
    return
예제 #30
0
def CancelPress():
    GUICommon.CloseOtherWindow(None)
    GemRB.SetNextScript(GemRB.GetToken("NextScript"))
    return
예제 #31
0
def SetupMenuWindowControls(Window, Gears, ReturnToGame):
    # FIXME: add "(key)" to tooltips!

    # Return to Game
    Button = Window.GetControl(0)
    Button.SetTooltip(16313)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 0)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, ReturnToGame)
    Button.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)

    # Map
    Button = Window.GetControl(1)
    Button.SetTooltip(16310)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 1)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIMA.OpenMapWindow)

    # Journal
    Button = Window.GetControl(2)
    Button.SetTooltip(16308)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 2)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIJRNL.OpenJournalWindow)

    # Inventory
    Button = Window.GetControl(3)
    Button.SetTooltip(16307)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 3)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIINV.OpenInventoryWindow)

    # Records
    Button = Window.GetControl(4)
    Button.SetTooltip(16306)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 4)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIREC.OpenRecordsWindow)

    # Mage
    Button = Window.GetControl(5)
    Button.SetTooltip(16309)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 5)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIMG.OpenMageWindow)
    # Priest
    Button = Window.GetControl(6)
    Button.SetTooltip(14930)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 6)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIPR.OpenPriestWindow)

    # Options
    Button = Window.GetControl(7)
    Button.SetTooltip(16311)
    #Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
    Button.SetVarAssoc("SelectedWindow", 7)
    Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUIOPT.OpenOptionsWindow)

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

    if Gears:
        # Gears (time), how doesn't have this in the right place
        if GUICommon.HasHOW():
            pos = GemRB.GetSystemVariable(SV_HEIGHT) - 71
            Window.CreateButton(9, 6, pos, 64, 71)
        Button = Window.GetControl(9)
        Button.SetAnimation("CGEAR")
        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(16041)

    MarkMenuButton(Window)
    return
예제 #32
0
def UpdateRecordsWindow():
    global alignment_help

    Window = RecordsWindow
    if not RecordsWindow:
        print "SelectionChange handler points to non existing window\n"
        return

    pc = GemRB.GameGetSelectedPCSingle()

    #update mage school
    GemRB.SetVar("MAGESCHOOL", 0)
    Kit = GUICommon.GetKitIndex(pc)
    if Kit and CommonTables.KitList.GetValue(Kit, 7) == 1:
        MageTable = GemRB.LoadTable("magesch")
        GemRB.SetVar(
            "MAGESCHOOL",
            MageTable.FindValue(3, CommonTables.KitList.GetValue(Kit, 6)))

    # exportable
    Button = Window.GetControl(36)
    if Exportable(pc):
        Button.SetState(IE_GUI_BUTTON_ENABLED)
    else:
        Button.SetState(IE_GUI_BUTTON_DISABLED)

    # dual-classable
    Button = Window.GetControl(0)
    if GUICommon.CanDualClass(pc):
        Button.SetState(IE_GUI_BUTTON_DISABLED)
    else:
        Button.SetState(IE_GUI_BUTTON_ENABLED)

    # levelup
    Button = Window.GetControl(37)
    if LUCommon.CanLevelUp(pc):
        Button.SetState(IE_GUI_BUTTON_ENABLED)
    else:
        Button.SetState(IE_GUI_BUTTON_DISABLED)

    # name
    Label = Window.GetControl(0x1000000e)
    Label.SetText(GemRB.GetPlayerName(pc, 0))

    # portrait
    Button = Window.GetControl(2)
    Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE | IE_GUI_BUTTON_PICTURE, OP_SET)
    Button.SetState(IE_GUI_BUTTON_LOCKED)
    if GameCheck.IsBG2() and not GameCheck.IsBG2Demo():
        Button.SetPicture(GemRB.GetPlayerPortrait(pc, 0), "NOPORTMD")
    else:
        Button.SetPicture(GemRB.GetPlayerPortrait(pc, 0), "NOPORTLG")

    # armorclass
    GUICommon.DisplayAC(pc, Window, 0x10000028)

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

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

    # stats
    sstr = GemRB.GetPlayerStat(pc, IE_STR)
    sstrx = GemRB.GetPlayerStat(pc, IE_STREXTRA)
    cstr = GetStatColor(pc, IE_STR)
    if sstrx > 0 and sstr == 18:
        sstr = "%d/%02d" % (sstr, sstrx % 100)
    else:
        sstr = str(sstr)

    sint = str(GemRB.GetPlayerStat(pc, IE_INT))
    cint = GetStatColor(pc, IE_INT)
    swis = str(GemRB.GetPlayerStat(pc, IE_WIS))
    cwis = GetStatColor(pc, IE_WIS)
    sdex = str(GemRB.GetPlayerStat(pc, IE_DEX))
    cdex = GetStatColor(pc, IE_DEX)
    scon = str(GemRB.GetPlayerStat(pc, IE_CON))
    ccon = GetStatColor(pc, IE_CON)
    schr = str(GemRB.GetPlayerStat(pc, IE_CHR))
    cchr = GetStatColor(pc, IE_CHR)

    Label = Window.GetControl(0x1000002f)
    Label.SetText(sstr)
    Label.SetTextColor(cstr[0], cstr[1], cstr[2])

    Label = Window.GetControl(0x10000009)
    Label.SetText(sdex)
    Label.SetTextColor(cdex[0], cdex[1], cdex[2])

    Label = Window.GetControl(0x1000000a)
    Label.SetText(scon)
    Label.SetTextColor(ccon[0], ccon[1], ccon[2])

    Label = Window.GetControl(0x1000000b)
    Label.SetText(sint)
    Label.SetTextColor(cint[0], cint[1], cint[2])

    Label = Window.GetControl(0x1000000c)
    Label.SetText(swis)
    Label.SetTextColor(cwis[0], cwis[1], cwis[2])

    Label = Window.GetControl(0x1000000d)
    Label.SetText(schr)
    Label.SetTextColor(cchr[0], cchr[1], cchr[2])

    # class
    ClassTitle = GUICommon.GetActorClassTitle(pc)
    Label = Window.GetControl(0x10000030)
    Label.SetText(ClassTitle)

    # race
    text = CommonTables.Races.GetValue(
        CommonTables.Races.FindValue(3, GemRB.GetPlayerStat(pc, IE_RACE)), 0)

    Label = Window.GetControl(0x1000000f)
    Label.SetText(text)

    # alignment
    text = CommonTables.Aligns.FindValue(3,
                                         GemRB.GetPlayerStat(pc, IE_ALIGNMENT))
    text = CommonTables.Aligns.GetValue(text, 0)
    Label = Window.GetControl(0x10000010)
    Label.SetText(text)

    # gender
    Label = Window.GetControl(0x10000011)
    if GemRB.GetPlayerStat(pc, IE_SEX) == 1:
        Label.SetText(7198)
    else:
        Label.SetText(7199)

    # help, info textarea
    Text = Window.GetControl(45)
    Text.SetText(GetStatOverview(pc))
    #TODO: making window visible/shaded depending on the pc's state
    Window.SetVisible(WINDOW_VISIBLE)
    return
예제 #33
0
def OpenSpellsWindow (actor, table, level, diff, kit=0, gen=0, recommend=True, booktype=0):
	"""Opens the spells selection window.

	table should refer to the name of the classes MXSPLxxx.2da.
	level contains the current level of the actor.
	diff contains the difference from the old level.
	kit should always be GetKitIndex except when dualclassing.
	gen is true if this is for character generation.
	recommend is used in bg2 for spell recommendation / autopick."""

	global SpellsWindow, DoneButton, SpellsSelectPointsLeft, Spells, chargen, SpellPointsLeftLabel
	global SpellsTextArea, SpellsKnownTable, SpellTopIndex, SpellBook, SpellLevel, pc, SpellStart
	global KitMask, EnhanceGUI, Memorization, SpellBookType, SpellsPickButton, ButtonCount, Class

	#enhance GUI?
	if (GemRB.GetVar("GUIEnhancements")&GE_SCROLLBARS) and not IWD2:
		EnhanceGUI = 1

	# save our pc
	pc = actor
	chargen = gen

	# this ensures compatibility with chargen, sorc, and dual-classing
	if kit == 0:
		KitMask = 0x4000
	else: # need to implement this if converted to CharGen
		KitMask = kit 

	if IWD2:
		# save the spellbook type (class) that corresponds to our table
		SpellBookType = booktype
		if not chargen:
			ButtonCount = 30

	# make sure there is an entry at the given level (bard)
	SpellsKnownTable = GemRB.LoadTable (table)
	if not SpellsKnownTable.GetValue (str(level), str(1), GTV_INT):
		if chargen:
			if GameCheck.IsBG2():
				GemRB.SetNextScript("GUICG6")
			elif GameCheck.IsBG1():
				# HACK
				from CharGenCommon import next
				next()
			elif IWD2:
				GemRB.SetNextScript ("CharGen7")
		return

	# load our window
	if chargen:
		GemRB.LoadWindowPack("GUICG", WIDTH, HEIGHT)
		SpellsWindow = GemRB.LoadWindow (7)
		if not recommend:
			GUICommon.CloseOtherWindow (SpellsWindow.Unload)
		DoneButton = SpellsWindow.GetControl (0)
		SpellsTextArea = SpellsWindow.GetControl (27)
		SpellPointsLeftLabel = SpellsWindow.GetControl (0x1000001b)
		if (EnhanceGUI):
			SpellsWindow.CreateScrollBar (1000, 325,42, 16,252)
			HideUnhideScrollBar(1)
		SpellStart = 2

		# cancel button only applicable for chargen
		SpellsCancelButton = SpellsWindow.GetControl(29)
		SpellsCancelButton.SetState(IE_GUI_BUTTON_ENABLED)
		SpellsCancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsCancelPress)
		SpellsCancelButton.SetText(13727)
		SpellsCancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)

		if (recommend):
			# recommended spell picks
			SpellsPickButton = SpellsWindow.GetControl(30)
			SpellsPickButton.SetState(IE_GUI_BUTTON_ENABLED)
			SpellsPickButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsPickPress)
			SpellsPickButton.SetText(34210)
	else:
		SpellsWindow = GemRB.LoadWindow (8)
		if IWD2:
			DoneButton = SpellsWindow.GetControl (33)
			SpellsTextArea = SpellsWindow.GetControl(30)
			SpellPointsLeftLabel = SpellsWindow.GetControl (0x10000022)
		else:
			DoneButton = SpellsWindow.GetControl (28)
			SpellsTextArea = SpellsWindow.GetControl(26)
			SpellPointsLeftLabel = SpellsWindow.GetControl (0x10000018)
		if(EnhanceGUI):
			SpellsWindow.CreateScrollBar (1000, 290,142, 16,252)
			HideUnhideScrollBar(1)
			#25th spell button for sorcerers
			SpellsWindow.CreateButton (24, 231, 345, 42, 42)
		SpellStart = 0

	# setup our variables
	GemRB.SetVar ("SpellTopIndex", 0)
	Memorization = 0
	Class = GemRB.GetPlayerStat (pc, IE_CLASS)
	if IWD2 and not chargen:
		LUClass = GemRB.GetVar ("LUClass")
		LUClassName = CommonTables.Classes.GetRowName (LUClass)
		LUClassID = CommonTables.Classes.GetValue (LUClassName, "ID")
		Class = LUClassID

	# the done button also doubles as a next button
	DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
	DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, SpellsDonePress)
	DoneButton.SetText(11973)
	DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)
		
	AlreadyShown = 0
	for i in range (9):
		# make sure we always have a value to minus (bards)
		SecondPoints = SpellsKnownTable.GetValue (str(level-diff), str(i+1), GTV_INT)
		if not SecondPoints:
			SecondPoints = 0

		# make sure we get more spells of each class before continuing
		SpellsSelectPointsLeft[i] = SpellsKnownTable.GetValue (str(level), str(i+1), GTV_INT) - SecondPoints
		if SpellsSelectPointsLeft[i] <= 0:
			continue
		elif chargen and KitMask != 0x4000 and (not IWD2 or Class == 11):
			# specialists get an extra spell per level
			SpellsSelectPointsLeft[i] += 1

		# chargen character seem to get more spells per level (this is kinda dirty hack)
		# except sorcerers
		if chargen and Class != 19 and not IWD2:
			SpellsSelectPointsLeft[i] += 1

		# get all the spells of the given level
		Spells[i] = Spellbook.GetMageSpells (KitMask, GemRB.GetPlayerStat (pc, IE_ALIGNMENT), i+1, Class)

		# dump all the spells we already know
		NumDeleted = 0
		for j in range (len (Spells[i])):
			CurrentIndex = j - NumDeleted # this ensure we don't go out of range
			if Spellbook.HasSpell (pc, SpellBookType, i, Spells[i][CurrentIndex][0]) >= 0:
				del Spells[i][CurrentIndex]
				NumDeleted += 1

		# display these spells if it's the first non-zero level
		if AlreadyShown == 0:
			# save the level and spellbook data
			SpellLevel = i
			SpellBook = [0]*len(Spells[i])

			if(EnhanceGUI):
				# setup the scrollbar
				ScrollBar = SpellsWindow.GetControl (1000)
#				ScrollBar.SetDefaultScrollBar ()

				# only scroll if we have more than 24 spells or 25 if extra 25th spell slot is available in sorcs LevelUp
				if len (Spells[i]) > ( ButtonCount + ExtraSpellButtons() ):
					ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ShowSpells)
					HideUnhideScrollBar(0)
					if chargen:
						ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount ) , 6 ) + 1 )
					else: #there are five rows of 5 spells in level up of sorcs
						ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceildiv ( ( len (Spells[i])-ButtonCount-1 ) , 5 ) + 1 )
				else:
					ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, None)
					ScrollBar.SetVarAssoc ("SpellTopIndex", 0)
					HideUnhideScrollBar(1)

			# show our spells
			ShowSpells ()
			AlreadyShown = 1

	# show the selection window
	if chargen:
		if recommend:
			SpellsWindow.SetVisible (WINDOW_VISIBLE)
		else:
			SpellsWindow.ShowModal (MODAL_SHADOW_NONE)
	else:
		SpellsWindow.ShowModal (MODAL_SHADOW_GRAY)

	return
예제 #34
0
def GetClassTitles(pc, LevelDiff):
    # class levels
    # 16480 <CLASS>: Level <LEVEL>
    # Experience: <EXPERIENCE>
    # Next Level: <NEXTLEVEL>
    stats = []
    # collecting tokens for stat overview
    ClassTitle = GUICommon.GetActorClassTitle(pc)
    GemRB.SetToken("CLASS", ClassTitle)
    Class = GUICommon.GetClassRowName(pc)
    Dual = GUICommon.IsDualClassed(pc, 1)
    Multi = GUICommon.IsMultiClassed(pc, 1)
    XP = GemRB.GetPlayerStat(pc, IE_XP)
    LevelDrain = GS(pc, IE_LEVELDRAIN)

    if GS(pc, IE_STATE_ID) & STATE_DEAD:
        stats.append((11829, 1, 'c'))  # DEAD
        stats.append("\n")

    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'))
        for i in range(Multi[0]):
            Class = GUICommon.GetClassRowName(Multi[i + 1], "class")
            # level 1 npc mod kits some multiclasses
            Kit = GUICommon.GetKitIndex(pc)
            KitClass = CommonTables.KitList.GetValue(str(Kit), "CLASS",
                                                     GTV_INT)
            if Kit and KitClass == Multi[i + 1]:
                ClassTitle = CommonTables.KitList.GetValue(
                    str(Kit), "MIXED", GTV_REF)
            else:
                ClassTitle = CommonTables.Classes.GetValue(
                    Class, "CAP_REF", GTV_REF)
            GemRB.SetToken("CLASS", ClassTitle)
            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("\n")
            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'))

        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]

        if Dual[0] == 3:
            ClassID = CommonTables.KitList.GetValue(Dual[2], 7)
            Class = GUICommon.GetClassRowName(ClassID, "class")
            ClassTitle = CommonTables.KitList.GetValue(Dual[2], 2, GTV_REF)
        else:
            Class = GUICommon.GetClassRowName(Dual[2], "index")
            ClassTitle = CommonTables.Classes.GetValue(Class, "CAP_REF",
                                                       GTV_REF)
        GemRB.SetToken("CLASS", ClassTitle)
        GemRB.SetToken("LEVEL", str(Levels[0] - LevelDrain))
        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("\n")

        # the first class (shown second)
        if Dual[0] == 1:
            ClassTitle = CommonTables.KitList.GetValue(Dual[1], 2, GTV_REF)
        else:
            Class = GUICommon.GetClassRowName(Dual[1], "index")
            ClassTitle = CommonTables.Classes.GetValue(Class, "CAP_REF",
                                                       GTV_REF)
        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] > 1:
            BaseClass = CommonTables.Classes.GetRowName(Dual[1])
        else:
            BaseClass = GUICommon.GetKitIndex(pc)
            BaseClass = CommonTables.KitList.GetValue(BaseClass, 7)
            BaseClass = GUICommon.GetClassRowName(BaseClass, "class")
        # 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("\n")
    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("\n")
        print "\t\tClass (Level):", Class, "(", Level, ")"
    return TypeSetStats(stats, pc)