Added automatic copying of last menu setup for higher level menus.

Added support for <, >, and ! to the menuIndex parameter.
Added support for i to the menuIndex parameter of menu items.
This will allow for easier support for multi-level layouts, e.g.

Rather than defining an animation for menuIndex 1, 2, 3, 4, ... you can use !0 or >0

Rather than defining the same menu for menuIndex 1, 2, 3, 4, ... with animations for that specific menuIndex you can create a single menu and set the menuIndex for the animations to i.
This commit is contained in:
Pieter Hulshoff 2017-05-21 09:57:19 +02:00
parent 465be1846b
commit d30158ea67
7 changed files with 217 additions and 85 deletions

View File

@ -89,7 +89,3 @@ void AnimationEvents::clear()
animationMap_.clear(); animationMap_.clear();
} }

View File

@ -18,6 +18,7 @@
#include "../../Graphics/ViewInfo.h" #include "../../Graphics/ViewInfo.h"
#include "../../Utility/Log.h" #include "../../Utility/Log.h"
#include "../../SDL.h" #include "../../SDL.h"
#include "../PageBuilder.h"
Component::Component(Page &p) Component::Component(Page &p)
: page(p) : page(p)
@ -127,7 +128,23 @@ void Component::update(float dt)
if(animationRequested_ && animationRequestedType_ != "") if(animationRequested_ && animationRequestedType_ != "")
{ {
Animation *newTweens = tweens_->getAnimation( animationRequestedType_, menuIndex_ ); Animation *newTweens;
// Check if this component is part of an active scrolling list
if(menuIndex_ >= MENU_INDEX_HIGH)
{
// Check for animation at index i
newTweens = tweens_->getAnimation( animationRequestedType_, MENU_INDEX_HIGH );
if(!(newTweens && newTweens->size() > 0))
{
// Check for animation at the current menuIndex
newTweens = tweens_->getAnimation( animationRequestedType_, menuIndex_ - MENU_INDEX_HIGH);
}
}
else
{
// Check for animation at the current menuIndex
newTweens = tweens_->getAnimation( animationRequestedType_, menuIndex_ );
}
if (newTweens && newTweens->size() > 0) if (newTweens && newTweens->size() > 0)
{ {
animationType_ = animationRequestedType_; animationType_ = animationRequestedType_;

View File

@ -72,6 +72,7 @@ ScrollingList::ScrollingList(Configuration &c,
ScrollingList::ScrollingList(const ScrollingList &copy) ScrollingList::ScrollingList(const ScrollingList &copy)
: Component(copy) : Component(copy)
, horizontalScroll(copy.horizontalScroll) , horizontalScroll(copy.horizontalScroll)
, layoutMode_(copy.layoutMode_)
, spriteList_(NULL) , spriteList_(NULL)
, itemIndex_(0) , itemIndex_(0)
, componentIndex_(0) , componentIndex_(0)

View File

@ -23,6 +23,7 @@
#include "Component/ScrollingList.h" #include "Component/ScrollingList.h"
#include "../Sound/Sound.h" #include "../Sound/Sound.h"
#include "ComponentItemBindingBuilder.h" #include "ComponentItemBindingBuilder.h"
#include "PageBuilder.h"
#include <algorithm> #include <algorithm>
#include <sstream> #include <sstream>
@ -358,9 +359,18 @@ void Page::highlightEnter()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "highlightEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerHighlightEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "highlightEnter", menuDepth_ - 1 ); menu->triggerEvent( "highlightEnter", menuDepth_ - 1 );
menu->triggerHighlightEnterEvent( menuDepth_ - 1 ); menu->triggerHighlightEnterEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -377,9 +387,18 @@ void Page::highlightExit()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "highlightExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerHighlightExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "highlightExit", menuDepth_ - 1 ); menu->triggerEvent( "highlightExit", menuDepth_ - 1 );
menu->triggerHighlightExitEvent( menuDepth_ - 1 ); menu->triggerHighlightExitEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -471,7 +490,7 @@ bool Page::pushCollection(CollectionInfo *collection)
{ {
// grow the menu as needed // grow the menu as needed
if(menus_.size() >= menuDepth_ && activeMenu_) if(menus_.size() <= menuDepth_ && activeMenu_)
{ {
activeMenu_ = new ScrollingList(*activeMenu_); activeMenu_ = new ScrollingList(*activeMenu_);
pushMenu(activeMenu_); pushMenu(activeMenu_);
@ -541,9 +560,18 @@ void Page::enterMenu()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "menuEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerMenuEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "menuEnter", menuDepth_ - 1 ); menu->triggerEvent( "menuEnter", menuDepth_ - 1 );
menu->triggerMenuEnterEvent( menuDepth_ - 1 ); menu->triggerMenuEnterEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -560,9 +588,18 @@ void Page::exitMenu()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
menu->triggerEvent( "menuExit" ); if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "menuExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerMenuExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "menuExit", menuDepth_ - 1 );
menu->triggerMenuExitEvent( menuDepth_ - 1 ); menu->triggerMenuExitEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -579,9 +616,18 @@ void Page::enterGame()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "gameEnter", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerGameEnterEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "gameEnter", menuDepth_ - 1 ); menu->triggerEvent( "gameEnter", menuDepth_ - 1 );
menu->triggerGameEnterEvent( menuDepth_ - 1 ); menu->triggerGameEnterEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {
@ -598,9 +644,18 @@ void Page::exitGame()
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
{ {
ScrollingList *menu = *it; ScrollingList *menu = *it;
menu->triggerEvent( "gameExit" ); if(menus_[menuDepth_-1] == menu)
{
// Also trigger animations for index i for active menu
menu->triggerEvent( "gameExit", MENU_INDEX_HIGH + menuDepth_ - 1 );
menu->triggerGameExitEvent( MENU_INDEX_HIGH + menuDepth_ - 1 );
}
else
{
menu->triggerEvent( "gameExit", menuDepth_ - 1 );
menu->triggerGameExitEvent( menuDepth_ - 1 ); menu->triggerGameExitEvent( menuDepth_ - 1 );
} }
}
for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it) for(std::vector<Component *>::iterator it = LayerComponents.begin(); it != LayerComponents.end(); ++it)
{ {

View File

@ -740,12 +740,73 @@ void PageBuilder::buildTweenSet(AnimationEvents *tweens, xml_node<> *componentXm
for(componentXml = componentXml->first_node(tagName.c_str()); componentXml; componentXml = componentXml->next_sibling(tagName.c_str())) for(componentXml = componentXml->first_node(tagName.c_str()); componentXml; componentXml = componentXml->next_sibling(tagName.c_str()))
{ {
xml_attribute<> *indexXml = componentXml->first_attribute("menuIndex"); xml_attribute<> *indexXml = componentXml->first_attribute("menuIndex");
int index = (indexXml) ? Utils::convertInt(indexXml->value()) : -1;
if(indexXml)
{
std::string indexs = indexXml->value();
if(indexs[0] == '!')
{
indexs.erase(0);
int index = Utils::convertInt(indexXml->value());
for(int i = 0; i < MENU_INDEX_HIGH-1; i++)
{
if(i != index)
{
Animation *animation = new Animation();
getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, i, animation);
}
}
}
else if(indexs[0] == '<')
{
indexs.erase(0);
int index = Utils::convertInt(indexXml->value());
for(int i = 0; i < MENU_INDEX_HIGH-1; i++)
{
if(i < index)
{
Animation *animation = new Animation();
getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, i, animation);
}
}
}
else if(indexs[0] == '>')
{
indexs.erase(0);
int index = Utils::convertInt(indexXml->value());
for(int i = 0; i < MENU_INDEX_HIGH-1; i++)
{
if(i > index)
{
Animation *animation = new Animation();
getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, i, animation);
}
}
}
else if(indexs[0] == 'i')
{
Animation *animation = new Animation();
getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, MENU_INDEX_HIGH, animation);
}
else
{
int index = Utils::convertInt(indexXml->value());
Animation *animation = new Animation(); Animation *animation = new Animation();
getTweenSet(componentXml, animation); getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, index, animation); tweens->setAnimation(tweenName, index, animation);
} }
}
else
{
Animation *animation = new Animation();
getTweenSet(componentXml, animation);
tweens->setAnimation(tweenName, -1, animation);
}
}
} }

View File

@ -22,6 +22,8 @@
#include <rapidxml.hpp> #include <rapidxml.hpp>
#include <vector> #include <vector>
static const int MENU_INDEX_HIGH = 16;
class ScrollingList; class ScrollingList;
class Page; class Page;
class ViewInfo; class ViewInfo;

View File

@ -20,7 +20,7 @@
std::string retrofe_version_major = "0"; std::string retrofe_version_major = "0";
std::string retrofe_version_minor = "8"; std::string retrofe_version_minor = "8";
std::string retrofe_version_build = "5"; std::string retrofe_version_build = "6";
std::string Version::getString() std::string Version::getString()