Skip to content

Commit

Permalink
You can now cycle through the settings window tabs via a gamepad:
Browse files Browse the repository at this point in the history
 + Cycling through settings window via left & right triggers. See
INJOY_MENU_SETTINGS_NEXT & INJOY_MENU_SETTINGS_PREV.
 + Outline selected inventory tab's button.
 + Some helper functions in menu.cpp for settings tab related business:
getSettingsTabButton(), changeSettingsTab().
 * No more magic numbers for settings_tab. :) Now uses SETTINGS_VIDEO_TAB,
SETTINGS_AUDIO_TAB, etc.
  • Loading branch information
addictgamer committed Jan 3, 2017
1 parent 65d5c9e commit 7e78daa
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 17 deletions.
2 changes: 2 additions & 0 deletions lang/en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,8 @@ client (player %d) (direct ip)#
1973 Next Shop Category#
1974 Previous Book Page#
1975 Next Book Page#
1976 Next Settings Tab#
1977 Previous Settings Tab#

1980 Gamepad#

Expand Down
18 changes: 18 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,24 @@ void handleButtons(void) {
ttfPrintText(ttf12,button->x+(button->sizex-w)/2-2,button->y+(button->sizey-h)/2+3,button->label);
}
}

if ( button->outline ) {
//Draw golden border.
//For such things as which settings tab the controller has presently selected.
Uint32 color = SDL_MapRGBA(mainsurface->format, 255, 255, 0, 127);
SDL_Rect pos;
pos.x = button->x;
pos.w = button->sizex;
pos.y = button->y;
pos.h = button->sizey;
drawBox(&pos, color, 127);
//Draw a 2 pixel thick box.
pos.x = button->x + 1;
pos.w = button->sizex - 2;
pos.y = button->y + 1;
pos.h = button->sizey -2;
drawBox(&pos, color, 127);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/interface/consolecommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ void consoleCommand(char *command_str) {
} else if (strstr(command_str, "INJOY_MENU_BOOK_PREV")) {
joyimpulses[INJOY_MENU_BOOK_PREV] = atoi(&command_str[9]);
printlog("[GAMEPAD] Bound INJOY_MENU_BOOK_PREV: %d\n", atoi(&command_str[9]));
} else if (strstr(command_str, "INJOY_MENU_SETTINGS_NEXT")) {
joyimpulses[INJOY_MENU_SETTINGS_NEXT] = atoi(&command_str[9]);
printlog("[GAMEPAD] Bound INJOY_MENU_SETTINGS_NEXT: %d\n", atoi(&command_str[9]));
} else if (strstr(command_str, "INJOY_MENU_SETTINGS_PREV")) {
joyimpulses[INJOY_MENU_SETTINGS_PREV] = atoi(&command_str[9]);
printlog("[GAMEPAD] Bound INJOY_MENU_SETTINGS_PREV: %d\n", atoi(&command_str[9]));
}
else
{
Expand Down
8 changes: 7 additions & 1 deletion src/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ void defaultImpulses()
joyimpulses[INJOY_MENU_CYCLE_SHOP_RIGHT] = 311;
joyimpulses[INJOY_MENU_BOOK_NEXT] = 311;
joyimpulses[INJOY_MENU_BOOK_PREV] = 310;
joyimpulses[INJOY_MENU_SETTINGS_NEXT] = 311;
joyimpulses[INJOY_MENU_SETTINGS_PREV] = 310;
}

void defaultConfig() {
Expand Down Expand Up @@ -443,6 +445,8 @@ void defaultConfig() {
consoleCommand("/joybind 311 INJOY_MENU_CYCLE_SHOP_RIGHT");
consoleCommand("/joybind 311 INJOY_MENU_BOOK_NEXT");
consoleCommand("/joybind 310 INJOY_MENU_BOOK_PREV");
consoleCommand("/joybind 311 INJOY_MENU_SETTINGS_NEXT");
consoleCommand("/joybind 310 INJOY_MENU_SETTINGS_PREV");
consoleCommand("/gamepad_deadzone 8000");
consoleCommand("/gamepad_trigger_deadzone 18000");
consoleCommand("/gamepad_leftx_sensitivity 1400");
Expand Down Expand Up @@ -502,7 +506,9 @@ static char joyimpulsenames[NUM_JOY_IMPULSES][30] = {
"MENU_CYCLE_SHOP_LEFT",
"MENU_CYCLE_SHOP_RIGHT",
"MENU_BOOK_NEXT",
"MENU_BOOK_PREV"
"MENU_BOOK_PREV",
"MENU_SETTINGS_NEXT",
"MENU_SETTINGS_PREV"
};

/*-------------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ extern bool stop;
#define INJOY_MENU_CYCLE_SHOP_RIGHT 25
#define INJOY_MENU_BOOK_NEXT 26
#define INJOY_MENU_BOOK_PREV 27
#define INJOY_MENU_SETTINGS_NEXT 28
#define INJOY_MENU_SETTINGS_PREV 29 //TODO: Only one "cycle tabs" binding?

//Game Exclusive:
//These should not trigger if the in-game interfaces are brought up (!shootmode). Inventory, books, shops, chests, etc.
Expand All @@ -195,7 +197,7 @@ extern bool stop;
#define INJOY_GAME_USE 5 //Used in-game for right click. NOTE: Not used in-inventory for in-world identification. Because clicking is disabled and whatnot. (Or can be done?)
#define INJOY_GAME_HOTBAR_ACTIVATE 15 //Activates hotbar slot in-game.

#define NUM_JOY_IMPULSES 28
#define NUM_JOY_IMPULSES 30

// since SDL2 gets rid of these and we're too lazy to fix them...
#define SDL_BUTTON_WHEELUP 4
Expand Down Expand Up @@ -295,6 +297,7 @@ typedef struct button_t {
int joykey; // gamepad button used to activate this button.
bool pressed; // whether the button is being pressed or not
bool needclick; // involved in triggering buttons
bool outline; // draw golden border if true. For such things as indicated which settings tab gamepad has selected.

// a pointer to the button's location in a list
node_t *node;
Expand Down
99 changes: 85 additions & 14 deletions src/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool lobby_window=FALSE;
bool settings_window=FALSE;
int connect_window=0;
int charcreation_step=0;

/*
* settings_tab
* valid values:
Expand All @@ -62,6 +63,14 @@ int charcreation_step=0;
* - 6 = Misc settings
*/
int settings_tab = 0;
button_t* button_video_tab = nullptr;
button_t* button_audio_tab = nullptr;
button_t* button_keyboard_tab = nullptr;
button_t* button_mouse_tab = nullptr;
button_t* button_gamepad_bindings_tab = nullptr;
button_t* button_gamepad_settings_tab = nullptr;
button_t* button_misc_tab = nullptr;

int score_window=0;
int resolutions[NUMRESOLUTIONS][2] = {
{ 960, 600 },
Expand Down Expand Up @@ -150,6 +159,50 @@ bool losingConnection[4] = { false };
bool subtitleVisible = false;
int subtitleCurrent = 0;

button_t* getSettingsTabButton() {
switch ( settings_tab ) {
case SETTINGS_VIDEO_TAB:
return button_video_tab;
case SETTINGS_AUDIO_TAB:
return button_audio_tab;
case SETTINGS_KEYBOARD_TAB:
return button_keyboard_tab;
case SETTINGS_MOUSE_TAB:
return button_mouse_tab;
case SETTINGS_GAMEPAD_BINDINGS_TAB:
return button_gamepad_bindings_tab;
case SETTINGS_GAMEPAD_SETTINGS_TAB:
return button_gamepad_settings_tab;
case SETTINGS_MISC_TAB:
return button_misc_tab;
}

return nullptr;
}

void changeSettingsTab(int option) {
if ( getSettingsTabButton() ) {
getSettingsTabButton()->outline = false;
}

settings_tab = option;

if ( settings_tab < 0 ) {
settings_tab = NUM_SETTINGS_TABS - 1;
}
if ( settings_tab >= NUM_SETTINGS_TABS ) {
settings_tab = 0;
}

if ( getSettingsTabButton() ) {
button_t* button = getSettingsTabButton();
button->outline = true;
int x = button->x + (button->sizex / 2);
int y = button->y + (button->sizey / 2);
SDL_WarpMouseInWindow(screen, x, y);
}
}

void handleMainMenu(bool mode) {
SDL_Rect pos, src, dest;
int x, c;
Expand Down Expand Up @@ -1163,8 +1216,17 @@ void handleMainMenu(bool mode) {
int hovering_selection = -1; //0 to NUM_SERVER_FLAGS used for the game flags settings, e.g. are traps enabled, are cheats enabled, is minotaur enabled, etc.
SDL_Rect tooltip_box;

if ( *inputPressed(joyimpulses[INJOY_MENU_SETTINGS_NEXT]) ) {
*inputPressed(joyimpulses[INJOY_MENU_SETTINGS_NEXT]) = 0;;
changeSettingsTab(settings_tab + 1);
}
if ( *inputPressed(joyimpulses[INJOY_MENU_SETTINGS_PREV]) ) {
*inputPressed(joyimpulses[INJOY_MENU_SETTINGS_PREV]) = 0;
changeSettingsTab(settings_tab - 1);
}

// video tab
if( settings_tab==0 ) {
if( settings_tab==SETTINGS_VIDEO_TAB ) {
// resolution
ttfPrintText(ttf12, subx1+24, suby1+60, language[1338]);
for( c=0; c<NUMRESOLUTIONS; c++ ) {
Expand Down Expand Up @@ -1250,15 +1312,15 @@ void handleMainMenu(bool mode) {
}

// audio tab
if( settings_tab==1 ) {
if( settings_tab==SETTINGS_AUDIO_TAB ) {
ttfPrintText(ttf12, subx1+24, suby1+60, language[1348]);
doSlider(subx1+24,suby1+84,15,0,128,0,&settings_sfxvolume);
ttfPrintText(ttf12, subx1+24, suby1+108, language[1349]);
doSlider(subx1+24,suby1+132,15,0,128,0,&settings_musvolume);
}

// keyboard tab
if( settings_tab==2 ) {
if( settings_tab==SETTINGS_KEYBOARD_TAB ) {
ttfPrintText(ttf12, subx1+24, suby1+60, language[1350]);

bool rebindingkey=FALSE;
Expand Down Expand Up @@ -1302,7 +1364,7 @@ void handleMainMenu(bool mode) {
}

// mouse tab
if( settings_tab==3 ) {
if( settings_tab==SETTINGS_MOUSE_TAB ) {
ttfPrintText(ttf12, subx1+24, suby1+60, language[1365]);
doSliderF(subx1+24,suby1+84,11,0,128,1,&settings_mousespeed);

Expand Down Expand Up @@ -1330,7 +1392,7 @@ void handleMainMenu(bool mode) {
}

//Gamepad tab
if (settings_tab == 4)
if (settings_tab == SETTINGS_GAMEPAD_BINDINGS_TAB)
{
ttfPrintText(ttf8, subx1 + 24, suby1 + 60, language[1350]);

Expand Down Expand Up @@ -1382,7 +1444,7 @@ void handleMainMenu(bool mode) {
}

//General gamepad settings
if (settings_tab == 5)
if (settings_tab == SETTINGS_GAMEPAD_SETTINGS_TAB)
{
int current_option_x = subx1 + 24;
int current_option_y = suby1 + 60;
Expand Down Expand Up @@ -1494,7 +1556,7 @@ void handleMainMenu(bool mode) {
}

// miscellaneous options
if (settings_tab == 6)
if (settings_tab == SETTINGS_MISC_TAB)
{
int current_x = subx1;
int current_y = suby1 + 60;
Expand Down Expand Up @@ -3809,6 +3871,7 @@ void openSettingsWindow() {
button->action = &buttonVideoTab;
button->visible = 1;
button->focused = 1;
button_video_tab = button;

tabx_so_far += strlen(language[1434])*12 + 8;

Expand All @@ -3820,6 +3883,7 @@ void openSettingsWindow() {
button->action = &buttonAudioTab;
button->visible = 1;
button->focused = 1;
button_audio_tab = button;

tabx_so_far += strlen(language[1435])*12 + 8;

Expand All @@ -3831,6 +3895,7 @@ void openSettingsWindow() {
button->action = &buttonKeyboardTab;
button->visible = 1;
button->focused = 1;
button_keyboard_tab = button;

tabx_so_far += strlen(language[1436])*12 + 8;

Expand All @@ -3842,6 +3907,7 @@ void openSettingsWindow() {
button->action = &buttonMouseTab;
button->visible = 1;
button->focused = 1;
button_mouse_tab = button;

tabx_so_far += strlen(language[1437])*12 + 8;

Expand All @@ -3853,6 +3919,7 @@ void openSettingsWindow() {
button->action = &buttonGamepadBindingsTab;
button->visible = 1;
button->focused = 1;
button_gamepad_bindings_tab = button;

tabx_so_far += strlen(language[1947])*12 + 8;

Expand All @@ -3864,6 +3931,7 @@ void openSettingsWindow() {
button->action = &buttonGamepadSettingsTab;
button->visible = 1;
button->focused = 1;
button_gamepad_settings_tab = button;

tabx_so_far += strlen(language[1980])*12 + 8;

Expand All @@ -3875,6 +3943,9 @@ void openSettingsWindow() {
button->action = &buttonMiscTab;
button->visible = 1;
button->focused = 1;
button_misc_tab = button;

changeSettingsTab(settings_tab);
}

void openSteamLobbyWaitWindow(button_t *my);
Expand Down Expand Up @@ -4841,43 +4912,43 @@ void buttonDisconnect(button_t *my) {
// open the video tab in the settings window
void buttonVideoTab(button_t *my)
{
settings_tab = 0;
changeSettingsTab(SETTINGS_VIDEO_TAB);
}

// open the audio tab in the settings window
void buttonAudioTab(button_t *my)
{
settings_tab = 1;
changeSettingsTab(SETTINGS_AUDIO_TAB);
}

// open the keyboard tab in the settings window
void buttonKeyboardTab(button_t *my)
{
settings_tab = 2;
changeSettingsTab(SETTINGS_KEYBOARD_TAB);
}

// open the mouse tab in the settings window
void buttonMouseTab(button_t *my)
{
settings_tab = 3;
changeSettingsTab(SETTINGS_MOUSE_TAB);
}

//Open the gamepad bindings tab in the settings window
void buttonGamepadBindingsTab(button_t *my)
{
settings_tab = 4;
changeSettingsTab(SETTINGS_GAMEPAD_BINDINGS_TAB);
}

//Open the general gamepad settings tab in the settings window
void buttonGamepadSettingsTab(button_t *my)
{
settings_tab = 5;
changeSettingsTab(SETTINGS_GAMEPAD_SETTINGS_TAB);
}

// open the misc tab in the settings window
void buttonMiscTab(button_t *my)
{
settings_tab = 6;
changeSettingsTab(SETTINGS_MISC_TAB);
}

// settings accept button
Expand Down
12 changes: 11 additions & 1 deletion src/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,14 @@ extern bool right_click_protect;
extern bool settings_auto_hotbar_new_items;
extern bool settings_disable_messages;
extern bool settings_right_click_protect;
extern bool settings_auto_appraise_new_items;
extern bool settings_auto_appraise_new_items;

static const int NUM_SETTINGS_TABS = 7;

static const int SETTINGS_VIDEO_TAB = 0;
static const int SETTINGS_AUDIO_TAB = 1;
static const int SETTINGS_KEYBOARD_TAB = 2;
static const int SETTINGS_MOUSE_TAB = 3;
static const int SETTINGS_GAMEPAD_BINDINGS_TAB = 4;
static const int SETTINGS_GAMEPAD_SETTINGS_TAB = 5;
static const int SETTINGS_MISC_TAB = 6;
3 changes: 3 additions & 0 deletions src/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ button_t *newButton(void) {
button->needclick=TRUE;
button->action=NULL;
strcpy(button->label,"nodef");

button->outline = false;

return button;
}

Expand Down

0 comments on commit 7e78daa

Please sign in to comment.