From c421576a8314fc512db6306893028c061f9cc4e7 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Wed, 14 Mar 2012 23:53:11 +0000 Subject: [PATCH] first steps for load game menu --- .../glest_game/menu/menu_state_load_game.cpp | 220 ++++++++++++++++++ source/glest_game/menu/menu_state_load_game.h | 58 +++++ source/glest_game/menu/menu_state_root.cpp | 12 + source/glest_game/menu/menu_state_root.h | 1 + 4 files changed, 291 insertions(+) create mode 100644 source/glest_game/menu/menu_state_load_game.cpp create mode 100644 source/glest_game/menu/menu_state_load_game.h diff --git a/source/glest_game/menu/menu_state_load_game.cpp b/source/glest_game/menu/menu_state_load_game.cpp new file mode 100644 index 000000000..e87ee56e6 --- /dev/null +++ b/source/glest_game/menu/menu_state_load_game.cpp @@ -0,0 +1,220 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2005 Marti�o Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#include "menu_state_load_game.h" + +#include "renderer.h" +#include "sound_renderer.h" +#include "core_data.h" +#include "config.h" +#include "menu_state_root.h" +#include "metrics.h" +#include "network_message.h" +#include "auto_test.h" + +#include "leak_dumper.h" + +namespace Glest{ namespace Game{ + +// ===================================================== +// class MenuStateLoadGame +// ===================================================== + +MenuStateLoadGame::MenuStateLoadGame(Program *program, MainMenu *mainMenu): + MenuState(program, mainMenu, "root") +{ + containerName = "LoadGame"; + Lang &lang= Lang::getInstance(); + + int buttonWidth = 120; + int yPos=30; + int xPos=20; + int xSpacing=20; + int slotsLineHeight=20; + int slotLinesYBase=650; + int slotsToRender=30; + int slotWidth=200; + + lines[0].init(0,slotLinesYBase+slotsLineHeight); + lines[1].init(0, slotLinesYBase-(slotsToRender-1)*slotsLineHeight-5); + //lines[1].setHorizontal(false); + + headerLabel.registerGraphicComponent(containerName,"headerLabel"); + headerLabel.init(400, 730); + headerLabel.setFont(CoreData::getInstance().getMenuFontBig()); + headerLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + headerLabel.setText(lang.get("LoadGameMenu")); + + noSavedGamesLabel.registerGraphicComponent(containerName,"noSavedGamesLabel"); + noSavedGamesLabel.init(20, 400); + noSavedGamesLabel.setFont(CoreData::getInstance().getMenuFontBig()); + noSavedGamesLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + noSavedGamesLabel.setText(lang.get("NoSavedGames")); + + savedGamesLabel.registerGraphicComponent(containerName,"savedGamesLabel"); + savedGamesLabel.init(120, slotLinesYBase+30); + savedGamesLabel.setFont(CoreData::getInstance().getMenuFontBig()); + savedGamesLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + savedGamesLabel.setText(lang.get("SavedGames")); + + infoHeaderLabel.registerGraphicComponent(containerName,"infoHeaderLabel"); + infoHeaderLabel.init(650, slotLinesYBase+30); + infoHeaderLabel.setFont(CoreData::getInstance().getMenuFontBig()); + infoHeaderLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + infoHeaderLabel.setText(lang.get("SavegameInfo")); + + infoTextLabel.registerGraphicComponent(containerName,"infoTextLabel"); + infoTextLabel.init(600, 400); +// infoTextLabel.setFont(CoreData::getInstance().getMenuFontBig()); +// infoTextLabel.setFont3D(CoreData::getInstance().getMenuFontBig3D()); + infoTextLabel.setText("Info block for the current slot, maybe screenshot above \ntest\ntest2"); + + abortButton.registerGraphicComponent(containerName,"abortButton"); + abortButton.init(xPos, yPos, buttonWidth); + abortButton.setText(lang.get("Abort")); + xPos+=buttonWidth+xSpacing; + loadButton.registerGraphicComponent(containerName,"loadButton"); + loadButton.init(xPos, yPos, buttonWidth); + loadButton.setText(lang.get("LoadGame")); + xPos+=buttonWidth+xSpacing; + deleteButton.registerGraphicComponent(containerName,"deleteButton"); + deleteButton.init(xPos, yPos, buttonWidth); + deleteButton.setText(lang.get("Delete")); + + slotsScrollBar.init(500-20,slotLinesYBase-slotsLineHeight*(slotsToRender-1),false,slotWidth,20); + slotsScrollBar.setLength(slotsLineHeight*slotsToRender); + slotsScrollBar.setElementCount(0); + slotsScrollBar.setVisibleSize(slotsToRender); + slotsScrollBar.setVisibleStart(0); + + + GraphicComponent::applyAllCustomProperties(containerName); +} + +MenuStateLoadGame::~MenuStateLoadGame() { + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); + clearSlots(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] END\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); +} + +void MenuStateLoadGame::clearSlots() { + while(!slots.empty()) { + delete slots.back(); + slots.pop_back(); + } +} + + +void MenuStateLoadGame::reloadUI() { + Lang &lang= Lang::getInstance(); + + abortButton.setText(lang.get("Abort")); + deleteButton.setText(lang.get("Delete")); + loadButton.setText(lang.get("LoadGame")); + + GraphicComponent::reloadFontsForRegisterGraphicComponents(containerName); +} + +void MenuStateLoadGame::mouseClick(int x, int y, MouseButton mouseButton){ + + CoreData &coreData= CoreData::getInstance(); + SoundRenderer &soundRenderer= SoundRenderer::getInstance(); + + if(abortButton.mouseClick(x, y)){ + soundRenderer.playFx(coreData.getClickSoundB()); + mainMenu->setState(new MenuStateRoot(program, mainMenu)); + } + else if(deleteButton.mouseClick(x, y)){ + soundRenderer.playFx(coreData.getClickSoundB()); + mainMenu->setState(new MenuStateRoot(program, mainMenu)); + } + else if(loadButton.mouseClick(x, y)){ + soundRenderer.playFx(coreData.getClickSoundB()); + mainMenu->setState(new MenuStateRoot(program, mainMenu)); + } + else if(slotsScrollBar.mouseClick(x, y)){ + soundRenderer.playFx(coreData.getClickSoundB()); + } + else { + if(slotsScrollBar.getElementCount()!=0){ + for(int i = slotsScrollBar.getVisibleStart(); i <= slotsScrollBar.getVisibleEnd(); ++i) { + if(slots[i]->mouseClick(x, y)) { + break; + } + } + } + } +} + +void MenuStateLoadGame::mouseMove(int x, int y, const MouseState *ms){ + + abortButton.mouseMove(x, y); + deleteButton.mouseMove(x, y); + loadButton.mouseMove(x, y); + if(slotsScrollBar.getElementCount()!=0){ + for(int i = slotsScrollBar.getVisibleStart(); i <= slotsScrollBar.getVisibleEnd(); ++i) { + if(slots[i]->mouseMove(x, y)) { + break; + } + } + } + slotsScrollBar.mouseMove(x,y); + +} + +void MenuStateLoadGame::render(){ + Renderer &renderer= Renderer::getInstance(); + + renderer.renderLabel(&headerLabel); + renderer.renderLabel(&savedGamesLabel); + renderer.renderLabel(&infoHeaderLabel); + renderer.renderLabel(&infoTextLabel); + + renderer.renderButton(&abortButton); + renderer.renderButton(&deleteButton); + renderer.renderButton(&loadButton); + + for(int i=0; irenderProgramMsgBox(); +} + +void MenuStateLoadGame::update(){ + if(Config::getInstance().getBool("AutoTest")){ + AutoTest::getInstance().updateNewGame(program, mainMenu); + } + console.update(); +} + +void MenuStateLoadGame::keyDown(SDL_KeyboardEvent key) { + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + //if(key == configKeys.getCharKey("SaveGUILayout")) { + if(isKeyPressed(configKeys.getSDLKey("SaveGUILayout"),key) == true) { + GraphicComponent::saveAllCustomProperties(containerName); + //Lang &lang= Lang::getInstance(); + //console.addLine(lang.get("GUILayoutSaved") + " [" + (saved ? lang.get("Yes") : lang.get("No"))+ "]"); + } +} + +}}//end namespace diff --git a/source/glest_game/menu/menu_state_load_game.h b/source/glest_game/menu/menu_state_load_game.h new file mode 100644 index 000000000..6481d18aa --- /dev/null +++ b/source/glest_game/menu/menu_state_load_game.h @@ -0,0 +1,58 @@ +// ============================================================== +// This file is part of Glest (www.glest.org) +// +// Copyright (C) 2001-2005 Marti�o Figueroa +// +// You can redistribute this code and/or modify it under +// the terms of the GNU General Public License as published +// by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version +// ============================================================== + +#ifndef _GLEST_GAME_MENUSTATELOADGAME_H_ +#define _GLEST_GAME_MENUSTATELOADGAME_H_ + +#include "main_menu.h" +#include "leak_dumper.h" + +namespace Glest{ namespace Game{ + +// =============================== +// class MenuStateLoadGame +// =============================== +typedef vector SaveSlotButtons; +class MenuStateLoadGame: public MenuState{ +private: + GraphicButton loadButton; + GraphicButton deleteButton; + GraphicButton abortButton; + SaveSlotButtons slots; + GraphicScrollBar slotsScrollBar; + + GraphicLabel headerLabel; + GraphicLabel noSavedGamesLabel; + GraphicLabel savedGamesLabel; + GraphicLabel infoHeaderLabel; + GraphicLabel infoTextLabel; + + GraphicLine lines[2]; + +public: + MenuStateLoadGame(Program *program, MainMenu *mainMenu); + ~MenuStateLoadGame(); + + void mouseClick(int x, int y, MouseButton mouseButton); + void mouseMove(int x, int y, const MouseState *mouseState); + void update(); + void render(); + virtual void keyDown(SDL_KeyboardEvent key); + + void reloadUI(); +private: + void clearSlots(); +}; + + +}}//end namespace + +#endif diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index d6f998460..bf704efab 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -16,6 +16,7 @@ #include "core_data.h" #include "config.h" #include "menu_state_new_game.h" +#include "menu_state_load_game.h" #include "menu_state_options.h" #include "menu_state_about.h" #include "menu_state_mods.h" @@ -55,6 +56,9 @@ MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu): buttonNewGame.registerGraphicComponent(containerName,"buttonNewGame"); buttonNewGame.init(425, yPos, 150); yPos-=40; + buttonLoadGame.registerGraphicComponent(containerName,"buttonLoadGame"); + buttonLoadGame.init(425, yPos, 150); + yPos-=40; buttonMods.registerGraphicComponent(containerName,"buttonMods"); buttonMods.init(425, yPos, 150); yPos-=40; @@ -68,6 +72,7 @@ MenuStateRoot::MenuStateRoot(Program *program, MainMenu *mainMenu): buttonExit.init(425, yPos, 150); buttonNewGame.setText(lang.get("NewGame")); + buttonLoadGame.setText(lang.get("LoadGame")); buttonMods.setText(lang.get("Mods")); buttonOptions.setText(lang.get("Options")); buttonAbout.setText(lang.get("About")); @@ -109,6 +114,7 @@ void MenuStateRoot::reloadUI() { } buttonNewGame.setText(lang.get("NewGame")); + buttonLoadGame.setText(lang.get("LoadGame")); buttonMods.setText(lang.get("Mods")); buttonOptions.setText(lang.get("Options")); buttonAbout.setText(lang.get("About")); @@ -160,6 +166,10 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){ soundRenderer.playFx(coreData.getClickSoundB()); mainMenu->setState(new MenuStateNewGame(program, mainMenu)); } + else if(mainMessageBox.getEnabled() == false && buttonLoadGame.mouseClick(x, y)){ + soundRenderer.playFx(coreData.getClickSoundB()); + mainMenu->setState(new MenuStateLoadGame(program, mainMenu)); + } else if(mainMessageBox.getEnabled() == false && buttonMods.mouseClick(x, y)){ soundRenderer.playFx(coreData.getClickSoundB()); mainMenu->setState(new MenuStateMods(program, mainMenu)); @@ -188,6 +198,7 @@ void MenuStateRoot::mouseClick(int x, int y, MouseButton mouseButton){ void MenuStateRoot::mouseMove(int x, int y, const MouseState *ms){ popupMenu.mouseMove(x, y); buttonNewGame.mouseMove(x, y); + buttonLoadGame.mouseMove(x, y); buttonMods.mouseMove(x, y); buttonOptions.mouseMove(x, y); buttonAbout.mouseMove(x, y); @@ -260,6 +271,7 @@ void MenuStateRoot::render() { } renderer.renderButton(&buttonNewGame); + renderer.renderButton(&buttonLoadGame); renderer.renderButton(&buttonMods); renderer.renderButton(&buttonOptions); renderer.renderButton(&buttonAbout); diff --git a/source/glest_game/menu/menu_state_root.h b/source/glest_game/menu/menu_state_root.h index fdac6205a..45e3dfa67 100644 --- a/source/glest_game/menu/menu_state_root.h +++ b/source/glest_game/menu/menu_state_root.h @@ -27,6 +27,7 @@ class PopupMenu; class MenuStateRoot: public MenuState { private: GraphicButton buttonNewGame; + GraphicButton buttonLoadGame; GraphicButton buttonMods; GraphicButton buttonOptions; GraphicButton buttonAbout;