#include <IGameState.h>
Inheritance diagram for IGameState:

Public Member Functions | |
| IGameState (IGameState *prev) | |
| virtual | ~IGameState () |
| void | Loop (const unsigned int ticks) |
| virtual void | Update (const unsigned int ticks)=0 |
| virtual void | Display ()=0 |
| virtual void | DoExit () |
| virtual void | CheckInput ()=0 |
| void | PrepareTopContainer () |
Static Public Member Functions | |
| static void | SetMainMenu (IGameState *menu) |
| static void | SetCurrentPtr (IGameState **current) |
Public Attributes | |
| std::auto_ptr< gcn::Container > | m_top |
Protected Member Functions | |
| void | TakeScreenshot () |
| void | DisplaySplashScreen (const std::string imageName, const std::string text, const std::string fontName, float shade) |
| void | DisplayBackground (GLuint imageTexture, float shade) |
| void | PrepareStateSwitch (IGameState *next, IGameState *prev) |
Protected Attributes | |
| IGameState * | m_previous |
Static Protected Attributes | |
| static IGameState * | s_mainMenu = NULL |
| static IGameState ** | s_currentPtr = NULL |
| static unsigned char | s_nextScreen = 0 |
Private Member Functions | |
| void | SwitchStates () |
| virtual void | SwitchTo (IGameState *oldState)=0 |
| virtual void | SwitchFrom ()=0 |
Private Attributes | |
| IGameState * | m_next |
Definition at line 13 of file IGameState.h.
| IGameState::IGameState | ( | IGameState * | prev | ) |
Definition at line 28 of file IGameState.cpp.
References m_next, m_previous, m_top, and Config::s_config.
00028 { 00029 m_previous = prev; 00030 m_next = NULL; 00031 00032 m_top.reset(new gcn::Container()); 00033 // Set the dimension of the top container to match the screen. 00034 m_top->setDimension(gcn::Rectangle(0, 0, 00035 Config::s_config->GetWinWidth(), 00036 Config::s_config->GetWinHeight())); 00037 }
| IGameState::~IGameState | ( | ) | [virtual] |
Definition at line 39 of file IGameState.cpp.
References CCGui::s_CCGui, and CCGui::SetTopContainer().
00039 { 00040 CCGui::s_CCGui->SetTopContainer(NULL); 00041 }
| virtual void IGameState::CheckInput | ( | ) | [pure virtual] |
Implemented in MainMenu, Map, Battle, StateDone, StateBattle, StateCity, StateNewGame, and StateSailing.
| virtual void IGameState::Display | ( | ) | [pure virtual] |
Implemented in MainMenu, Map, Battle, StateDone, StateBattle, StateCity, StateNewGame, and StateSailing.
Referenced by Loop().
| void IGameState::DisplayBackground | ( | GLuint | imageTexture, | |
| float | shade | |||
| ) | [protected] |
Definition at line 221 of file IGameState.cpp.
References Config::GetWinHeight(), Config::GetWinWidth(), and Config::s_config.
Referenced by StateNewGame::Display(), StateCity::Display(), StateDone::Display(), StateBattle::Display(), Map::Display(), MainMenu::Display(), and DisplaySplashScreen().
00221 { 00222 // Temp storage for window width & height 00223 int width = Config::s_config->GetWinWidth(); 00224 int height = Config::s_config->GetWinHeight(); 00225 00226 // Clear the depth buffer 00227 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 00228 00229 // Set the color 00230 glColor3f(shade, shade, shade); 00231 00232 glEnable(GL_TEXTURE_2D); 00233 00234 glBindTexture(GL_TEXTURE_2D, myLoadingTexture); 00235 00236 // Draw the actual background quad 00237 glBegin(GL_QUADS); 00238 glTexCoord2f(0, 0); 00239 glVertex3f(0, 0, 0); 00240 glTexCoord2f(0, 1); 00241 glVertex3f(0, height, 0); 00242 glTexCoord2f(1, 1); 00243 glVertex3f(width, height, 0); 00244 glTexCoord2f(1, 0); 00245 glVertex3f(width, 0, 0); 00246 glEnd(); 00247 }
| void IGameState::DisplaySplashScreen | ( | const std::string | imageName, | |
| const std::string | text, | |||
| const std::string | fontName, | |||
| float | shade | |||
| ) | [protected] |
Definition at line 174 of file IGameState.cpp.
References DisplayBackground(), EnterTextMode(), CCGui::GetTopContainer(), Config::GetWinHeight(), Config::GetWinWidth(), CCGui::s_CCGui, Config::s_config, CCGui::SetTopContainer(), and CCGui::UpdateGui().
Referenced by MainMenu::MainMenu(), and StateSailing::StateSailing().
00174 { 00175 bool needsText = text.length() > 0; 00176 gcn::Widget* oldTop; 00177 gcn::Container* tempTop; 00178 auto_ptr<CCLabel> myLabel; 00179 00180 // Temp storage for window width & height 00181 int width = Config::s_config->GetWinWidth(); 00182 int height = Config::s_config->GetWinHeight(); 00183 00184 auto_ptr<Texture> texture(new Texture(imageName)); 00185 00186 // Get ready for text mode 00187 EnterTextMode(width, height); 00188 00189 DisplayBackground(texture->GetTexture(), shade); 00190 00191 // Only do all of the guichan work if there is text to display 00192 if (needsText) { 00193 tempTop = new gcn::Container(); 00194 // Set the dimension of the top container to match the screen. 00195 tempTop->setDimension(gcn::Rectangle(0, 0, 00196 Config::s_config->GetWinWidth(), 00197 Config::s_config->GetWinHeight())); 00198 00199 tempTop->setOpaque(false); 00200 tempTop->setVisible(true); 00201 00202 myLabel.reset(new CCLabel(text, fontName)); 00203 tempTop->add(myLabel.get(), (Config::s_config->GetWinWidth() / 2) - (myLabel->getWidth() / 2), 00204 (Config::s_config->GetWinHeight() / 2) - (myLabel->getHeight() / 2)); 00205 00206 oldTop = CCGui::s_CCGui->GetTopContainer(); 00207 CCGui::s_CCGui->SetTopContainer(tempTop); 00208 CCGui::s_CCGui->UpdateGui(); 00209 } 00210 00211 SDL_GL_SwapBuffers(); 00212 00213 if (needsText) { 00214 CCGui::s_CCGui->SetTopContainer(oldTop); 00215 delete tempTop; 00216 } 00217 }
| void IGameState::DoExit | ( | ) | [virtual] |
Reimplemented in MainMenu.
Definition at line 88 of file IGameState.cpp.
References DoExit(), and s_mainMenu.
Referenced by StateSailing::CheckInput(), StateNewGame::CheckInput(), Battle::CheckInput(), Map::CheckInput(), and DoExit().
00088 { 00089 // The MainMenu object needs to overload this 00090 if (s_mainMenu != NULL) { 00091 s_mainMenu->DoExit(); 00092 } 00093 }
| void IGameState::Loop | ( | const unsigned int | ticks | ) |
Definition at line 59 of file IGameState.cpp.
References Display(), EnterTextMode(), m_next, Log::Message(), CCGui::s_CCGui, Config::s_config, Log::s_log, SwitchStates(), Update(), and CCGui::UpdateGui().
Referenced by main().
00059 { 00060 Update(ticks); 00061 00062 // Don't need to clear color buffer, since every pixel is redrawn 00063 // Just do it anyway, while it's in development 00064 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00065 00066 Display(); 00067 00068 try { 00069 glPushAttrib(GL_ENABLE_BIT|GL_COLOR_BUFFER_BIT); 00070 glPushMatrix(); 00071 glLoadIdentity(); 00072 EnterTextMode(Config::s_config->GetWinWidth(), Config::s_config->GetWinHeight()); 00073 CCGui::s_CCGui->UpdateGui(); 00074 //ExitTextMode(); 00075 glPopMatrix(); 00076 glPopAttrib(); 00077 } catch (gcn::Exception e) { 00078 Log::s_log->Message("Guichan exception: %s\n\t%s: line %i", e.getMessage().c_str(), e.getFilename().c_str(), e.getLine()); 00079 } 00080 00081 SDL_GL_SwapBuffers(); 00082 00083 if (m_next != NULL) { 00084 SwitchStates(); 00085 } 00086 }
| void IGameState::PrepareStateSwitch | ( | IGameState * | next, | |
| IGameState * | prev | |||
| ) | [protected] |
Definition at line 159 of file IGameState.cpp.
References m_next, m_previous, Log::Message(), and Log::s_log.
Referenced by StateNewGame::Accept(), MainMenu::Accept(), StateBattle::Attack(), Battle::BattleFinished(), StateNewGame::Cancel(), MainMenu::ContinueGame(), StateCity::Exit(), StateDone::Exit(), StateBattle::Exit(), StateSailing::HandleKeyDown(), StateSailing::HandleKeyUp(), Battle::HandleKeyUp(), Map::HandleKeyUp(), MainMenu::LoadGame(), MainMenu::SaveGame(), and StateSailing::Timer().
00159 { 00160 if (m_next != NULL){ 00161 Log::s_log->Message("Warning: SetNextState called on a non-null m_next"); 00162 } 00163 00164 // Set the next pointer, so at the end of the game loop, the state is changed 00165 m_next = next; 00166 00167 // Set the next state's previous pointer, if it's not NULL 00168 // If it is null, just leave the previous pointer alone 00169 if (prev != NULL) { 00170 m_next->m_previous = prev; 00171 } 00172 }
| void IGameState::PrepareTopContainer | ( | ) |
Definition at line 249 of file IGameState.cpp.
References m_top, CCGui::s_CCGui, and CCGui::SetTopContainer().
Referenced by init(), and SwitchStates().
00249 { 00250 if (m_top.get() != NULL) { 00251 m_top->setOpaque(false); 00252 m_top->setVisible(true); 00253 } 00254 CCGui::s_CCGui->SetTopContainer(m_top.get()); 00255 }
| void IGameState::SetCurrentPtr | ( | IGameState ** | current | ) | [static] |
Definition at line 52 of file IGameState.cpp.
References current, Log::Message(), s_currentPtr, and Log::s_log.
Referenced by init().
00052 { 00053 if (s_currentPtr != NULL) { 00054 Log::s_log->Message("Warning: setCurrentPtr called with non-null currentPtr pointer"); 00055 } 00056 s_currentPtr = current; 00057 }
| void IGameState::SetMainMenu | ( | IGameState * | menu | ) | [static] |
Definition at line 44 of file IGameState.cpp.
References Log::Message(), Log::s_log, and s_mainMenu.
Referenced by MainMenu::MainMenu(), and MainMenu::~MainMenu().
00044 { 00045 if ((menu != NULL) && (s_mainMenu != NULL)) { 00046 Log::s_log->Message("Warning: setMainMenu called with non-null mainMenu pointer"); 00047 } 00048 s_mainMenu = menu; 00049 }
| virtual void IGameState::SwitchFrom | ( | ) | [private, pure virtual] |
Implemented in MainMenu, Map, Battle, StateDone, StateBattle, StateCity, StateNewGame, and StateSailing.
Referenced by SwitchStates().
| void IGameState::SwitchStates | ( | ) | [private] |
Definition at line 141 of file IGameState.cpp.
References m_next, Log::Message(), PrepareTopContainer(), s_currentPtr, Log::s_log, SwitchFrom(), and SwitchTo().
Referenced by Loop().
00141 { 00142 if (m_next == NULL) { 00143 Log::s_log->Message("Warning: SwitchState called with null m_next"); 00144 return; 00145 } 00146 00147 // Prepare to leave this state 00148 SwitchFrom(); 00149 00150 // Prepare to enter the next state 00151 m_next->SwitchTo(this); 00152 m_next->PrepareTopContainer(); 00153 00154 // Hand control over to the next state 00155 *s_currentPtr = m_next; 00156 m_next = NULL; 00157 }
| virtual void IGameState::SwitchTo | ( | IGameState * | oldState | ) | [private, pure virtual] |
Implemented in MainMenu, Map, Battle, StateDone, StateBattle, StateCity, StateNewGame, and StateSailing.
Referenced by SwitchStates().
| void IGameState::TakeScreenshot | ( | ) | [protected] |
Definition at line 95 of file IGameState.cpp.
References done, Config::GetWinHeight(), Config::GetWinWidth(), Log::Message(), Config::s_config, Log::s_log, s_nextScreen, and SaveScreenshot().
Referenced by StateNewGame::CheckInput(), StateCity::CheckInput(), StateDone::CheckInput(), StateBattle::CheckInput(), MainMenu::CheckInput(), StateSailing::HandleKeyDown(), Battle::HandleKeyDown(), and Map::HandleKeyDown().
00095 { 00096 string buffer; 00097 ifstream fileStream; 00098 00099 bool loop = false; 00100 bool done = false; 00101 unsigned char count = s_nextScreen; 00102 00103 int width = Config::s_config->GetWinWidth(); 00104 int height = Config::s_config->GetWinHeight(); 00105 00106 while (!done) { 00107 if (count == 0) { 00108 if (loop == true) { 00109 Log::s_log->Message("Error: All 256 screenshot names are taken, could not take screenshot"); 00110 return; 00111 } 00112 else { 00113 loop = true; 00114 } 00115 } 00116 00117 // Create the file name 00118 ostringstream outputString; 00119 outputString << (int) count; 00120 buffer = "Screenshot" + outputString.str() + ".tga"; 00121 00122 // Check to see if the file already exists 00123 fileStream.open(buffer.c_str(), ios::in); 00124 if (!fileStream) { 00125 // The file doesn't exist, so this is the name to use 00126 done = true; 00127 } else { 00128 // A file by that name already exists, close the file & look for new name 00129 fileStream.close(); 00130 } 00131 00132 count++; 00133 } 00134 00135 s_nextScreen = count; 00136 00137 SaveScreenshot(buffer.c_str(), width, height); 00138 Log::s_log->Message((string) "Screenshot saved as " + buffer); 00139 }
| virtual void IGameState::Update | ( | const unsigned int | ticks | ) | [pure virtual] |
Implemented in MainMenu, Map, Battle, StateDone, StateBattle, StateCity, StateNewGame, and StateSailing.
Referenced by Loop().
IGameState* IGameState::m_next [private] |
Definition at line 67 of file IGameState.h.
Referenced by IGameState(), Loop(), PrepareStateSwitch(), and SwitchStates().
IGameState* IGameState::m_previous [protected] |
Definition at line 43 of file IGameState.h.
Referenced by StateBattle::Attack(), Battle::BattleFinished(), MainMenu::ContinueGame(), StateCity::Exit(), StateDone::Exit(), StateBattle::Exit(), Map::HandleKeyUp(), IGameState(), PrepareStateSwitch(), and MainMenu::~MainMenu().
| std::auto_ptr<gcn::Container> IGameState::m_top |
Definition at line 64 of file IGameState.h.
Referenced by IGameState(), Battle::InitHUD(), StateSailing::Initialize(), StateCity::InitMenu(), Map::InitMenu(), MainMenu::MainMenu(), PrepareTopContainer(), StateDone::SetupMenu(), StateBattle::StateBattle(), StateDone::StateDone(), and StateNewGame::StateNewGame().
IGameState ** IGameState::s_currentPtr = NULL [static, protected] |
IGameState * IGameState::s_mainMenu = NULL [static, protected] |
Definition at line 46 of file IGameState.h.
Referenced by StateNewGame::Accept(), StateNewGame::Cancel(), DoExit(), StateSailing::HandleKeyUp(), Battle::HandleKeyUp(), and SetMainMenu().
unsigned char IGameState::s_nextScreen = 0 [static, protected] |
1.4.7