about summary refs log tree commit diff stats
path: root/tracker_panel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tracker_panel.cpp')
-rw-r--r--tracker_panel.cpp117
1 files changed, 85 insertions, 32 deletions
diff --git a/tracker_panel.cpp b/tracker_panel.cpp index 1aa7dcf..73cac41 100644 --- a/tracker_panel.cpp +++ b/tracker_panel.cpp
@@ -1,7 +1,13 @@
1#include "tracker_panel.h" 1#include "tracker_panel.h"
2 2
3#include "ap_state.h"
3#include "area_popup.h" 4#include "area_popup.h"
4#include "game_data.h" 5#include "game_data.h"
6#include "tracker_state.h"
7
8constexpr int AREA_ACTUAL_SIZE = 64;
9constexpr int AREA_BORDER_SIZE = 5;
10constexpr int AREA_EFFECTIVE_SIZE = AREA_ACTUAL_SIZE + AREA_BORDER_SIZE * 2;
5 11
6TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) { 12TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
7 map_image_ = wxImage("assets/lingo_map.png", wxBITMAP_TYPE_PNG); 13 map_image_ = wxImage("assets/lingo_map.png", wxBITMAP_TYPE_PNG);
@@ -10,30 +16,26 @@ TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
10 } 16 }
11 17
12 for (const MapArea &map_area : GetGameData().GetMapAreas()) { 18 for (const MapArea &map_area : GetGameData().GetMapAreas()) {
13 AreaPopup *area_popup = new AreaPopup(this, map_area.id); 19 AreaIndicator area;
14 area_popup->SetPosition({0, 0}); 20 area.area_id = map_area.id;
15 area_popup->Raise(); 21
16 area_popups_.push_back(area_popup); 22 area.popup = new AreaPopup(this, map_area.id);
17 23 area.popup->SetPosition({0, 0});
18 AreaWindow *area_window = new AreaWindow(this, map_area.id, area_popup); 24
19 area_window->Lower(); 25 areas_.push_back(area);
20 area_windows_.push_back(area_window);
21 } 26 }
22 27
23 Redraw(); 28 Redraw();
24 29
25 Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this); 30 Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this);
31 Bind(wxEVT_MOTION, &TrackerPanel::OnMouseMove, this);
26} 32}
27 33
28void TrackerPanel::UpdateIndicators() { 34void TrackerPanel::UpdateIndicators() {
29 Redraw(); 35 Redraw();
30 36
31 for (AreaWindow *area_window : area_windows_) { 37 for (AreaIndicator& area : areas_) {
32 area_window->UpdateIndicators(); 38 area.popup->UpdateIndicators();
33 }
34
35 for (AreaPopup *area_popup : area_popups_) {
36 area_popup->UpdateIndicators();
37 } 39 }
38} 40}
39 41
@@ -44,6 +46,21 @@ void TrackerPanel::OnPaint(wxPaintEvent &event) {
44 46
45 wxPaintDC dc(this); 47 wxPaintDC dc(this);
46 dc.DrawBitmap(rendered_, 0, 0); 48 dc.DrawBitmap(rendered_, 0, 0);
49
50 event.Skip();
51}
52
53void TrackerPanel::OnMouseMove(wxMouseEvent &event) {
54 for (AreaIndicator &area : areas_) {
55 if (area.real_x1 <= event.GetX() && event.GetX() < area.real_x2 &&
56 area.real_y1 <= event.GetY() && event.GetY() < area.real_y2) {
57 area.popup->Show();
58 } else {
59 area.popup->Hide();
60 }
61 }
62
63 event.Skip();
47} 64}
48 65
49void TrackerPanel::Redraw() { 66void TrackerPanel::Redraw() {
@@ -70,30 +87,66 @@ void TrackerPanel::Redraw() {
70 map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) 87 map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL)
71 .Size(panel_size, {final_x, final_y}, 0, 0, 0)); 88 .Size(panel_size, {final_x, final_y}, 0, 0, 0));
72 89
73 for (AreaWindow *area_window : area_windows_) { 90 wxMemoryDC dc;
74 const MapArea &map_area = 91 dc.SelectObject(rendered_);
75 GetGameData().GetMapArea(area_window->GetAreaId()); 92
93 for (AreaIndicator& area : areas_) {
94 const wxBrush *brush_color = wxGREY_BRUSH;
95
96 const MapArea &map_area = GetGameData().GetMapArea(area.area_id);
97 bool has_reachable_unchecked = false;
98 bool has_unreachable_unchecked = false;
99 for (int section_id = 0; section_id < map_area.locations.size();
100 section_id++) {
101 if (!GetAPState().HasCheckedGameLocation(area.area_id,
102 section_id)) {
103 if (GetTrackerState().IsLocationReachable(area.area_id,
104 section_id)) {
105 has_reachable_unchecked = true;
106 } else {
107 has_unreachable_unchecked = true;
108 }
109 }
110 }
111
112 if (has_reachable_unchecked && has_unreachable_unchecked) {
113 brush_color = wxYELLOW_BRUSH;
114 } else if (has_reachable_unchecked) {
115 brush_color = wxGREEN_BRUSH;
116 } else if (has_unreachable_unchecked) {
117 brush_color = wxRED_BRUSH;
118 }
119
76 int real_area_size = 120 int real_area_size =
77 final_width * AreaWindow::EFFECTIVE_SIZE / image_size.GetWidth(); 121 final_width * AREA_EFFECTIVE_SIZE / image_size.GetWidth();
78 area_window->SetSize({real_area_size, real_area_size}); 122 int actual_border_size =
79 area_window->SetPosition({ 123 real_area_size * AREA_BORDER_SIZE / AREA_EFFECTIVE_SIZE;
80 final_x + (map_area.map_x - (AreaWindow::EFFECTIVE_SIZE / 2)) * 124 int real_area_x =
81 final_width / image_size.GetWidth(), 125 final_x + (map_area.map_x - (AREA_EFFECTIVE_SIZE / 2)) *
82 final_y + (map_area.map_y - (AreaWindow::EFFECTIVE_SIZE / 2)) * 126 final_width / image_size.GetWidth();
83 final_width / image_size.GetWidth(), 127 int real_area_y =
84 }); 128 final_y + (map_area.map_y - (AREA_EFFECTIVE_SIZE / 2)) *
85 129 final_width / image_size.GetWidth();
86 AreaPopup *area_popup = area_window->GetPopup(); 130
131 dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size));
132 dc.SetBrush(*brush_color);
133 dc.DrawRectangle({real_area_x, real_area_y}, {real_area_size, real_area_size});
134
135 area.real_x1 = real_area_x;
136 area.real_x2 = real_area_x + real_area_size;
137 area.real_y1 = real_area_y;
138 area.real_y2 = real_area_y + real_area_size;
139
87 int popup_x = 140 int popup_x =
88 final_x + map_area.map_x * final_width / image_size.GetWidth(); 141 final_x + map_area.map_x * final_width / image_size.GetWidth();
89 int popup_y = 142 int popup_y =
90 final_y + map_area.map_y * final_width / image_size.GetWidth(); 143 final_y + map_area.map_y * final_width / image_size.GetWidth();
91 if (popup_x + area_popup->GetSize().GetWidth() > panel_size.GetWidth()) { 144 if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) {
92 popup_x = panel_size.GetWidth() - area_popup->GetSize().GetWidth(); 145 popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth();
93 } 146 }
94 if (popup_y + area_popup->GetSize().GetHeight() > panel_size.GetHeight()) { 147 if (popup_y + area.popup->GetSize().GetHeight() > panel_size.GetHeight()) {
95 popup_y = panel_size.GetHeight() - area_popup->GetSize().GetHeight(); 148 popup_y = panel_size.GetHeight() - area.popup->GetSize().GetHeight();
96 } 149 }
97 area_popup->SetPosition({popup_x, popup_y}); 150 area.popup->SetPosition({popup_x, popup_y});
98 } 151 }
99} 152}