Functionality seems to have been restored at last.

This commit is contained in:
Aloshi 2013-04-09 13:13:47 -05:00
parent 4747d70e1f
commit 05c258f515
13 changed files with 217 additions and 45 deletions

View file

@ -2,7 +2,7 @@ CXX=g++
CXXFLAGS=-Wall -g -O2
LDFLAGS=
SRC_SOURCES=AudioManager.cpp Window.cpp InputConfig.cpp Log.cpp FolderData.cpp Font.cpp GameData.cpp Gui.cpp InputManager.cpp main.cpp MathExp.cpp Renderer_draw_gl.cpp Renderer_init.cpp Sound.cpp SystemData.cpp XMLReader.cpp components/GuiAnimation.cpp components/GuiBox.cpp components/GuiFastSelect.cpp components/GuiGameList.cpp components/GuiImage.cpp components/GuiInputConfig.cpp components/GuiMenu.cpp components/GuiTheme.cpp pugiXML/pugixml.cpp
SRC_SOURCES=AudioManager.cpp Window.cpp InputConfig.cpp Log.cpp FolderData.cpp Font.cpp GameData.cpp Gui.cpp InputManager.cpp main.cpp MathExp.cpp Renderer_draw_gl.cpp Renderer_init.cpp Sound.cpp SystemData.cpp XMLReader.cpp components/GuiAnimation.cpp components/GuiBox.cpp components/GuiFastSelect.cpp components/GuiGameList.cpp components/GuiImage.cpp components/GuiMenu.cpp components/GuiTheme.cpp components/GuiInputConfig.cpp components/GuiDetectDevice.cpp pugiXML/pugixml.cpp
SOURCES=$(addprefix src/,$(SRC_SOURCES))
OBJECTS=$(SOURCES:.cpp=.o)
DEPS=$(SOURCES:.cpp=.d)

View file

@ -4,6 +4,7 @@
Window::Window()
{
mInputManager = new InputManager(this);
mInputManager->init();
}
Window::~Window()

View file

@ -0,0 +1,99 @@
#include "GuiDetectDevice.h"
#include "../Window.h"
#include "../Renderer.h"
#include "../Font.h"
#include "GuiInputConfig.h"
#include <iostream>
#include <string>
#include <sstream>
GuiDetectDevice::GuiDetectDevice(Window* window) : Gui(window)
{
//clear any player information from the InputManager
for(int i = 0; i < mWindow->getInputManager()->getNumPlayers(); i++)
{
InputConfig* cfg = mWindow->getInputManager()->getInputConfigByPlayer(i);
cfg->setPlayerNum(-1);
cfg->clear();
}
mWindow->getInputManager()->setNumPlayers(0);
mCurrentPlayer = 0;
mHoldingFinish = false;
}
void GuiDetectDevice::input(InputConfig* config, Input input)
{
if((input.type == TYPE_BUTTON || input.type == TYPE_KEY))
{
if(config->getPlayerNum() != -1)
{
if(config->getPlayerNum() == 0)
{
if(input.value)
{
mFinishTimer = 0;
mHoldingFinish = true;
}else{
mHoldingFinish = false;
}
}
return;
}
if(!input.value)
return;
config->setPlayerNum(mCurrentPlayer);
mWindow->getInputManager()->setNumPlayers(mWindow->getInputManager()->getNumPlayers() + 1); //inc total number of players
mCurrentPlayer++;
//mapped everything we possibly can?
if(mCurrentPlayer >= mWindow->getInputManager()->getNumJoysticks() + 1) //+1 for keyboard
{
done();
}
}
}
void GuiDetectDevice::done()
{
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(0)));
delete this;
}
void GuiDetectDevice::update(int deltaTime)
{
if(mHoldingFinish)
{
mFinishTimer += deltaTime;
if(mFinishTimer > 1000)
done();
}
}
void GuiDetectDevice::render()
{
Font* font = Renderer::getDefaultFont(Renderer::MEDIUM);
std::string playerString;
std::stringstream stream;
stream << (mCurrentPlayer + 1);
stream >> playerString;
Renderer::drawCenteredText("Press a button on the device for", 0, Renderer::getScreenHeight() / 3, 0x000000FF, font);
Renderer::drawCenteredText("PLAYER " + playerString, 0, (int)(Renderer::getScreenHeight()*1.5) / 3, 0x333333FF, font);
if(mWindow->getInputManager()->getNumPlayers() > 0)
{
Renderer::drawCenteredText("(P1 - hold a button to finish)", 0, (int)(Renderer::getScreenHeight()*2) / 3, (mHoldingFinish ? 0x0000FFFF : 0x000066FF), font);
}
if(mWindow->getInputManager()->getNumJoysticks() == 0)
{
Renderer::drawCenteredText("No joysticks detected!", 0, Renderer::getScreenHeight()-(font->getHeight()*2)-10, 0xFF0000FF, font);
}
Renderer::drawCenteredText("Press F4 to quit.", 0, Renderer::getScreenHeight()-font->getHeight() - 2 , 0x000000FF, font);
}

View file

@ -0,0 +1,23 @@
#ifndef _GUIDETECTDEVICE_H_
#define _GUIDETECTDEVICE_H_
#include "../Gui.h"
class GuiDetectDevice : public Gui
{
public:
GuiDetectDevice(Window* window);
void input(InputConfig* config, Input input);
void update(int deltaTime);
void render();
private:
void done();
bool mHoldingFinish;
int mFinishTimer;
int mCurrentPlayer;
};
#endif

View file

@ -10,7 +10,7 @@
class GuiGameList;
class GuiFastSelect : Gui
class GuiFastSelect : public Gui
{
public:
GuiFastSelect(Window* window, GuiGameList* parent, GuiList<FileData*>* list, char startLetter, GuiBoxData data, int textcolor, Sound* scrollsound, Font* font);

View file

@ -105,6 +105,8 @@ void GuiGameList::render()
void GuiGameList::input(InputConfig* config, Input input)
{
mList->input(config, input);
if(config->isMappedTo("a", input) && mFolder->getFileCount() > 0 && input.value != 0)
{
//play select sound
@ -154,13 +156,13 @@ void GuiGameList::input(InputConfig* config, Input input)
//open the "start menu"
if(config->isMappedTo("menu", input) && input.value != 0)
{
new GuiMenu(mWindow, this);
mWindow->pushGui(new GuiMenu(mWindow, this));
}
//open the fast select menu
if(config->isMappedTo("select", input) && input.value != 0)
{
new GuiFastSelect(mWindow, this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getColor("fastSelect"), mTheme->getSound("menuScroll"), mTheme->getFastSelectFont());
mWindow->pushGui(new GuiFastSelect(mWindow, this, mList, mList->getSelectedObject()->getName()[0], mTheme->getBoxData(), mTheme->getColor("fastSelect"), mTheme->getSound("menuScroll"), mTheme->getFastSelectFont()));
}
if(mDetailed)
@ -304,3 +306,9 @@ GuiGameList* GuiGameList::create(Window* window)
window->pushGui(list);
return list;
}
void GuiGameList::update(int deltaTime)
{
mImageAnimation->update(deltaTime);
mList->update(deltaTime);
}

View file

@ -22,8 +22,9 @@ public:
void setSystemId(int id);
void render();
void input(InputConfig* config, Input input);
void update(int deltaTime);
void render();
void onInit();
void onDeinit();

View file

@ -17,6 +17,7 @@ GuiImage::GuiImage(Window* window, int offsetX, int offsetY, std::string path, u
//default origin is the center of image
mOriginX = 0.5;
mOriginY = 0.5;
mOpacity = 255;
mWidth = mDrawWidth = 0;
mHeight = mDrawHeight = 0;

View file

@ -1,27 +1,80 @@
#include "GuiInputConfig.h"
#include "GuiGameList.h"
#include "../Window.h"
#include "../Renderer.h"
#include <iostream>
#include <fstream>
#include "../Log.h"
#include "../Font.h"
#include "GuiGameList.h"
extern bool DEBUG; //defined in main.cpp
static int inputCount = 8;
static std::string inputName[8] = { "Up", "Down", "Left", "Right", "A", "B", "Menu", "Select"};
std::string GuiInputConfig::sInputs[] = { "UP", "DOWN", "LEFT", "RIGHT", "A", "B", "START", "SELECT", "PAGEUP", "PAGEDOWN" }; //must be same order as InputManager::InputButton enum; only add to the end to preserve backwards compatibility
int GuiInputConfig::sInputCount = 10;
GuiInputConfig::GuiInputConfig(Window* window) : Gui(window)
GuiInputConfig::GuiInputConfig(Window* window, InputConfig* target) : Gui(window), mTargetConfig(target)
{
mCurInputId = 0;
}
GuiInputConfig::~GuiInputConfig()
void GuiInputConfig::update(int deltaTime)
{
}
void GuiInputConfig::render()
{
Renderer::drawCenteredText("IN DEVELOPMENT", 0, 2, 0x000000FF, Renderer::getDefaultFont(Renderer::MEDIUM));
}
void GuiInputConfig::input(InputConfig* config, Input input)
{
if(config != mTargetConfig || input.value == 0)
return;
if(mCurInputId >= inputCount)
{
//done
if(input.type == TYPE_BUTTON || input.type == TYPE_KEY)
{
if(mTargetConfig->getPlayerNum() < mWindow->getInputManager()->getNumPlayers() - 1)
{
mWindow->pushGui(new GuiInputConfig(mWindow, mWindow->getInputManager()->getInputConfigByPlayer(mTargetConfig->getPlayerNum() + 1)));
}else{
GuiGameList::create(mWindow);
}
delete this;
}
}else{
if(config->getMappedTo(input).size() > 0)
{
mErrorMsg = "Already mapped!";
return;
}
input.configured = true;
std::cout << "[" << input.string() << "] -> " << inputName[mCurInputId] << "\n";
config->mapInput(inputName[mCurInputId], input);
mCurInputId++;
mErrorMsg = "";
}
}
void GuiInputConfig::render()
{
Font* font = Renderer::getDefaultFont(Renderer::MEDIUM);
std::stringstream stream;
stream << "PLAYER " << mTargetConfig->getPlayerNum() + 1 << ", press...";
Renderer::drawText(stream.str(), 10, 10, 0x000000FF, font);
int y = 14 + font->getHeight();
for(int i = 0; i < mCurInputId; i++)
{
Renderer::drawText(inputName[i], 10, y, 0x00CC00FF, font);
y += font->getHeight() + 5;
}
if(mCurInputId >= inputCount)
{
Renderer::drawCenteredText("Basic config done!", 0, (int)(Renderer::getScreenHeight() * 0.6), 0x00CC00FF, font);
Renderer::drawCenteredText("Press any button to continue.", 0, (int)(Renderer::getScreenHeight() * 0.6) + font->getHeight() + 4, 0x000000FF, font);
}else{
Renderer::drawText(inputName[mCurInputId], 10, y, 0x000000FF, font);
}
if(!mErrorMsg.empty())
Renderer::drawCenteredText(mErrorMsg, 0, Renderer::getScreenHeight() - font->getHeight() - 10, 0xFF0000FF, font);
}

View file

@ -2,22 +2,21 @@
#define _GUIINPUTCONFIG_H_
#include "../Gui.h"
#include <map>
#include <SDL/SDL.h>
#include <string>
class GuiInputConfig : public Gui
{
public:
GuiInputConfig(Window* window);
~GuiInputConfig();
GuiInputConfig(Window* window, InputConfig* target);
void render();
void input(InputConfig* config, Input input);
void update(int deltaTime);
void render();
private:
bool mDone;
int mInputNum;
static std::string sInputs[];
static int sInputCount;
std::string mErrorMsg;
InputConfig* mTargetConfig;
int mCurInputId;
};
#endif

View file

@ -24,6 +24,8 @@ GuiMenu::~GuiMenu()
void GuiMenu::input(InputConfig* config, Input input)
{
mList->input(config, input);
if(config->isMappedTo("menu", input) && input.value != 0)
{
delete this;

View file

@ -257,7 +257,7 @@ void GuiTheme::readXML(std::string path)
LOG(LogInfo) << "Theme loading complete.";
}
//recursively creates components (with proper parenting)
//recursively creates components
void GuiTheme::createComponentChildren(pugi::xml_node node, Gui* parent)
{
for(pugi::xml_node data = node.child("component"); data; data = data.next_sibling("component"))

View file

@ -5,7 +5,7 @@
#include "components/GuiGameList.h"
#include "SystemData.h"
#include <boost/filesystem.hpp>
#include "components/GuiInputConfig.h"
#include "components/GuiDetectDevice.h"
#include <SDL.h>
#include "AudioManager.h"
#include "platform.h"
@ -135,26 +135,11 @@ int main(int argc, char* argv[])
//choose which GUI to open depending on Input configuration
if(fs::exists(InputManager::getConfigPath()))
{
LOG(LogDebug) << "Found input config in " << InputManager::getConfigPath() << "\n";
//an input config already exists - load it and proceed to the gamelist as usual.
window.getInputManager()->loadConfig();
GuiGameList::create(&window);
}else{
if(DEBUG)
std::cout << "SDL_NumJoysticks() reports " << SDL_NumJoysticks() << " present.\n";
//if no input.cfg is present, but a joystick is connected, launch the input config GUI
if(SDL_NumJoysticks() > 0)
{
LOG(LogDebug) << " at least one joystick detected, launching config GUI...\n";
window.pushGui(new GuiInputConfig(&window));
}else{
LOG(LogDebug) << " no joystick detected, ignoring...\n";
GuiGameList::create(&window);
}
window.pushGui(new GuiDetectDevice(&window));
}
}
}