Merge pull request #590 from ccfly42/ui-network-settings

Add ui network settings
This commit is contained in:
Louis Gombert 2024-10-15 22:48:51 +02:00 committed by GitHub
commit 652e31f442
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 79 additions and 19 deletions

View File

@ -930,6 +930,7 @@ struct sound_menu {
#define UID_SHORTCUT_JOYSETTINGS 0x1000 #define UID_SHORTCUT_JOYSETTINGS 0x1000
#define UID_SHORTCUT_KEYSETTINGS 0x1001 #define UID_SHORTCUT_KEYSETTINGS 0x1001
#define UID_SHORTCUT_FORCEFEED 0x1002 #define UID_SHORTCUT_FORCEFEED 0x1002
#define UID_SHORTCUT_NETSETTINGS 0x1003
struct toggles_menu { struct toggles_menu {
newuiSheet *sheet; newuiSheet *sheet;
@ -991,6 +992,10 @@ struct toggles_menu {
if (ff_found) { if (ff_found) {
sheet->AddLongButton(TXT_CFG_CONFIGFORCEFEEDBACK, UID_SHORTCUT_FORCEFEED); sheet->AddLongButton(TXT_CFG_CONFIGFORCEFEEDBACK, UID_SHORTCUT_FORCEFEED);
} }
sheet->NewGroup("Misc", 110, ff_found ? 200 : 190);
sheet->AddLongButton("Network Settings", UID_SHORTCUT_NETSETTINGS);
return sheet; return sheet;
}; };
@ -1026,6 +1031,9 @@ struct toggles_menu {
key_settings_dialog(); key_settings_dialog();
SaveControlConfig(); SaveControlConfig();
break; break;
case UID_SHORTCUT_NETSETTINGS:
net_settings_dialog();
break;
} }
}; };
}; };

View File

@ -293,6 +293,8 @@
#include "hlsoundlib.h" #include "hlsoundlib.h"
#include "ddio.h" #include "ddio.h"
#include "pserror.h" #include "pserror.h"
#include "networking.h"
#include "appdatabase.h"
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
#define IDV_KCONFIG 10 #define IDV_KCONFIG 10
@ -1289,6 +1291,62 @@ void key_settings_dialog() {
wnd.Close(); wnd.Close();
wnd.Destroy(); wnd.Destroy();
} }
void net_settings_dialog() {
newuiTiledWindow wnd;
newuiSheet *sheet;
int res;
int16_t curpos;
int16_t *pps_client_current_t;
tSliderSettings slider_set;
int cfg_range = CFG_NETWORK_CLIENT_PPS_MAX - CFG_NETWORK_CLIENT_PPS_MIN;
int nwRecommendPPS = nw_ReccomendPPS();
LOG_DEBUG.printf("Load network settings. PPS:%d.", nwRecommendPPS);
// Create window
wnd.Create("Network Settings", 0, 0, 384, 256);
// add group
sheet = wnd.GetSheet();
sheet->NewGroup("", 0, 0);
// slider setup
slider_set.min_val.i = CFG_NETWORK_CLIENT_PPS_MIN;
slider_set.max_val.i = CFG_NETWORK_CLIENT_PPS_MAX;
slider_set.type = SLIDER_UNITS_INT;
curpos = CALC_SLIDER_POS_INT(nwRecommendPPS, &slider_set, cfg_range);
pps_client_current_t = sheet->AddSlider("PPS", cfg_range, curpos, &slider_set);
// add group "window ctrl buttons"
sheet->NewGroup(NULL, 180, 160, NEWUI_ALIGN_HORIZ);
sheet->AddButton(TXT_OK, UID_OK);
sheet->AddButton(TXT_CANCEL, UID_CANCEL);
// render
wnd.Open();
do {
res = wnd.DoUI();
if (res == NEWUIRES_FORCEQUIT) {
break;
}
} while (res != UID_OK && res != UID_CANCEL);
if (res == UID_OK) {
// save changes
nwRecommendPPS = CALC_SLIDER_INT_VALUE(*pps_client_current_t, CFG_NETWORK_CLIENT_PPS_MIN, CFG_NETWORK_CLIENT_PPS_MAX, cfg_range);
LOG_DEBUG.printf("Write network client pps %d.", nwRecommendPPS);
Database->write(CTLCONFIG_PPS_CLIENT_DB_KEY, nwRecommendPPS);
}
wnd.Close();
wnd.Destroy();
}
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// configure controller new way // configure controller new way
struct t_ctlcfgswitchcb_data { struct t_ctlcfgswitchcb_data {

View File

@ -59,6 +59,12 @@
#define CTLCONFIG_CONTROLLER 1 #define CTLCONFIG_CONTROLLER 1
#define CTLCONFIG_WPNSEL 2 #define CTLCONFIG_WPNSEL 2
#define CTLCONFIG_PPS_CLIENT_DB_KEY "ClientPPS"
#define CFG_NETWORK_CLIENT_PPS_MIN 7
#define CFG_NETWORK_CLIENT_PPS_MAX 30
struct t_cfg_element { struct t_cfg_element {
int16_t fn_id; // -1 = group start int16_t fn_id; // -1 = group start
int16_t text; // text string id. int16_t text; // text string id.
@ -76,5 +82,6 @@ void CtlConfig(int mode);
// opens the settings dialogs. // opens the settings dialogs.
void joystick_settings_dialog(); void joystick_settings_dialog();
void key_settings_dialog(); void key_settings_dialog();
void net_settings_dialog();
#endif #endif

View File

@ -160,7 +160,7 @@ extern char PXO_hosted_lobby_name[];
// the dedicated server // the dedicated server
static cvar_entry CVars[] = { static cvar_entry CVars[] = {
{"PPS", CVAR_TYPE_INT, &Netgame.packets_per_second, 2, 20, CVAR_GAMEINIT}, // 0 {"PPS", CVAR_TYPE_INT, &Netgame.packets_per_second, 2, 40, CVAR_GAMEINIT}, // 0
{"TimeLimit", CVAR_TYPE_INT, &Netgame.timelimit, 0, 10000, CVAR_GAMEINIT}, {"TimeLimit", CVAR_TYPE_INT, &Netgame.timelimit, 0, 10000, CVAR_GAMEINIT},
{"KillGoal", CVAR_TYPE_INT, &Netgame.killgoal, 0, 10000, CVAR_GAMEINIT}, {"KillGoal", CVAR_TYPE_INT, &Netgame.killgoal, 0, 10000, CVAR_GAMEINIT},
{"RespawnTime", CVAR_TYPE_INT, &Netgame.respawn_time, 0, 10000, CVAR_GAMEINIT}, {"RespawnTime", CVAR_TYPE_INT, &Netgame.respawn_time, 0, 10000, CVAR_GAMEINIT},

View File

@ -327,6 +327,7 @@ typedef int socklen_t;
#include "game.h" #include "game.h"
#include "args.h" #include "args.h"
#include "byteswap.h" #include "byteswap.h"
#include "ctlconfig.h"
#ifndef WIN32 #ifndef WIN32
bool Use_DirectPlay = false; bool Use_DirectPlay = false;
@ -2266,24 +2267,10 @@ void CDECLCALL gethostbynameworker(void *parm)
} }
int nw_ReccomendPPS() { int nw_ReccomendPPS() {
static char szconnspeed[100]; int clientPPS = CFG_NETWORK_CLIENT_PPS_MAX;
int len = 99; Database->read_int(CTLCONFIG_PPS_CLIENT_DB_KEY, &clientPPS);
strcpy(szconnspeed, "");
Database->read("ConnectionSpeed", szconnspeed, &len); return clientPPS;
if (stricmp(szconnspeed, "28K") == 0)
return 5;
else if (stricmp(szconnspeed, "33K") == 0)
return 6;
else if (stricmp(szconnspeed, "56K") == 0)
return 7;
else if (stricmp(szconnspeed, "ISDN") == 0)
return 8;
else if (stricmp(szconnspeed, "Cable") == 0)
return 9;
else if (stricmp(szconnspeed, "Fast") == 0)
return 12;
else
return 7;
} }
// Register the networking library to call your function back // Register the networking library to call your function back