Added optional config ini file for configuring key mappings used by Edit Mode.

This commit is contained in:
Kyzentun
2014-11-17 04:24:20 -07:00
parent 9b847caa45
commit a5d9f029f3
7 changed files with 452 additions and 1 deletions
+1 -1
View File
@@ -639,7 +639,7 @@ const InputScheme *InputMapper::GetInputScheme() const
return m_pInputScheme;
}
static const RString DEVICE_INPUT_SEPARATOR = ":"; // this isn't used in any key names
const RString DEVICE_INPUT_SEPARATOR = ":"; // this isn't used in any key names
void InputMapper::ReadMappingsFromDisk()
{
+1
View File
@@ -9,6 +9,7 @@ struct Game;
const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one game input
const int NUM_SHOWN_GAME_TO_DEVICE_SLOTS = 3;
const int NUM_USER_GAME_TO_DEVICE_SLOTS = 2;
extern const RString DEVICE_INPUT_SEPARATOR;
struct AutoMappingEntry
{
+155
View File
@@ -30,6 +30,7 @@
#include "ScreenTextEntry.h"
#include "SongManager.h"
#include "SongUtil.h"
#include "SpecialFiles.h"
#include "StepsUtil.h"
#include "Style.h"
#include "ThemeManager.h"
@@ -115,8 +116,120 @@ static const char *EditStateNames[] = {
XToString( EditState );
LuaXType( EditState );
map<RString, EditButton> name_to_edit_button;
void ScreenEdit::InitEditMappings()
{
// Created courtesy of query replace regex.
name_to_edit_button["COLUMN_0"]= EDIT_BUTTON_COLUMN_0;
name_to_edit_button["COLUMN_1"]= EDIT_BUTTON_COLUMN_1;
name_to_edit_button["COLUMN_2"]= EDIT_BUTTON_COLUMN_2;
name_to_edit_button["COLUMN_3"]= EDIT_BUTTON_COLUMN_3;
name_to_edit_button["COLUMN_4"]= EDIT_BUTTON_COLUMN_4;
name_to_edit_button["COLUMN_5"]= EDIT_BUTTON_COLUMN_5;
name_to_edit_button["COLUMN_6"]= EDIT_BUTTON_COLUMN_6;
name_to_edit_button["COLUMN_7"]= EDIT_BUTTON_COLUMN_7;
name_to_edit_button["COLUMN_8"]= EDIT_BUTTON_COLUMN_8;
name_to_edit_button["COLUMN_9"]= EDIT_BUTTON_COLUMN_9;
name_to_edit_button["RIGHT_SIDE"]= EDIT_BUTTON_RIGHT_SIDE;
name_to_edit_button["LAY_ROLL"]= EDIT_BUTTON_LAY_ROLL;
name_to_edit_button["LAY_TAP_ATTACK"]= EDIT_BUTTON_LAY_TAP_ATTACK;
name_to_edit_button["REMOVE_NOTE"]= EDIT_BUTTON_REMOVE_NOTE;
name_to_edit_button["CYCLE_TAP_LEFT"]= EDIT_BUTTON_CYCLE_TAP_LEFT;
name_to_edit_button["CYCLE_TAP_RIGHT"]= EDIT_BUTTON_CYCLE_TAP_RIGHT;
name_to_edit_button["CYCLE_SEGMENT_LEFT"]= EDIT_BUTTON_CYCLE_SEGMENT_LEFT;
name_to_edit_button["CYCLE_SEGMENT_RIGHT"]= EDIT_BUTTON_CYCLE_SEGMENT_RIGHT;
name_to_edit_button["SCROLL_UP_LINE"]= EDIT_BUTTON_SCROLL_UP_LINE;
name_to_edit_button["SCROLL_UP_PAGE"]= EDIT_BUTTON_SCROLL_UP_PAGE;
name_to_edit_button["SCROLL_UP_TS"]= EDIT_BUTTON_SCROLL_UP_TS;
name_to_edit_button["SCROLL_DOWN_LINE"]= EDIT_BUTTON_SCROLL_DOWN_LINE;
name_to_edit_button["SCROLL_DOWN_PAGE"]= EDIT_BUTTON_SCROLL_DOWN_PAGE;
name_to_edit_button["SCROLL_DOWN_TS"]= EDIT_BUTTON_SCROLL_DOWN_TS;
name_to_edit_button["SCROLL_NEXT_MEASURE"]= EDIT_BUTTON_SCROLL_NEXT_MEASURE;
name_to_edit_button["SCROLL_PREV_MEASURE"]= EDIT_BUTTON_SCROLL_PREV_MEASURE;
name_to_edit_button["SCROLL_HOME"]= EDIT_BUTTON_SCROLL_HOME;
name_to_edit_button["SCROLL_END"]= EDIT_BUTTON_SCROLL_END;
name_to_edit_button["SCROLL_NEXT"]= EDIT_BUTTON_SCROLL_NEXT;
name_to_edit_button["SCROLL_PREV"]= EDIT_BUTTON_SCROLL_PREV;
name_to_edit_button["SEGMENT_NEXT"]= EDIT_BUTTON_SEGMENT_NEXT;
name_to_edit_button["SEGMENT_PREV"]= EDIT_BUTTON_SEGMENT_PREV;
name_to_edit_button["SCROLL_SELECT"]= EDIT_BUTTON_SCROLL_SELECT;
name_to_edit_button["LAY_SELECT"]= EDIT_BUTTON_LAY_SELECT;
name_to_edit_button["SCROLL_SPEED_UP"]= EDIT_BUTTON_SCROLL_SPEED_UP;
name_to_edit_button["SCROLL_SPEED_DOWN"]= EDIT_BUTTON_SCROLL_SPEED_DOWN;
name_to_edit_button["SNAP_NEXT"]= EDIT_BUTTON_SNAP_NEXT;
name_to_edit_button["SNAP_PREV"]= EDIT_BUTTON_SNAP_PREV;
name_to_edit_button["OPEN_EDIT_MENU"]= EDIT_BUTTON_OPEN_EDIT_MENU;
name_to_edit_button["OPEN_TIMING_MENU"]= EDIT_BUTTON_OPEN_TIMING_MENU;
name_to_edit_button["OPEN_ALTER_MENU"]= EDIT_BUTTON_OPEN_ALTER_MENU;
name_to_edit_button["OPEN_AREA_MENU"]= EDIT_BUTTON_OPEN_AREA_MENU;
name_to_edit_button["OPEN_BGCHANGE_LAYER1_MENU"]= EDIT_BUTTON_OPEN_BGCHANGE_LAYER1_MENU;
name_to_edit_button["OPEN_BGCHANGE_LAYER2_MENU"]= EDIT_BUTTON_OPEN_BGCHANGE_LAYER2_MENU;
name_to_edit_button["OPEN_COURSE_MENU"]= EDIT_BUTTON_OPEN_COURSE_MENU;
name_to_edit_button["OPEN_COURSE_ATTACK_MENU"]= EDIT_BUTTON_OPEN_COURSE_ATTACK_MENU;
name_to_edit_button["OPEN_STEP_ATTACK_MENU"]= EDIT_BUTTON_OPEN_STEP_ATTACK_MENU;
name_to_edit_button["ADD_STEP_MODS"]= EDIT_BUTTON_ADD_STEP_MODS;
name_to_edit_button["OPEN_INPUT_HELP"]= EDIT_BUTTON_OPEN_INPUT_HELP;
name_to_edit_button["BAKE_RANDOM_FROM_SONG_GROUP"]= EDIT_BUTTON_BAKE_RANDOM_FROM_SONG_GROUP;
name_to_edit_button["BAKE_RANDOM_FROM_SONG_GROUP_AND_GENRE"]= EDIT_BUTTON_BAKE_RANDOM_FROM_SONG_GROUP_AND_GENRE;
name_to_edit_button["PLAY_FROM_START"]= EDIT_BUTTON_PLAY_FROM_START;
name_to_edit_button["PLAY_FROM_CURSOR"]= EDIT_BUTTON_PLAY_FROM_CURSOR;
name_to_edit_button["PLAY_SELECTION"]= EDIT_BUTTON_PLAY_SELECTION;
name_to_edit_button["RECORD_FROM_CURSOR"]= EDIT_BUTTON_RECORD_FROM_CURSOR;
name_to_edit_button["RECORD_SELECTION"]= EDIT_BUTTON_RECORD_SELECTION;
name_to_edit_button["RETURN_TO_EDIT"]= EDIT_BUTTON_RETURN_TO_EDIT;
name_to_edit_button["INSERT"]= EDIT_BUTTON_INSERT;
name_to_edit_button["DELETE"]= EDIT_BUTTON_DELETE;
name_to_edit_button["INSERT_SHIFT_PAUSES"]= EDIT_BUTTON_INSERT_SHIFT_PAUSES;
name_to_edit_button["DELETE_SHIFT_PAUSES"]= EDIT_BUTTON_DELETE_SHIFT_PAUSES;
name_to_edit_button["OPEN_NEXT_STEPS"]= EDIT_BUTTON_OPEN_NEXT_STEPS;
name_to_edit_button["OPEN_PREV_STEPS"]= EDIT_BUTTON_OPEN_PREV_STEPS;
name_to_edit_button["PLAY_SAMPLE_MUSIC"]= EDIT_BUTTON_PLAY_SAMPLE_MUSIC;
name_to_edit_button["BPM_UP"]= EDIT_BUTTON_BPM_UP;
name_to_edit_button["BPM_DOWN"]= EDIT_BUTTON_BPM_DOWN;
name_to_edit_button["STOP_UP"]= EDIT_BUTTON_STOP_UP;
name_to_edit_button["STOP_DOWN"]= EDIT_BUTTON_STOP_DOWN;
name_to_edit_button["DELAY_UP"]= EDIT_BUTTON_DELAY_UP;
name_to_edit_button["DELAY_DOWN"]= EDIT_BUTTON_DELAY_DOWN;
name_to_edit_button["OFFSET_UP"]= EDIT_BUTTON_OFFSET_UP;
name_to_edit_button["OFFSET_DOWN"]= EDIT_BUTTON_OFFSET_DOWN;
name_to_edit_button["SAMPLE_START_UP"]= EDIT_BUTTON_SAMPLE_START_UP;
name_to_edit_button["SAMPLE_START_DOWN"]= EDIT_BUTTON_SAMPLE_START_DOWN;
name_to_edit_button["SAMPLE_LENGTH_UP"]= EDIT_BUTTON_SAMPLE_LENGTH_UP;
name_to_edit_button["SAMPLE_LENGTH_DOWN"]= EDIT_BUTTON_SAMPLE_LENGTH_DOWN;
name_to_edit_button["ADJUST_FINE"]= EDIT_BUTTON_ADJUST_FINE;
name_to_edit_button["SAVE"]= EDIT_BUTTON_SAVE;
name_to_edit_button["UNDO"]= EDIT_BUTTON_UNDO;
name_to_edit_button["ADD_COURSE_MODS"]= EDIT_BUTTON_ADD_COURSE_MODS;
name_to_edit_button["SWITCH_PLAYERS"]= EDIT_BUTTON_SWITCH_PLAYERS;
name_to_edit_button["SWITCH_TIMINGS"]= EDIT_BUTTON_SWITCH_TIMINGS;
m_EditMappingsDeviceInput.Clear();
// Common mappings:
@@ -381,8 +494,50 @@ void ScreenEdit::InitEditMappings()
m_RecordPausedMappingsDeviceInput.button[EDIT_BUTTON_RETURN_TO_EDIT][0] = DeviceInput(DEVICE_KEYBOARD, KEY_ESC);
m_RecordPausedMappingsMenuButton.button[EDIT_BUTTON_RETURN_TO_EDIT][1] = GAME_BUTTON_BACK;
m_RecordPausedMappingsDeviceInput.button[EDIT_BUTTON_UNDO][0] = DeviceInput(DEVICE_KEYBOARD, KEY_Cu);
IniFile mapping_ini;
// Only use the mappings file if it exists. It's meant to be optional, and
// only used in rare cases like someone having critical keys broken. -Kyz
if(mapping_ini.ReadFile(SpecialFiles::EDIT_MODE_KEYMAPS_PATH))
{
LoadKeymapSectionIntoMappingsMember(mapping_ini.GetChild("Edit"),
m_EditMappingsDeviceInput);
LoadKeymapSectionIntoMappingsMember(mapping_ini.GetChild("Play"),
m_PlayMappingsDeviceInput);
LoadKeymapSectionIntoMappingsMember(mapping_ini.GetChild("Record"),
m_RecordMappingsDeviceInput);
LoadKeymapSectionIntoMappingsMember(mapping_ini.GetChild("RecordPaused"),
m_RecordPausedMappingsDeviceInput);
}
}
void ScreenEdit::LoadKeymapSectionIntoMappingsMember(XNode const* section, MapEditToDI& mappings)
{
if(section == NULL) {return;} // Not an error, sections are optional. -Kyz
FOREACH_CONST_Attr(section, attr)
{
map<RString, EditButton>::iterator name_entry=
name_to_edit_button.find(attr->first);
if(name_entry != name_to_edit_button.end())
{
RString joined_names;
attr->second->GetValue(joined_names);
vector<RString> key_names;
split(joined_names, DEVICE_INPUT_SEPARATOR, key_names, false);
for(size_t k= 0; k < key_names.size() && k < NUM_EDIT_TO_DEVICE_SLOTS; ++k)
{
DeviceInput devi;
devi.FromString(key_names[k]);
if(devi.IsValid())
{
mappings.button[name_entry->second][k]= devi;
}
}
}
}
}
/* Given a DeviceInput that was just depressed, return an active edit function. */
EditButton ScreenEdit::DeviceToEdit( const DeviceInput &DeviceI ) const
{
+3
View File
@@ -39,6 +39,7 @@ LuaDeclareType( EditState );
enum EditButton
{
// Add to the name_to_edit_button list when adding to this enum. -Kyz
EDIT_BUTTON_COLUMN_0,
EDIT_BUTTON_COLUMN_1,
EDIT_BUTTON_COLUMN_2,
@@ -151,6 +152,7 @@ enum EditButton
EDIT_BUTTON_SWITCH_TIMINGS, /**< Allow switching between Song and Step TimingData. */
// Add to the name_to_edit_button list when adding to this enum. -Kyz
NUM_EditButton, // leave this at the end
EditButton_Invalid
};
@@ -665,6 +667,7 @@ public:
bool EditIsBeingPressed( EditButton button ) const;
const MapEditToDI *GetCurrentDeviceInputMap() const;
const MapEditButtonToMenuButton *GetCurrentMenuButtonMap() const;
void LoadKeymapSectionIntoMappingsMember(XNode const* section, MapEditToDI& mappings);
MapEditToDI m_EditMappingsDeviceInput;
MapEditToDI m_PlayMappingsDeviceInput;
MapEditToDI m_RecordMappingsDeviceInput;
+1
View File
@@ -4,6 +4,7 @@
const RString SpecialFiles::USER_PACKAGES_DIR = "UserPackages/";
const RString SpecialFiles::PACKAGES_DIR = "Packages/";
const RString SpecialFiles::KEYMAPS_PATH = "Save/Keymaps.ini";
const RString SpecialFiles::EDIT_MODE_KEYMAPS_PATH = "Save/EditMode_Keymaps.ini";
const RString SpecialFiles::PREFERENCES_INI_PATH = "Save/Preferences.ini";
const RString SpecialFiles::THEMES_DIR = "Themes/";
const RString SpecialFiles::LANGUAGES_SUBDIR = "Languages/";
+4
View File
@@ -16,6 +16,10 @@ namespace SpecialFiles
* This is not the user packages directory. */
extern const RString PACKAGES_DIR;
extern const RString KEYMAPS_PATH;
/** @brief Edit Mode keymaps are separate from standard keymaps because
* it should not change with the gametype, and to avoid possible
* interference with the normal keymaps system. -Kyz */
extern const RString EDIT_MODE_KEYMAPS_PATH;
extern const RString PREFERENCES_INI_PATH;
/** @brief The directory that contains the themes. */
extern const RString THEMES_DIR;