diff --git a/src/gba/GBALink.cpp b/src/gba/GBALink.cpp index 17c919d4..247cda64 100644 --- a/src/gba/GBALink.cpp +++ b/src/gba/GBALink.cpp @@ -98,7 +98,10 @@ bool gba_link_enabled = false; bool speedhack = true; #define LOCAL_LINK_NAME "VBA link memory" -#define IP_LINK_PORT 5738 + +#include + +uint32_t IP_LINK_PORT = 5738; #include "../common/Port.h" #include "GBA.h" diff --git a/src/gba/GBALink.h b/src/gba/GBALink.h index 596e2f3b..8e757691 100644 --- a/src/gba/GBALink.h +++ b/src/gba/GBALink.h @@ -1,6 +1,10 @@ #ifndef GBA_GBALINK_H #define GBA_GBALINK_H +#include + +extern uint32_t IP_LINK_PORT; + /** * Link modes to be passed to InitLink */ diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index cb0fe727..a5fbf802 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -89,6 +89,8 @@ public: if (!dlg->Validate() || !dlg->TransferDataFromWindow()) return; + IP_LINK_PORT = gopts.link_port; + if (!server) { bool valid = SetLinkServerHost(gopts.link_host.utf8_str()); @@ -3181,6 +3183,11 @@ bool MainFrame::BindControls() tc = SafeXRCCTRL(d, n); \ tc->SetValidator(wxPositiveDoubleValidator(&o)); \ } while (0) +#define getutc(n, o) \ + do { \ + tc = SafeXRCCTRL(d, n); \ + tc->SetValidator(wxUIntValidator(&o)); \ + } while (0) #ifndef NO_LINK { net_link_handler.dlg = d; @@ -3199,6 +3206,7 @@ bool MainFrame::BindControls() addrber(lab, true); gettc("ServerIP", gopts.link_host); addrber(tc, true); + getutc("ServerPort", gopts.link_port); wxWindow* okb = d->FindWindow(wxID_OK); if (okb) // may be gone if style guidlines removed it diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index 6faa7eaf..4a1a3fd5 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -223,6 +223,7 @@ opt_desc opts[] = { BOOLOPT("GBA/LinkAuto", "LinkAuto", wxTRANSLATE("Enable link at boot"), gopts.link_auto), INTOPT("GBA/LinkFast", "SpeedOn", wxTRANSLATE("Enable faster network protocol by default"), linkHacks, 0, 1), STROPT("GBA/LinkHost", "", wxTRANSLATE("Default network link client host"), gopts.link_host), + UINTOPT("GBA/LinkPort", "", wxTRANSLATE("Default network link port (server and client)"), gopts.link_port, 0, 65535), INTOPT("GBA/LinkProto", "LinkProto", wxTRANSLATE("Default network protocol"), gopts.link_proto, 0, 1), INTOPT("GBA/LinkTimeout", "LinkTimeout", wxTRANSLATE("Link timeout (ms)"), linkTimeout, 0, 9999999), INTOPT("GBA/LinkType", "LinkType", wxTRANSLATE("Link cable type"), gopts.gba_link_type, 0, 5), @@ -359,6 +360,7 @@ opts_t::opts_t() autoPatch = true; // quick fix for issues #48 and #445 link_host = "127.0.0.1"; + link_port = 5738; } // for binary_search() and friends diff --git a/src/wx/opts.h b/src/wx/opts.h index 809d51ed..734bee7f 100644 --- a/src/wx/opts.h +++ b/src/wx/opts.h @@ -38,6 +38,7 @@ extern struct opts_t { wxString gba_bios; int gba_link_type; wxString link_host; + uint32_t link_port; int link_proto; bool link_auto; wxString gba_rom_dir; diff --git a/src/wx/widgets/wxmisc.cpp b/src/wx/widgets/wxmisc.cpp index 136d0655..07ff7352 100644 --- a/src/wx/widgets/wxmisc.cpp +++ b/src/wx/widgets/wxmisc.cpp @@ -1,4 +1,9 @@ // utility widgets + +#include +#include +#include + #include "wx/wxmisc.h" #include #include @@ -443,36 +448,62 @@ wxUIntValidator::wxUIntValidator(uint32_t* _val) bool wxUIntValidator::TransferToWindow() { - wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl); - if (ctrl && uint_val) { - ctrl->SetValue(*uint_val); - return true; + if (uint_val) { + wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl); + if (spin) { + spin->SetValue(*uint_val); + return true; + } + + wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl); + if (txt) { + txt->SetValue(wxString::Format(wxT("%d"), *uint_val)); + return true; + } } + return false; } bool wxUIntValidator::TransferFromWindow() { - wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl); - if (ctrl && uint_val) { - *uint_val = ctrl->GetValue(); - return true; + if (uint_val) { + wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl); + if (spin) { + *uint_val = spin->GetValue(); + return true; + } + + wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl); + if (txt) { + *uint_val = wxAtoi(txt->GetValue()); + return true; + } } + return false; } bool wxUIntValidator::Validate(wxWindow* parent) { (void)parent; // unused params - wxSpinCtrl* ctrl = wxDynamicCast(GetWindow(), wxSpinCtrl); - if (ctrl) { - if (ctrl->GetValue() >= 0) { + wxSpinCtrl* spin = wxDynamicCast(GetWindow(), wxSpinCtrl); + if (spin) { + if (spin->GetValue() >= 0) { return true; } return false; } + wxTextCtrl* txt = wxDynamicCast(GetWindow(), wxTextCtrl); + if (txt) { + std::string val = std::string(txt->GetValue().mb_str()); + + return !val.empty() + && std::find_if(val.begin(), val.end(), [](unsigned char c) { return !std::isdigit(c); }) == val.end(); + } + return false; } diff --git a/src/wx/xrc/NetLink.xrc b/src/wx/xrc/NetLink.xrc index bd74dd4c..9ea3c113 100644 --- a/src/wx/xrc/NetLink.xrc +++ b/src/wx/xrc/NetLink.xrc @@ -76,6 +76,19 @@ wxALL|wxEXPAND 5 + + + + + wxALL|wxALIGN_CENTRE_VERTICAL + 5 + + + + + wxALL|wxEXPAND + 5 + wxEXPAND