1 ///////////////////////////////////////////////////////////////////////////////
2 //            Copyright (C) 2004-2010 by The Allacrost Project
3 //                         All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 /** ****************************************************************************
11 *** \file    boot_credits.cpp
12 *** \author  Viljami Korhonen, mindflayer@allacrost.org
13 *** \brief   Source file for the boot credits window
14 *** ***************************************************************************/
15 
16 #include "script.h"
17 #include "system.h"
18 #include "video.h"
19 
20 #include "boot_credits.h"
21 
22 using namespace std;
23 
24 using namespace hoa_utils;
25 using namespace hoa_video;
26 using namespace hoa_gui;
27 using namespace hoa_script;
28 using namespace hoa_system;
29 
30 namespace hoa_boot {
31 
32 namespace private_boot {
33 
CreditsWindow()34 CreditsWindow::CreditsWindow() :
35 	_active(false),
36 	_loaded(false),
37 	_scroll_offset(0.0f)
38 {
39 	_window.Create(880.0f, 640.0f);
40 	_window.SetPosition(512.0f, 384.0f);
41 	_window.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
42 	_window.SetDisplayMode(VIDEO_MENU_EXPAND_FROM_CENTER);
43 
44 	_credits_text.SetStyle(TextStyle("text22"));
45 }
46 
47 
48 
~CreditsWindow()49 CreditsWindow::~CreditsWindow() {
50 	_window.Destroy();
51 }
52 
53 
54 
Draw()55 void CreditsWindow::Draw() {
56 	_window.Draw();
57 
58 	// Don't draw any contents of the window until the window is fully shown
59 	if (_window.GetState() != VIDEO_MENU_STATE_SHOWN)
60 		return;
61 
62 	// Set clip region for the text and draw the visible part of it
63 	VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_TOP, 0);
64 	VideoManager->Move(512.0f, 384.0f + _scroll_offset);
65 	VideoManager->EnableScissoring();
66 	// TODO: This returns a bad scissor rect due to a known bug in the GUI code
67 // 	VideoManager->SetScissorRect(_window.GetScissorRect());
68 	VideoManager->SetScissorRect(ScreenRect(0.0f, 80.0f, 1024.0f, 610.0f));
69 
70 	// Initially fade in the text from completely transparent to fully opaque
71 	float color_alpha = _scroll_offset * 0.025f;
72 	if (color_alpha >= 1.0f)
73 		_credits_text.Draw();
74 	else
75 		_credits_text.Draw(Color(1.0f, 1.0f, 1.0f, color_alpha));
76 	VideoManager->DisableScissoring();
77 }
78 
79 
80 
Update()81 void CreditsWindow::Update() {
82 	_window.Update(SystemManager->GetUpdateTime());
83 	_scroll_offset += static_cast<float>(SystemManager->GetUpdateTime()) * 0.025f;
84 }
85 
86 
87 
Show()88 void CreditsWindow::Show() {
89 	_active = true;
90 	_window.Show();
91 	_scroll_offset = 0.0f;
92 
93 	if (_loaded == true)
94 		return;
95 
96 	// Load the credits text from the Lua file
97 	ReadScriptDescriptor credits_file;
98 	if (credits_file.OpenFile("dat/credits.lua") == false) {
99 		IF_PRINT_WARNING(BOOT_DEBUG) << "failed to open the Lua credits file" << endl;
100 	}
101 	_credits_text.SetText(MakeUnicodeString(credits_file.ReadString("credits_text")));
102 	credits_file.CloseFile();
103 	_loaded = true;
104 }
105 
106 
107 
Hide()108 void CreditsWindow::Hide() {
109 	_active = false;
110 	_window.Hide();
111 }
112 
113 } // namespace private_boot
114 
115 } // namespace hoa_boot
116