fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / GUIJRNL.py
blobab686ce28655c03a4c9efb0ee9a239d0faa36521
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 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 import GemRB
24 from GUIDefines import *
25 import GUICommon
27 ###################################################
28 JournalWindow = None
29 PortraitWindow = None
30 OldPortraitWindow = None
31 OldOptionsWindow = None
33 global Section
34 Section = 1
35 Chapter = 0
36 Order = 0
37 StartTime = 0
38 StartYear = 0
40 ###################################################
41 def OpenJournalWindow ():
42 import GUICommonWindows
43 global JournalWindow, OptionsWindow, PortraitWindow
44 global OldPortraitWindow, OldOptionsWindow
45 global StartTime, StartYear
46 global Chapter
48 if GUICommon.CloseOtherWindow (OpenJournalWindow):
50 if JournalWindow:
51 JournalWindow.Unload ()
52 if OptionsWindow:
53 OptionsWindow.Unload ()
54 if PortraitWindow:
55 PortraitWindow.Unload ()
57 JournalWindow = None
58 GemRB.SetVar ("OtherWindow", -1)
59 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
60 GemRB.UnhideGUI ()
61 GUICommonWindows.PortraitWindow = OldPortraitWindow
62 OldPortraitWindow = None
63 GUICommonWindows.OptionsWindow = OldOptionsWindow
64 OldOptionsWindow = None
65 GUICommonWindows.SetSelectionChangeHandler (None)
66 return
68 Table = GemRB.LoadTable("YEARS")
69 StartTime = Table.GetValue("STARTTIME", "VALUE") / 4500
70 StartYear = Table.GetValue("STARTYEAR", "VALUE")
72 GemRB.HideGUI ()
73 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
75 GemRB.LoadWindowPack ("GUIJRNL", 640, 480)
76 JournalWindow = Window = GemRB.LoadWindow (2)
77 GemRB.SetVar ("OtherWindow", JournalWindow.ID)
78 #saving the original portrait window
79 OldOptionsWindow = GUICommonWindows.OptionsWindow
80 OptionsWindow = GemRB.LoadWindow (0)
81 GUICommonWindows.MarkMenuButton (OptionsWindow)
82 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenJournalWindow)
83 OptionsWindow.SetFrame ()
84 OldPortraitWindow = GUICommonWindows.PortraitWindow
85 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
87 # prev. chapter
88 Button = JournalWindow.GetControl (3)
89 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, PrevChapterPress)
91 # next chapter
92 Button = JournalWindow.GetControl (4)
93 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, NextChapterPress)
95 GemRB.SetVar ("Section", Section)
96 # Quests
97 Button = JournalWindow.GetControl (6)
98 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
99 Button.SetVarAssoc ("Section", 1)
100 Button.SetText (45485)
101 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateLogWindow)
103 # Quests completed
104 Button = JournalWindow.GetControl (7)
105 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
106 Button.SetVarAssoc ("Section", 2)
107 Button.SetText (45486)
108 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateLogWindow)
110 # Journal
111 Button = JournalWindow.GetControl (8)
112 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
113 Button.SetVarAssoc ("Section", 4)
114 Button.SetText (15333)
115 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateLogWindow)
117 # User
118 Button = JournalWindow.GetControl (9)
119 Button.SetFlags (IE_GUI_BUTTON_RADIOBUTTON, OP_OR)
120 Button.SetVarAssoc ("Section", 0)
121 Button.SetText (45487)
122 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, UpdateLogWindow)
124 # Order
125 Button = JournalWindow.GetControl (10)
126 Button.SetText (4627)
127 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, ToggleOrderWindow)
129 # Done
130 #Button = JournalWindow.GetControl (3)
131 #Button.SetText (20636)
132 #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenJournalWindow)
134 Chapter = GemRB.GetGameVar("chapter")
135 if Chapter>65535:
136 Chapter=0
138 GUICommonWindows.SetSelectionChangeHandler (UpdateLogWindow)
139 UpdateLogWindow ()
140 OptionsWindow.SetVisible (WINDOW_VISIBLE)
141 Window.SetVisible (WINDOW_FRONT)
142 PortraitWindow.SetVisible (WINDOW_VISIBLE)
143 return
145 def ToggleOrderWindow ():
146 global Order
148 if Order:
149 Order = 0
150 else:
151 Order = 1
152 UpdateLogWindow ()
153 return
155 def UpdateLogWindow ():
157 # text area
158 Window = JournalWindow
160 Section = GemRB.GetVar("Section")
161 GemRB.SetToken ("CurrentChapter", str(Chapter) )
162 # CurrentChapter
163 Label = JournalWindow.GetControl (0x1000000a)
164 Label.SetText (15873)
165 print "Chapter ", Chapter, "Section ", Section
167 Text = Window.GetControl (1)
169 Text.Clear ()
170 for i in range (GemRB.GetJournalSize (Chapter, Section)):
171 je = GemRB.GetJournalEntry (Chapter, i, Section)
173 if je == None:
174 continue
175 hours = je['GameTime'] / 4500
176 days = int(hours/24)
177 year = str (StartYear + int(days/365))
178 dayandmonth = StartTime + days%365
179 GemRB.SetToken ("GAMEDAYS", str(days) ) #Other IE games use "GAMEDAY"
180 GemRB.SetToken ("HOUR",str(hours%24 ) )
181 GemRB.SetVar ("DAYANDMONTH",dayandmonth)
182 GemRB.SetToken ("YEAR",year)
184 # each journal entry consists of the title and description
185 # but the game displays the entry date between the two
186 je2 = GemRB.GetString(je['Text']).split("\n",1)
187 JournalTitle = "[color=d00000]" + je2[0] + "[/color]" + "\n"
188 JournalText = je2[1]
190 Text.Append (JournalTitle + GemRB.GetString(15980), 3*i)
191 Text.Append (JournalText, 3*i+1)
192 Text.Append ("", 3*i + 2)
194 Window.SetVisible (WINDOW_VISIBLE)
195 return
197 ###################################################
198 def PrevChapterPress ():
199 global Chapter
200 if GUICommon.GameIsTOB():
201 firstChapter = 0
202 else:
203 firstChapter = 1
205 if Chapter > firstChapter:
206 Chapter = Chapter - 1
207 GemRB.SetToken ("CurrentChapter", str(Chapter) )
208 UpdateLogWindow ()
209 return
211 ###################################################
212 def NextChapterPress ():
213 global Chapter
215 if Chapter < GemRB.GetGameVar("chapter"):
216 Chapter = Chapter + 1
217 GemRB.SetToken ("CurrentChapter", str(Chapter) )
218 UpdateLogWindow ()
219 return
221 ###################################################
222 # End of file GUIJRNL.py