1 //
2 // Cross-platform free Puyo-Puyo clone.
3 // Copyright (C) 2006, 2007 Emma's Software
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (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 #if defined (HAVE_CONFIG_H)
20 #include <config.h>
21 #endif // HAVE_CONFIG_H
22 #include <SDL.h>
23 #include <sstream>
24 #include "CreditsState.h"
25 #include "File.h"
26 #include "Font.h"
27 #include "Options.h"
28 #include "OptionsMenuState.h"
29 #include "System.h"
30 #include "TrainingState.h"
31
32 using namespace Amoebax;
33
34 ///
35 /// \brief Default constructor.
36 ///
CreditsState(void)37 CreditsState::CreditsState (void):
38 IState (),
39 m_Background (0),
40 m_NamesFont (0),
41 m_SectionsFont (0),
42 m_StateRemoved (false)
43 {
44 loadGraphicResources ();
45 }
46
47 void
joyMotion(uint8_t joystick,uint8_t axis,int16_t value)48 CreditsState::joyMotion (uint8_t joystick, uint8_t axis, int16_t value)
49 {
50 }
51
52 void
joyDown(uint8_t joystick,uint8_t button)53 CreditsState::joyDown (uint8_t joystick, uint8_t button)
54 {
55 removeCreditsState ();
56 }
57
58 void
joyUp(uint8_t joystick,uint8_t button)59 CreditsState::joyUp (uint8_t joystick, uint8_t button)
60 {
61 }
62
63 #if !defined (IS_GP2X_HOST)
64 void
keyDown(uint32_t key)65 CreditsState::keyDown (uint32_t key)
66 {
67 removeCreditsState ();
68 }
69
70 void
keyUp(uint32_t key)71 CreditsState::keyUp (uint32_t key)
72 {
73 }
74 #endif // !IS_GP2X_HOST
75
76 ///
77 /// \brief Loads all graphic resources.
78 ///
79 void
loadGraphicResources(void)80 CreditsState::loadGraphicResources (void)
81 {
82 const float screenScale = System::getInstance ().getScreenScaleFactor ();
83 m_Background.reset (
84 Surface::fromFile (File::getGraphicsFilePath ("menuBackground.png")));
85 {
86 std::auto_ptr<Surface> title (
87 Surface::fromFile (File::getGraphicsFilePath("credits.png")));
88 title->blit (m_Background->getWidth () / 2 -
89 title->getWidth () / 2, 0, m_Background->toSDLSurface ());
90 }
91 m_Background->resize (screenScale);
92
93 // Load fonts.
94 m_SectionsFont.reset (Font::fromFile (File::getFontFilePath ("fontMenu")));
95 m_NamesFont.reset (Font::fromFile (File::getFontFilePath ("fontMenuSelected")));
96
97 }
98
99 ///
100 /// \brief Removes the credits state if it's the active state.
101 ///
102 void
removeCreditsState()103 CreditsState::removeCreditsState ()
104 {
105 // if we call the removeActiveState() function twice (i.e.,press two keys
106 // at once) not only the credits state would be removed, but the main
107 // menu state as well, and the game would quit. To prevent that, and since
108 // we have no method to check which state is active, we only allow the
109 // removeActiveState() function to be called once.
110 if ( !m_StateRemoved )
111 {
112 System::getInstance ().removeActiveState ();
113 m_StateRemoved = true;
114 }
115 }
116
117 void
redrawBackground(SDL_Rect * region,SDL_Surface * screen)118 CreditsState::redrawBackground (SDL_Rect *region, SDL_Surface *screen)
119 {
120 m_Background->blit (region->x, region->y, region->w, region->h,
121 region->x, region->y, screen);
122
123 // The credits won't change, so draw as if they were part of the
124 // background.
125 const uint16_t fontHeight = m_SectionsFont->getHeight ();
126 const float screenScale = System::getInstance ().getScreenScaleFactor ();
127 // Get the horizontal possition for the sections and the names.
128 const uint16_t titleX = static_cast<uint16_t>(240 * screenScale);
129 const uint16_t nameX = static_cast<uint16_t>(400 * screenScale);
130 // Get the initial vertical possition to start to write.
131 uint16_t y = static_cast<uint16_t>((225 + fontHeight / 2.0) * screenScale);
132
133 // Draw coders' name.
134 m_SectionsFont->write (std::string ("Code"), titleX, y, screen);
135 y += fontHeight;
136 m_NamesFont->write (std::string ("Jordi Fita"), nameX, y, screen);
137 y += static_cast<uint16_t> (fontHeight * 1.5);
138
139 // Draw graphists' name.
140 m_SectionsFont->write (std::string ("Graphics"), titleX, y, screen);
141 y += fontHeight;
142 m_NamesFont->write (std::string ("Safareig Creatiu"), nameX, y, screen);
143 y += static_cast<uint16_t> (fontHeight * 1.5);
144
145 // Draw musicians' name.
146 m_SectionsFont->write (std::string ("Music & Sound"), titleX, y, screen);
147 y += fontHeight;
148 m_NamesFont->write (std::string ("Alex Almarza"), nameX, y, screen);
149 y += static_cast<uint16_t> (fontHeight * 1.5);
150
151 // Draw web artists' name.
152 m_SectionsFont->write (std::string ("Web Page"), titleX, y, screen);
153 y += fontHeight;
154 m_NamesFont->write (std::string ("Ferran Brugat"), nameX, y, screen);
155 }
156
157 void
render(SDL_Surface * screen)158 CreditsState::render (SDL_Surface *screen)
159 {
160 }
161
162 void
update(uint32_t elapsedTime)163 CreditsState::update (uint32_t elapsedTime)
164 {
165 }
166
167 void
videoModeChanged(void)168 CreditsState::videoModeChanged (void)
169 {
170 loadGraphicResources ();
171 }
172