about summary refs log tree commit diff stats
path: root/src/tracker_frame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tracker_frame.cpp')
-rw-r--r--src/tracker_frame.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp new file mode 100644 index 0000000..2a862a5 --- /dev/null +++ b/src/tracker_frame.cpp
@@ -0,0 +1,86 @@
1#include "tracker_frame.h"
2
3#include "ap_state.h"
4#include "connection_dialog.h"
5#include "tracker_config.h"
6#include "tracker_panel.h"
7
8enum TrackerFrameIds { ID_CONNECT = 1 };
9
10wxDEFINE_EVENT(STATE_CHANGED, wxCommandEvent);
11wxDEFINE_EVENT(STATUS_CHANGED, wxCommandEvent);
12
13TrackerFrame::TrackerFrame()
14 : wxFrame(nullptr, wxID_ANY, "Lingo Archipelago Tracker", wxDefaultPosition,
15 wxDefaultSize, wxDEFAULT_FRAME_STYLE | wxFULL_REPAINT_ON_RESIZE) {
16 ::wxInitAllImageHandlers();
17
18 AP_SetTrackerFrame(this);
19
20 SetSize(1280, 728);
21
22 wxMenu *menuFile = new wxMenu();
23 menuFile->Append(ID_CONNECT, "&Connect");
24 menuFile->Append(wxID_EXIT);
25
26 wxMenu *menuHelp = new wxMenu();
27 menuHelp->Append(wxID_ABOUT);
28
29 wxMenuBar *menuBar = new wxMenuBar();
30 menuBar->Append(menuFile, "&File");
31 menuBar->Append(menuHelp, "&Help");
32
33 SetMenuBar(menuBar);
34
35 CreateStatusBar();
36 SetStatusText("Not connected to Archipelago.");
37
38 Bind(wxEVT_MENU, &TrackerFrame::OnAbout, this, wxID_ABOUT);
39 Bind(wxEVT_MENU, &TrackerFrame::OnExit, this, wxID_EXIT);
40 Bind(wxEVT_MENU, &TrackerFrame::OnConnect, this, ID_CONNECT);
41 Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this);
42 Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this);
43
44 tracker_panel_ = new TrackerPanel(this);
45}
46
47void TrackerFrame::SetStatusMessage(std::string message) {
48 wxCommandEvent *event = new wxCommandEvent(STATUS_CHANGED);
49 event->SetString(message.c_str());
50
51 QueueEvent(event);
52}
53
54void TrackerFrame::UpdateIndicators() {
55 QueueEvent(new wxCommandEvent(STATE_CHANGED));
56}
57
58void TrackerFrame::OnAbout(wxCommandEvent &event) {
59 wxMessageBox("Lingo Archipelago Tracker by hatkirby",
60 "About lingo-ap-tracker", wxOK | wxICON_INFORMATION);
61}
62
63void TrackerFrame::OnExit(wxCommandEvent &event) { Close(true); }
64
65void TrackerFrame::OnConnect(wxCommandEvent &event) {
66 ConnectionDialog dlg;
67
68 if (dlg.ShowModal() == wxID_OK) {
69 GetTrackerConfig().ap_server = dlg.GetServerValue();
70 GetTrackerConfig().ap_player = dlg.GetPlayerValue();
71 GetTrackerConfig().ap_password = dlg.GetPasswordValue();
72 GetTrackerConfig().Save();
73
74 AP_Connect(dlg.GetServerValue(), dlg.GetPlayerValue(),
75 dlg.GetPasswordValue());
76 }
77}
78
79void TrackerFrame::OnStateChanged(wxCommandEvent &event) {
80 tracker_panel_->UpdateIndicators();
81 Refresh();
82}
83
84void TrackerFrame::OnStatusChanged(wxCommandEvent &event) {
85 SetStatusText(event.GetString());
86}