From: Daniel Karbach Date: Fri, 30 Nov 2012 13:49:22 +0000 (+0100) Subject: added scenario menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=37f46a0eb5ddbf9e3de672cf6da97605e41bd1f4;p=l2e.git added scenario menu --- diff --git a/src/main.cpp b/src/main.cpp index 580c5db..f310399 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -464,6 +464,16 @@ int main(int argc, char **argv) { menuResources.configMusicStereo = "STEREO"; menuResources.configMusicMono = "MONO"; + graphics::MenuProperties scenarioMenuProperties; + scenarioMenuProperties.cols = 1; + scenarioMenuProperties.rows = 6; + scenarioMenuProperties.charsPerEntry = 14; + scenarioMenuProperties.rowGap = 8; + scenarioMenuProperties.cursor = &menuCursor; + scenarioMenuProperties.font = &menuFont; + menuResources.scenarioMenuProperties = &scenarioMenuProperties; + menuResources.scenarioMenuHeadline = "SCENARIO ITEM"; + InitScreen screen(width, height); app::State *state(0); diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 99e86d1..619d7e1 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -12,6 +12,7 @@ #include "EquipMenu.h" #include "InventoryMenu.h" #include "Resources.h" +#include "ScenarioMenu.h" #include "SelectHero.h" #include "SpellMenu.h" #include "StatusMenu.h" @@ -118,6 +119,7 @@ void PartyMenu::HandleEvents(const Input &input) { Ctrl().PushState(new ConfigMenu(this)); break; case MENU_ITEM_SCENARIO: + Ctrl().PushState(new ScenarioMenu(this)); break; default: break; diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 83daa10..38cf6f8 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -86,7 +86,10 @@ Resources::Resources() , configCursorMemory(0) , configMusicLabel(0) , configMusicStereo(0) -, configMusicMono(0) { +, configMusicMono(0) + +, scenarioMenuProperties(0) +, scenarioMenuHeadline(0) { } diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 026e3da..62b825d 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -93,6 +93,9 @@ struct Resources { const char *configMusicStereo; const char *configMusicMono; + graphics::MenuProperties *scenarioMenuProperties; + const char *scenarioMenuHeadline; + Resources(); }; diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp new file mode 100644 index 0000000..a2aca87 --- /dev/null +++ b/src/menu/ScenarioMenu.cpp @@ -0,0 +1,128 @@ +/* + * ScenarioMenu.cpp + * + * Created on: Nov 30, 2012 + * Author: holy + */ + +#include "ScenarioMenu.h" + +#include "PartyMenu.h" +#include "Resources.h" +#include "../app/Input.h" +#include "../common/GameConfig.h" +#include "../common/GameState.h" +#include "../common/Inventory.h" +#include "../common/Item.h" +#include "../graphics/Font.h" +#include "../graphics/Frame.h" + +using app::Input; +using common::Inventory; +using common::Item; +using geometry::Vector; +using graphics::Font; +using graphics::Frame; + +namespace menu { + +ScenarioMenu::ScenarioMenu(PartyMenu *parent) +: parent(parent) +, itemMenu(*parent->Res().scenarioMenuProperties) { + +} + + +void ScenarioMenu::OnEnterState(SDL_Surface *) { + LoadItems(); +} + +void ScenarioMenu::LoadItems() { + const Inventory &inv(parent->Game().state->inventory); + itemMenu.Clear(); + itemMenu.Reserve(inv.MaxScenarioItems()); + int i = 0; + for (; i < inv.NumScenarioItems(); ++i) { + const Item *item(inv.ScenarioItemAt(i)); + itemMenu.Add(item->Name(), item, item->CanUseOnStatusScreen(), item->MenuIcon(), inv.ItemCountAt(i)); + } + for (; i < inv.MaxScenarioItems(); ++i) { + itemMenu.AddEmptyEntry(); + } +} + +void ScenarioMenu::OnExitState(SDL_Surface *) { + +} + +void ScenarioMenu::OnResumeState(SDL_Surface *) { + +} + +void ScenarioMenu::OnPauseState(SDL_Surface *) { + +} + + +void ScenarioMenu::OnResize(int width, int height) { + +} + + +void ScenarioMenu::HandleEvents(const Input &input) { + if (input.JustPressed(Input::PAD_DOWN)) { + itemMenu.NextRow(); + } + if (input.JustPressed(Input::PAD_UP)) { + itemMenu.PreviousRow(); + } + if (input.JustPressed(Input::ACTION_B)) { + Ctrl().PopState(); + } +} + +void ScenarioMenu::UpdateWorld(float deltaT) { + +} + + +void ScenarioMenu::Render(SDL_Surface *screen) { + const Font &font(*parent->Res().normalFont); + Vector offset((screen->w - Width()) / 2, (screen->h - Height()) / 2); + Vector headlineOffset(font.CharWidth(), 13 * font.CharHeight() + font.CharHeight() / 8); + Vector itemsOffset(font.CharWidth(), 16 * font.CharHeight() + font.CharHeight() / 8); + + parent->RenderBackground(screen); + parent->RenderHeros(screen, offset); + RenderHeadline(screen, offset + headlineOffset); + RenderItems(screen, offset + itemsOffset); +} + +int ScenarioMenu::Width() const { + return parent->Width(); +} + +int ScenarioMenu::Height() const { + return parent->Height(); +} + +void ScenarioMenu::RenderHeadline(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector textOffset(2 * font.CharWidth(), font.CharHeight()); + + int width = font.StringWidth(parent->Res().scenarioMenuHeadline) + 4 * font.CharWidth(); + frame.Draw(screen, offset, width, 3 * font.CharHeight()); + font.DrawString(parent->Res().scenarioMenuHeadline, screen, offset + textOffset); +} + +void ScenarioMenu::RenderItems(SDL_Surface *screen, const geometry::Vector &offset) const { + const Font &font(*parent->Res().normalFont); + const Frame &frame(*parent->Res().statusFrame); + const Vector menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4); + + frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight()); + itemMenu.Draw(screen, offset + menuOffset); +} + +} diff --git a/src/menu/ScenarioMenu.h b/src/menu/ScenarioMenu.h new file mode 100644 index 0000000..bcc2bbc --- /dev/null +++ b/src/menu/ScenarioMenu.h @@ -0,0 +1,54 @@ +/* + * ScenarioMenu.h + * + * Created on: Nov 30, 2012 + * Author: holy + */ + +#ifndef MENU_SCENARIOMENU_H_ +#define MENU_SCENARIOMENU_H_ + +#include "fwd.h" +#include "../app/State.h" +#include "../common/fwd.h" +#include "../geometry/Vector.h" +#include "../graphics/Menu.h" + +namespace menu { + +class ScenarioMenu +: public app::State { + +public: + explicit ScenarioMenu(PartyMenu *parent); + +public: + virtual void HandleEvents(const app::Input &); + virtual void UpdateWorld(float deltaT); + virtual void Render(SDL_Surface *); + + int Width() const; + int Height() const; + +private: + virtual void OnEnterState(SDL_Surface *screen); + virtual void OnExitState(SDL_Surface *screen); + virtual void OnResumeState(SDL_Surface *screen); + virtual void OnPauseState(SDL_Surface *screen); + + virtual void OnResize(int width, int height); + + void LoadItems(); + + void RenderHeadline(SDL_Surface *screen, const geometry::Vector &offset) const; + void RenderItems(SDL_Surface *screen, const geometry::Vector &offset) const; + +private: + PartyMenu *parent; + graphics::Menu itemMenu; + +}; + +} + +#endif /* MENU_SCENARIOMENU_H_ */ diff --git a/src/menu/fwd.h b/src/menu/fwd.h index b0ad85a..b4b96e5 100644 --- a/src/menu/fwd.h +++ b/src/menu/fwd.h @@ -17,6 +17,7 @@ class HeroStatus; class InventoryMenu; class PartyMenu; struct Resources; +class ScenarioMenu; class SelectHero; class SpellMenu; class StatusMenu;