From 2844eecb65501f7dafa4de15d7377bfb810e1158 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 18 Dec 2024 13:36:52 -0500 Subject: Make IPC opt-in and configurable --- src/ipc_dialog.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/ipc_dialog.cpp (limited to 'src/ipc_dialog.cpp') diff --git a/src/ipc_dialog.cpp b/src/ipc_dialog.cpp new file mode 100644 index 0000000..f17c2d8 --- /dev/null +++ b/src/ipc_dialog.cpp @@ -0,0 +1,53 @@ +#include "ipc_dialog.h" + +#include "tracker_config.h" + +constexpr const char* kDefaultIpcAddress = "ws://127.0.0.1:41253"; + +IpcDialog::IpcDialog() : wxDialog(nullptr, wxID_ANY, "Connect to game") { + std::string address_value; + if (GetTrackerConfig().ipc_address.empty()) { + address_value = kDefaultIpcAddress; + } else { + address_value = GetTrackerConfig().ipc_address; + } + + address_box_ = + new wxTextCtrl(this, -1, address_value, wxDefaultPosition, {300, -1}); + + wxButton* reset_button = new wxButton(this, -1, "Use Default"); + reset_button->Bind(wxEVT_BUTTON, &IpcDialog::OnResetClicked, this); + + wxFlexGridSizer* form_sizer = new wxFlexGridSizer(3, 10, 10); + form_sizer->Add( + new wxStaticText(this, -1, "Address:"), + wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); + form_sizer->Add(address_box_, wxSizerFlags().Expand()); + form_sizer->Add(reset_button); + + wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); + wxStaticText* top_text = new wxStaticText(this, -1, ""); + top_sizer->Add(top_text, wxSizerFlags().Align(wxALIGN_LEFT).DoubleBorder().Expand()); + top_sizer->Add(form_sizer, wxSizerFlags().DoubleBorder().Expand()); + top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), + wxSizerFlags().Border().Center()); + + SetSizer(top_sizer); + Layout(); + Fit(); + + int width = top_text->GetClientSize().GetWidth(); + top_text->SetLabel( + "This allows you to connect to a running Lingo game and track non-multiworld " + "state, such as the player's position and what panels are solved. Unless " + "you are doing something weird, the default value for the address is " + "probably correct."); + top_text->Wrap(width); + + Fit(); + Center(); +} + +void IpcDialog::OnResetClicked(wxCommandEvent& event) { + address_box_->SetValue(kDefaultIpcAddress); +} -- cgit 1.4.1