about summary refs log tree commit diff stats
path: root/src/ipc_dialog.cpp
blob: f17c2d87fc3095487ba17780d57eae0e01bcd6fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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);
}