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
24 from GUIDefines
import *
27 ###################################################
30 OldPortraitWindow
= None
31 OldOptionsWindow
= None
40 ###################################################
41 def OpenJournalWindow ():
42 import GUICommonWindows
43 global JournalWindow
, OptionsWindow
, PortraitWindow
44 global OldPortraitWindow
, OldOptionsWindow
45 global StartTime
, StartYear
48 if GUICommon
.CloseOtherWindow (OpenJournalWindow
):
51 JournalWindow
.Unload ()
53 OptionsWindow
.Unload ()
55 PortraitWindow
.Unload ()
58 GemRB
.SetVar ("OtherWindow", -1)
59 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
61 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
62 OldPortraitWindow
= None
63 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
64 OldOptionsWindow
= None
65 GUICommonWindows
.SetSelectionChangeHandler (None)
68 Table
= GemRB
.LoadTable("YEARS")
69 StartTime
= Table
.GetValue("STARTTIME", "VALUE") / 4500
70 StartYear
= Table
.GetValue("STARTYEAR", "VALUE")
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)
88 Button
= JournalWindow
.GetControl (3)
89 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, PrevChapterPress
)
92 Button
= JournalWindow
.GetControl (4)
93 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, NextChapterPress
)
95 GemRB
.SetVar ("Section", Section
)
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
)
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
)
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
)
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
)
125 Button
= JournalWindow
.GetControl (10)
126 Button
.SetText (4627)
127 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ToggleOrderWindow
)
130 #Button = JournalWindow.GetControl (3)
131 #Button.SetText (20636)
132 #Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenJournalWindow)
134 Chapter
= GemRB
.GetGameVar("chapter")
138 GUICommonWindows
.SetSelectionChangeHandler (UpdateLogWindow
)
140 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
141 Window
.SetVisible (WINDOW_FRONT
)
142 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
145 def ToggleOrderWindow ():
155 def UpdateLogWindow ():
158 Window
= JournalWindow
160 Section
= GemRB
.GetVar("Section")
161 GemRB
.SetToken ("CurrentChapter", str(Chapter
) )
163 Label
= JournalWindow
.GetControl (0x1000000a)
164 Label
.SetText (15873)
165 print "Chapter ", Chapter
, "Section ", Section
167 Text
= Window
.GetControl (1)
170 for i
in range (GemRB
.GetJournalSize (Chapter
, Section
)):
171 je
= GemRB
.GetJournalEntry (Chapter
, i
, Section
)
175 hours
= je
['GameTime'] / 4500
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"
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
)
197 ###################################################
198 def PrevChapterPress ():
200 if GUICommon
.GameIsTOB():
205 if Chapter
> firstChapter
:
206 Chapter
= Chapter
- 1
207 GemRB
.SetToken ("CurrentChapter", str(Chapter
) )
211 ###################################################
212 def NextChapterPress ():
215 if Chapter
< GemRB
.GetGameVar("chapter"):
216 Chapter
= Chapter
+ 1
217 GemRB
.SetToken ("CurrentChapter", str(Chapter
) )
221 ###################################################
222 # End of file GUIJRNL.py