From d532e4937fbf9c1d1458f9bdfb02ed54c50122c3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Thu, 7 Mar 2024 10:31:22 -0500 Subject: Added connection history --- src/connection_dialog.cpp | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'src/connection_dialog.cpp') diff --git a/src/connection_dialog.cpp b/src/connection_dialog.cpp index 45be8b8..64fee98 100644 --- a/src/connection_dialog.cpp +++ b/src/connection_dialog.cpp @@ -4,12 +4,15 @@ ConnectionDialog::ConnectionDialog() : wxDialog(nullptr, wxID_ANY, "Connect to Archipelago") { - server_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_server, - wxDefaultPosition, {300, -1}); - player_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_player, - wxDefaultPosition, {300, -1}); - password_box_ = new wxTextCtrl(this, -1, GetTrackerConfig().ap_password, - wxDefaultPosition, {300, -1}); + server_box_ = + new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_server, + wxDefaultPosition, {300, -1}); + player_box_ = + new wxTextCtrl(this, -1, GetTrackerConfig().connection_details.ap_player, + wxDefaultPosition, {300, -1}); + password_box_ = new wxTextCtrl( + this, -1, GetTrackerConfig().connection_details.ap_password, + wxDefaultPosition, {300, -1}); wxFlexGridSizer* form_sizer = new wxFlexGridSizer(2, 10, 10); @@ -26,15 +29,42 @@ ConnectionDialog::ConnectionDialog() wxSizerFlags().Align(wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT)); form_sizer->Add(password_box_, wxSizerFlags().Expand()); + history_list_ = new wxListBox(this, -1); + for (const ConnectionDetails& details : GetTrackerConfig().connection_history) { + wxString display_text; + display_text << details.ap_player; + display_text << " ("; + display_text << details.ap_server; + display_text << ")"; + + history_list_->Append(display_text); + } + + history_list_->Bind(wxEVT_LISTBOX, &ConnectionDialog::OnOldConnectionChosen, this); + + wxBoxSizer* mid_sizer = new wxBoxSizer(wxHORIZONTAL); + mid_sizer->Add(form_sizer, wxSizerFlags().Proportion(3).Expand()); + mid_sizer->AddSpacer(10); + mid_sizer->Add(history_list_, wxSizerFlags().Proportion(2).Expand()); + wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); top_sizer->Add(new wxStaticText( this, -1, "Enter the details to connect to Archipelago."), wxSizerFlags().Align(wxALIGN_LEFT).DoubleBorder()); - top_sizer->Add(form_sizer, wxSizerFlags().DoubleBorder().Expand()); - top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Center()); + top_sizer->Add(mid_sizer, wxSizerFlags().DoubleBorder().Expand()); + top_sizer->Add(CreateButtonSizer(wxOK | wxCANCEL), wxSizerFlags().Border().Center()); SetSizerAndFit(top_sizer); Center(); server_box_->SetFocus(); } + +void ConnectionDialog::OnOldConnectionChosen(wxCommandEvent& e) { + if (e.IsSelection()) { + const ConnectionDetails& details = GetTrackerConfig().connection_history.at(e.GetSelection()); + server_box_->SetValue(details.ap_server); + player_box_->SetValue(details.ap_player); + password_box_->SetValue(details.ap_password); + } +} -- cgit 1.4.1