factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / bg1 / GUIJRNL.py
blobdea6a10d3483b5b0a2bd8f9f1db7776c8b31778d
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # GUIJRNL.py - scripts to control journal/diary windows from GUIJRNL winpack
23 ###################################################
24 import GemRB
25 import GUICommon
26 import GUICommonWindows
27 from GUIDefines import *
29 ###################################################
30 JournalWindow = None
31 OldOptionsWindow = None
32 OldPortraitWindow = None
33 OverSlot = None
34 Chapter = 0
35 StartTime = 0
36 StartYear = 0
38 ###################################################
39 def OpenJournalWindow ():
40 global JournalWindow, OptionsWindow, PortraitWindow
41 global OldPortraitWindow, OldOptionsWindow
42 global StartTime, StartYear, Chapter
44 if GUICommon.CloseOtherWindow (OpenJournalWindow):
46 if JournalWindow:
47 JournalWindow.Unload ()
48 if OptionsWindow:
49 OptionsWindow.Unload ()
50 if PortraitWindow:
51 PortraitWindow.Unload ()
53 JournalWindow = None
54 GemRB.SetVar ("OtherWindow", -1)
55 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
56 GemRB.UnhideGUI ()
57 GUICommonWindows.PortraitWindow = OldPortraitWindow
58 OldPortraitWindow = None
59 GUICommonWindows.OptionsWindow = OldOptionsWindow
60 OldOptionsWindow = None
61 GUICommonWindows.SetSelectionChangeHandler (None)
62 return
64 Table = GemRB.LoadTable("YEARS")
65 #StartTime is the time offset for ingame time, beginning from the startyear
66 StartTime = Table.GetValue("STARTTIME", "VALUE") / 4500
67 #StartYear is the year of the lowest ingame date to be printed
68 StartYear = Table.GetValue("STARTYEAR", "VALUE")
70 GemRB.HideGUI ()
71 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
73 GemRB.LoadWindowPack ("GUIJRNL", 640, 480)
74 JournalWindow = Window = GemRB.LoadWindow (2)
75 GemRB.SetVar ("OtherWindow", JournalWindow.ID)
76 #saving the original portrait window
77 OldOptionsWindow = GUICommonWindows.OptionsWindow
78 OptionsWindow = GemRB.LoadWindow (0)
79 GUICommonWindows.MarkMenuButton (OptionsWindow)
80 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenJournalWindow)
81 OptionsWindow.SetFrame ()
82 OldPortraitWindow = GUICommonWindows.PortraitWindow
83 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
85 Button = Window.GetControl (3)
86 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, JournalPrevSectionPress)
88 Button = Window.GetControl (4)
89 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, JournalNextSectionPress)
91 Chapter = GemRB.GetGameVar("chapter")
92 GemRB.SetVar("TopIndex", 0)
93 GUICommonWindows.SetSelectionChangeHandler (UpdateJournalWindow)
94 UpdateJournalWindow ()
96 OptionsWindow.SetVisible (WINDOW_VISIBLE)
97 Window.SetVisible (WINDOW_VISIBLE)
98 PortraitWindow.SetVisible (WINDOW_VISIBLE)
99 return
101 ###################################################
102 def UpdateJournalWindow ():
103 Window = JournalWindow
105 # Title
106 Title = Window.GetControl (5)
107 Title.SetText (16202 + Chapter)
109 # text area
110 Text = Window.GetControl (1)
111 Text.Clear ()
113 for i in range (GemRB.GetJournalSize (Chapter)):
114 je = GemRB.GetJournalEntry (Chapter, i)
116 if je == None:
117 continue
119 hours = je['GameTime'] / 4500
120 days = int(hours/24)
121 year = str (StartYear + int(days/365))
122 dayandmonth = StartTime + days%365
123 GemRB.SetToken("GAMEDAY", str(days) )
124 GemRB.SetToken("HOUR",str(hours%24 ) )
125 GemRB.SetVar("DAYANDMONTH",dayandmonth)
126 GemRB.SetToken("YEAR",year)
127 #Text.Append ("[color=FFFF00]"+GemRB.GetString(15980)+"[/color]", 3*i)
128 Text.Append (GemRB.GetString(15980), 3*i)
129 Text.Append (je['Text'], 3*i + 1)
130 Text.Append ("", 3*i + 2)
133 ###################################################
134 def JournalPrevSectionPress ():
135 global Chapter
137 if Chapter > 0:
138 Chapter = Chapter - 1
139 UpdateJournalWindow ()
142 ###################################################
143 def JournalNextSectionPress ():
144 global Chapter
146 #if GemRB.GetJournalSize (Chapter + 1) > 0:
147 if Chapter < GemRB.GetGameVar("chapter"):
148 Chapter = Chapter + 1
149 UpdateJournalWindow ()
152 ###################################################
153 # End of file GUIJRNL.py