Initial commit
This commit is contained in:
127
engines/crab/input/cursor.cpp
Normal file
127
engines/crab/input/cursor.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
// Author: Arvind
|
||||
// Purpose: Cursor class
|
||||
//=============================================================================
|
||||
#include "graphics/cursorman.h"
|
||||
#include "graphics/managed_surface.h"
|
||||
#include "crab/crab.h"
|
||||
#include "crab/input/cursor.h"
|
||||
|
||||
namespace Crab {
|
||||
using namespace pyrodactyl::input;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Reset all values
|
||||
//------------------------------------------------------------------------
|
||||
void Cursor::reset() {
|
||||
_motion.x = 0;
|
||||
_motion.y = 0;
|
||||
|
||||
_button.x = 0;
|
||||
_button.y = 0;
|
||||
|
||||
_rel.x = 0;
|
||||
_rel.y = 0;
|
||||
|
||||
// set to -1, so its set to 0 on first update
|
||||
_state = -1;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Reset all values
|
||||
//------------------------------------------------------------------------
|
||||
void Cursor::load(rapidxml::xml_node<char> *node) {
|
||||
if (nodeValid("normal", node)) {
|
||||
rapidxml::xml_node<char> *nornode = node->first_node("normal");
|
||||
_img.load(nornode, "img");
|
||||
_imgS.load(nornode, "img_s");
|
||||
}
|
||||
|
||||
if (nodeValid("hover", node)) {
|
||||
rapidxml::xml_node<char> *hovnode = node->first_node("hover");
|
||||
_imgHover.load(hovnode, "img");
|
||||
_imgHoverS.load(hovnode, "img_s");
|
||||
|
||||
if (nodeValid("offset", hovnode))
|
||||
_hoverOffset.load(hovnode->first_node("offset"));
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Handle Events
|
||||
//------------------------------------------------------------------------
|
||||
void Cursor::handleEvents(const Common::Event &event) {
|
||||
g_engine->_mouse->_hover = false;
|
||||
|
||||
if (event.type == Common::EVENT_MOUSEMOVE) {
|
||||
_motion.x = event.mouse.x;
|
||||
_motion.y = event.mouse.y;
|
||||
|
||||
_rel.x = event.relMouse.x;
|
||||
_rel.y = event.relMouse.y;
|
||||
} else if (event.type == Common::EVENT_LBUTTONDOWN) {
|
||||
_pressed = true;
|
||||
|
||||
_button.x = event.mouse.x;
|
||||
_button.y = event.mouse.y;
|
||||
} else if (event.type == Common::EVENT_LBUTTONUP) {
|
||||
_pressed = false;
|
||||
|
||||
_button.x = event.mouse.x;
|
||||
_button.y = event.mouse.y;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Draw
|
||||
//------------------------------------------------------------------------
|
||||
void Cursor::draw() {
|
||||
uint8 oldState = _state;
|
||||
_state = (_hover ? 1 : 0) | (_pressed << 1);
|
||||
|
||||
if (_state != oldState) {
|
||||
if (_hover) {
|
||||
if (_pressed)
|
||||
CursorMan.replaceCursor(_imgHoverS._texture->rawSurface(), 0, 0, 0);
|
||||
else
|
||||
CursorMan.replaceCursor(_imgHover._texture->rawSurface(), 0, 0, 0);
|
||||
} else {
|
||||
if (_pressed)
|
||||
CursorMan.replaceCursor(_imgS._texture->rawSurface(), 0, 0, 0);
|
||||
else
|
||||
CursorMan.replaceCursor(_img._texture->rawSurface(), 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
99
engines/crab/input/cursor.h
Normal file
99
engines/crab/input/cursor.h
Normal file
@@ -0,0 +1,99 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
//=============================================================================
|
||||
// Author: Arvind
|
||||
// Purpose: Cursor object
|
||||
//=============================================================================
|
||||
#ifndef CRAB_CURSOR_H
|
||||
#define CRAB_CURSOR_H
|
||||
|
||||
#include "common/events.h"
|
||||
#include "crab/vectors.h"
|
||||
#include "crab/image/Image.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace input {
|
||||
class Cursor {
|
||||
// Mouse images
|
||||
pyrodactyl::image::Image _img, _imgS, _imgHover, _imgHoverS;
|
||||
|
||||
// The hover mouse cursor is drawn at a slight offset to the normal cursor
|
||||
Vector2i _hoverOffset;
|
||||
|
||||
// Mouse image changes slightly if left click button is pressed
|
||||
bool _pressed;
|
||||
|
||||
int8 _state;
|
||||
|
||||
public:
|
||||
// Various coordinates
|
||||
Vector2i _motion, _button, _rel;
|
||||
|
||||
// Is the mouse inside the HUD? Used to disable level mouse movement if true
|
||||
bool _insideHud;
|
||||
|
||||
// Was the last click on an NPC?
|
||||
bool _hover;
|
||||
|
||||
Cursor() {
|
||||
_pressed = false;
|
||||
_insideHud = false;
|
||||
_hover = false;
|
||||
reset();
|
||||
}
|
||||
~Cursor() {}
|
||||
|
||||
void quit() {
|
||||
_img.deleteImage();
|
||||
_imgS.deleteImage();
|
||||
_imgHover.deleteImage();
|
||||
_imgHoverS.deleteImage();
|
||||
}
|
||||
|
||||
void reset();
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
void handleEvents(const Common::Event &event);
|
||||
|
||||
void draw();
|
||||
bool pressed() {
|
||||
return _pressed;
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace input
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_CURSOR_H
|
||||
53
engines/crab/input/fightinput.cpp
Normal file
53
engines/crab/input/fightinput.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/loaders.h"
|
||||
#include "crab/input/fightinput.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::input;
|
||||
|
||||
void FightInput::load(rapidxml::xml_node<char> *node) {
|
||||
loadEnum(_type, "type", node);
|
||||
loadNum(_state, "state", node);
|
||||
}
|
||||
|
||||
FightAnimationType FightInput::handleEvents(const Common::Event &event) {
|
||||
if (g_engine->_inputManager->state(IG_ATTACK))
|
||||
return FA_ATTACK;
|
||||
else if (g_engine->_inputManager->state(IG_BLOCK))
|
||||
return FA_BLOCK;
|
||||
|
||||
return FA_IDLE;
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
92
engines/crab/input/fightinput.h
Normal file
92
engines/crab/input/fightinput.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_FIGHTINPUT_H
|
||||
#define CRAB_FIGHTINPUT_H
|
||||
|
||||
#include "crab/input/input.h"
|
||||
#include "crab/rapidxml/rapidxml.hpp"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace input {
|
||||
// The animations a sprite can play
|
||||
enum FightAnimationType {
|
||||
// Idle state, you can launch new moves from this state only
|
||||
// You return to this state once a move animation is done
|
||||
FA_IDLE,
|
||||
|
||||
// The moves a sprite can do
|
||||
FA_ATTACK,
|
||||
FA_BLOCK,
|
||||
|
||||
// The hurt animation
|
||||
FA_HURT,
|
||||
|
||||
// The death animation
|
||||
FA_DEAD
|
||||
};
|
||||
|
||||
// The input necessary to launch a move
|
||||
struct FightInput {
|
||||
// The state needed to execute this move
|
||||
FightAnimationType _type;
|
||||
|
||||
// The sprite state, used to have different moves trigger from the same move
|
||||
uint _state;
|
||||
|
||||
FightInput() {
|
||||
reset();
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_type = FA_IDLE;
|
||||
_state = 0;
|
||||
}
|
||||
|
||||
bool operator==(const FightInput &input) {
|
||||
return _type == input._type && _state == input._state;
|
||||
}
|
||||
|
||||
bool idle() {
|
||||
return _type == FA_IDLE;
|
||||
}
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
|
||||
FightAnimationType handleEvents(const Common::Event &event);
|
||||
};
|
||||
} // End of namespace input
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_FIGHTINPUT_H
|
||||
57
engines/crab/input/hotkey.cpp
Normal file
57
engines/crab/input/hotkey.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/loaders.h"
|
||||
#include "crab/input/hotkey.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::input;
|
||||
|
||||
void HotKey::load(rapidxml::xml_node<char> *node) {
|
||||
loadEnum(_input, "input", node);
|
||||
|
||||
_name = g_engine->_inputManager->getAssociatedKey(_input);
|
||||
}
|
||||
|
||||
bool HotKey::handleEvents(const Common::Event &event) {
|
||||
if (_input > IT_NONE && _input < IT_TOTAL) {
|
||||
return g_engine->_inputManager->state(_input);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *HotKey::name() {
|
||||
return _name.c_str();
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
76
engines/crab/input/hotkey.h
Normal file
76
engines/crab/input/hotkey.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_HOTKEY_H
|
||||
#define CRAB_HOTKEY_H
|
||||
|
||||
#include "crab/crab.h"
|
||||
#include "crab/input/input.h"
|
||||
#include "crab/rapidxml/rapidxml.hpp"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace input {
|
||||
// This class is built to integrate the input check for hotkeys bound to buttons
|
||||
class HotKey {
|
||||
// The type of input the hotkey is checking for
|
||||
InputType _input;
|
||||
|
||||
// Has the key been pressed?
|
||||
bool _keydown;
|
||||
|
||||
// Description of the key associated with the Input
|
||||
Common::String _name;
|
||||
|
||||
public:
|
||||
HotKey() {
|
||||
_input = IT_NONE;
|
||||
_keydown = false;
|
||||
}
|
||||
|
||||
void set(const InputType &val) {
|
||||
_input = val;
|
||||
_name = g_engine->_inputManager->getAssociatedKey(_input);
|
||||
}
|
||||
|
||||
const char *name();
|
||||
|
||||
void load(rapidxml::xml_node<char> *node);
|
||||
|
||||
bool handleEvents(const Common::Event &event);
|
||||
|
||||
};
|
||||
} // End of namespace input
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_HOTKEY_H
|
||||
316
engines/crab/input/input.cpp
Normal file
316
engines/crab/input/input.cpp
Normal file
@@ -0,0 +1,316 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
#include "common/system.h"
|
||||
#include "common/translation.h"
|
||||
#include "crab/crab.h"
|
||||
#include "crab/loaders.h"
|
||||
#include "crab/XMLDoc.h"
|
||||
#include "crab/input/input.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
using namespace pyrodactyl::input;
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
// Purpose: Return pressed/depressed state of key
|
||||
//------------------------------------------------------------------------
|
||||
bool InputManager::state(const InputType &val) {
|
||||
return _ivState[val];
|
||||
}
|
||||
|
||||
void InputManager::populateKeyTable() {
|
||||
for (uint type = IG_START; type < IT_TOTAL; type++) {
|
||||
_keyDescs[type] = '\0';
|
||||
}
|
||||
|
||||
setKeyBindingMode(KBM_GAME);
|
||||
for (uint i = IG_START; i < IG_SIZE + IG_START; i++) {
|
||||
getAssociatedKey((InputType)i);
|
||||
}
|
||||
|
||||
setKeyBindingMode(KBM_UI);
|
||||
for (uint i = IU_START; i < IU_SIZE + IU_START; i++) {
|
||||
getAssociatedKey((InputType)i);
|
||||
}
|
||||
}
|
||||
|
||||
Common::String InputManager::getAssociatedKey(const InputType &type) {
|
||||
// Return cached copy if available
|
||||
if (_keyDescs[type].size() > 0)
|
||||
return _keyDescs[type];
|
||||
|
||||
Common::KeymapArray keymapArr = g_system->getEventManager()->getKeymapper()->getKeymaps();
|
||||
for(Common::Keymap *keymap : keymapArr) {
|
||||
if (keymap->getType() != Common::Keymap::kKeymapTypeGame)
|
||||
continue;
|
||||
|
||||
const Common::Keymap::ActionArray actions = keymap->getActions();
|
||||
for (Common::Action *action : actions) {
|
||||
if ((int)action->event.customType == type) {
|
||||
_keyDescs[type] = Common::String(keymap->getActionMapping(action)[0].description);
|
||||
_keyDescs[type].toUppercase();
|
||||
_iv[type] = Common::String(action->description);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return _keyDescs[type];
|
||||
}
|
||||
|
||||
Common::Keymap* InputManager::getDefaultKeyMapsForGame() {
|
||||
using namespace Common;
|
||||
|
||||
Keymap *keymap = new Keymap(Keymap::kKeymapTypeGame, "Unrest-Game", "Keymappings for Game");
|
||||
|
||||
Action *act;
|
||||
|
||||
act = new Action(kStandardActionMoveUp, _("Up"));
|
||||
act->setCustomEngineActionEvent(IG_UP);
|
||||
act->addDefaultInputMapping("UP");
|
||||
act->addDefaultInputMapping("JOY_UP");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action(kStandardActionMoveDown, _("Down"));
|
||||
act->setCustomEngineActionEvent(IG_DOWN);
|
||||
act->addDefaultInputMapping("DOWN");
|
||||
act->addDefaultInputMapping("JOY_DOWN");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action(kStandardActionMoveLeft, _("Left"));
|
||||
act->setCustomEngineActionEvent(IG_LEFT);
|
||||
act->addDefaultInputMapping("LEFT");
|
||||
act->addDefaultInputMapping("JOY_LEFT");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action(kStandardActionMoveRight, _("Right"));
|
||||
act->setCustomEngineActionEvent(IG_RIGHT);
|
||||
act->addDefaultInputMapping("RIGHT");
|
||||
act->addDefaultInputMapping("JOY_RIGHT");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action("TALK", _("Talk / Interact"));
|
||||
act->setCustomEngineActionEvent(IG_TALK);
|
||||
act->addDefaultInputMapping("RETURN");
|
||||
act->addDefaultInputMapping("JOY_A");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action("ATTACK", _("Attack"));
|
||||
act->setCustomEngineActionEvent(IG_ATTACK);
|
||||
act->addDefaultInputMapping("z");
|
||||
keymap->addAction(act);
|
||||
|
||||
act = new Action("BLOCK", _("Block"));
|
||||
act->setCustomEngineActionEvent(IG_BLOCK);
|
||||
act->addDefaultInputMapping("x");
|
||||
keymap->addAction(act);
|
||||
|
||||
return keymap;
|
||||
}
|
||||
|
||||
Common::Keymap* InputManager::getDefaultKeyMapsForUI() {
|
||||
using namespace Common;
|
||||
|
||||
Keymap *uiKeymap = new Keymap(Keymap::kKeymapTypeGame, "Unrest-UI", "Keymappings for UI");
|
||||
|
||||
Action *act;
|
||||
|
||||
act = new Action("UI_UP", _("Up"));
|
||||
act->setCustomEngineActionEvent(IU_UP);
|
||||
act->addDefaultInputMapping("UP");
|
||||
act->addDefaultInputMapping("JOY_UP");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_DOWN", _("Down"));
|
||||
act->setCustomEngineActionEvent(IU_DOWN);
|
||||
act->addDefaultInputMapping("DOWN");
|
||||
act->addDefaultInputMapping("JOY_DOWN");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_LEFT", _("Left"));
|
||||
act->setCustomEngineActionEvent(IU_LEFT);
|
||||
act->addDefaultInputMapping("LEFT");
|
||||
act->addDefaultInputMapping("JOY_LEFT");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_RIGHT", _("Right"));
|
||||
act->setCustomEngineActionEvent(IU_RIGHT);
|
||||
act->addDefaultInputMapping("RIGHT");
|
||||
act->addDefaultInputMapping("JOY_RIGHT");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_ACCEPT", _("Accept"));
|
||||
act->setCustomEngineActionEvent(IU_ACCEPT);
|
||||
act->addDefaultInputMapping("RETURN");
|
||||
act->addDefaultInputMapping("JOY_A");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_BACK", _("Back"));
|
||||
act->setCustomEngineActionEvent(IU_BACK);
|
||||
act->addDefaultInputMapping("ESCAPE");
|
||||
act->addDefaultInputMapping("JOY_B");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_NEXT", _("Next"));
|
||||
act->setCustomEngineActionEvent(IU_NEXT);
|
||||
act->addDefaultInputMapping("TAB");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("UI_PREV", _("Previous"));
|
||||
act->setCustomEngineActionEvent(IU_PREV);
|
||||
act->addDefaultInputMapping("r");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY1", _("Reply 1"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_0);
|
||||
act->addDefaultInputMapping("1");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY2", _("Reply 2"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_1);
|
||||
act->addDefaultInputMapping("2");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY3", _("Reply 3"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_2);
|
||||
act->addDefaultInputMapping("3");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY4", _("Reply 4"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_3);
|
||||
act->addDefaultInputMapping("4");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY5", _("Reply 5"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_4);
|
||||
act->addDefaultInputMapping("5");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("REPLY6", _("Reply 6"));
|
||||
act->setCustomEngineActionEvent(IU_REPLY_5);
|
||||
act->addDefaultInputMapping("6");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("NEXTPAGE", _("Next page"));
|
||||
act->setCustomEngineActionEvent(IU_PAGE_NEXT);
|
||||
act->addDefaultInputMapping("PERIOD");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
act = new Action("PREVPAGE", _("Previous page"));
|
||||
act->setCustomEngineActionEvent(IU_PAGE_PREV);
|
||||
act->addDefaultInputMapping("COMMA");
|
||||
uiKeymap->addAction(act);
|
||||
|
||||
return uiKeymap;
|
||||
}
|
||||
|
||||
Common::Keymap* InputManager::getDefaultKeyMapsForHUD() {
|
||||
using namespace Common;
|
||||
|
||||
Keymap *hudKeymap = new Keymap(Keymap::kKeymapTypeGame, "Unrest-HUD", "Keymappings for HUD");
|
||||
|
||||
Action *act;
|
||||
|
||||
act = new Action("MAP", _("Map"));
|
||||
act->setCustomEngineActionEvent(IG_MAP);
|
||||
act->addDefaultInputMapping("m");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("JOURNAL", _("Journal"));
|
||||
act->setCustomEngineActionEvent(IG_JOURNAL);
|
||||
act->addDefaultInputMapping("j");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("INVENTORY", _("Inventory"));
|
||||
act->setCustomEngineActionEvent(IG_INVENTORY);
|
||||
act->addDefaultInputMapping("i");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("TRAITS", _("Traits"));
|
||||
act->setCustomEngineActionEvent(IG_CHARACTER);
|
||||
act->addDefaultInputMapping("t");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("PAUSE", _("Pause"));
|
||||
act->setCustomEngineActionEvent(IG_PAUSE);
|
||||
act->addDefaultInputMapping("p");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("QUICKSAVE", _("Quick save"));
|
||||
act->setCustomEngineActionEvent(IG_QUICKSAVE);
|
||||
act->addDefaultInputMapping("F5");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
act = new Action("QUICKLOAD", _("Quick load"));
|
||||
act->setCustomEngineActionEvent(IG_QUICKLOAD);
|
||||
act->addDefaultInputMapping("F9");
|
||||
hudKeymap->addAction(act);
|
||||
|
||||
return hudKeymap;
|
||||
}
|
||||
|
||||
void InputManager::setKeyBindingMode(KeyBindingMode mode) {
|
||||
_keyMode = mode;
|
||||
|
||||
Common::Keymapper *const mapper = g_engine->getEventManager()->getKeymapper();
|
||||
|
||||
switch (mode) {
|
||||
case KBM_NONE:
|
||||
mapper->disableAllGameKeymaps();
|
||||
break;
|
||||
|
||||
case KBM_GAME:
|
||||
mapper->disableAllGameKeymaps();
|
||||
mapper->setGameKeymapState("Unrest-HUD", true);
|
||||
mapper->setGameKeymapState("Unrest-Game", true);
|
||||
break;
|
||||
|
||||
case KBM_UI:
|
||||
mapper->disableAllGameKeymaps();
|
||||
mapper->setGameKeymapState("Unrest-HUD", true);
|
||||
mapper->setGameKeymapState("Unrest-UI", true);
|
||||
break;
|
||||
}
|
||||
|
||||
// Clear All inputs
|
||||
clearInputs();
|
||||
}
|
||||
|
||||
void InputManager::save() {
|
||||
Common::KeymapArray keymapArr = g_system->getEventManager()->getKeymapper()->getKeymaps();
|
||||
for(Common::Keymap *keymap : keymapArr) {
|
||||
if (keymap->getType() != Common::Keymap::kKeymapTypeGame)
|
||||
continue;
|
||||
|
||||
keymap->saveMappings();
|
||||
}
|
||||
}
|
||||
|
||||
} // End of namespace Crab
|
||||
153
engines/crab/input/input.h
Normal file
153
engines/crab/input/input.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/* ScummVM - Graphic Adventure Engine
|
||||
*
|
||||
* ScummVM is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* This code is based on the CRAB engine
|
||||
*
|
||||
* Copyright (c) Arvind Raja Yadav
|
||||
*
|
||||
* Licensed under MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CRAB_INPUT_H
|
||||
#define CRAB_INPUT_H
|
||||
|
||||
#include "backends/keymapper/action.h"
|
||||
#include "backends/keymapper/keymapper.h"
|
||||
#include "backends/keymapper/standard-actions.h"
|
||||
|
||||
namespace Crab {
|
||||
|
||||
namespace pyrodactyl {
|
||||
namespace input {
|
||||
enum InputType {
|
||||
IT_NONE = -1,
|
||||
|
||||
// Game related input values
|
||||
IG_UP,
|
||||
IG_DOWN,
|
||||
IG_RIGHT,
|
||||
IG_LEFT,
|
||||
IG_TALK,
|
||||
IG_MAP,
|
||||
IG_JOURNAL,
|
||||
IG_INVENTORY,
|
||||
IG_CHARACTER,
|
||||
IG_PAUSE,
|
||||
IG_QUICKSAVE,
|
||||
IG_QUICKLOAD,
|
||||
IG_ATTACK,
|
||||
IG_BLOCK,
|
||||
|
||||
// UI related input values
|
||||
IU_UP,
|
||||
IU_DOWN,
|
||||
IU_RIGHT,
|
||||
IU_LEFT,
|
||||
IU_ACCEPT,
|
||||
IU_BACK,
|
||||
IU_NEXT,
|
||||
IU_PREV,
|
||||
IU_REPLY_0,
|
||||
IU_REPLY_1,
|
||||
IU_REPLY_2,
|
||||
IU_REPLY_3,
|
||||
IU_REPLY_4,
|
||||
IU_REPLY_5,
|
||||
IU_PAGE_NEXT,
|
||||
IU_PAGE_PREV,
|
||||
|
||||
IT_TOTAL
|
||||
};
|
||||
|
||||
enum KeyBindingMode {
|
||||
KBM_NONE = 0,
|
||||
KBM_GAME = 1,
|
||||
KBM_UI = 2
|
||||
};
|
||||
|
||||
// Constants related to menu size
|
||||
const int IG_START = IG_UP, IG_SIZE = IG_BLOCK - IG_START + 1;
|
||||
const int IU_START = IU_UP, IU_SIZE = IT_TOTAL - IU_START;
|
||||
|
||||
class InputManager {
|
||||
// Load key configuration from file
|
||||
void load(const Common::String &filename);
|
||||
|
||||
// The current version of the input scheme
|
||||
uint _version;
|
||||
|
||||
// The current mode of keymap applied
|
||||
KeyBindingMode _keyMode;
|
||||
|
||||
// The keybinds in string format for hotkeys and other places
|
||||
Common::String _keyDescs[IT_TOTAL];
|
||||
|
||||
public:
|
||||
InputManager() {
|
||||
_version = 0;
|
||||
_keyMode = KBM_GAME;
|
||||
|
||||
clearInputs();
|
||||
}
|
||||
|
||||
~InputManager() {}
|
||||
|
||||
static Common::Keymap *getDefaultKeyMapsForGame();
|
||||
static Common::Keymap *getDefaultKeyMapsForUI();
|
||||
static Common::Keymap *getDefaultKeyMapsForHUD();
|
||||
|
||||
void clearInputs() {
|
||||
for (int i = 0; i < IT_TOTAL; i++)
|
||||
_ivState[i] = false;
|
||||
}
|
||||
|
||||
void populateKeyTable();
|
||||
|
||||
void setKeyBindingMode(KeyBindingMode mode);
|
||||
|
||||
KeyBindingMode getKeyBindingMode() const {
|
||||
return _keyMode;
|
||||
}
|
||||
|
||||
// NOTE: The lower level arrays can have buttons in common, but buttons cannot be common within these arrays
|
||||
// Ex. UI and Fight can have buttons in common, but not two keys within UI
|
||||
|
||||
// Inputs used in the game
|
||||
Common::String _iv[IT_TOTAL];
|
||||
bool _ivState[IT_TOTAL];
|
||||
|
||||
// These functions return true if key is pressed, false otherwise
|
||||
bool state(const InputType &val);
|
||||
|
||||
Common::String getAssociatedKey(const InputType &type);
|
||||
|
||||
// Save and flush the keymaps to disk
|
||||
void save();
|
||||
};
|
||||
|
||||
} // End of namespace input
|
||||
} // End of namespace pyrodactyl
|
||||
|
||||
} // End of namespace Crab
|
||||
|
||||
#endif // CRAB_INPUT_H
|
||||
Reference in New Issue
Block a user