Refactored kart selection screen code to work towards multiplayer
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3700 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
@@ -2,12 +2,9 @@
|
||||
|
||||
<label width="100%" height="25" text="Choose a Kart (more players can join by pressing 'fire' now)" align="center" text_align="center" />
|
||||
|
||||
|
||||
<label width="100%" height="25" text="(P1) Keyboard 1" align="center" text_align="center" />
|
||||
<spinner id="player" width="40%" height="40" min_value="0" max_value="8" align="center"/>
|
||||
|
||||
<model id="modelview" width="40%" proportion="3" align="center"/>
|
||||
<label id="currkartname" width="100%" height="25" text="Tux" align="center" text_align="center" />
|
||||
<div id="playerskarts" width="100%" proportion="4">
|
||||
<!-- Contents is added programatically -->
|
||||
</div>
|
||||
|
||||
<spacer height="15" width="25"/>
|
||||
|
||||
|
||||
@@ -77,6 +77,8 @@ supertuxkart_SOURCES = \
|
||||
gui/engine.hpp \
|
||||
gui/font.cpp \
|
||||
gui/font.hpp \
|
||||
gui/kart_selection.cpp \
|
||||
gui/kart_selection.hpp \
|
||||
gui/modaldialog.cpp \
|
||||
gui/modaldialog.hpp \
|
||||
gui/my_button.cpp \
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <string>
|
||||
#include "config/user_config.hpp"
|
||||
|
||||
class InputDevice;
|
||||
|
||||
/**
|
||||
* class for managing player name and control configuration
|
||||
*/
|
||||
@@ -37,10 +39,19 @@ private:
|
||||
|
||||
int m_last_kart_id;
|
||||
|
||||
InputDevice* m_device;
|
||||
|
||||
public:
|
||||
|
||||
Player(const char* name) : m_player_group("Player", "Represents one human player"),
|
||||
m_name(name, "name", &m_player_group),
|
||||
m_last_kart_id(-1) {}
|
||||
m_last_kart_id(-1)
|
||||
{
|
||||
m_device = NULL;
|
||||
}
|
||||
|
||||
InputDevice* getDevice() { return m_device; }
|
||||
void setDevice(InputDevice* device) { m_device = device; }
|
||||
|
||||
void setName(const std::string &name_){m_name = name_;}
|
||||
|
||||
|
||||
@@ -335,9 +335,9 @@ void IrrDriver::renderToTexture(ptr_vector<scene::IMesh, REF>& mesh, std::vector
|
||||
|
||||
ICameraSceneNode* camera = m_scene_manager->addCameraSceneNode();
|
||||
|
||||
camera->setPosition( core::vector3df(0.0, 25.0f, 70.0f) );
|
||||
camera->setPosition( core::vector3df(0.0, 30.0f, 70.0f) );
|
||||
camera->setUpVector( core::vector3df(0.0, -1.0, 0.0) );
|
||||
camera->setTarget( core::vector3df(0, 0 ,0) );
|
||||
camera->setTarget( core::vector3df(0, 10, 0.0f) );
|
||||
camera->updateAbsolutePosition();
|
||||
|
||||
m_device->getVideoDriver()->setRenderTarget(target);
|
||||
|
||||
225
src/gui/kart_selection.cpp
Normal file
225
src/gui/kart_selection.cpp
Normal file
@@ -0,0 +1,225 @@
|
||||
// $Id$
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2006
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "config/player.hpp"
|
||||
#include "config/user_config.hpp"
|
||||
#include "kart_selection.hpp"
|
||||
#include "gui/widget.hpp"
|
||||
#include "gui/engine.hpp"
|
||||
#include "gui/screen.hpp"
|
||||
#include "gui/state_manager.hpp"
|
||||
#include "input/input_device.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
InputDevice* player_1_device = NULL;
|
||||
|
||||
using namespace GUIEngine;
|
||||
|
||||
namespace StateManager
|
||||
{
|
||||
class PlayerKart : public Widget
|
||||
{
|
||||
public:
|
||||
LabelWidget* playerID;
|
||||
SpinnerWidget* playerName;
|
||||
ModelViewWidget* modelView;
|
||||
LabelWidget* kartName;
|
||||
|
||||
PlayerKart(Widget* area) : Widget()
|
||||
{
|
||||
this->m_properties[PROP_ID] = "@p1";
|
||||
this->x = area->x;
|
||||
this->y = area->y;
|
||||
this->w = area->w;
|
||||
this->h = area->h;
|
||||
|
||||
playerID = new LabelWidget();
|
||||
playerID->m_properties[PROP_TEXT] = _("Player 1 (keyboard)");
|
||||
playerID->m_properties[PROP_TEXT_ALIGN] = "center";
|
||||
playerID->m_properties[PROP_ID] = "@p1_label";
|
||||
playerID->x = area->x;
|
||||
playerID->y = area->y;
|
||||
playerID->w = area->w;
|
||||
playerID->h = 25;
|
||||
//playerID->setParent(this);
|
||||
m_children.push_back(playerID);
|
||||
|
||||
const int playerAmount = UserConfigParams::m_player.size();
|
||||
const int spinnerWidth = std::min(400, area->w/3 /* FIXME : replace by number of players */);
|
||||
playerName = new SpinnerWidget();
|
||||
playerName->x = area->x + area->w/2 - spinnerWidth/2;
|
||||
playerName->y = area->y + 25;
|
||||
playerName->w = spinnerWidth;
|
||||
playerName->h = 40;
|
||||
|
||||
playerName->m_properties[PROP_MIN_VALUE] = "0";
|
||||
playerName->m_properties[PROP_MAX_VALUE] = (playerAmount-1);
|
||||
playerName->m_properties[PROP_ID] = "@p1_spinner";
|
||||
//playerName->setParent(this);
|
||||
m_children.push_back(playerName);
|
||||
|
||||
|
||||
modelView = new ModelViewWidget();
|
||||
const int modelY = area->y + 65;
|
||||
const int modelMaxHeight = area->h - 25 - 65;
|
||||
const int modelMaxWidth = area->w;
|
||||
const int bestSize = std::min(modelMaxWidth, modelMaxHeight);
|
||||
|
||||
std::cout << "bestSize=" << bestSize << std::endl;
|
||||
|
||||
modelView->x = area->x + area->w/2 - bestSize*1.2/2;
|
||||
modelView->y = modelY + modelMaxHeight/2 - bestSize/2;
|
||||
modelView->w = bestSize*1.2; // FIXME : for some reason, it looks better this way, though full square should be ok
|
||||
modelView->h = bestSize;
|
||||
modelView->m_properties[PROP_ID] = "@p1_model";
|
||||
//modelView->setParent(this);
|
||||
m_children.push_back(modelView);
|
||||
|
||||
|
||||
kartName = new LabelWidget();
|
||||
kartName->m_properties[PROP_TEXT] = _("Tux");
|
||||
kartName->m_properties[PROP_TEXT_ALIGN] = "center";
|
||||
kartName->m_properties[PROP_ID] = "@p1_kartname";
|
||||
kartName->x = area->x;
|
||||
kartName->y = area->y + area->h - 25;
|
||||
kartName->w = area->w;
|
||||
kartName->h = 25;
|
||||
//kartName->setParent(this);
|
||||
m_children.push_back(kartName);
|
||||
}
|
||||
virtual void add()
|
||||
{
|
||||
playerID->add();
|
||||
playerName->add();
|
||||
modelView->add();
|
||||
kartName->add();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// TODO : have one per player
|
||||
PlayerKart* playerKart1 = NULL;
|
||||
|
||||
class KartHoverListener : public RibbonGridHoverListener
|
||||
{
|
||||
public:
|
||||
void onSelectionChanged(RibbonGridWidget* theWidget, const std::string& selectionID)
|
||||
{
|
||||
//std::cout << "hovered " << selectionID.c_str() << std::endl;
|
||||
|
||||
if(selectionID.size() == 0) return;
|
||||
|
||||
ModelViewWidget* w3 = playerKart1->modelView;
|
||||
assert( w3 != NULL );
|
||||
|
||||
const KartProperties* kart = kart_properties_manager->getKart(selectionID);
|
||||
if(kart == NULL) return;
|
||||
KartModel* kartModel = kart->getKartModel();
|
||||
|
||||
w3->clearModels();
|
||||
w3->addModel( kartModel->getModel() );
|
||||
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
w3->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
w3->update(0);
|
||||
|
||||
playerKart1->kartName->setText( kart->getName().c_str() );
|
||||
}
|
||||
};
|
||||
KartHoverListener* karthoverListener = NULL;
|
||||
|
||||
/**
|
||||
* Callback handling events from the kart selection menu
|
||||
*/
|
||||
void menuEventKarts(Widget* widget, std::string& name)
|
||||
{
|
||||
if(name == "init")
|
||||
{
|
||||
|
||||
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
if(karthoverListener == NULL)
|
||||
{
|
||||
karthoverListener = new KartHoverListener();
|
||||
w->registerHoverListener(karthoverListener);
|
||||
}
|
||||
|
||||
if(!getCurrentScreen()->m_inited)
|
||||
{
|
||||
|
||||
Widget* area = getCurrentScreen()->getWidget("playerskarts");
|
||||
|
||||
playerKart1 = new PlayerKart(area);
|
||||
getCurrentScreen()->manualAddWidget(playerKart1);
|
||||
playerKart1->add();
|
||||
|
||||
// Build kart list
|
||||
const int kart_amount = kart_properties_manager->getNumberOfKarts();
|
||||
for(int n=0; n<kart_amount; n++)
|
||||
{
|
||||
const KartProperties* prop = kart_properties_manager->getKartById(n);
|
||||
std::string icon_path = "karts/";
|
||||
icon_path += prop->getIdent() + "/" + prop->getIconFile();
|
||||
w->addItem(prop->getName().c_str(), prop->getIdent().c_str(), icon_path.c_str());
|
||||
|
||||
}
|
||||
|
||||
// Build player list
|
||||
const int playerAmount = UserConfigParams::m_player.size();
|
||||
for(int n=0; n<playerAmount; n++)
|
||||
{
|
||||
playerKart1->playerName->addLabel( UserConfigParams::m_player[n].getName() );
|
||||
}
|
||||
|
||||
// Init kart model
|
||||
KartModel* kartModel = kart_properties_manager->getKart("tux")->getKartModel();
|
||||
|
||||
playerKart1->modelView->addModel( kartModel->getModel() );
|
||||
playerKart1->modelView->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
playerKart1->modelView->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
playerKart1->modelView->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
playerKart1->modelView->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
playerKart1->modelView->update(0);
|
||||
|
||||
|
||||
getCurrentScreen()->m_inited = true;
|
||||
}
|
||||
w->updateItemDisplay();
|
||||
|
||||
|
||||
getCurrentScreen()->m_inited = true;
|
||||
} // end if init
|
||||
else if(name == "karts")
|
||||
{
|
||||
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
race_manager->setLocalKartInfo(0, w->getSelectionIDString());
|
||||
|
||||
StateManager::pushMenu("racesetup.stkgui");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
30
src/gui/kart_selection.hpp
Normal file
30
src/gui/kart_selection.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
// $Id: font.cpp 3625 2009-06-21 01:10:43Z auria $
|
||||
//
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2006
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace GUIEngine
|
||||
{
|
||||
class Widget;
|
||||
}
|
||||
|
||||
namespace StateManager
|
||||
{
|
||||
void menuEventKarts(GUIEngine::Widget* widget, std::string& name);
|
||||
}
|
||||
@@ -302,6 +302,11 @@ void Screen::elementsWereDeleted(ptr_vector<Widget>* within_vector)
|
||||
}
|
||||
}
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void Screen::manualAddWidget(Widget* w)
|
||||
{
|
||||
m_widgets.push_back(w);
|
||||
}
|
||||
|
||||
#if 0
|
||||
#pragma mark -
|
||||
|
||||
@@ -82,6 +82,8 @@ namespace GUIEngine
|
||||
void addWidgets();
|
||||
void calculateLayout();
|
||||
|
||||
void manualAddWidget(Widget* w);
|
||||
|
||||
const std::string& getName() const { return m_filename; }
|
||||
|
||||
void elementsWereDeleted(ptr_vector<Widget>* within_vector = NULL);
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "gui/credits.hpp"
|
||||
#include "gui/engine.hpp"
|
||||
#include "gui/kart_selection.hpp"
|
||||
#include "gui/modaldialog.hpp"
|
||||
#include "gui/options_screen.hpp"
|
||||
#include "gui/screen.hpp"
|
||||
@@ -34,8 +35,6 @@
|
||||
#include "input/device_manager.hpp"
|
||||
#include "input/input_manager.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "karts/kart.hpp"
|
||||
#include "karts/kart_properties_manager.hpp"
|
||||
#include "network/network_manager.hpp"
|
||||
#include "race/race_manager.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@@ -90,107 +89,6 @@ namespace StateManager
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
class KartHoverListener : public RibbonGridHoverListener
|
||||
{
|
||||
public:
|
||||
void onSelectionChanged(RibbonGridWidget* theWidget, const std::string& selectionID)
|
||||
{
|
||||
//std::cout << "hovered " << selectionID.c_str() << std::endl;
|
||||
|
||||
if(selectionID.size() == 0) return;
|
||||
|
||||
ModelViewWidget* w3 = getCurrentScreen()->getWidget<ModelViewWidget>("modelview");
|
||||
assert( w3 != NULL );
|
||||
|
||||
const KartProperties* kart = kart_properties_manager->getKart(selectionID);
|
||||
if(kart == NULL) return;
|
||||
KartModel* kartModel = kart->getKartModel();
|
||||
|
||||
w3->clearModels();
|
||||
w3->addModel( kartModel->getModel() );
|
||||
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
w3->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
w3->update(0);
|
||||
|
||||
LabelWidget* label = getCurrentScreen()->getWidget<LabelWidget>("currkartname");
|
||||
assert(label != NULL);
|
||||
label->setText( kart->getName().c_str() );
|
||||
}
|
||||
};
|
||||
KartHoverListener* karthoverListener = NULL;
|
||||
|
||||
/**
|
||||
* Callback handling events from the kart selection menu
|
||||
*/
|
||||
void menuEventKarts(Widget* widget, std::string& name)
|
||||
{
|
||||
if(name == "init")
|
||||
{
|
||||
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
if(karthoverListener == NULL)
|
||||
{
|
||||
karthoverListener = new KartHoverListener();
|
||||
w->registerHoverListener(karthoverListener);
|
||||
}
|
||||
|
||||
if(!getCurrentScreen()->m_inited)
|
||||
{
|
||||
const int kart_amount = kart_properties_manager->getNumberOfKarts();
|
||||
for(int n=0; n<kart_amount; n++)
|
||||
{
|
||||
const KartProperties* prop = kart_properties_manager->getKartById(n);
|
||||
std::string icon_path = "karts/";
|
||||
icon_path += prop->getIdent() + "/" + prop->getIconFile();
|
||||
w->addItem(prop->getName().c_str(), prop->getIdent().c_str(), icon_path.c_str());
|
||||
|
||||
}
|
||||
|
||||
getCurrentScreen()->m_inited = true;
|
||||
}
|
||||
w->updateItemDisplay();
|
||||
|
||||
// Set-up player list
|
||||
SpinnerWidget* w2 = getCurrentScreen()->getWidget<SpinnerWidget>("player");
|
||||
assert( w2 != NULL );
|
||||
|
||||
const int playerAmount = UserConfigParams::m_player.size();
|
||||
for(int n=0; n<playerAmount; n++)
|
||||
{
|
||||
w2->addLabel( UserConfigParams::m_player[n].getName() );
|
||||
}
|
||||
|
||||
// Set-up kart model preview
|
||||
ModelViewWidget* w3 = getCurrentScreen()->getWidget<ModelViewWidget>("modelview");
|
||||
assert( w3 != NULL );
|
||||
|
||||
KartModel* kartModel = kart_properties_manager->getKart("tux")->getKartModel();
|
||||
|
||||
w3->addModel( kartModel->getModel() );
|
||||
w3->addModel( kartModel->getWheelModel(0), kartModel->getWheelGraphicsPosition(0) );
|
||||
w3->addModel( kartModel->getWheelModel(1), kartModel->getWheelGraphicsPosition(1) );
|
||||
w3->addModel( kartModel->getWheelModel(2), kartModel->getWheelGraphicsPosition(2) );
|
||||
w3->addModel( kartModel->getWheelModel(3), kartModel->getWheelGraphicsPosition(3) );
|
||||
w3->update(0);
|
||||
|
||||
getCurrentScreen()->m_inited = true;
|
||||
} // end if init
|
||||
else if(name == "karts")
|
||||
{
|
||||
RibbonGridWidget* w = getCurrentScreen()->getWidget<RibbonGridWidget>("karts");
|
||||
assert( w != NULL );
|
||||
|
||||
race_manager->setLocalKartInfo(0, w->getSelectionIDString());
|
||||
|
||||
StateManager::pushMenu("racesetup.stkgui");
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Callback handling events from the race setup menu
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
9507E9D10FC1CDCE00BD2B92 /* Ogg.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 9551C7F90FC1B63C00DB481B /* Ogg.framework */; };
|
||||
9507E9D20FC1CDCE00BD2B92 /* OpenAL.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 9551C7FA0FC1B63C00DB481B /* OpenAL.framework */; };
|
||||
9507E9DB0FC1CDD500BD2B92 /* Vorbis.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 9551C7FB0FC1B63C00DB481B /* Vorbis.framework */; };
|
||||
9516162D0FFFB12B004B16D8 /* kart_selection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9516162C0FFFB12B004B16D8 /* kart_selection.cpp */; };
|
||||
951BC65E0FFAF290006B5FF1 /* ipo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 951BC65C0FFAF290006B5FF1 /* ipo.cpp */; };
|
||||
95263DEC0FD7471900CF5F92 /* grand_prix_data.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95263DE00FD7471900CF5F92 /* grand_prix_data.cpp */; };
|
||||
95263DED0FD7471900CF5F92 /* grand_prix_manager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 95263DE20FD7471900CF5F92 /* grand_prix_manager.cpp */; };
|
||||
@@ -305,6 +306,8 @@
|
||||
9507E9500FC1C8C200BD2B92 /* RenderTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RenderTexture.cpp; path = ../../bullet/Demos/OpenGL/RenderTexture.cpp; sourceTree = SOURCE_ROOT; };
|
||||
9507E9510FC1C8C200BD2B92 /* RenderTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RenderTexture.h; path = games/supertuxkart/src/bullet/Demos/OpenGL/RenderTexture.h; sourceTree = SYSTEM_DEVELOPER_DIR; };
|
||||
9507E9B60FC1CCE900BD2B92 /* stk.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = stk.icns; sourceTree = SOURCE_ROOT; };
|
||||
9516162C0FFFB12B004B16D8 /* kart_selection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = kart_selection.cpp; path = ../../gui/kart_selection.cpp; sourceTree = SOURCE_ROOT; };
|
||||
9516164D0FFFB1F0004B16D8 /* kart_selection.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = kart_selection.hpp; path = ../../gui/kart_selection.hpp; sourceTree = SOURCE_ROOT; };
|
||||
951BC65C0FFAF290006B5FF1 /* ipo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ipo.cpp; path = ../../animations/ipo.cpp; sourceTree = SOURCE_ROOT; };
|
||||
951BC65D0FFAF290006B5FF1 /* ipo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = ipo.hpp; path = ../../animations/ipo.hpp; sourceTree = SOURCE_ROOT; };
|
||||
951C357D0FC05BF400A48379 /* quad_set.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = quad_set.hpp; path = ../../tracks/quad_set.hpp; sourceTree = SOURCE_ROOT; };
|
||||
@@ -1013,16 +1016,18 @@
|
||||
9505577B0F696A900056E88C /* engine.hpp */,
|
||||
95C1E3FF0F699427005D33E6 /* font.cpp */,
|
||||
95C1E4020F69943D005D33E6 /* font.hpp */,
|
||||
9516162C0FFFB12B004B16D8 /* kart_selection.cpp */,
|
||||
9516164D0FFFB1F0004B16D8 /* kart_selection.hpp */,
|
||||
954A57DB0FEC5AE40073C16C /* modaldialog.cpp */,
|
||||
954A57ED0FEC5BB00073C16C /* modaldialog.hpp */,
|
||||
9505577C0F696A900056E88C /* my_button.cpp */,
|
||||
9505577D0F696A900056E88C /* my_button.hpp */,
|
||||
95D1F6180FC8CDBB00FF6968 /* options_screen.cpp */,
|
||||
95D1F6170FC8CDBB00FF6968 /* options_screen.hpp */,
|
||||
950557800F696A900056E88C /* screen.hpp */,
|
||||
95C1E3F10F699079005D33E6 /* race_gui.cpp */,
|
||||
95C1E3EB0F698F23005D33E6 /* race_gui.hpp */,
|
||||
9505577F0F696A900056E88C /* screen.cpp */,
|
||||
950557800F696A900056E88C /* screen.hpp */,
|
||||
950557810F696A900056E88C /* screen_loader.cpp */,
|
||||
953F038B0F6C880D00C77FE2 /* state_manager.cpp */,
|
||||
953F038E0F6C8AD800C77FE2 /* state_manager.hpp */,
|
||||
@@ -2321,6 +2326,7 @@
|
||||
954E4C2F0FF98B6F0047FE3E /* billboard_animation.cpp in Sources */,
|
||||
954E4C300FF98B6F0047FE3E /* three_d_animation.cpp in Sources */,
|
||||
951BC65E0FFAF290006B5FF1 /* ipo.cpp in Sources */,
|
||||
9516162D0FFFB12B004B16D8 /* kart_selection.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -9,28 +9,27 @@ InputDevice::InputDevice()
|
||||
{
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
m_bindings[n].id = -1;
|
||||
m_bindings[n].type = Input::IT_NONE;
|
||||
m_bindings[n].dir = Input::AD_NEGATIVE;
|
||||
m_default_bindings[n].id = -1;
|
||||
m_default_bindings[n].type = Input::IT_NONE;
|
||||
m_default_bindings[n].dir = Input::AD_NEGATIVE;
|
||||
}
|
||||
|
||||
m_player = "default";
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void InputDevice::serialize(std::ofstream& stream)
|
||||
{
|
||||
if (m_type == DT_KEYBOARD) stream << "<keyboard ";
|
||||
else if (m_type == DT_GAMEPAD) stream << "<gamepad name=\"" << m_name.c_str() << "\" ";
|
||||
if (m_type == DT_KEYBOARD) stream << "<keyboard>\n\n";
|
||||
else if (m_type == DT_GAMEPAD) stream << "<gamepad name=\"" << m_name.c_str() << "\" >\n\n";
|
||||
else std::cerr << "Warning, unknown input device type, skipping it\n";
|
||||
|
||||
stream << "owner=\"" << m_player << "\">\n\n";
|
||||
// stream << "owner=\"" << m_player << "\">\n\n";
|
||||
|
||||
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
stream << " <action name=\"" << KartActionStrings[n] << "\" id=\""
|
||||
<< m_bindings[n].id << "\" event=\"" << m_bindings[n].type << "\" ";
|
||||
<< m_default_bindings[n].id << "\" event=\"" << m_default_bindings[n].type << "\" ";
|
||||
|
||||
if (m_type == DT_GAMEPAD) stream << "direction=\"" << m_bindings[n].dir << "\"";
|
||||
if (m_type == DT_GAMEPAD) stream << "direction=\"" << m_default_bindings[n].dir << "\"";
|
||||
|
||||
stream << "/>\n";
|
||||
}
|
||||
@@ -71,8 +70,8 @@ bool InputDevice::deserializeAction(irr::io::IrrXMLReader* xml)
|
||||
if(event_string == NULL) return false;
|
||||
const int event_id = atoi(event_string);
|
||||
|
||||
m_bindings[binding_id].id = id;
|
||||
m_bindings[binding_id].type = (Input::InputType)event_id;
|
||||
m_default_bindings[binding_id].id = id;
|
||||
m_default_bindings[binding_id].type = (Input::InputType)event_id;
|
||||
|
||||
|
||||
// ---- read axis direction
|
||||
@@ -80,7 +79,7 @@ bool InputDevice::deserializeAction(irr::io::IrrXMLReader* xml)
|
||||
if(dir_string != NULL)
|
||||
{
|
||||
const int dir = atoi(dir_string);
|
||||
m_bindings[binding_id].dir = (Input::AxisDirection)dir;
|
||||
m_default_bindings[binding_id].dir = (Input::AxisDirection)dir;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -89,7 +88,7 @@ bool InputDevice::deserializeAction(irr::io::IrrXMLReader* xml)
|
||||
// -----------------------------------------------------------------------------
|
||||
std::string InputDevice::getBindingAsString(const PlayerAction action) const
|
||||
{
|
||||
return Input::getInputAsString(m_bindings[action].type, m_bindings[action].id, m_bindings[action].dir);
|
||||
return Input::getInputAsString(m_default_bindings[action].type, m_default_bindings[action].id, m_default_bindings[action].dir);
|
||||
}
|
||||
|
||||
#if 0
|
||||
@@ -107,37 +106,34 @@ KeyboardDevice::KeyboardDevice(irr::io::IrrXMLReader* xml)
|
||||
{
|
||||
m_type = DT_KEYBOARD;
|
||||
|
||||
const char* owner_string = xml->getAttributeValue("owner");
|
||||
if(owner_string == NULL) m_player = "default";
|
||||
else m_player = owner_string;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void KeyboardDevice::loadDefaults()
|
||||
{
|
||||
m_bindings[PA_NITRO].id = KEY_KEY_N;
|
||||
m_bindings[PA_ACCEL].id = KEY_UP;
|
||||
m_bindings[PA_BRAKE].id = KEY_DOWN;
|
||||
m_bindings[PA_LEFT].id = KEY_LEFT;
|
||||
m_bindings[PA_RIGHT].id = KEY_RIGHT;
|
||||
m_bindings[PA_DRIFT].id = KEY_KEY_V;
|
||||
m_bindings[PA_RESCUE].id = KEY_BACK;
|
||||
m_bindings[PA_FIRE].id = KEY_SPACE;
|
||||
m_bindings[PA_LOOK_BACK].id = KEY_KEY_B ;
|
||||
m_default_bindings[PA_NITRO].id = KEY_KEY_N;
|
||||
m_default_bindings[PA_ACCEL].id = KEY_UP;
|
||||
m_default_bindings[PA_BRAKE].id = KEY_DOWN;
|
||||
m_default_bindings[PA_LEFT].id = KEY_LEFT;
|
||||
m_default_bindings[PA_RIGHT].id = KEY_RIGHT;
|
||||
m_default_bindings[PA_DRIFT].id = KEY_KEY_V;
|
||||
m_default_bindings[PA_RESCUE].id = KEY_BACK;
|
||||
m_default_bindings[PA_FIRE].id = KEY_SPACE;
|
||||
m_default_bindings[PA_LOOK_BACK].id = KEY_KEY_B ;
|
||||
|
||||
m_bindings[PA_NITRO].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_ACCEL].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_BRAKE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_LEFT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_RIGHT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_DRIFT].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_RESCUE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_FIRE].type = Input::IT_KEYBOARD;
|
||||
m_bindings[PA_LOOK_BACK].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_NITRO].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_ACCEL].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_BRAKE].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_LEFT].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_RIGHT].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_DRIFT].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_RESCUE].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_FIRE].type = Input::IT_KEYBOARD;
|
||||
m_default_bindings[PA_LOOK_BACK].type = Input::IT_KEYBOARD;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void KeyboardDevice::editBinding(PlayerAction action, int key_id)
|
||||
{
|
||||
m_bindings[action].id = key_id;
|
||||
m_default_bindings[action].id = key_id;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/** checks if this key belongs to this belongs. if yes, sets action and returns true; otherwise returns false */
|
||||
@@ -145,7 +141,7 @@ bool KeyboardDevice::hasBinding(const int key_id, PlayerAction* action /* out */
|
||||
{
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].id == key_id)
|
||||
if(m_default_bindings[n].id == key_id)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
@@ -172,10 +168,6 @@ GamePadDevice::GamePadDevice(irr::io::IrrXMLReader* xml)
|
||||
m_prevAxisDirections = NULL;
|
||||
m_deadzone = DEADZONE_JOYSTICK;
|
||||
|
||||
const char* owner_string = xml->getAttributeValue("owner");
|
||||
if(owner_string == NULL) m_player = "default";
|
||||
else m_player = owner_string;
|
||||
|
||||
const char* name_string = xml->getAttributeValue("name");
|
||||
if(name_string == NULL)
|
||||
{
|
||||
@@ -223,37 +215,37 @@ void GamePadDevice::open(const int irrIndex, const std::string name, const int a
|
||||
void GamePadDevice::loadDefaults()
|
||||
{
|
||||
// buttons
|
||||
m_bindings[PA_FIRE].type = Input::IT_STICKBUTTON;
|
||||
m_bindings[PA_FIRE].id = 0;
|
||||
m_default_bindings[PA_FIRE].type = Input::IT_STICKBUTTON;
|
||||
m_default_bindings[PA_FIRE].id = 0;
|
||||
|
||||
m_bindings[PA_NITRO].type = Input::IT_STICKBUTTON;
|
||||
m_bindings[PA_NITRO].id = 1;
|
||||
m_default_bindings[PA_NITRO].type = Input::IT_STICKBUTTON;
|
||||
m_default_bindings[PA_NITRO].id = 1;
|
||||
|
||||
m_bindings[PA_DRIFT].type = Input::IT_STICKBUTTON;
|
||||
m_bindings[PA_DRIFT].id = 2;
|
||||
m_default_bindings[PA_DRIFT].type = Input::IT_STICKBUTTON;
|
||||
m_default_bindings[PA_DRIFT].id = 2;
|
||||
|
||||
m_bindings[PA_RESCUE].type = Input::IT_STICKBUTTON;
|
||||
m_bindings[PA_RESCUE].id = 3;
|
||||
m_default_bindings[PA_RESCUE].type = Input::IT_STICKBUTTON;
|
||||
m_default_bindings[PA_RESCUE].id = 3;
|
||||
|
||||
m_bindings[PA_LOOK_BACK].type = Input::IT_STICKBUTTON;
|
||||
m_bindings[PA_LOOK_BACK].id = 4;
|
||||
m_default_bindings[PA_LOOK_BACK].type = Input::IT_STICKBUTTON;
|
||||
m_default_bindings[PA_LOOK_BACK].id = 4;
|
||||
|
||||
// axes
|
||||
m_bindings[PA_ACCEL].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_ACCEL].id = 1;
|
||||
m_bindings[PA_ACCEL].dir = Input::AD_NEGATIVE;
|
||||
m_default_bindings[PA_ACCEL].type = Input::IT_STICKMOTION;
|
||||
m_default_bindings[PA_ACCEL].id = 1;
|
||||
m_default_bindings[PA_ACCEL].dir = Input::AD_NEGATIVE;
|
||||
|
||||
m_bindings[PA_BRAKE].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_BRAKE].id = 1;
|
||||
m_bindings[PA_BRAKE].dir = Input::AD_POSITIVE;
|
||||
m_default_bindings[PA_BRAKE].type = Input::IT_STICKMOTION;
|
||||
m_default_bindings[PA_BRAKE].id = 1;
|
||||
m_default_bindings[PA_BRAKE].dir = Input::AD_POSITIVE;
|
||||
|
||||
m_bindings[PA_LEFT].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_LEFT].id = 0;
|
||||
m_bindings[PA_LEFT].dir = Input::AD_NEGATIVE;
|
||||
m_default_bindings[PA_LEFT].type = Input::IT_STICKMOTION;
|
||||
m_default_bindings[PA_LEFT].id = 0;
|
||||
m_default_bindings[PA_LEFT].dir = Input::AD_NEGATIVE;
|
||||
|
||||
m_bindings[PA_RIGHT].type = Input::IT_STICKMOTION;
|
||||
m_bindings[PA_RIGHT].id = 0;
|
||||
m_bindings[PA_RIGHT].dir = Input::AD_POSITIVE;
|
||||
m_default_bindings[PA_RIGHT].type = Input::IT_STICKMOTION;
|
||||
m_default_bindings[PA_RIGHT].id = 0;
|
||||
m_default_bindings[PA_RIGHT].dir = Input::AD_POSITIVE;
|
||||
|
||||
|
||||
/*
|
||||
@@ -281,9 +273,9 @@ void GamePadDevice::setButtonPressed(const int i, bool isButtonPressed)
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::editBinding(const PlayerAction action, const Input::InputType type, const int id, Input::AxisDirection direction)
|
||||
{
|
||||
m_bindings[action].type = type;
|
||||
m_bindings[action].id = id;
|
||||
m_bindings[action].dir = direction;
|
||||
m_default_bindings[action].type = type;
|
||||
m_default_bindings[action].id = id;
|
||||
m_default_bindings[action].dir = direction;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void GamePadDevice::resetAxisDirection(const int axis, Input::AxisDirection direction, const int player)
|
||||
@@ -292,7 +284,7 @@ void GamePadDevice::resetAxisDirection(const int axis, Input::AxisDirection dire
|
||||
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].id == axis && m_bindings[n].dir == direction)
|
||||
if(m_default_bindings[n].id == axis && m_default_bindings[n].dir == direction)
|
||||
{
|
||||
RaceManager::getWorld()->getLocalPlayerKart(player)->action((PlayerAction)n, 0);
|
||||
return;
|
||||
@@ -354,14 +346,14 @@ bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int va
|
||||
// find corresponding action and return it
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].type == type && m_bindings[n].id == id)
|
||||
if(m_default_bindings[n].type == type && m_default_bindings[n].id == id)
|
||||
{
|
||||
if(m_bindings[n].dir == Input::AD_NEGATIVE && value < 0)
|
||||
if(m_default_bindings[n].dir == Input::AD_NEGATIVE && value < 0)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
}
|
||||
else if(m_bindings[n].dir == Input::AD_POSITIVE && value > 0)
|
||||
else if(m_default_bindings[n].dir == Input::AD_POSITIVE && value > 0)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
@@ -375,7 +367,7 @@ bool GamePadDevice::hasBinding(Input::InputType type, const int id, const int va
|
||||
// find corresponding action and return it
|
||||
for(int n=0; n<PA_COUNT; n++)
|
||||
{
|
||||
if(m_bindings[n].type == type && m_bindings[n].id == id)
|
||||
if(m_default_bindings[n].type == type && m_default_bindings[n].id == id)
|
||||
{
|
||||
*action = (PlayerAction)n;
|
||||
return true;
|
||||
|
||||
@@ -27,9 +27,8 @@ class InputDevice
|
||||
{
|
||||
protected:
|
||||
DeviceType m_type;
|
||||
KeyBinding m_bindings[PA_COUNT];
|
||||
KeyBinding m_default_bindings[PA_COUNT];
|
||||
|
||||
std::string m_player;
|
||||
|
||||
public:
|
||||
std::string m_name; // if device has a name; unused for keyboards since AFAIK we can't tell keyboards apart
|
||||
|
||||
Reference in New Issue
Block a user