Skip to content

Commit

Permalink
Set default keys for input on first run.
Browse files Browse the repository at this point in the history
We use the following key input if the config `vbam.ini` does not exist:

input  | keyboard
A      | A
B      | S
L      | Q
R      | W
SELECT | Z
START  | X

We also set a joystick default, using the XBOX 360 controller as a
base.

- Fix #463.
  • Loading branch information
denisfa authored and rkitover committed Jul 25, 2019
1 parent 9bc8f33 commit 3dc738b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/wx/opts.cpp
Expand Up @@ -144,17 +144,17 @@ const wxString joynames[NUM_KEYS] = {

wxJoyKeyBinding defkeys_keyboard[NUM_KEYS] = {
WJKB(WXK_UP), WJKB(WXK_DOWN), WJKB(WXK_LEFT), WJKB(WXK_RIGHT),
WJKB(wxT('Z')), WJKB(wxT('X')), WJKB(wxT('A')), WJKB(wxT('S')),
WJKB(wxT('C')), WJKB(wxT('V')),
WJKB(wxT('A')), WJKB(wxT('S')), WJKB(wxT('Q')), WJKB(wxT('W')),
WJKB(wxT('Z')), WJKB(wxT('X')),
WJKB(0), WJKB(0), WJKB(0), WJKB(0),
WJKB(0), WJKB(0), WJKB(0), WJKB(0),
WJKB(WXK_SPACE), WJKB(0), WJKB(0)
};

wxJoyKeyBinding defkeys_joystick[NUM_KEYS] = {
WJKB(1, WXJB_AXIS_MINUS, 1), WJKB(1, WXJB_AXIS_PLUS, 1), WJKB(0, WXJB_AXIS_MINUS, 1), WJKB(0, WXJB_AXIS_PLUS, 1),
WJKB(0, WXJB_BUTTON, 1), WJKB(1, WXJB_BUTTON, 1), WJKB(2, WXJB_BUTTON, 1), WJKB(3, WXJB_BUTTON, 1),
WJKB(4, WXJB_BUTTON, 1), WJKB(5, WXJB_BUTTON, 1),
WJKB(0, WXJB_BUTTON, 1), WJKB(1, WXJB_BUTTON, 1), WJKB(4, WXJB_BUTTON, 1), WJKB(5, WXJB_BUTTON, 1),
WJKB(6, WXJB_BUTTON, 1), WJKB(7, WXJB_BUTTON, 1),
WJKB(0), WJKB(0), WJKB(0), WJKB(0),
WJKB(0), WJKB(0), WJKB(0), WJKB(0),
WJKB(0), WJKB(0), WJKB(0)
Expand Down Expand Up @@ -346,13 +346,6 @@ opts_t::opts_t()
bilinear = true;
default_stick = 1;

for (int i = 0; i < NUM_KEYS; i++) {
if (defkeys_keyboard[i].key)
joykey_bindings[0][i].push_back(defkeys_keyboard[i]);
if (defkeys_joystick[i].key)
joykey_bindings[0][i].push_back(defkeys_joystick[i]);
}

recent = new wxFileHistory(10);
autofire_rate = 1;
print_auto_page = true;
Expand All @@ -368,6 +361,17 @@ bool opt_lt(const opt_desc& opt1, const opt_desc& opt2)
return wxStrcmp(opt1.opt, opt2.opt) < 0;
}

// set default input keys
void set_default_keys()
{
for (int i = 0; i < NUM_KEYS; i++) {
if (defkeys_keyboard[i].key)
gopts.joykey_bindings[0][i].push_back(defkeys_keyboard[i]);
if (defkeys_joystick[i].joy)
gopts.joykey_bindings[0][i].push_back(defkeys_joystick[i]);
}
}

// FIXME: simulate MakeInstanceFilename(vbam.ini) using subkeys (Slave%d/*)
void load_opts()
{
Expand Down
2 changes: 2 additions & 0 deletions src/wx/opts.h
Expand Up @@ -115,6 +115,8 @@ extern const int num_opts;
extern const wxAcceleratorEntry default_accels[];
extern const int num_def_accels;

// call to setup default keys.
void set_default_keys();
// call to load config (once)
// will write defaults for options not present and delete bad opts
// will also initialize opts[] array translations
Expand Down
4 changes: 3 additions & 1 deletion src/wx/wxvbam.cpp
Expand Up @@ -165,6 +165,8 @@ wxString wxvbamApp::GetConfigurationPath()
break;
}
}
// use default keys for input.
set_default_keys();
}

return data_path;
Expand Down Expand Up @@ -488,7 +490,7 @@ void wxvbamApp::OnInitCmdLine(wxCmdLineParser& cl)
N_("Print configuration path and exit"),
wxCMD_LINE_VAL_NONE, 0 },
{ wxCMD_LINE_SWITCH, t("f"), t("fullscreen"),
N_("Start in full-screen mode"),
N_("Start in full-screen mode"),
wxCMD_LINE_VAL_NONE, 0 },
#if !defined(NO_LINK) && !defined(__WXMSW__)
{ wxCMD_LINE_SWITCH, t("s"), t("delete-shared-state"),
Expand Down

0 comments on commit 3dc738b

Please sign in to comment.