Skip to content

Commit

Permalink
I separated the configuration, via command line, of the keyboard and …
Browse files Browse the repository at this point in the history
…joystick shortcuts.
  • Loading branch information
punesemu committed Feb 14, 2024
1 parent 96fec15 commit f2a29ac
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 115 deletions.
43 changes: 18 additions & 25 deletions src/gui/cmd_line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
for (int a = 1; a < argc; a++) {
arg = uQString(argv[a]);
splitted = arg.split("=");
key = QString(splitted.at(0));
key = splitted.at(0);
bool elaborate = false;

if (key.startsWith("--")) {
Expand All @@ -134,7 +134,7 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
skey = opt_long[b].sopt;
if (opt_long[b].ra == req_arg) {
if (splitted.count() > 1) {
value = QString(splitted.at(1));
value = splitted.at(1);
} else {
if ((a + 1) >= argc) {
QMessageBox::warning(nullptr, "Error",
Expand Down Expand Up @@ -228,22 +228,19 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
} else if (key.startsWith("shortcut.")) {
QStringList list = key.toLower().split(".");

if (list.length() == 2) {
key = QString(list.at(1));
if (list.length() == 3) {
QString type = list.at(1);

key = list.at(2);
for (int i = SET_INP_SC_OPEN; i < SET_INP_SC_OPEN + SET_MAX_NUM_SC; i++) {
const _settings *s = &inp_cfg[i];
QString skey = uQString(s->key).toLower().replace(" ", "_");

if (key == skey) {
list = value.split(",");
if (!list.length()) {
break;
}
if (list.length() >= 1) {
settings_inp_wr_sc((void *)&list.at(0), i, KEYBOARD);
}
if (list.length() >= 2) {
settings_inp_wr_sc((void *)&list.at(0), i, JOYSTICK);
if (type == "k") {
settings_inp_wr_sc((void *)&value, i, KEYBOARD);
} else if (type == "j") {
settings_inp_wr_sc((void *)&value, i, JOYSTICK);
}
}
}
Expand All @@ -261,26 +258,22 @@ BYTE cmd_line_parse(int argc, uTCHAR **argv) {
{ 3, SET_INP_P4K_A, SET_INP_P4K_TURBOB }
};

if (list.length() == 2) {
key = QString(list.at(1));
if ((list.length() == 3) && (list.at(1).length() == 3)) {
QString type = list.at(1).mid(2, 1);

key = list.at(1).mid(0,2) + "k_" + list.at(2);
for (unsigned int r = 0; r < LENGTH(range); r++) {
for (int i = range[r].start; i <= range[r].end ; i++) {
const _settings *s = &inp_cfg[i];
QString skey = uQString(s->key).toLower().replace(" ", "_");

if (key == skey) {
list = value.split(",");

if (!list.length()) {
break;
}
if (list.length() >= 1) {
if (type == "k") {
port[range[r].port].input[KEYBOARD][i - range[r].start] =
settings_inp_wr_port((void *)&list.at(0), i, KEYBOARD);
}
if (list.length() >= 2) {
settings_inp_wr_port((void *)&value, i, KEYBOARD);
} else if (type == "j") {
port[range[r].port].input[JOYSTICK][i - range[r].start] =
settings_inp_wr_port((void *)&list.at(1), i, JOYSTICK);
settings_inp_wr_port((void *)&value, i, JOYSTICK);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/designer/dlgCmdLineHelp.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>791</width>
<width>830</width>
<height>354</height>
</rect>
</property>
Expand Down
31 changes: 18 additions & 13 deletions src/gui/dlgCmdLineHelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ dlgCmdLineHelp::dlgCmdLineHelp(QWidget *parent, const QString name) : QDialog(pa
const uTCHAR *istructions = {
uL("Usage: %%1 [options] file...\n\n")
uL("Options:\n")
uL("-h, --help print this help\n")
uL("-V, --version print the version\n")
uL(" --portable start in portable mode\n")
uL("-h, --help print this help\n")
uL("-V, --version print the version\n")
uL(" --portable start in portable mode\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
uL("" uPs("") "\n")
Expand Down Expand Up @@ -85,16 +85,21 @@ dlgCmdLineHelp::dlgCmdLineHelp(QWidget *parent, const QString name) : QDialog(pa
uL("" uPs("") "\n")
};
const uTCHAR *sch_input = {
uL(" --shurtcut.[desc] set up the shortcut : [keyboard],[joystick]" NEWLINE)
uL(" descriptions can be found in the puNES.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --shurtcut.open=Alt+O" NEWLINE)
uL(" --shurtcut.hard_reset=F11" NEWLINE)
uL(" --input.[desc] input sequence : [keyboard],[joystick]" NEWLINE)
uL(" descriptions can be found in the input.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --input.p1k_up=Up" NEWLINE)
uL(" --input.p1k_turboa=W")
uL(" --shortcut.[type].[desc] set up the shortcut : [keyboard] or [joystick]" NEWLINE)
uL(" the [type] must be k for keyboard mapping" NEWLINE)
uL(" and j for joystick mapping." NEWLINE)
uL(" [desc] can be found in the puNES.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --shortcut.k.open=Alt+O" NEWLINE)
uL(" --shortcut.j.hard_reset=BTN05" NEWLINE)
uL(" --input.[type].[desc] input sequence : [keyboard] or [joystick]" NEWLINE)
uL(" the [type] must be p1k, p2k, p3k and p4k" NEWLINE)
uL(" for keyboard mapping and p1j, p2j, p3j and p4j" NEWLINE)
uL(" for joystick mapping." NEWLINE)
uL(" [desc] can be found in the input.cfg" NEWLINE)
uL(" e.g." NEWLINE)
uL(" --input.p1k.up=Up" NEWLINE)
uL(" --input.p1j.turboa=BTN05")
};

usage_string = (uTCHAR *)malloc(1024 * 9);
Expand Down
Loading

0 comments on commit f2a29ac

Please sign in to comment.