00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pent_include.h"
00020 #include "PentagramMenuGump.h"
00021
00022 #include "RenderSurface.h"
00023 #include "GUIApp.h"
00024 #include "GameWidget.h"
00025 #include "SettingManager.h"
00026 #include "FileSystem.h"
00027 #include "IDataSource.h"
00028 #include "TexturePNG.h"
00029
00030 DEFINE_RUNTIME_CLASSTYPE_CODE(PentagramMenuGump,ModalGump);
00031
00032 PentagramMenuGump::PentagramMenuGump(int X, int Y, int Width, int Height) :
00033 ModalGump(X,Y,Width,Height)
00034 {
00035 gameScrollPos = 0;
00036 gameScrollTarget = 0;
00037 gameScrollLastDelta = 0;
00038 titleImage = 0;
00039 navbarImage = 0;
00040 coversImage = 0;
00041 flagsImage = 0;
00042 }
00043
00044 PentagramMenuGump::~PentagramMenuGump()
00045 {
00046 delete titleImage;
00047 delete navbarImage;
00048 delete coversImage;
00049 delete flagsImage;
00050 }
00051
00052 void PentagramMenuGump::InitGump(Gump* newparent, bool take_focus)
00053 {
00054 ModalGump::InitGump(newparent, take_focus);
00055
00056 Pentagram::istring game;
00057
00058 GameWidget* g;
00059 int y = 50;
00060
00061 std::vector<Pentagram::istring> games;
00062
00063 games = SettingManager::get_instance()->listGames();
00064 unsigned int index = 0;
00065 for (unsigned int i = 0; i < games.size(); ++i) {
00066 Pentagram::istring game = games[i];
00067
00068 if (game == "pentagram") continue;
00069 if (!GUIApp::get_instance()->getGameInfo(game)) continue;
00070
00071 g = new GameWidget(150, y, game);
00072 g->InitGump(this, false);
00073 g->SetIndex(index++);
00074 y += 114;
00075 }
00076
00077 gamecount = index;
00078
00079 IDataSource* ds = FileSystem::get_instance()->ReadFile("@data/title.png");
00080 titleImage = Texture::Create(ds, "title.png");
00081 delete ds;
00082
00083 ds = FileSystem::get_instance()->ReadFile("@data/navbar.png");
00084 navbarImage = Texture::Create(ds, "navbar.png");
00085 delete ds;
00086
00087 ds = FileSystem::get_instance()->ReadFile("@data/covers.png");
00088 coversImage = Texture::Create(ds, "covers.png");
00089 delete ds;
00090
00091 ds = FileSystem::get_instance()->ReadFile("@data/flags.png");
00092 flagsImage = Texture::Create(ds, "flags.png");
00093 delete ds;
00094 }
00095
00096 void PentagramMenuGump::PaintThis(RenderSurface *surf, sint32 lerp_factor, bool )
00097 {
00098 int w = dims.w, h = dims.h;
00099 #if 1
00100
00101 for (int i = 0; i < h; i+=4) {
00102 unsigned int r = (140 * i)/h;
00103 unsigned int gb = (21 * i)/h;
00104 uint32 col = 0xFF000000 + (r << 16) + (gb << 8) + gb;
00105 surf->Fill32(col, 0, i, w, 4);
00106 }
00107 #else
00108 surf->Fill32(0xFF440A0A, 0, 0, w, h);
00109 #endif
00110
00111
00112 surf->Blit(navbarImage, 0,0, navbarImage->width, navbarImage->height, 9,0);
00113
00114
00115 surf->Blit(titleImage, 0,0, titleImage->width, titleImage->height, 200, 6);
00116 }
00117
00118 void PentagramMenuGump::PaintChildren(RenderSurface *surf, sint32 lerp_factor, bool scaled)
00119 {
00120
00121 std::list<Gump*>::iterator it = children.begin();
00122 std::list<Gump*>::iterator end = children.end();
00123
00124 Pentagram::Rect game_clip_rect(0, 45, 640, dims.h - 58);
00125 Pentagram::Rect cur_clip_rect;
00126 surf->GetClippingRect(cur_clip_rect);
00127
00128
00129 while (it != end)
00130 {
00131 Gump *g = *it;
00132
00133 if (g->IsOfType<GameWidget>()) {
00134 surf->SetClippingRect(game_clip_rect);
00135 g->Move(150, 50 + 114*g->GetIndex() + gameScrollPos);
00136 }
00137
00138 g->Paint(surf, lerp_factor, scaled);
00139
00140 surf->SetClippingRect(cur_clip_rect);
00141
00142 ++it;
00143 }
00144 }
00145
00146
00147 void PentagramMenuGump::ChildNotify(Gump *child, uint32 message)
00148 {
00149 if (child->IsOfType<GameWidget>()) {
00150
00151 GameWidget* gw = p_dynamic_cast<GameWidget*>(child);
00152 Pentagram::istring gamename = gw->getGameName();
00153
00154 switch (message) {
00155 case GameWidget::GAME_PLAY:
00156 GUIApp::get_instance()->changeGame(gamename);
00157 break;
00158 case GameWidget::GAME_LOAD:
00159 break;
00160 case GameWidget::GAME_SETTINGS:
00161 break;
00162 case GameWidget::GAME_REMOVE:
00163 break;
00164 }
00165 }
00166 }
00167
00168 bool PentagramMenuGump::Run(const uint32 framenum)
00169 {
00170 int oldpos = gameScrollPos;
00171
00172 if (gameScrollPos != gameScrollTarget) {
00173 int diff = gameScrollTarget - gameScrollPos;
00174 if (diff < 20 && diff > -20) {
00175 gameScrollPos = gameScrollTarget;
00176 } else {
00177 gameScrollPos += diff/3;
00178 }
00179 }
00180
00181 gameScrollLastDelta = gameScrollPos - oldpos;
00182
00183 return true;
00184 }
00185
00186
00187 bool PentagramMenuGump::OnKeyDown(int key, int mod)
00188 {
00189 int delta = 0;
00190
00191 if (key == SDLK_DOWN) {
00192 delta = -114;
00193 } else if (key == SDLK_UP) {
00194 delta = 114;
00195 }
00196
00197 if (delta && gamecount > 3) {
00198 gameScrollTarget += delta;
00199
00200 if (gameScrollTarget > 0)
00201 gameScrollTarget = 0;
00202 if (gameScrollTarget < -114*(gamecount-3))
00203 gameScrollTarget = -114*(gamecount-3);
00204
00205 return true;
00206 }
00207
00208 return false;
00209 }