From: Daniel Karbach Date: Sat, 19 Jan 2013 04:21:25 +0000 (-0600) Subject: added menu cursor animations X-Git-Url: http://git.localhorst.tv/?p=l2e.git;a=commitdiff_plain;h=ec824200aec12d6870b70304bcd2e2aeadba767b added menu cursor animations --- diff --git a/src/graphics/Menu.cpp b/src/graphics/Menu.cpp index 1b81f85..2d7e237 100644 --- a/src/graphics/Menu.cpp +++ b/src/graphics/Menu.cpp @@ -1,5 +1,6 @@ #include "Menu.h" +#include "Animation.h" #include "../loader/Interpreter.h" #include "../loader/TypeDescription.h" @@ -20,6 +21,8 @@ void MenuProperties::CreateTypeDescription() { td.AddField("disabledFont", FieldDescription(((char *)&p.disabledFont) - ((char *)&p), Font::TYPE_ID).SetReferenced().SetDescription("the font for disabled entries")); td.AddField("cursor", FieldDescription(((char *)&p.cursor) - ((char *)&p), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite indicating the current selection")); td.AddField("selectedCursor", FieldDescription(((char *)&p.selectedCursor) - ((char *)&p), Sprite::TYPE_ID).SetReferenced().SetDescription("the cursor sprite used when fixating a selection")); + td.AddField("cursorAnimation", FieldDescription(((char *)&p.cursorAnimation) - ((char *)&p), Animation::TYPE_ID).SetReferenced().SetDescription("an animation for the cursor sprite")); + td.AddField("selectedCursorAnimation", FieldDescription(((char *)&p.selectedCursorAnimation) - ((char *)&p), Animation::TYPE_ID).SetReferenced().SetDescription("an animation for the selected cursor")); td.AddField("charsPerEntry", FieldDescription(((char *)&p.charsPerEntry) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("width of an entry in characters")); td.AddField("rows", FieldDescription(((char *)&p.rows) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("number of visible rows")); td.AddField("rowGap", FieldDescription(((char *)&p.rowGap) - ((char *)&p), Interpreter::NUMBER_ID).SetDescription("space between rows in pixles")); diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index e288f2d..19ad907 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -1,6 +1,12 @@ #ifndef GRAPHICS_MENU_H_ #define GRAPHICS_MENU_H_ +namespace app { + class Application; + class State; +} + +#include "Animation.h" #include "Font.h" #include "Sprite.h" #include "../math/Vector.h" @@ -18,6 +24,8 @@ struct MenuProperties { const Font *disabledFont; const Sprite *cursor; const Sprite *selectedCursor; + const Animation *cursorAnimation; + const Animation *selectedCursorAnimation; int charsPerEntry; int rows; int rowGap; @@ -34,6 +42,7 @@ struct MenuProperties { MenuProperties() : font(0), disabledFont(0), cursor(0), selectedCursor(0) + , cursorAnimation(0), selectedCursorAnimation(0) , charsPerEntry(0), rows(1), rowGap(0) , iconSpace(0), cols(1), colGap(0) , charsPerNumber(0), charsPerAdditionalText(0) @@ -104,12 +113,19 @@ public: void Clear() { entries.clear(); } void ClearEntry(int at) { entries[at] = Entry(0, T(), false); } + void StartAnimation(app::Application &ctrl); + void StartAnimation(app::State &ctrl); + void StopAnimation(); + void Draw(SDL_Surface *dest, const math::Vector &position) const; private: int GetRow(int index) const { return index / cols; } int GetCol(int index) const { return index % cols; } + void DrawCursor(SDL_Surface *, const math::Vector &) const; + void DrawSelectedCursor(SDL_Surface *, const math::Vector &) const; + private: struct Entry { Entry(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0, int number = 0, const char *additionalText = 0) @@ -121,6 +137,8 @@ private: T value; bool enabled; }; + AnimationRunner animation; + AnimationRunner selectedAnimation; std::vector entries; int selected; int secondarySelection; @@ -149,6 +167,8 @@ Menu::Menu() template Menu::Menu(const MenuProperties &p) : MenuProperties(p) +, animation(cursorAnimation) +, selectedAnimation(selectedCursorAnimation) , selected(0) , secondarySelection(0) , topRow(0) @@ -229,6 +249,33 @@ void Menu::SelectIndex(int index) { } +template +void Menu::StartAnimation(app::Application &ctrl) { + if (cursorAnimation) { + animation.Start(ctrl); + } + if (selectedCursorAnimation) { + selectedAnimation.Start(ctrl); + } +} + +template +void Menu::StartAnimation(app::State &ctrl) { + if (cursorAnimation) { + animation.Start(ctrl); + } + if (selectedCursorAnimation) { + selectedAnimation.Start(ctrl); + } +} + +template +void Menu::StopAnimation() { + animation.Stop(); + selectedAnimation.Stop(); +} + + template void Menu::Draw(SDL_Surface *dest, const math::Vector &position) const { int start(topRow * cols); @@ -280,24 +327,46 @@ void Menu::Draw(SDL_Surface *dest, const math::Vector &position) const { case STATE_INACTIVE: break; case STATE_ACTIVE: - cursor->Draw(dest, position + cursorOffset); + DrawCursor(dest, position + cursorOffset); break; case STATE_SELECTED: - selectedCursor->Draw(dest, position + cursorOffset); + DrawSelectedCursor(dest, position + cursorOffset); break; case STATE_DUAL: - cursor->Draw(dest, position + cursorOffset + DrawCursor(dest, position + cursorOffset - math::Vector(selectedCursor->Width(), 0)); if (secondarySelection >= start && secondarySelection <= end) { math::Vector secondaryOffset( (secondarySelection % cols) * (ColWidth() + colGap) - cursor->Width(), ((secondarySelection - start) / cols) * RowHeight()); - selectedCursor->Draw(dest, position + secondaryOffset); + DrawSelectedCursor(dest, position + secondaryOffset); } break; } } +template +void Menu::DrawCursor( + SDL_Surface *dest, + const math::Vector &position) const { + if (animation.Running()) { + animation.Draw(dest, position); + } else { + cursor->Draw(dest, position); + } +} + +template +void Menu::DrawSelectedCursor( + SDL_Surface *dest, + const math::Vector &position) const { + if (selectedAnimation.Running()) { + selectedAnimation.Draw(dest, position); + } else { + selectedCursor->Draw(dest, position); + } +} + } #endif diff --git a/src/menu/CapsuleFeedMenu.cpp b/src/menu/CapsuleFeedMenu.cpp index 07808f6..ead0d71 100644 --- a/src/menu/CapsuleFeedMenu.cpp +++ b/src/menu/CapsuleFeedMenu.cpp @@ -34,7 +34,9 @@ CapsuleFeedMenu::CapsuleFeedMenu(CapsuleMenu *parent) void CapsuleFeedMenu::OnEnterState(SDL_Surface *) { menu.SetSelected(); + menu.StartAnimation(Ctrl()); itemMenu.SetActive(); + itemMenu.StartAnimation(Ctrl()); } void CapsuleFeedMenu::LoadInventory() { diff --git a/src/menu/CapsuleMenu.cpp b/src/menu/CapsuleMenu.cpp index 6b2eeeb..b45a204 100644 --- a/src/menu/CapsuleMenu.cpp +++ b/src/menu/CapsuleMenu.cpp @@ -35,7 +35,7 @@ CapsuleMenu::CapsuleMenu(PartyMenu *parent) void CapsuleMenu::OnEnterState(SDL_Surface *) { - + menu.StartAnimation(Ctrl()); } void CapsuleMenu::OnExitState(SDL_Surface *) { diff --git a/src/menu/ConfigMenu.cpp b/src/menu/ConfigMenu.cpp index 274f30a..fa51f77 100644 --- a/src/menu/ConfigMenu.cpp +++ b/src/menu/ConfigMenu.cpp @@ -29,7 +29,7 @@ ConfigMenu::ConfigMenu(PartyMenu *parent) void ConfigMenu::OnEnterState(SDL_Surface *) { - + configMenu.StartAnimation(Ctrl()); } void ConfigMenu::OnExitState(SDL_Surface *) { diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index d04d2f4..1a433be 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -43,8 +43,11 @@ EquipMenu::EquipMenu(PartyMenu *parent, int cursor) void EquipMenu::OnEnterState(SDL_Surface *) { + actionMenu.StartAnimation(Ctrl()); equipmentMenu.SetInactive(); + equipmentMenu.StartAnimation(Ctrl()); inventoryMenu.SetInactive(); + inventoryMenu.StartAnimation(Ctrl()); } void EquipMenu::OnExitState(SDL_Surface *) { diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index a288171..de60edc 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -34,7 +34,9 @@ InventoryMenu::InventoryMenu(PartyMenu *parent) void InventoryMenu::OnEnterState(SDL_Surface *) { menu.SetSelected(); + menu.StartAnimation(Ctrl()); LoadInventory(); + itemMenu.StartAnimation(Ctrl()); } void InventoryMenu::LoadInventory() { diff --git a/src/menu/PartyMenu.cpp b/src/menu/PartyMenu.cpp index 46e271b..4a347c5 100644 --- a/src/menu/PartyMenu.cpp +++ b/src/menu/PartyMenu.cpp @@ -53,7 +53,7 @@ PartyMenu::~PartyMenu() { void PartyMenu::OnEnterState(SDL_Surface *) { - + mainMenu.StartAnimation(Ctrl()); } void PartyMenu::OnExitState(SDL_Surface *) { diff --git a/src/menu/ScenarioMenu.cpp b/src/menu/ScenarioMenu.cpp index 18fa55a..59e075b 100644 --- a/src/menu/ScenarioMenu.cpp +++ b/src/menu/ScenarioMenu.cpp @@ -30,6 +30,7 @@ ScenarioMenu::ScenarioMenu(PartyMenu *parent) void ScenarioMenu::OnEnterState(SDL_Surface *) { LoadItems(); + itemMenu.StartAnimation(Ctrl()); } void ScenarioMenu::LoadItems() { diff --git a/src/menu/SpellMenu.cpp b/src/menu/SpellMenu.cpp index 5f12573..0c79365 100644 --- a/src/menu/SpellMenu.cpp +++ b/src/menu/SpellMenu.cpp @@ -45,7 +45,9 @@ void SpellMenu::OnEnterState(SDL_Surface *) { SDL_SetAlpha(highlight, SDL_SRCALPHA|SDL_RLEACCEL, 0x20); actionMenu.SetSelected(); + actionMenu.StartAnimation(Ctrl()); LoadSpells(); + spellMenu.StartAnimation(Ctrl()); } void SpellMenu::LoadSpells() { diff --git a/src/menu/StatusMenu.cpp b/src/menu/StatusMenu.cpp index 41f848f..b2435ed 100644 --- a/src/menu/StatusMenu.cpp +++ b/src/menu/StatusMenu.cpp @@ -34,7 +34,7 @@ StatusMenu::StatusMenu(PartyMenu *parent, int cursor) void StatusMenu::OnEnterState(SDL_Surface *) { - + menu.StartAnimation(Ctrl()); } void StatusMenu::OnExitState(SDL_Surface *) { diff --git a/test-data/test.l2s b/test-data/test.l2s index ed457ca..24f4bb2 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -672,6 +672,18 @@ Sprite menuActiveCursor { image: :"menu-cursor-active.png", size: <32, 18> } +SimpleAnimation menuCursorAnimation { + sprite: menuCursor, + frametime: fourFramesTime, + framecount: 6, + repeat: true +} +SimpleAnimation menuActiveCursorAnimation { + sprite: menuActiveCursor, + frametime: fourFramesTime, + framecount: 5, + repeat: true +} export MenuResources menuResources { menubg: Texture { @@ -697,6 +709,7 @@ export MenuResources menuResources { rowGap: 8, colGap: 32, cursor: menuCursor, + cursorAnimation: menuCursorAnimation, font: menuFont, disabledFont: menuInactiveFont, wrapX: true, @@ -740,6 +753,7 @@ export MenuResources menuResources { charsPerEntry: 6, colGap: 16, cursor: menuCursor, + cursorAnimation: menuCursorAnimation, font: menuFont, wrapX: true }, @@ -753,6 +767,8 @@ export MenuResources menuResources { colGap: 16, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont, wrapX: true, wrapY: true @@ -768,6 +784,8 @@ export MenuResources menuResources { rowGap: 8, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont, disabledFont: menuInactiveFont, iconSpace: 16, @@ -783,6 +801,8 @@ export MenuResources menuResources { colGap: 48, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont, disabledFont: menuInactiveFont, charsPerNumber: 2, @@ -795,6 +815,8 @@ export MenuResources menuResources { rowGap: 8, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont }, equipmentMenu: MenuProperties { @@ -804,6 +826,8 @@ export MenuResources menuResources { rowGap: 16, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: normalFont, iconSpace: 16, wrapY: true @@ -819,6 +843,7 @@ export MenuResources menuResources { charsPerEntry: 8, rowGap: 32, cursor: menuCursor, + cursorAnimation: menuCursorAnimation, font: menuFont, wrapY: true }, @@ -839,6 +864,7 @@ export MenuResources menuResources { charsPerEntry: 14, rowGap: 8, cursor: menuCursor, + cursorAnimation: menuCursorAnimation, font: menuFont }, scenarioMenuHeadline: "SCENARIO ITEM", @@ -852,6 +878,8 @@ export MenuResources menuResources { charsPerEntry: 7, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont, thirdColumnHack: 2 }, @@ -862,6 +890,8 @@ export MenuResources menuResources { colGap: 32, cursor: menuCursor, selectedCursor: menuActiveCursor, + cursorAnimation: menuCursorAnimation, + selectedCursorAnimation: menuActiveCursorAnimation, font: menuFont }, capsuleFeedLabel: "FEED",