Commit 09624535 authored by Gerhard Stein's avatar Gerhard Stein

CGameLauncher now can be controlled also via Keyboard and/or Gamepad

parent 1308e3df
......@@ -37,7 +37,7 @@ CGameLauncher::CGameLauncher()
bool CGameLauncher::init()
{
bool gamedetected = false;
// Scan for games...
m_DirList.clear();
m_Entries.clear();
......@@ -60,24 +60,28 @@ bool CGameLauncher::init()
gamedetected = true;
g_pResourceLoader->setPermilage(900);
if(!gamedetected)
return false;
// Save any custom labels
putLabels();
CGUITextSelectionList *List = new CGUITextSelectionList();
CGUITextSelectionList *list = new CGUITextSelectionList();
std::vector<GameEntry>::iterator it = m_Entries.begin();
for( ; it != m_Entries.end() ; it++ )
{
List->addText(it->name);
list->addText(it->name);
}
list->setConfirmButtonEvent(new GMStart(list->mSelection));
mpLauncherDialog->addControl(new CGUIText("Pick a Game"), CRect<float>(0.0f, 0.0f, 1.0f, 0.05f));
mpLauncherDialog->addControl(List, CRect<float>(0.0f, 0.05f, 1.0f, 0.85f));
mpLauncherDialog->addControl(list, CRect<float>(0.0f, 0.05f, 1.0f, 0.85f));
mpLauncherDialog->addControl(new CGUIButton( "Exit", new GMQuit() ),
CRect<float>(0.1f, 0.915f, 0.2f, 0.07f) );
mpLauncherDialog->addControl(new CGUIButton( "Ok", new GMStart(List->mSelection) ),
mpLauncherDialog->addControl(new CGUIButton( "Ok", new GMStart(list->mSelection) ),
CRect<float>(0.7f, 0.915f, 0.2f, 0.07f) );
g_pResourceLoader->setPermilage(1000);
......@@ -211,7 +215,18 @@ void CGameLauncher::process()
return;
}
mpLauncherDialog->processLogic();
// Command (Keyboard/Joystick) are handled here
for( int cmd = IC_LEFT ; cmd < MAX_COMMANDS ; cmd++ )
{
if( g_pInput->getPressedCommand(cmd) )
{
mpLauncherDialog->sendEvent(new CommandEvent( static_cast<InputCommands>(cmd) ));
break;
}
}
mpLauncherDialog->processLogic();
if( GMStart *Starter = g_pBehaviorEngine->m_EventList.occurredEvent<GMStart>() )
{
......
......@@ -6,6 +6,7 @@
*/
#include "CGUITextSelectionList.h"
#include "common/CBehaviorEngine.h"
#include "sdl/CVideoDriver.h"
#include "graphics/CGfxEngine.h"
#include "sdl/input/InputEvents.h"
......@@ -13,6 +14,35 @@
const float TEXT_HEIGHT = 10.0f;
void CGUITextSelectionList::setConfirmButtonEvent(const SmartPointer<CEvent> ev)
{
mConfirmEvent = ev;
}
void CGUITextSelectionList::sendEvent(const InputCommands command)
{
if(command == IC_UP)
{
mSelection--;
if(mSelection < 0)
mSelection = mItemList.size()-1;
}
else if(command == IC_DOWN)
{
mSelection++;
if(mSelection >= static_cast<int>(mItemList.size()) )
mSelection = 0;
}
else if(command == IC_STATUS || command == IC_JUMP)
{
if(!mConfirmEvent.empty())
g_pBehaviorEngine->m_EventList.add(mConfirmEvent);
}
}
void CGUITextSelectionList::addText(const std::string &text)
{
mItemList.push_back(text);
......@@ -22,7 +52,7 @@ void CGUITextSelectionList::processLogic()
{
// Here we check if the mouse-cursor/Touch entry clicked on something!!
const float bw = g_pVideoDriver->getGameResolution().w;
//const float bw = g_pVideoDriver->getGameResolution().w;
const float bh = g_pVideoDriver->getGameResolution().h;
const float fx = mRect.x;
......
......@@ -21,6 +21,9 @@ public:
mHoverSelection(0),
mSelection(0) {}
void setConfirmButtonEvent(const SmartPointer<CEvent> ev);
void sendEvent(const InputCommands command);
void addText(const std::string &text);
void processLogic();
void processRender(const CRect<float> &RectDispCoordFloat);
......@@ -29,6 +32,8 @@ public:
int mHoverSelection;
int mSelection;
SmartPointer<CEvent> mConfirmEvent;
};
#endif /* CGUITEXTSELECTIONLIST_H_ */
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