From: Daniel Karbach Date: Wed, 8 Aug 2012 22:23:39 +0000 (+0200) Subject: fixed scrolling in Menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=2ef82e057748751f795c60dcf826a001516b5ca0;p=l2e.git fixed scrolling in Menu --- diff --git a/src/battle/BattleState.cpp b/src/battle/BattleState.cpp index 549fdb4..d7b5a07 100644 --- a/src/battle/BattleState.cpp +++ b/src/battle/BattleState.cpp @@ -58,12 +58,20 @@ void BattleState::EnterState(Application &ctrl, SDL_Surface *screen) { spellMenus.back().Add("Stronger : 8", 0); spellMenus.back().Add("Champion :16", 0); spellMenus.back().Add("Rally :10", 0); + spellMenus.back().Add("Escape : 8", 0, false); spellMenus.back().Add("Valor :30", 0); spellMenus.back().Add("Poison : 2", 0); + spellMenus.back().Add("Warp : 8", 0, false); spellMenus.back().Add("Release : 2", 0); spellMenus.back().Add("Waken : 4", 0); + spellMenus.back().Add("Light : 0", 0, false); spellMenus.back().Add("Fake : 4", 0); spellMenus.back().Add("Trick : 5", 0); + spellMenus.back().Add("Flash : 5", 0); + spellMenus.back().Add("Fireball : 6", 0); + spellMenus.back().Add("Vortex : 7", 0); + spellMenus.back().Add("Blizzard : 8", 0); + spellMenus.back().Add("Spark : 3", 0); heroTags.push_back(HeroTag(&heroes[i], &attackChoices[i], res, HeroTag::Alignment((i + 1) % 2))); } } diff --git a/src/battle/states/SelectSpell.cpp b/src/battle/states/SelectSpell.cpp index 954b39e..be5c610 100644 --- a/src/battle/states/SelectSpell.cpp +++ b/src/battle/states/SelectSpell.cpp @@ -16,8 +16,6 @@ #include "../../geometry/Point.h" #include "../../graphics/Frame.h" -#include - using app::Application; using app::Input; using geometry::Point; @@ -60,24 +58,16 @@ void SelectSpell::HandleInput(const Input &input) { ctrl->PopState(); // return control to parent } if (input.JustPressed(Input::PAD_UP)) { - std::cout << "pressed up" << std::endl; battle->GetSpellMenu().PreviousRow(); - std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; } if (input.JustPressed(Input::PAD_RIGHT)) { - std::cout << "pressed right" << std::endl; battle->GetSpellMenu().NextItem(); - std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; } if (input.JustPressed(Input::PAD_DOWN)) { - std::cout << "pressed down" << std::endl; battle->GetSpellMenu().NextRow(); - std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; } if (input.JustPressed(Input::PAD_LEFT)) { - std::cout << "pressed left" << std::endl; battle->GetSpellMenu().PreviousItem(); - std::cout << "selected index: " << battle->GetSpellMenu().SelectedIndex() << std::endl; } } diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index f35a2be..decd99d 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -14,7 +14,6 @@ #include "../geometry/Point.h" #include "../geometry/Vector.h" -#include #include #include @@ -29,7 +28,6 @@ class Menu { public: Menu(); Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap = 0, int cols = 1, int colGap = 0); - Menu(const Menu &); public: int Width() const; @@ -119,22 +117,6 @@ Menu::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, } -template -Menu::Menu(const Menu &other) -: font(other.font) -, disabledFont(other.disabledFont) -, cursor(other.cursor) -, entries(other.entries) -, charsPerEntry(other.charsPerEntry) -, rows(other.rows) -, rowGap(other.rowGap) -, cols(other.cols) -, colGap(other.colGap) -, selected(other.selected) -, topRow(other.topRow) { - std::cout << "copied Menu" << std::endl; -} - template int Menu::Width() const { @@ -169,11 +151,10 @@ void Menu::PreviousRow() { template void Menu::SelectIndex(int index) { - if (index < 0 || int(entries.size()) < index) return; - std::cout << "selecting index " << index << std::endl; + if (index < 0 || int(entries.size()) <= index) return; selected = index; - if (GetRow(selected) - rows > topRow) { - topRow = GetRow(selected) - rows; + if (topRow <= GetRow(selected) - rows) { + topRow = GetRow(selected) - rows + 1; } else if (GetRow(selected) < topRow) { topRow = GetRow(selected); } @@ -183,9 +164,9 @@ void Menu::SelectIndex(int index) { template void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { int start(topRow * cols); - int slots((topRow + rows) * cols); + int slots(rows * cols); int items(entries.size() - start); - int end(items < slots ? items : slots); + int end(start + (items < slots ? items : slots)); for (int i(0), count(end - start); i < count; ++i) { geometry::Vector offset( (i % cols) * (ColWidth() + colGap), @@ -198,7 +179,7 @@ void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { } geometry::Vector cursorOffset( (selected % cols) * (ColWidth() + colGap) - cursor->Width(), - (selected / cols) * RowHeight()); + ((selected - start) / cols) * RowHeight()); cursor->Draw(dest, position + cursorOffset); }