Skip to content

Commit

Permalink
PST: fixish window loading
Browse files Browse the repository at this point in the history
they open... thats about it
  • Loading branch information
bradallred committed Mar 31, 2018
1 parent 07e84de commit 8434db7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 130 deletions.
45 changes: 16 additions & 29 deletions gemrb/GUIScripts/pst/GUIINV.py
Expand Up @@ -31,8 +31,6 @@
from ie_stats import *
from ie_slots import *


InventoryWindow = None
ItemAmountWindow = None
OverSlot = None

Expand All @@ -58,24 +56,14 @@
# 0x10000000 + 63 - class


def OpenInventoryWindow ():
def InitInventoryWindow (Window):
"""Opens the inventory window."""

global AvSlotsTable
global InventoryWindow

AvSlotsTable = GemRB.LoadTable ('avslots')

if GUICommon.CloseOtherWindow (OpenInventoryWindow):
if InventoryWindow:
InventoryWindow.Unload ()
InventoryWindow = None
GemRB.SetVar ("OtherWindow", -1)
GUICommonWindows.SetSelectionChangeHandler (None)
return
Window.AddAlias("WIN_INV")

InventoryWindow = Window = GemRB.LoadWindow (3, "GUIINV")
GemRB.SetVar ("OtherWindow", InventoryWindow.ID)
AvSlotsTable = GemRB.LoadTable ('avslots')
Window.GetControl(0x1000003d).AddAlias("MsgSys", 1)

# inventory slots
Expand All @@ -88,7 +76,7 @@ def OpenInventoryWindow ():
color = {'r' : 128, 'g' : 128, 'b' : 255, 'a' : 64}
Button.SetBorder (0,color,0,1)
color['r'], color['b'] = color['b'], color['r']
Button.SetBorde (1,color,0,1)
Button.SetBorder (1,color,0,1)

Button.SetEvent (IE_GUI_MOUSE_ENTER_BUTTON, MouseEnterSlot)
Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, MouseLeaveSlot)
Expand All @@ -109,7 +97,7 @@ def OpenInventoryWindow ():
Button.SetEvent (IE_GUI_MOUSE_LEAVE_BUTTON, InventoryCommon.MouseLeaveGround)

ScrollBar = Window.GetControl (45)
ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, RefreshInventoryWindow)
ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, lambda: RefreshInventoryWindow(Window))

for i in range (57, 64):
Label = Window.GetControl (0x10000000 + i)
Expand Down Expand Up @@ -143,20 +131,16 @@ def OpenInventoryWindow ():
Label = Window.GetControl (0x1000003d)
Label.SetTextColor(255, 255, 255)
Label.SetText ("")
GemRB.SetVar ("TopIndex", 0)
GUICommonWindows.SetSelectionChangeHandler (UpdateInventoryWindow)
UpdateInventoryWindow ()

GUICommonWindows.PortraitWindow.Focus()
GUICommonWindows.OptionsWindow.Focus()
return

def UpdateInventoryWindow ():
def UpdateInventoryWindow (Window = None):
"""Redraws the inventory window and resets TopIndex."""
global ItemHash
global slot_list

Window = InventoryWindow
if Window == None:
Window = GemRB.GetView("WIN_INV")

GUICommonWindows.UpdateAnimation ()

Expand All @@ -168,7 +152,7 @@ def UpdateInventoryWindow ():
if Count<1:
Count=1
ScrollBar.SetVarAssoc ("TopIndex", Count)
RefreshInventoryWindow ()
RefreshInventoryWindow (Window)
# And now for the items ....

ItemHash = {}
Expand All @@ -181,13 +165,14 @@ def UpdateInventoryWindow ():
for i in range (46):
UpdateSlot (pc, i)

ToggleInventoryWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIINV", GUICommonWindows.ToggleWindow, InitInventoryWindow, UpdateInventoryWindow, WINDOW_TOP)
OpenInventoryWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIINV", GUICommonWindows.OpenWindowOnce, InitInventoryWindow, UpdateInventoryWindow, WINDOW_TOP)

InventoryCommon.UpdateInventoryWindow = UpdateInventoryWindow

def RefreshInventoryWindow ():
def RefreshInventoryWindow (Window):
"""Partial redraw without resetting TopIndex."""

Window = InventoryWindow

pc = GemRB.GameGetSelectedPCSingle ()

# name
Expand All @@ -199,7 +184,9 @@ def RefreshInventoryWindow ():
Button = Window.GetControl (44)
Button.SetPicture (GUICommonWindows.GetActorPortrait (pc, 'INVENTORY'))

Label = Window.GetControl (0x1000003a)
GUICommon.SetEncumbranceLabels (Window, 46, None, pc, True)
Label = Window.GetControl (0x1000003a)

# armor class
ac = GemRB.GetPlayerStat (pc, IE_ARMORCLASS)
Expand Down Expand Up @@ -270,7 +257,7 @@ def RefreshInventoryWindow ():
return

def UpdateSlot (pc, i):
Window = InventoryWindow
Window = GemRB.GetView("WIN_INV")

# NOTE: there are invisible items (e.g. MORTEP) in inaccessible slots
# used to assign powers and protections
Expand Down
28 changes: 5 additions & 23 deletions gemrb/GUIScripts/pst/GUIJRNL.py
Expand Up @@ -59,31 +59,12 @@
StartTime = 0

###################################################
def OpenJournalWindow ():
global JournalWindow, PortraitWindow, ActionsWindow
def InitJournalWindow (JournalWindow):
global StartTime

Table = GemRB.LoadTable("YEARS")
StartTime = Table.GetValue("STARTTIME", "VALUE")

if GUICommon.CloseOtherWindow (OpenJournalWindow):
if LogWindow: OpenLogWindow()
if BeastsWindow: OpenBeastsWindow()
if QuestsWindow: OpenQuestsWindow()

if JournalWindow:
JournalWindow.Unload()
#making the portraitwindow visible again
GUICommonWindows.EnableAnimatedWindows ()
GemRB.SetVar ("OtherWindow", -1)
PortraitWindow = None
ActionsWindow = None
JournalWindow = None

return

JournalWindow = GemRB.LoadWindow (0, "GUIJRNL")
GemRB.SetVar ("OtherWindow", JournalWindow.ID)
GUICommonWindows.DisableAnimatedWindows ()

# Quests
Expand All @@ -104,12 +85,13 @@ def OpenJournalWindow ():
# Done
Button = JournalWindow.GetControl (3)
Button.SetText (20636)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenJournalWindow)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, lambda: JournalWindow.Close())
Button.MakeEscape()
Button.Focus()

#JournalWindow.Focus()
return

ToggleJournalWindow = GUICommonWindows.CreateTopWinLoader(0, "GUIJRNL", GUICommonWindows.ToggleWindow, InitJournalWindow)
OpenJournalWindow = GUICommonWindows.CreateTopWinLoader(0, "GUIJRNL", GUICommonWindows.OpenWindowOnce, InitJournalWindow)

###################################################
def OpenQuestsWindow ():
Expand Down
27 changes: 8 additions & 19 deletions gemrb/GUIScripts/pst/GUIMA.py
Expand Up @@ -33,21 +33,7 @@
PosY = 0

###################################################
def OpenMapWindow ():
global MapWindow

if GUICommon.CloseOtherWindow (OpenMapWindow):
if WorldMapWindow: OpenWorldMapWindowInside ()

if MapWindow:
MapWindow.Unload ()
MapWindow = None
GemRB.SetVar ("OtherWindow", -1)

return

MapWindow = Window = GemRB.LoadWindow (3, "GUIMA")
GemRB.SetVar ("OtherWindow", MapWindow.ID)
def InitMapWindow (Window):

# World Map
Button = Window.GetControl (0)
Expand All @@ -67,8 +53,7 @@ def OpenMapWindow ():

# Map Control
# ronote and usernote are the pins for the notes
# 4 is the Label's control ID
Map = Window.CreateMapControl (3, 24, 23, 480, 360, 4, "USERNOTE", "RONOTE")
Map = Window.CreateMapControl (3, 24, 23, 480, 360, Text, "USERNOTE", "RONOTE")
GemRB.SetVar ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES)
Map.SetVarAssoc ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES)

Expand All @@ -87,9 +72,13 @@ def OpenMapWindow ():
# Done
Button = Window.GetControl (5)
Button.SetText (1403)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenMapWindow)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, lambda: Window.Close())
Button.MakeEscape()
Button.Focus()

return

ToggleMapWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMA", GUICommonWindows.ToggleWindow, InitMapWindow, None, WINDOW_TOP)
OpenMapWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMA", GUICommonWindows.OpenWindowOnce, InitMapWindow, None, WINDOW_TOP)

def NoteChanged ():
#shift focus to the static label
Expand Down
4 changes: 2 additions & 2 deletions gemrb/GUIScripts/pst/GUIMG.py
Expand Up @@ -128,8 +128,8 @@ def UpdateMageWindow (Window=None):
CantCast = CommonTables.ClassSkills.GetValue (GUICommon.GetClassRowName (pc), "MAGESPELL") == "*"
# GUICommon.AdjustWindowVisibility (Window, pc, CantCast)

ToggleSpellWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMG", GUICommonWindows.ToggleWindow, InitMageWindow, UpdateMageWindow)
OpenSpellWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMG", GUICommonWindows.OpenWindowOnce, InitMageWindow, UpdateMageWindow)
ToggleSpellWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMG", GUICommonWindows.ToggleWindow, InitMageWindow, UpdateMageWindow, WINDOW_TOP)
OpenSpellWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIMG", GUICommonWindows.OpenWindowOnce, InitMageWindow, UpdateMageWindow, WINDOW_TOP)

def MagePrevLevelPress ():
global MageSpellLevel
Expand Down
18 changes: 7 additions & 11 deletions gemrb/GUIScripts/pst/GUIOPT.py
Expand Up @@ -48,22 +48,13 @@
QuitMsgWindow = None

###################################################
def OpenOptionsWindow ():
def InitOptionsWindow (Window):
"""Open main options window (peacock tail)"""
global OptionsWindow

if GUICommon.CloseOtherWindow (OpenOptionsWindow):
GemRB.SetVar ("OtherWindow", -1)
GUICommonWindows.EnableAnimatedWindows ()

return

GemRB.GamePause (1, 1)
TrySavingConfiguration ()

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

def ConfigOptButton(button, strref, action):
Expand All @@ -72,7 +63,7 @@ def ConfigOptButton(button, strref, action):
button.SetFlags (IE_GUI_BUTTON_MULTILINE, OP_OR)

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

# Quit Game
ConfigOptButton(Window.GetControl (1), 2595, OpenQuitMsgWindow)
Expand Down Expand Up @@ -101,6 +92,11 @@ def ConfigOptButton(button, strref, action):
# game version, e.g. v1.1.0000
Label = Window.GetControl (0x10000007)
Label.SetText (GemRB.GEMRB_VERSION)

return

ToggleOptionsWindow = GUICommonWindows.CreateTopWinLoader(0, "GUIOPT", GUICommonWindows.ToggleWindow, InitOptionsWindow)
OpenOptionsWindow = GUICommonWindows.CreateTopWinLoader(0, "GUIOPT", GUICommonWindows.OpenWindowOnce, InitOptionsWindow)

def TrySavingConfiguration():
if not GemRB.SaveConfig():
Expand Down
29 changes: 10 additions & 19 deletions gemrb/GUIScripts/pst/GUIPR.py
Expand Up @@ -36,21 +36,7 @@
PriestSpellUnmemorizeWindow = None


def OpenPriestWindow ():
global PriestWindow

if GUICommon.CloseOtherWindow (OpenPriestWindow):
if PriestWindow:
PriestWindow.Unload ()
PriestWindow = None
GemRB.SetVar ("OtherWindow", -1)

GUICommonWindows.SetSelectionChangeHandler (None)
return

PriestWindow = Window = GemRB.LoadWindow (3, "GUIPR")
GemRB.SetVar ("OtherWindow", PriestWindow.ID)

def InitPriestWindow (Window):
Button = Window.GetControl (0)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PriestPrevLevelPress)

Expand All @@ -63,16 +49,17 @@ def OpenPriestWindow ():
color = {'r' : 0, 'g' : 0, 'b' :0, 'a' : 160}
Icon.SetBorder (0, color, 0, 1)

GUICommonWindows.SetSelectionChangeHandler (UpdatePriestWindow)
UpdatePriestWindow ()
return

def UpdatePriestWindow ():
def UpdatePriestWindow (Window=None):
global PriestMemorizedSpellList, PriestKnownSpellList

if Window == None:
Window = PriestSpellWindow

PriestMemorizedSpellList = []
PriestKnownSpellList = []

Window = PriestWindow
pc = GemRB.GameGetSelectedPCSingle ()
type = IE_SPELL_TYPE_PRIEST
level = PriestSpellLevel
Expand Down Expand Up @@ -143,6 +130,10 @@ def UpdatePriestWindow ():
CantCast += GemRB.GetPlayerStat(pc, IE_DISABLEDBUTTON)&(1<<ACT_CAST)
GUICommon.AdjustWindowVisibility (Window, pc, CantCast)

return

TogglePriestWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIPR", GUICommonWindows.ToggleWindow, InitPriestWindow, UpdatePriestWindow, WINDOW_TOP)
OpenPriestWindow = GUICommonWindows.CreateTopWinLoader(3, "GUIPR", GUICommonWindows.OpenWindowOnce, InitPriestWindow, UpdatePriestWindow, WINDOW_TOP)

def PriestPrevLevelPress ():
global PriestSpellLevel
Expand Down

0 comments on commit 8434db7

Please sign in to comment.