diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters index b060d540c0..2386e891db 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj.filters +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -205,6 +205,9 @@ GUI\Cheats + + GUI\NetPlay + @@ -375,6 +378,9 @@ GUI\Cheats + + GUI\NetPlay + diff --git a/Source/Core/DolphinWX/GameListCtrl.cpp b/Source/Core/DolphinWX/GameListCtrl.cpp index 2bb88f10ab..f9ef00d910 100644 --- a/Source/Core/DolphinWX/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/GameListCtrl.cpp @@ -1138,7 +1138,7 @@ void CGameListCtrl::OnNetPlayHost(wxCommandEvent& WXUNUSED(event)) config.FromIniConfig(netplay_section); config.game_name = iso->GetUniqueIdentifier(); config.game_list_ctrl = this; - config.parent_window = m_parent; + config.SetDialogInfo(netplay_section, m_parent); netplay_section.Set("SelectedHostGame", config.game_name); ini_file.Save(dolphin_ini); diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp index 8c1cab04df..4f8e3aeed5 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.cpp @@ -2,13 +2,15 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include "NetPlayLauncher.h" +#include + #include "Common/CommonTypes.h" #include "Common/FileUtil.h" #include "Common/IniFile.h" #include "Common/StringUtil.h" +#include "DolphinWX/NetPlay/NetPlayLauncher.h" +#include "DolphinWX/NetPlay/NetWindow.h" #include "DolphinWX/WxUtils.h" -#include "NetWindow.h" bool NetPlayLauncher::Host(const NetPlayHostConfig& config) { @@ -49,6 +51,7 @@ bool NetPlayLauncher::Host(const NetPlayHostConfig& config) if (netplay_client->IsConnected()) { + npd->SetSize(config.window_pos); npd->Show(); netplay_server->SetNetPlayUI(NetPlayDialog::GetInstance()); return true; @@ -78,6 +81,7 @@ bool NetPlayLauncher::Join(const NetPlayJoinConfig& config) config.traversal_host, config.traversal_port); if (netplay_client->IsConnected()) { + npd->SetSize(config.window_pos); npd->Show(); return true; } @@ -89,10 +93,9 @@ bool NetPlayLauncher::Join(const NetPlayJoinConfig& config) } const std::string NetPlayLaunchConfig::DEFAULT_TRAVERSAL_HOST = "stun.dolphin-emu.org"; -const u16 NetPlayLaunchConfig::DEFAULT_TRAVERSAL_PORT = 6262; -const u16 NetPlayHostConfig::DEFAULT_LISTEN_PORT = 2626; -std::string NetPlayLaunchConfig::GetTraversalHostFromIniConfig(IniFile::Section& netplay_section) +std::string +NetPlayLaunchConfig::GetTraversalHostFromIniConfig(const IniFile::Section& netplay_section) { std::string host; @@ -105,7 +108,7 @@ std::string NetPlayLaunchConfig::GetTraversalHostFromIniConfig(IniFile::Section& return host; } -u16 NetPlayLaunchConfig::GetTraversalPortFromIniConfig(IniFile::Section& netplay_section) +u16 NetPlayLaunchConfig::GetTraversalPortFromIniConfig(const IniFile::Section& netplay_section) { std::string port_str; unsigned long port; @@ -119,6 +122,22 @@ u16 NetPlayLaunchConfig::GetTraversalPortFromIniConfig(IniFile::Section& netplay return static_cast(port); } +void NetPlayLaunchConfig::SetDialogInfo(const IniFile::Section& section, wxWindow* parent) +{ + parent_window = parent; + + section.Get("NetWindowPosX", &window_pos.x, window_defaults.GetX()); + section.Get("NetWindowPosY", &window_pos.y, window_defaults.GetY()); + section.Get("NetWindowWidth", &window_pos.width, window_defaults.GetWidth()); + section.Get("NetWindowHeight", &window_pos.height, window_defaults.GetHeight()); + + if (window_pos.GetX() == window_defaults.GetX() || window_pos.GetY() == window_defaults.GetY()) + { + // Center over toplevel dolphin window + window_pos = window_defaults.CenterIn(parent_window->GetScreenRect()); + } +} + void NetPlayHostConfig::FromIniConfig(IniFile::Section& netplay_section) { std::string traversal_choice_setting; diff --git a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h index 30d7807a72..513c15bedc 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h +++ b/Source/Core/DolphinWX/NetPlay/NetPlayLauncher.h @@ -7,16 +7,19 @@ #include "Common/IniFile.h" class CGameListCtrl; +class wxRect; class wxWindow; class NetPlayLaunchConfig { public: - static std::string GetTraversalHostFromIniConfig(IniFile::Section& netplay_section); - static u16 GetTraversalPortFromIniConfig(IniFile::Section& netplay_section); + static std::string GetTraversalHostFromIniConfig(const IniFile::Section& netplay_section); + static u16 GetTraversalPortFromIniConfig(const IniFile::Section& netplay_section); + void SetDialogInfo(const IniFile::Section& section, wxWindow* parent); static const std::string DEFAULT_TRAVERSAL_HOST; - static const u16 DEFAULT_TRAVERSAL_PORT; + static constexpr u16 DEFAULT_TRAVERSAL_PORT = 6262; + const wxRect window_defaults{wxDefaultCoord, wxDefaultCoord, 768, 768 - 128}; std::string player_name; const CGameListCtrl* game_list_ctrl; @@ -24,6 +27,7 @@ public: bool use_traversal; std::string traversal_host; u16 traversal_port; + wxRect window_pos{window_defaults}; }; class NetPlayHostConfig : public NetPlayLaunchConfig @@ -31,7 +35,7 @@ class NetPlayHostConfig : public NetPlayLaunchConfig public: void FromIniConfig(IniFile::Section& netplay_section); - static const u16 DEFAULT_LISTEN_PORT; + static constexpr u16 DEFAULT_LISTEN_PORT = 2626; std::string game_name; u16 listen_port = 0; diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp index b29205ac06..c9f0e0f86b 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.cpp @@ -305,7 +305,7 @@ void NetPlaySetupFrame::DoHost() host_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE; host_config.player_name = WxStrToStr(m_nickname_text->GetValue()); host_config.game_list_ctrl = m_game_list; - host_config.parent_window = m_parent; + host_config.SetDialogInfo(netplay_section, m_parent); host_config.forward_port = m_upnp_chk->GetValue(); if (host_config.use_traversal) @@ -347,7 +347,7 @@ void NetPlaySetupFrame::DoJoin() join_config.use_traversal = m_direct_traversal->GetCurrentSelection() == TRAVERSAL_CHOICE; join_config.player_name = WxStrToStr(m_nickname_text->GetValue()); join_config.game_list_ctrl = m_game_list; - join_config.parent_window = m_parent; + join_config.SetDialogInfo(netplay_section, m_parent); unsigned long port = 0; m_connect_port_text->GetValue().ToULong(&port); diff --git a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h index 7518de6954..be565b1452 100644 --- a/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h +++ b/Source/Core/DolphinWX/NetPlay/NetPlaySetupFrame.h @@ -29,6 +29,7 @@ private: static constexpr int DIRECT_CHOICE = 0; static constexpr int TRAVERSAL_CHOICE = 1; + void GetWindowRect(const IniFile::Section& section, wxRect* rect) const; void OnJoin(wxCommandEvent& event); void OnHost(wxCommandEvent& event); void DoJoin();