Skip to content

Commit

Permalink
GUISAVE: used the existing control id abstraction to simplify and sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxlynxlynx committed Aug 18, 2015
1 parent 3807975 commit a7643f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
32 changes: 15 additions & 17 deletions gemrb/GUIScripts/GUISAVE.py
Expand Up @@ -38,7 +38,7 @@
# this lookup table is used only by bg2
str_chapter = (48007, 48006, 16205, 16206, 16207, 16208, 16209, 71020, 71021, 71022)
num_rows = 4
ctrl_offset = (26, 30, 40, 0x10000008, 0x10000010)
ctrl_offset = (26, 30, 40, 0x10000008, 0x10000010, 25, 34, 3, 0x10000004, 40, 7, 8, 2)
sav_version = 0

def OpenSaveWindow ():
Expand All @@ -57,16 +57,17 @@ def OpenSaveWindow ():
if GameCheck.IsIWD2():
GemRB.LoadWindowPack ("GUISAVE", 800, 600)
num_rows = 5
ctrl_offset = (55, 60, 25, 0x10000005, 0x1000000a)
ctrl_offset = (55, 60, 25, 0x10000005, 0x1000000a, 23, 22, 3, 0x10000004, 40, 7, 8, 2)
sav_version = 22
else:
GemRB.LoadWindowPack ("GUISAVE", 640, 480)
if GameCheck.IsPST():
ctrl_offset = (14, 18, 22, 0x10000004, 0x10000008, 13, 46, 1, 0x10000002, 6, 4, 5, 3)
SaveWindow = Window = GemRB.LoadWindow (0)
Window.SetFrame ()
if GameCheck.IsIWD2():
CancelButton=Window.GetControl (22)
else:
CancelButton=Window.GetControl (34)

# Cancel button
CancelButton = Window.GetControl (ctrl_offset[6])
CancelButton.SetText (13727)
CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenSaveWindow)
CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
Expand Down Expand Up @@ -96,10 +97,7 @@ def OpenSaveWindow ():
Button.SetState (IE_GUI_BUTTON_LOCKED)
Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)

if GameCheck.IsIWD2():
ScrollBar=Window.GetControl (23)
else:
ScrollBar=Window.GetControl (25)
ScrollBar = Window.GetControl (ctrl_offset[5])
ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ScrollBarPress)
Games=GemRB.GetSaveGames ()
TopIndex = max (0, len(Games) - num_rows + 1) #one more for the 'new game'
Expand Down Expand Up @@ -182,7 +180,7 @@ def ConfirmedSaveGame():
global ConfirmWindow

Pos = GemRB.GetVar ("TopIndex") + GemRB.GetVar ("SaveIdx")
Label = ConfirmWindow.GetControl (3)
Label = ConfirmWindow.GetControl (ctrl_offset[7])
Slotname = Label.QueryText ()
Slotname = Slotname.replace ("/", "|") # can't have path separators in the name

Expand Down Expand Up @@ -224,7 +222,7 @@ def OpenConfirmWindow ():
Slotname = ""
save_strref = 15588

NameField = ConfirmWindow.GetControl (3)
NameField = ConfirmWindow.GetControl (ctrl_offset[7])
NameField.SetText (Slotname)
NameField.SetEvent (IE_GUI_EDIT_ON_CHANGE, EditChange)

Expand All @@ -237,7 +235,7 @@ def OpenConfirmWindow ():
Slotname = Games[Pos].GetGameDate()
else:
Slotname = ""
Label = ConfirmWindow.GetControl (0x10000004)
Label = ConfirmWindow.GetControl (ctrl_offset[8])
Label.SetText (Slotname)

# Areapreview
Expand All @@ -250,22 +248,22 @@ def OpenConfirmWindow ():

# PC portraits
for j in range(min(6, PARTY_SIZE)):
Button = ConfirmWindow.GetControl (40+j)
Button = ConfirmWindow.GetControl (ctrl_offset[9]+j)
if Pos<len(Games):
Button.SetSprite2D(Games[Pos].GetPortrait(j))
else:
Button.SetPicture("")

# Save/Overwrite
SaveButton = ConfirmWindow.GetControl (7)
SaveButton = ConfirmWindow.GetControl (ctrl_offset[10])
SaveButton.SetText (save_strref)
SaveButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ConfirmedSaveGame)
SaveButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
if Slotname == "":
SaveButton.SetState (IE_GUI_BUTTON_DISABLED)

# Cancel
CancelButton = ConfirmWindow.GetControl (8)
CancelButton = ConfirmWindow.GetControl (ctrl_offset[11])
CancelButton.SetText (13727)
CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbortedSaveGame)
CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
Expand Down Expand Up @@ -315,7 +313,7 @@ def DeleteGamePress():
global ConfirmWindow

SaveWindow.SetVisible (WINDOW_INVISIBLE)
ConfirmWindow=GemRB.LoadWindow (2)
ConfirmWindow=GemRB.LoadWindow (ctrl_offset[12])

Text=ConfirmWindow.GetControl (0)
Text.SetText (15305)
Expand Down
40 changes: 21 additions & 19 deletions gemrb/GUIScripts/pst/GUISAVE.py
Expand Up @@ -38,7 +38,7 @@
# this lookup table is used only by bg2
str_chapter = (48007, 48006, 16205, 16206, 16207, 16208, 16209, 71020, 71021, 71022)
num_rows = 4
ctrl_offset = (26, 30, 40, 0x10000008, 0x10000010)
ctrl_offset = (26, 30, 40, 0x10000008, 0x10000010, 25, 34, 3, 0x10000004, 40, 7, 8, 2)
sav_version = 0

def OpenSaveWindow ():
Expand All @@ -57,28 +57,30 @@ def OpenSaveWindow ():
if GameCheck.IsIWD2():
GemRB.LoadWindowPack ("GUISAVE", 800, 600)
num_rows = 5
ctrl_offset = (55, 60, 25, 0x10000005, 0x1000000a)
ctrl_offset = (55, 60, 25, 0x10000005, 0x1000000a, 23, 22, 3, 0x10000004, 40, 7, 8, 2)
sav_version = 22
else:
GemRB.LoadWindowPack ("GUISAVE", 640, 480)
if GameCheck.IsPST():
ctrl_offset = (14, 18, 22, 0x10000004, 0x10000008, 13, 46, 1, 0x10000002, 6, 4, 5, 3)
SaveWindow = Window = GemRB.LoadWindow (0)
GemRB.SetVar ("OtherWindow", SaveWindow.ID)

# Cancel button
CancelButton = Window.GetControl (46)
CancelButton = Window.GetControl (ctrl_offset[6])
CancelButton.SetText (4196)
CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenSaveWindow)
CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
GemRB.SetVar ("SaveIdx", 0)

for i in range (num_rows):
Button = Window.GetControl (14 + i)
Button = Window.GetControl (ctrl_offset[0] + i)
Button.SetText (28645)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenConfirmWindow)
Button.SetState (IE_GUI_BUTTON_DISABLED)
Button.SetVarAssoc ("SaveIdx", i)

Button = Window.GetControl (18 + i)
Button = Window.GetControl (ctrl_offset[1] + i)
Button.SetText (28640)
Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGamePress)
Button.SetState (IE_GUI_BUTTON_DISABLED)
Expand All @@ -91,11 +93,11 @@ def OpenSaveWindow ():

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

ScrollBar = Window.GetControl (13)
ScrollBar = Window.GetControl (ctrl_offset[5])
ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ScrollBarPress)
Games = GemRB.GetSaveGames()
TopIndex = max (0, len(Games) - num_rows + 1) #one more for the 'new game'
Expand All @@ -114,8 +116,8 @@ def ScrollBarPress():
for i in range (num_rows):
ActPos = Pos + i

Button1 = Window.GetControl (14 + i)
Button2 = Window.GetControl (18 + i)
Button1 = Window.GetControl (ctrl_offset[0] + i)
Button2 = Window.GetControl (ctrl_offset[1] + i)
if ActPos <= len(Games):
Button1.SetState (IE_GUI_BUTTON_ENABLED)
else:
Expand All @@ -134,10 +136,10 @@ def ScrollBarPress():
Slottime = ""
Button2.SetState (IE_GUI_BUTTON_DISABLED)

Label = Window.GetControl (0x10000004+i)
Label = Window.GetControl (ctrl_offset[3]+i)
Label.SetText (Slotname)

Label = Window.GetControl (0x10000008 + i)
Label = Window.GetControl (ctrl_offset[4] + i)
Label.SetText (Slottime)

Button = Window.GetControl (1 + i)
Expand All @@ -147,7 +149,7 @@ def ScrollBarPress():
Button.SetPicture ("")

for j in range (min(6, PARTY_SIZE)):
Button = Window.GetControl (22 + i*6 + j)
Button = Window.GetControl (ctrl_offset[2] + i*min(6, PARTY_SIZE) + j)
if ActPos < len(Games):
Button.SetSprite2D(Games[ActPos].GetPortrait(j))
else:
Expand Down Expand Up @@ -179,7 +181,7 @@ def ConfirmedSaveGame ():
global ConfirmWindow

Pos = GemRB.GetVar ("TopIndex") + GemRB.GetVar ("SaveIdx")
Label = ConfirmWindow.GetControl (1)
Label = ConfirmWindow.GetControl (ctrl_offset[7])
Slotname = Label.QueryText ()
Slotname = Slotname.replace ("/", "|") # can't have path separators in the name

Expand Down Expand Up @@ -222,7 +224,7 @@ def OpenConfirmWindow ():
Slotname = ""
save_strref = 28645 # save

NameField = ConfirmWindow.GetControl (1)
NameField = ConfirmWindow.GetControl (ctrl_offset[7])
NameField.SetText (Slotname)
NameField.SetEvent (IE_GUI_EDIT_ON_CHANGE, EditChange)

Expand All @@ -235,7 +237,7 @@ def OpenConfirmWindow ():
Slotname = Games[Pos].GetGameDate()
else:
Slotname = ""
Label = ConfirmWindow.GetControl (0x10000002)
Label = ConfirmWindow.GetControl (ctrl_offset[8])
Label.SetText (Slotname)

# Areapreview
Expand All @@ -248,22 +250,22 @@ def OpenConfirmWindow ():

# PC portraits
for j in range(min(6, PARTY_SIZE)):
Button = ConfirmWindow.GetControl (6+j)
Button = ConfirmWindow.GetControl (ctrl_offset[9]+j)
if Pos<len(Games):
Button.SetSprite2D(Games[Pos].GetPortrait(j))
else:
Button.SetPicture("")

# Save/Overwrite
SaveButton = ConfirmWindow.GetControl (4)
SaveButton = ConfirmWindow.GetControl (ctrl_offset[10])
SaveButton.SetText (save_strref)
SaveButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ConfirmedSaveGame)
SaveButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
if Slotname == "":
SaveButton.SetState (IE_GUI_BUTTON_DISABLED)

# Cancel
CancelButton = ConfirmWindow.GetControl (5)
CancelButton = ConfirmWindow.GetControl (ctrl_offset[11])
CancelButton.SetText (4196)
CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, AbortedSaveGame)
CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
Expand Down Expand Up @@ -312,7 +314,7 @@ def DeleteGamePress():
global ConfirmWindow

SaveWindow.SetVisible (WINDOW_INVISIBLE)
ConfirmWindow=GemRB.LoadWindow (3)
ConfirmWindow=GemRB.LoadWindow (ctrl_offset[12])

Text=ConfirmWindow.GetControl (0)
Text.SetText (28639)
Expand Down

0 comments on commit a7643f7

Please sign in to comment.