1# -*-python-*-
2# GemRB - Infinity Engine Emulator
3# Copyright (C) 2003-2004 The GemRB Project
4#
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.
9#
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.
14#
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.
18#
19
20# LoadScreen.py - display Loading screen
21
22###################################################
23
24import GemRB
25import GameCheck
26from GUIDefines import *
27
28LoadScreen = None
29
30def SetLoadScreen ():
31	return
32
33def StartLoadScreen ():
34	global LoadScreen
35
36	LoadScreen = GemRB.LoadWindow (0, "guils")
37	LoadScreen.AddAlias("LOADWIN")
38
39	Middle = LoadScreen.GetControl (3)
40	Progress = GemRB.GetVar ("Progress")
41
42	if not GameCheck.IsBG2Demo():
43		LoadPic = GemRB.GetGameString (STR_LOADMOS)
44		if LoadPic == "":
45			#the addition of 1 is not an error, bg2 loadpic resrefs are GTRSK002-GTRSK006
46			LoadPic = "GTRSK00"+str(GemRB.Roll(1,5,1) )
47		Middle.SetMOS (LoadPic)
48	else:
49		# During loading, this fn is called at 0% and 70%, so take advantage of that
50		#   and display the "quiet" frame first and the "flaming" frame the second time.
51		#   It would be even better to display the phases inbetween as well; however,
52		#   the bg2demo does not either, even though the frames are there.
53		if Progress:
54			Middle.SetBAM ("COADCNTR", 1, 0)
55		else:
56			Middle.SetBAM ("COADCNTR", 0, 0)
57
58	if GameCheck.HasTOB():
59		Table = GemRB.LoadTable ("loadh25")
60	else:
61		Table = GemRB.LoadTable ("loadhint")
62	tmp = Table.GetRowCount ()
63	tmp = GemRB.Roll (1, tmp-1, 0)
64	HintStr = Table.GetValue (tmp, 0)
65
66	Label = LoadScreen.GetControl (2)
67	Label.SetText(HintStr)
68
69	def EndLoadScreen ():
70		GemRB.SetVar ("Progress", 0)
71		TMessageTA = GemRB.GetView("MsgSys", 0)
72		TMessageTA.Append("[p][color=f1f28d]" + GemRB.GetString (HintStr) + "[/color][/p]\n")
73
74		if GameCheck.IsBG2Demo():
75			Middle = LoadScreen.GetControl (3)
76			Middle.SetBAM ("COADCNTR", 1, 0)
77
78		LoadScreen.SetAction(lambda win: GemRB.GamePause(0, 0), ACTION_WINDOW_CLOSED)
79		GemRB.SetTimer(LoadScreen.Close, 500, 0)
80		return
81
82	Bar = LoadScreen.GetControl (0)
83	Bar.SetVarAssoc ("Progress", Progress)
84	Bar.SetEvent (IE_GUI_PROGRESS_END_REACHED, EndLoadScreen)
85	LoadScreen.ShowModal(MODAL_SHADOW_NONE)
86
87
88