started implementing input sensing in options. currently, detects keypresses and prints them to the console. No gamepad supprot yet, bindings are not actually changed yet

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3552 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2009-05-30 01:41:09 +00:00
parent 7926d5fe97
commit 83a731500c
8 changed files with 102 additions and 23 deletions

View File

@ -300,6 +300,14 @@ namespace StateManager
std::cerr << "Cannot read internal input device ID : " << selection.c_str() << std::endl;
}
}
else if(name.find("binding_") != std::string::npos)
{
getCurrentScreen()->showModalDialog();
//INPUT_SENSE_PREFER_AXIS,
//INPUT_SENSE_PREFER_BUTTON,
input_manager->setMode(InputManager::INPUT_SENSE_PREFER_BUTTON);
std::cout << "in sensing mode\n";
}
}
// -----------------------------------------------------------------------------

View File

@ -3,6 +3,7 @@
#include <assert.h>
#include "irrlicht.h"
#include "utils/translation.hpp"
#include "gui/screen.hpp"
#include "gui/engine.hpp"
@ -237,6 +238,29 @@ void Screen::addWidgetsRecursively(ptr_vector<Widget>& widgets, Widget* parent)
} // next widget
}
// -----------------------------------------------------------------------------
//ok, global is not nice... but in the end there will only ever be maximum 1 dialog at a time
static IGUIWindow* modalWindow = NULL;
void Screen::showModalDialog()
{
const core::dimension2d<s32>& frame_size = GUIEngine::getDriver()->getCurrentRenderTargetSize();
const int w = frame_size.Width*0.4;
const int h = frame_size.Height*0.4;
core::rect< s32 > area( position2d< s32 >(frame_size.Width/2 - w/2, frame_size.Height/2 - h/2),
dimension2d< s32 >(w, h) );
modalWindow = GUIEngine::getGUIEnv()->addWindow ( area, true /* modal */ );
core::rect< s32 > area2(0, 0, w, h);
GUIEngine::getGUIEnv()->addButton( area2, modalWindow, -1, stringw(_("Press a key")).c_str() );
}
// -----------------------------------------------------------------------------
void Screen::dismissModalDialog()
{
modalWindow->remove();
}
// -----------------------------------------------------------------------------
/**
* Called when screen is removed. This means all irrlicht widgets this object has pointers

View File

@ -62,6 +62,9 @@ namespace GUIEngine
void addWidgets();
void calculateLayout();
void showModalDialog();
void dismissModalDialog();
const std::string& getName() const { return m_filename; }
void elementsWereDeleted(ptr_vector<Widget>* within_vector = NULL);

View File

@ -754,11 +754,6 @@ void Skin::draw3DButtonPaneStandard (IGUIElement *element, const core::rect< s32
process3DPane(element, rect, false /* pressed */ );
}
void Skin::draw3DMenuPane (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
//printf("draw menu pane\n");
}
void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool flat, bool fillBackGround, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
// e.g. the checkbox square
@ -771,6 +766,34 @@ void Skin::draw3DSunkenPane (IGUIElement *element, video::SColor bgcolor, bool f
GUIEngine::getDriver()->draw2DRectangle( SColor(255, 0, 150, 0), rect );
}
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
// fade out background
GUIEngine::getDriver()->draw2DRectangle( SColor(150, 255, 255, 255),
core::rect< s32 >(position2d< s32 >(0,0) , GUIEngine::getDriver()->getCurrentRenderTargetSize()) );
static BoxRenderParams params;
params.left_border = 15;
params.right_border = 15;
params.top_border = 15;
params.bottom_border = 15;
params.hborder_out_portion = 1.0;
params.vborder_out_portion = 0.2f;
// draw frame (since it's transluscent, draw many times to get opacity)
drawBoxFromStretchableTexture(rect, m_tex_section, params);
drawBoxFromStretchableTexture(rect, m_tex_section, params);
return rect;
}
void Skin::draw3DMenuPane (IGUIElement *element, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
//printf("draw menu pane\n");
}
void Skin::draw3DTabBody (IGUIElement *element, bool border, bool background, const core::rect< s32 > &rect, const core::rect< s32 > *clip, s32 tabHeight, gui::EGUI_ALIGNMENT alignment)
{
//printf("draw tab body\n");
@ -785,12 +808,6 @@ void Skin::draw3DToolBar (IGUIElement *element, const core::rect< s32 > &rect, c
{
}
core::rect< s32 > Skin::draw3DWindowBackground (IGUIElement *element, bool drawTitleBar, video::SColor titleBarColor, const core::rect< s32 > &rect, const core::rect< s32 > *clip)
{
//printf("draw 3d window bg\n");
return rect;
}
void Skin::drawIcon (IGUIElement *element, EGUI_DEFAULT_ICON icon, const core::position2di position, u32 starttime, u32 currenttime, bool loop, const core::rect< s32 > *clip)
{
/* m_fallback_skin->drawIcon(element, icon, position, starttime, currenttime, loop, clip); */

View File

@ -387,6 +387,27 @@ namespace StateManager
popMenu();
}
}
void gotSensedInput(Input* sensedInput)
{
std::cout << "got sensed input\n";
if(sensedInput->type == Input::IT_KEYBOARD)
{
std::cout << "key " << Input::getInputAsString(Input::IT_KEYBOARD, sensedInput->id0) << std::endl;
}
else if(sensedInput->type == Input::IT_STICKMOTION)
{
std::cout << "gamepad axis " << sensedInput->id0 << " " << sensedInput->id1 << " " << sensedInput->id2 << std::endl;
}
else if(sensedInput->type == Input::IT_STICKBUTTON)
{
std::cout << "gamepad button " << sensedInput->id0 << " " << sensedInput->id1 << " " << sensedInput->id2 << std::endl;
}
getCurrentScreen()->dismissModalDialog();
input_manager->setMode(InputManager::MENU);
}
#if 0

View File

@ -3,6 +3,8 @@
#include <string>
class Input;
namespace StateManager
{
void initGUI();
@ -15,6 +17,8 @@ namespace StateManager
bool isGameState();
void reshowTopMostMenu();
void gotSensedInput(Input* sensedInput);
void escapePressed();
}

View File

@ -47,7 +47,7 @@ struct Input
static const int IT_LAST = IT_MOUSEBUTTON;
InputType type;
int id0;
int id0; // FIXME : give meaningful names to these variables...
int id1;
int id2;
@ -89,7 +89,7 @@ struct Input
// Nothing to do.
}
static std::string getInputAsString(const Input::InputType type, const int id, const Input::AxisDirection dir);
static std::string getInputAsString(const Input::InputType type, const int id, const Input::AxisDirection dir=AD_NEUTRAL);
};

View File

@ -1,7 +1,6 @@
// $Id: plibdrv.cpp 757 2006-09-11 22:27:39Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2004 Steve Baker <sjbaker1@airmail.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
@ -192,19 +191,20 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2,
// std::cout << "Input code=" << id0 << " found=" << action_found << std::endl;
//GameAction ga = m_action_map->getEntry(type, id0, id1, id2);
#if 0 // TODO - input sensing
// Act different in input sensing mode.
if (m_mode >= INPUT_SENSE_PREFER_AXIS &&
m_mode <= INPUT_SENSE_PREFER_BUTTON)
{
// Input sensing should be canceled.
if (ga == GA_LEAVE && m_sensed_input->type==Input::IT_KEYBOARD)
{
handleGameAction(GA_SENSE_CANCEL, value);
}
// Input sensing should be canceled. (TODO)
//if (ga == GA_LEAVE && m_sensed_input->type==Input::IT_KEYBOARD)
//{
// StateManager::gotSensedInput(NULL);
//}
// Stores the sensed input when the button/key/axes/<whatever> is
// released only and is not used in a fixed mapping.
else if (!user_config->isFixedInput(type, id0, id1, id2) )
//else
//if (!user_config->isFixedInput(type, id0, id1, id2) ) // ignore static actions (TODO)
{
// See if the new input should be stored. This happens if:
// 1) the value is larger
@ -232,11 +232,13 @@ void InputManager::input(Input::InputType type, int id0, int id1, int id2,
// Notify the completion of the input sensing if the key/stick/
// ... is released.
if(value==0)
handleGameAction(GA_SENSE_COMPLETE, 0);
{
StateManager::gotSensedInput(m_sensed_input);
}
}
} // if m_mode==INPUT_SENSE_PREFER_{AXIS,BUTTON}
else
#endif
if (action_found)
{
if(StateManager::isGameState())