00001
00002
00003
00004
00005 #include <string>
00006 #include <sstream>
00007 #include <guichan.hpp>
00008 #include <guichan/sdl.hpp>
00009 #include <guichan/opengl.hpp>
00010 #include "SDL.h"
00011 #include "GLee.h"
00012 #include "Menu/CCGui.h"
00013 #include "Menu/CCButton.h"
00014 #include "Menu/CCTable.h"
00015 #include "Menu/CCLabel.h"
00016 #include "Config.h"
00017 #include "Log.h"
00018 #include "Texture.h"
00019 #include "font.h"
00020 #include "IGameState.h"
00021 #include "StateBattle/Battle.h"
00022 #include "Player.h"
00023 #include "Ship.h"
00024 #include "StateBattle.h"
00025
00026 using namespace std;
00027
00028 const string StateBattle::s_mainFontName = "papyrus.png";
00029 const string StateBattle::s_highlightFontName = "highlightPapyrus.png";
00030 const string StateBattle::s_disabledFontName = "disabledPapyrus.png";
00031
00032 StateBattle::StateBattle(): IGameState(NULL) {
00033 m_actualBattle = NULL;
00034
00035
00036 Player::player->ship->m_speed = 0;
00037 Player::player->ship->SetSails(NOSAILS);
00038
00039 m_exitCallback.SetCallback(this, &StateBattle::Exit);
00040 m_attackCallback.SetCallback(this, &StateBattle::Attack);
00041
00042 Log::s_log->Message("Callbacks Set");
00043
00044 m_background = new Texture("enterbattle.png");
00045
00046 Log::s_log->Message("Background Texture built");
00047
00048 Log::s_log->Message("Top Created");
00049 m_menuList = new CCTable(1, 2);
00050
00051 m_attackButton = new CCButton("Attack!", "attack_button", s_mainFontName, s_highlightFontName, s_disabledFontName, &m_attackCallback);
00052 m_sailAwayButton = new CCButton("Sail Away", "sailAway_button", s_mainFontName, s_highlightFontName, s_disabledFontName, &m_exitCallback);
00053
00054 m_title = new CCLabel("Ship sighted!", s_mainFontName);
00055
00056 m_menuList->add(0, 0, m_sailAwayButton);
00057 m_menuList->add(0, 1, m_attackButton);
00058
00059 m_menuList->setVisible(true);
00060 m_menuList->setOpaque(false);
00061
00062 Log::s_log->Message("Table Set...Label Set");
00063
00064 m_top->add(m_menuList, 10, 200);
00065 m_top->add(m_title, (Config::s_config->GetWinWidth() / 2) - (m_title->getWidth() / 2), 50);
00066
00067 Log::s_log->Message("StateBattle initialization done.");
00068
00069 }
00070
00071 StateBattle::~StateBattle() {
00072 delete m_menuList;
00073 delete m_title;
00074
00075 delete m_actualBattle;
00076
00077 delete m_background;
00078
00079 Log::s_log->Message("State Battle deleted");
00080 }
00081
00082 void StateBattle::Update(const unsigned int ticks) {
00083 CheckInput();
00084 }
00085
00086 void StateBattle::Display() {
00087 glLoadIdentity();
00088 DisplayBackground(m_background->GetTexture(), 1);
00089 }
00090
00091 void StateBattle::CheckInput() {
00092 SDL_Event event;
00093
00094
00095
00096 while(SDL_PollEvent(&event))
00097 {
00098 if (event.type == SDL_KEYDOWN)
00099 {
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 if (event.key.keysym.sym == SDLK_z) {
00115 TakeScreenshot();
00116 }
00117 }
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 CCGui::s_CCGui->m_input->pushInput(event);
00128 }
00129 }
00130
00131 void StateBattle::Exit(int ID) {
00132 PrepareStateSwitch(m_previous, this);
00133 }
00134
00135 void StateBattle::Attack(int ID) {
00136
00137 if (m_actualBattle != NULL) {
00138 delete m_actualBattle;
00139 }
00140 m_actualBattle = new Battle();
00141 PrepareStateSwitch(m_actualBattle, m_previous);
00142 }
00143
00144 void StateBattle::SwitchTo(IGameState *oldState) {
00145 EnterTextMode(Config::s_config->GetWinWidth(), Config::s_config->GetWinHeight());
00146 }
00147
00148 void StateBattle::SwitchFrom() {
00149 }