Merge branch 'master' of https://github.com/daniel-dressler/ppsspp into daniel-dressler-master

Conflicts:
	CMakeLists.txt
This commit is contained in:
Henrik Rydgård 2013-07-03 17:59:44 +02:00
commit c01a69df30
6 changed files with 290 additions and 324 deletions

View File

@ -581,7 +581,9 @@ add_library(native STATIC
native/input/gesture_detector.cpp
native/input/gesture_detector.h
native/input/input_state.cpp
native/input/keycodes.h
native/input/input_state.h
native/input/input_state.cpp
native/json/json_writer.cpp
native/json/json_writer.h
native/math/curves.cpp
@ -643,6 +645,7 @@ add_library(native STATIC
native/util/random/rng.h
native/util/text/utf8.h
native/util/text/utf8.cpp
native/util/const_map.h
native/ext/rapidxml/rapidxml.hpp
native/ext/rapidxml/rapidxml_iterators.hpp
native/ext/rapidxml/rapidxml_print.hpp

View File

@ -25,36 +25,23 @@ using namespace KeyMap;
// default
std::map<int,int> *platform_keymap = NULL;
// Default key mapping
// Ugly, yet the cleanest way
// I could find to create a
// static map.
// Still nicer than what
// I once did in C.
// TODO: Make use const_map.h from native
struct DefaultKeyMap {
static std::map<int,int> init()
{
std::map<int,int> m;
m[KEY_x] = PAD_BUTTON_A;
m[KEY_z] = PAD_BUTTON_B;
m[KEY_s] = PAD_BUTTON_X;
m[KEY_a] = PAD_BUTTON_Y;
m[KEY_q] = PAD_BUTTON_LBUMPER;
m[KEY_w] = PAD_BUTTON_RBUMPER;
m[KEY_SPACE] = PAD_BUTTON_START;
m[KEY_ENTER] = PAD_BUTTON_SELECT;
m[KEY_ARROW_UP] = PAD_BUTTON_UP;
m[KEY_ARROW_DOWN] = PAD_BUTTON_DOWN;
m[KEY_ARROW_LEFT] = PAD_BUTTON_LEFT;
m[KEY_ARROW_RIGHT] = PAD_BUTTON_RIGHT;
m[KEY_TAB] = PAD_BUTTON_MENU;
m[KEY_BACKSPACE] = PAD_BUTTON_BACK;
m[KEY_ANALOG_UP] = PAD_BUTTON_JOY_UP;
m[KEY_ANALOG_DOWN] = PAD_BUTTON_JOY_DOWN;
m[KEY_ANALOG_LEFT] = PAD_BUTTON_JOY_LEFT;
m[KEY_ANALOG_RIGHT] = PAD_BUTTON_JOY_RIGHT;
m[KEY_CTRL_LEFT] = PAD_BUTTON_LEFT_THUMB;
m[KEY_ALT_LEFT] = PAD_BUTTON_RIGHT_THUMB;
m[KEYCODE_X] = CTRL_SQUARE;
m[KEYCODE_Z] = CTRL_TRIANGLE;
m[KEYCODE_S] = CTRL_CIRCLE;
m[KEYCODE_A] = CTRL_CROSS;
m[KEYCODE_Q] = CTRL_LTRIGGER;
m[KEYCODE_W] = CTRL_RTRIGGER;
m[KEYCODE_SPACE] = CTRL_START;
m[KEYCODE_ENTER] = CTRL_SELECT;
m[KEYCODE_DPAD_UP] = CTRL_UP;
m[KEYCODE_DPAD_DOWN] = CTRL_DOWN;
m[KEYCODE_DPAD_LEFT] = CTRL_LEFT;
m[KEYCODE_DPAD_RIGHT] = CTRL_RIGHT;
return m;
}
static std::map<int,int> KeyMap;
@ -68,145 +55,83 @@ struct KeyMap_IntStrPair {
std::string name;
};
const KeyMap_IntStrPair key_names[] = {
{KEY_a, "a"},
{KEY_b, "b"},
{KEY_c, "c"},
{KEY_d, "d"},
{KEY_e, "e"},
{KEY_f, "f"},
{KEY_g, "g"},
{KEY_h, "h"},
{KEY_i, "i"},
{KEY_j, "j"},
{KEY_k, "k"},
{KEY_l, "l"},
{KEY_m, "m"},
{KEY_n, "n"},
{KEY_o, "o"},
{KEY_p, "p"},
{KEY_q, "q"},
{KEY_r, "r"},
{KEY_s, "s"},
{KEY_t, "t"},
{KEY_u, "u"},
{KEY_v, "v"},
{KEY_w, "w"},
{KEY_x, "x"},
{KEY_y, "y"},
{KEY_z, "z"},
{KEYCODE_A, "A"},
{KEYCODE_B, "B"},
{KEYCODE_C, "C"},
{KEYCODE_D, "D"},
{KEYCODE_E, "E"},
{KEYCODE_F, "F"},
{KEYCODE_G, "G"},
{KEYCODE_H, "H"},
{KEYCODE_I, "I"},
{KEYCODE_J, "J"},
{KEYCODE_K, "K"},
{KEYCODE_L, "L"},
{KEYCODE_M, "M"},
{KEYCODE_N, "N"},
{KEYCODE_O, "O"},
{KEYCODE_P, "P"},
{KEYCODE_Q, "Q"},
{KEYCODE_R, "R"},
{KEYCODE_S, "S"},
{KEYCODE_T, "T"},
{KEYCODE_U, "U"},
{KEYCODE_V, "V"},
{KEYCODE_W, "W"},
{KEYCODE_X, "X"},
{KEYCODE_Y, "Y"},
{KEYCODE_Z, "Z"},
{KEY_A, "A"},
{KEY_B, "B"},
{KEY_C, "C"},
{KEY_D, "D"},
{KEY_E, "E"},
{KEY_F, "F"},
{KEY_G, "G"},
{KEY_H, "H"},
{KEY_I, "I"},
{KEY_J, "J"},
{KEY_K, "K"},
{KEY_L, "L"},
{KEY_M, "M"},
{KEY_N, "N"},
{KEY_O, "O"},
{KEY_P, "P"},
{KEY_Q, "Q"},
{KEY_R, "R"},
{KEY_S, "S"},
{KEY_T, "T"},
{KEY_U, "U"},
{KEY_V, "V"},
{KEY_W, "W"},
{KEY_X, "X"},
{KEY_Y, "Y"},
{KEY_Z, "Z"},
{KEY_1, "1"},
{KEY_2, "2"},
{KEY_3, "3"},
{KEY_4, "4"},
{KEY_5, "5"},
{KEY_6, "6"},
{KEY_7, "7"},
{KEY_8, "8"},
{KEY_9, "9"},
{KEY_0, "0"},
{KEYCODE_1, "1"},
{KEYCODE_2, "2"},
{KEYCODE_3, "3"},
{KEYCODE_4, "4"},
{KEYCODE_5, "5"},
{KEYCODE_6, "6"},
{KEYCODE_7, "7"},
{KEYCODE_8, "8"},
{KEYCODE_9, "9"},
{KEYCODE_0, "0"},
{KEY_BACKSPACE, "Backspace"},
{KEY_TAB, "Tab"},
{KEY_ENTER, "Enter"},
{KEY_SHIFT_LEFT, "Shift"},
{KEY_SHIFT_RIGHT, "Shift"},
{KEY_CTRL_LEFT, "Ctrl"},
{KEY_CTRL_RIGHT, "Ctrl"},
{KEY_ALT_LEFT, "Alt"},
{KEY_ALT_RIGHT, "Alt"},
{KEY_SPACE, "Space"},
{KEY_SUPER, "Super"},
{KEY_SPACE, "Space"},
{KEYCODE_BACK, "Back"},
{KEYCODE_TAB, "Tab"},
{KEYCODE_ENTER, "Enter"},
{KEYCODE_SHIFT_LEFT, "Shift"},
{KEYCODE_SHIFT_RIGHT, "Shift"},
{KEYCODE_CTRL_LEFT, "Ctrl"},
{KEYCODE_CTRL_RIGHT, "Ctrl"},
{KEYCODE_ALT_LEFT, "Alt"},
{KEYCODE_ALT_RIGHT, "Alt"},
{KEYCODE_SPACE, "Space"},
{KEYCODE_WINDOW, "Windows"},
{KEY_VOLUME_UP, "Vol Up"},
{KEY_VOLUME_DOWN, "Vol Down"},
{KEY_HOME, "Home"},
{KEY_CALL_START, "Start Call"},
{KEY_CALL_END, "End Call"},
{KEYCODE_VOLUME_UP, "Vol Up"},
{KEYCODE_VOLUME_DOWN, "Vol Down"},
{KEYCODE_HOME, "Home"},
{KEYCODE_CALL, "Start Call"},
{KEYCODE_ENDCALL, "End Call"},
{KEY_FASTFORWARD, "Fast foward"},
{KEY_ARROW_LEFT, "Left"},
{KEY_ARROW_UP, "Up"},
{KEY_ARROW_RIGHT, "Right"},
{KEY_ARROW_DOWN, "Down"},
{KEY_ANALOG_LEFT, "Analog Left"},
{KEY_ANALOG_UP, "Analog Up"},
{KEY_ANALOG_RIGHT, "Analog Right"},
{KEY_ANALOG_DOWN, "Analog Down"},
{KEY_ANALOG_ALT_LEFT, "Alt analog Left"},
{KEY_ANALOG_ALT_UP, "Alt analog Up"},
{KEY_ANALOG_ALT_RIGHT, "Alt analog Right"},
{KEY_ANALOG_ALT_DOWN, "Alt analog Down"},
{KEY_EXTRA1, "Extra1"},
{KEY_EXTRA2, "Extra2"},
{KEY_EXTRA3, "Extra3"},
{KEY_EXTRA4, "Extra4"},
{KEY_EXTRA5, "Extra5"},
{KEY_EXTRA6, "Extra6"},
{KEY_EXTRA7, "Extra7"},
{KEY_EXTRA8, "Extra8"},
{KEY_EXTRA9, "Extra9"},
{KEY_EXTRA0, "Extra0"},
{KEYCODE_DPAD_LEFT, "Left"},
{KEYCODE_DPAD_UP, "Up"},
{KEYCODE_DPAD_RIGHT, "Right"},
{KEYCODE_DPAD_DOWN, "Down"},
};
static int key_names_count = sizeof(key_names) / sizeof(key_names[0]);
static std::string unknown_key_name = "Unknown";
const KeyMap_IntStrPair psp_button_names[] = {
{PAD_BUTTON_A, ""},
{PAD_BUTTON_B, ""},
{PAD_BUTTON_X, ""},
{PAD_BUTTON_Y, ""},
{PAD_BUTTON_LBUMPER, "L"},
{PAD_BUTTON_RBUMPER, "R"},
{PAD_BUTTON_START, "Start"},
{PAD_BUTTON_SELECT, "Select"},
{PAD_BUTTON_UP, "Up"},
{PAD_BUTTON_DOWN, "Down"},
{PAD_BUTTON_LEFT, "Left"},
{PAD_BUTTON_RIGHT, "Right"},
{PAD_BUTTON_MENU, "Menu"},
{PAD_BUTTON_BACK, "Back"},
{PAD_BUTTON_JOY_UP, "Analog Up"},
{PAD_BUTTON_JOY_DOWN, "Analog Down"},
{PAD_BUTTON_JOY_LEFT, "Analog Left"},
{PAD_BUTTON_JOY_RIGHT, "Analog Right"},
{PAD_BUTTON_LEFT_THUMB, "Left analog click"},
{PAD_BUTTON_RIGHT_THUMB, "Right analog click"},
{CTRL_CIRCLE, ""},
{CTRL_CROSS, ""},
{CTRL_SQUARE, ""},
{CTRL_TRIANGLE, ""},
{CTRL_LTRIGGER, "L"},
{CTRL_RTRIGGER, "R"},
{CTRL_START, "Start"},
{CTRL_SELECT, "Select"},
{CTRL_UP, "Up"},
{CTRL_DOWN, "Down"},
{CTRL_LEFT, "Left"},
{CTRL_RIGHT, "Right"},
};
static int psp_button_names_count = sizeof(psp_button_names) / sizeof(psp_button_names[0]);
@ -220,20 +145,20 @@ static std::string FindName(int key, const KeyMap_IntStrPair list[], int size)
return unknown_key_name;
}
static std::string KeyMap::GetKeyName(KeyMap::Key key)
std::string KeyMap::GetKeyName(int key)
{
return FindName((int)key, key_names, key_names_count);
return FindName(key, key_names, key_names_count);
}
static std::string KeyMap::GetPspButtonName(int btn)
std::string KeyMap::GetPspButtonName(int btn)
{
return FindName(btn, key_names, key_names_count);
return FindName(btn, psp_button_names, psp_button_names_count);
}
static bool FindKeyMapping(int key, int *map_id, int *psp_button)
{
std::map<int,int>::iterator it;
if (*map_id >= 0) {
if (*map_id <= 0) {
// check user configuration
std::map<int,int> user_map = g_Config.iMappingMap;
it = user_map.find(key);
@ -244,7 +169,7 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button)
}
}
if (*map_id >= 1 && platform_keymap != NULL) {
if (*map_id <= 1 && platform_keymap != NULL) {
// check optional platform specific keymap
std::map<int,int> port_map = *platform_keymap;
it = port_map.find(key);
@ -255,13 +180,13 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button)
}
}
if (*map_id >= 2) {
if (*map_id <= 2) {
// check default keymap
const std::map<int,int> default_map = DefaultKeyMap::KeyMap;
const std::map<int,int>::const_iterator it = default_map.find(key);
if (it != default_map.end()) {
const std::map<int,int>::const_iterator const_it = default_map.find(key);
if (const_it != default_map.end()) {
*map_id = 2;
*psp_button = it->second;
*psp_button = const_it->second;
return true;
}
}
@ -272,36 +197,36 @@ static bool FindKeyMapping(int key, int *map_id, int *psp_button)
static int KeyMap::KeyToPspButton(const KeyMap::Key key)
int KeyMap::KeyToPspButton(const int key)
{
int search_start_layer = 0;
int psp_button;
if (FindKeyMapping((int)key, &search_start_layer, &psp_button))
if (FindKeyMapping(key, &search_start_layer, &psp_button))
return psp_button;
return KEYMAP_ERROR_UNKNOWN_KEY;
}
static bool KeyMap::IsMappedKey(Key key)
bool KeyMap::IsMappedKey(int key)
{
return KeyMap::KeyToPspButton(key) != KEYMAP_ERROR_UNKNOWN_KEY;
}
static std::string KeyMap::NamePspButtonFromKey(KeyMap::Key key)
std::string KeyMap::NamePspButtonFromKey(int key)
{
return KeyMap::GetPspButtonName(KeyMap::KeyToPspButton(key));
}
static std::string KeyMap::NameKeyFromPspButton(int btn)
std::string KeyMap::NameKeyFromPspButton(int btn)
{
// We drive our iteration
// with the list of key names.
for (int i = 0; i < key_names_count; i++) {
const struct KeyMap_IntStrPair *key_name = key_names + i;
if (btn == KeyMap::KeyToPspButton((KeyMap::Key)key_name->key))
return key_name->name;
const struct KeyMap_IntStrPair key_name = key_names[i];
if (btn == KeyMap::KeyToPspButton(key_name.key))
return key_name.name;
}
// all psp buttons are mapped from some key
@ -310,7 +235,7 @@ static std::string KeyMap::NameKeyFromPspButton(int btn)
return unknown_key_name;
}
static int KeyMap::SetKeyMapping(KeyMap::Key key, int btn)
int KeyMap::SetKeyMapping(int key, int btn)
{
if (KeyMap::IsMappedKey(key))
return KEYMAP_ERROR_KEY_ALREADY_USED;
@ -319,7 +244,7 @@ static int KeyMap::SetKeyMapping(KeyMap::Key key, int btn)
return btn;
}
static int KeyMap::RegisterPlatformDefaultKeyMap(std::map<int,int> *overriding_map)
int KeyMap::RegisterPlatformDefaultKeyMap(std::map<int,int> *overriding_map)
{
if (overriding_map == NULL)
return 1;
@ -327,7 +252,7 @@ static int KeyMap::RegisterPlatformDefaultKeyMap(std::map<int,int> *overriding_m
return 0;
}
static void KeyMap::DeregisterPlatformDefaultKeyMap(void)
void KeyMap::DeregisterPlatformDefaultKeyMap(void)
{
platform_keymap = NULL;
return;

View File

@ -19,6 +19,8 @@
#include <string>
#include <map>
#include "input/keycodes.h" // keyboard keys
#include "Core/HLE/sceCtrl.h" // psp keys
#define KEYMAP_ERROR_KEY_ALREADY_USED -1
#define KEYMAP_ERROR_UNKNOWN_KEY 0
@ -38,146 +40,14 @@
// Then have KeyMap transform
// those into psp buttons.
namespace KeyMap {
enum Key {
// Lower class latin
KEY_q = 1, // top row
KEY_w,
KEY_e,
KEY_r,
KEY_t,
KEY_y,
KEY_u,
KEY_i,
KEY_o,
KEY_p,
KEY_a, // mid row
KEY_s,
KEY_d,
KEY_f,
KEY_g,
KEY_h,
KEY_j,
KEY_k,
KEY_l,
KEY_z, // low row
KEY_x,
KEY_c,
KEY_v,
KEY_b,
KEY_n,
KEY_m,
// Upper class latin
KEY_Q, // top row
KEY_W,
KEY_E,
KEY_R,
KEY_T,
KEY_Y,
KEY_U,
KEY_I,
KEY_O,
KEY_P,
KEY_A, // mid row
KEY_S,
KEY_D,
KEY_F,
KEY_G,
KEY_H,
KEY_J,
KEY_K,
KEY_L,
KEY_Z, // low row
KEY_X,
KEY_C,
KEY_V,
KEY_B,
KEY_N,
KEY_M,
// Numeric
KEY_1,
KEY_2,
KEY_3,
KEY_4,
KEY_5,
KEY_6,
KEY_7,
KEY_8,
KEY_9,
KEY_0,
// Special keys
KEY_ARROW_LEFT,
KEY_ARROW_RIGHT,
KEY_ARROW_UP,
KEY_ARROW_DOWN,
KEY_ANALOG_LEFT,
KEY_ANALOG_RIGHT,
KEY_ANALOG_UP,
KEY_ANALOG_DOWN,
KEY_ANALOG_ALT_LEFT,
KEY_ANALOG_ALT_RIGHT,
KEY_ANALOG_ALT_UP,
KEY_ANALOG_ALT_DOWN,
KEY_SPACE,
KEY_ENTER,
KEY_CTRL_LEFT,
KEY_CTRL_RIGHT,
KEY_SHIFT_LEFT,
KEY_SHIFT_RIGHT,
KEY_ALT_LEFT,
KEY_ALT_RIGHT,
KEY_BACKSPACE,
KEY_SUPER,
KEY_TAB,
// Mobile Keys
KEY_VOLUME_UP,
KEY_VOLUME_DOWN,
KEY_HOME,
KEY_CALL_START,
KEY_CALL_END,
// Special PPSSPP keys
KEY_FASTFORWARD,
// Extra keys
// Use for platform specific keys.
// Example: android's back btn
KEY_EXTRA1,
KEY_EXTRA2,
KEY_EXTRA3,
KEY_EXTRA4,
KEY_EXTRA5,
KEY_EXTRA6,
KEY_EXTRA7,
KEY_EXTRA8,
KEY_EXTRA9,
KEY_EXTRA0,
// TODO: Add any missing keys.
// Many can be found in the
// window's port's keyboard
// files.
};
// Use if you need to
// display the textual
// name
// These functions are not
// fast, do not call them
// a million times.
static std::string GetKeyName(Key);
static std::string GetPspButtonName(int);
std::string GetKeyName(int);
std::string GetPspButtonName(int);
// Use if to translate
// KeyMap Keys to PSP
@ -189,18 +59,18 @@ namespace KeyMap {
//
// Returns KEYMAP_ERROR_UNKNOWN_KEY
// for any unmapped key
static int KeyToPspButton(Key);
int KeyToPspButton(int);
static bool IsMappedKey(Key);
bool IsMappedKey(int);
// Might be usful if you want
// to provide hints to users
// upon mapping conflicts
static std::string NamePspButtonFromKey(Key);
std::string NamePspButtonFromKey(int);
// Use for showing the existing
// key mapping.
static std::string NameKeyFromPspButton(int);
std::string NameKeyFromPspButton(int);
// Configure the key mapping.
// Any configuration will
@ -209,7 +79,7 @@ namespace KeyMap {
//
// Returns KEYMAP_ERROR_KEY_ALREADY_USED
// for mapping conflicts. 0 otherwise.
static int SetKeyMapping(Key, int);
int SetKeyMapping(int kb_key, int psp_key);
// Platform specific keymaps
// override KeyMap's defaults.
@ -220,7 +90,7 @@ namespace KeyMap {
// all psp buttons.
// Any buttons missing will
// fallback to KeyMap's keymap.
static int RegisterPlatformDefaultKeyMap(std::map<int,int> *);
static void DeregisterPlatformDefaultKeyMap(void);
int RegisterPlatformDefaultKeyMap(std::map<int,int> *);
void DeregisterPlatformDefaultKeyMap(void);
}

View File

@ -25,6 +25,8 @@
#include "ui/ui.h"
#include "i18n/i18n.h"
#include "Common/KeyMap.h"
#include "Core/Config.h"
#include "Core/CoreTiming.h"
#include "Core/CoreParameter.h"
@ -200,6 +202,11 @@ void EmuScreen::update(InputState &input) {
}
#endif
// Set Keys ----
__CtrlButtonUp(-1); // blanks all buttons
uint32_t pressed = 0;
// Legacy key mapping
// Then translate pad input into PSP pad input. Also, add in tilt.
static const int mapping[12][2] = {
{PAD_BUTTON_A, CTRL_CROSS},
@ -217,14 +224,21 @@ void EmuScreen::update(InputState &input) {
};
for (int i = 0; i < 12; i++) {
if (input.pad_buttons_down & mapping[i][0]) {
__CtrlButtonDown(mapping[i][1]);
}
if (input.pad_buttons_up & mapping[i][0]) {
__CtrlButtonUp(mapping[i][1]);
}
pressed |= input.pad_buttons_down & mapping[i][0];
}
// Modern key mapping
for (int i = 0; i < MAX_KEYQUEUESIZE; i++) {
int key = input.key_queue[i];
if (key == 0)
break;
// TODO: Add virt_sce_* codes for analog sticks
pressed |= KeyMap::KeyToPspButton(key);
}
__CtrlButtonDown(pressed);
// End Set Keys --
float stick_x = input.pad_lstick_x;
float stick_y = input.pad_lstick_y;
float rightstick_x = input.pad_rstick_x;

View File

@ -42,6 +42,7 @@
#include "UIShader.h"
#include "Common/StringUtils.h"
#include "Common/KeyMap.h"
#include "Core/System.h"
#include "Core/CoreParameter.h"
#include "Core/HW/atrac3plus.h"
@ -622,6 +623,7 @@ void SettingsScreen::render() {
UIEnd();
}
// TODO: Move these into a superclass
void DeveloperScreen::update(InputState &input) {
if (input.pad_buttons_down & PAD_BUTTON_BACK) {
g_Config.Save();
@ -671,6 +673,25 @@ void ControlsScreen::update(InputState &input) {
}
}
void KeyMappingScreen::update(InputState &input) {
if (input.pad_buttons_down & PAD_BUTTON_BACK) {
g_Config.Save();
screenManager()->finishDialog(this, DR_OK);
}
}
void KeyMappingNewKeyDialog::update(InputState &input) {
int new_key = input.key_queue[0];
if (new_key != 0)
last_kb_key = new_key;
if (input.pad_buttons_down & PAD_BUTTON_BACK) {
g_Config.Save();
screenManager()->finishDialog(this, DR_OK);
}
}
void LanguageScreen::update(InputState &input) {
if (input.pad_buttons_down & PAD_BUTTON_BACK) {
g_Config.Save();
@ -1485,6 +1506,117 @@ void ControlsScreen::render() {
g_Config.iTouchButtonOpacity = bTransparent ? 15 : 65;
}
// Button to KeyMapping screen
I18NCategory *keyI18N = GetI18NCategory("KeyMapping");
if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Key Mapping"), ALIGN_BOTTOMLEFT)) {
screenManager()->push(new KeyMappingScreen());
}
UIEnd();
}
void KeyMappingScreen::render() {
UIShader_Prepare();
UIBegin(UIShader_Get());
DrawBackground(1.0f);
I18NCategory *keyI18N = GetI18NCategory("KeyMapping");
I18NCategory *generalI18N = GetI18NCategory("General");
#define KeyBtn(x, y, symbol) \
if (UIButton(GEN_ID, Pos(x, y), 50, 0, (KeyMap::GetPspButtonName(symbol)).c_str(), \
ALIGN_TOPLEFT)) {\
screenManager()->push(new KeyMappingNewKeyDialog(symbol), 0); \
UIReset(); \
}
KeyMap::DeregisterPlatformDefaultKeyMap();
int pad = 150;
int hlfpad = pad / 2;
int left = 30;
KeyBtn(left, 30, CTRL_LTRIGGER);
KeyBtn(dp_yres, 30, CTRL_RTRIGGER);
int top = 100;
KeyBtn(left+hlfpad, top, CTRL_UP); // ^
KeyBtn(left, top+hlfpad, CTRL_LEFT);// <
KeyBtn(left+pad, top+hlfpad, CTRL_RIGHT); // >
KeyBtn(left+hlfpad, top+pad, CTRL_DOWN); // <
left = dp_yres;
KeyBtn(left+hlfpad, top, CTRL_TRIANGLE); // Triangle
KeyBtn(left, top+hlfpad, CTRL_SQUARE); // Square
KeyBtn(left+pad, top+hlfpad, CTRL_CIRCLE); // Circle
KeyBtn(left+hlfpad, top+pad, CTRL_CROSS); // Cross
top += pad;
left = dp_yres /2;
KeyBtn(left, top, CTRL_START);
KeyBtn(left + pad, top, CTRL_SELECT);
#undef KeyBtn
if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Back"), ALIGN_RIGHT | ALIGN_BOTTOM)) {
screenManager()->finishDialog(this, DR_OK);
}
UIEnd();
}
void KeyMappingNewKeyDialog::render() {
UIShader_Prepare();
UIBegin(UIShader_Get());
DrawBackground(1.0f);
I18NCategory *keyI18N = GetI18NCategory("KeyMapping");
I18NCategory *generalI18N = GetI18NCategory("General");
#define KeyText(x, y, sentence) \
ui_draw2d.DrawText(UBUNTU24, (sentence), x, y, 0xFFFFFFFF, ALIGN_TOPLEFT);
#define KeyScale(width) \
ui_draw2d.SetFontScale(width, width);
int top = 10;
int left = 10;
int stride = 70;
KeyScale(1.6f);
KeyText(left, top, keyI18N->T("Map a new key for button: "));
KeyText(left, top += stride, (KeyMap::GetPspButtonName(this->pspBtn)).c_str());
KeyScale(1.3f);
KeyText(left, top += stride, keyI18N->T("Current key"));
KeyScale(2.0f);
KeyText(left, top + stride, (KeyMap::NameKeyFromPspButton(this->pspBtn)).c_str());
int right = dp_yres;
KeyScale(1.4f);
KeyText(right, top, keyI18N->T("New Key"));
KeyScale(2.0f);
if (last_kb_key != 0) {
bool key_used = KeyMap::IsMappedKey(last_kb_key);
if (!key_used) {
KeyText(right, top + stride, KeyMap::GetKeyName(last_kb_key).c_str());
} else {
KeyScale(1.0f);
KeyText(left + stride, top + 2*stride,
keyI18N->T("Error: Key is already used"));
}
}
KeyScale(1.0f);
#undef KeyText
#undef KeyScale
// Save & cancel buttons
if (UIButton(GEN_ID, Pos(10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, keyI18N->T("Save Mapping"), ALIGN_LEFT | ALIGN_BOTTOM)) {
KeyMap::SetKeyMapping(this->last_kb_key, this->pspBtn);
g_Config.Save();
screenManager()->finishDialog(this, DR_OK);
}
if (UIButton(GEN_ID, Pos(dp_xres - 10, dp_yres - 10), LARGE_BUTTON_WIDTH, 0, generalI18N->T("Cancel"), ALIGN_RIGHT | ALIGN_BOTTOM)) {
screenManager()->finishDialog(this, DR_OK);
}
UIEnd();
}

View File

@ -132,6 +132,28 @@ public:
void render();
};
class KeyMappingScreen : public Screen
{
public:
void update(InputState &input);
void render();
};
// Dialog box, meant to be pushed
class KeyMappingNewKeyDialog : public Screen
{
private:
int pspBtn;
int last_kb_key;
public:
KeyMappingNewKeyDialog(int btn) {
pspBtn = btn;
last_kb_key = 0;
}
void update(InputState &input);
void render();
};
struct FileSelectScreenOptions {
const char* filter; // Enforced extension filter. Case insensitive, extensions separated by ":".
bool allowChooseDirectory;