Commit f7fae477 authored by Gerhard Stein's avatar Gerhard Stein

Player selection code updated

parent 66a7a287
......@@ -55,6 +55,9 @@ public:
void drawDialogBox(SDL_Surface *DialogSurface, int x1, int y1, int w, int h, Uint32 colour = 0xFFFFFF);
int getNumSprites(const int var);
std::vector< std::vector<GsSprite> > &spriteVecVec()
{ return mSprite; }
GsTilemap &getTileMap(size_t tilemap);
std::vector<GsTilemap> &getTileMaps();
GsBitmap &getBitmapFromId(Uint16 slot);
......
......@@ -58,6 +58,11 @@ public:
setupButtonSurface(" " + mText);
}
std::shared_ptr<CEvent> &event()
{
return mEvent;
}
std::string getText()
{ return mText; }
......
......@@ -109,10 +109,11 @@ private:
std::map<std::string, int> mIdMap;
int mCurId = 0;
int mCurIdx = 0;
ComboSelection *mpComboSelection = nullptr;
GameButton *mpGameButton = nullptr;
};
......
#include <base/CInput.h>
#include "SelectionMenu.h"
#include "graphics/GsGraphics.h"
CPlayerSpriteVarSelection::
CPlayerSpriteVarSelection(const GsControl::Style style) :
GameMenu( GsRect<float>(0.25f, 0.2f, 0.5f, 0.5f), style )
{
mpMenuDialog->addControl( new GameButton( "Start",
new SelectPlayerSpriteVarEvent(mCurId),
style ) );
for( auto &SpriteVec : gGraphics.spriteVecVec() )
{
std::shared_ptr<GsBitmap> playerBmp(
new GsBitmap(SpriteVec[6].exportBitmap()));
mpPlayerBmpVec.push_back(playerBmp);
}
if(!mpPlayerBmpVec.empty())
{
mBmpBox = new CGUIBitmap(mpPlayerBmpVec[0]);
mpMenuDialog->addControl( mBmpBox,
GsRect<float>(0.07f, 0.41f,
0.15f, 0.2f));
}
mpGameButton = new GameButton( "Start",
new SelectPlayerSpriteVarEvent(mCurIdx),
style);
mpMenuDialog->addControl( mpGameButton,
GsRect<float>(0.07f, 0.71f,
0.1f, 0.8f));
}
void
CPlayerSpriteVarSelection::
ponder(const float deltaT)
{
// If IC_BACK is invoked, make the menu controller close the controller
if( gInput.getPressedCommand(IC_BACK) )
{
gEventManager.add( new CloseMenuEvent() );
return;
}
bool update = false;
if( gInput.getPressedCommand(IC_LEFT) )
{
update = true;
mCurIdx--;
}
else if( gInput.getPressedCommand(IC_RIGHT) )
{
update = true;
mCurIdx++;
}
else if( gInput.getPressedCommand(IC_JUMP) ||
gInput.getPressedCommand(IC_STATUS))
{
gEventManager.add( new SelectPlayerSpriteVarEvent(mCurIdx) );
return;
}
mpMenuDialog->processLogic();
if( mCurIdx < 0 )
{
mCurIdx = 0;
return;
}
if( mCurIdx >= int(mpPlayerBmpVec.size()) )
{
mCurIdx = mpPlayerBmpVec.size()-1;
return;
}
if(update)
{
mBmpBox->setBitmapPtr(mpPlayerBmpVec[mCurIdx]);
}
// TODO: Code for Player selection here!
GameMenu::ponder(deltaT);
// Change data in the event of the game button
auto event = mpGameButton->event();
auto spsv = std::dynamic_pointer_cast<SelectPlayerSpriteVarEvent>(event);
spsv->mSpecialIdx = mCurIdx;
}
......@@ -61,10 +61,10 @@ struct StartNewGameEvent : CEvent
// Invoked when New Game -> 1 Player-> Sprite Number
struct SelectPlayerSpriteVarEvent : CEvent
{
SelectPlayerSpriteVarEvent(const int sprite) :
mSprite(sprite) {}
SelectPlayerSpriteVarEvent(const int special) :
mSpecialIdx(special) {}
const int mSprite = 0;
int mSpecialIdx = 0;
};
......
......@@ -420,7 +420,7 @@ void GalaxyEngine::pumpEvent(const CEvent *evPtr)
else if( const SelectPlayerSpriteVarEvent* pStart =
dynamic_cast<const SelectPlayerSpriteVarEvent*>(evPtr) )
{
mSpriteVars.assign(1, pStart->mSprite);
mSpriteVars.assign(1, pStart->mSpecialIdx);
gEventManager.add( new OpenMenuEvent(
new CDifficultySelection(GsControl::Style::GALAXY)) );
return;
......
......@@ -710,7 +710,7 @@ bool CEGAGraphicsGalaxy::begin()
if(!File)
{
gLogging.textOut(FONTCOLORS::RED,"Error the file \"" + filename + "\" is missing or can't be read!");
gLogging.textOut(FONTCOLORS::RED, "Error the file \"" + filename + "\" is missing or can't be read!");
return false;
}
......@@ -719,7 +719,7 @@ bool CEGAGraphicsGalaxy::begin()
egagraphlen = File.tellg();
if(egagraphlen == 0)
{
gLogging.textOut(FONTCOLORS::RED,"Error the file \"" + filename + "\" is empty!");
gLogging.textOut(FONTCOLORS::RED, "Error the file \"" + filename + "\" is empty!");
return false;
}
egagraphlen--;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment