about summary refs log tree commit diff stats
path: root/src/tracker_panel.cpp
blob: 5580068d4bd2c54f36c24163855fed815391fee6 (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
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /*
#include "tracker_panel.h"

#include "ap_state.h"
#include "area_popup.h"
#include "game_data.h"
#include "tracker_state.h"

constexpr int AREA_ACTUAL_SIZE = 64;
constexpr int AREA_BORDER_SIZE = 5;
constexpr int AREA_EFFECTIVE_SIZE = AREA_ACTUAL_SIZE + AREA_BORDER_SIZE * 2;

TrackerPanel::TrackerPanel(wxWindow *parent) : wxPanel(parent, wxID_ANY) {
  map_image_ = wxImage("assets/lingo_map.png", wxBITMAP_TYPE_PNG);
  if (!map_image_.IsOk()) {
    return;
  }

  for (const MapArea &map_area : GD_GetMapAreas()) {
    AreaIndicator area;
    area.area_id = map_area.id;

    area.popup = new AreaPopup(this, map_area.id);
    area.popup->SetPosition({0, 0});

    areas_.push_back(area);
  }

  Redraw();

  Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this);
  Bind(wxEVT_MOTION, &TrackerPanel::OnMouseMove, this);
}

void TrackerPanel::UpdateIndicators() {
  Redraw();

  for (AreaIndicator &area : areas_) {
    area.popup->UpdateIndicators();
  }
}

void TrackerPanel::OnPaint(wxPaintEvent &event) {
  if (GetSize() != rendered_.GetSize()) {
    Redraw();
  }

  wxPaintDC dc(this);
  dc.DrawBitmap(rendered_, 0, 0);

  event.Skip();
}

void TrackerPanel::OnMouseMove(wxMouseEvent &event) {
  for (AreaIndicator &area : areas_) {
    if (area.active && area.real_x1 <= event.GetX() &&
        event.GetX() < area.real_x2 && area.real_y1 <= event.GetY() &&
        event.GetY() < area.real_y2) {
      area.popup->Show();
    } else {
      area.popup->Hide();
    }
  }

  event.Skip();
}

void TrackerPanel::Redraw() {
  wxSize panel_size = GetSize();
  wxSize image_size = map_image_.GetSize();

  int final_x = 0;
  int final_y = 0;
  int final_width = panel_size.GetWidth();
  int final_height = panel_size.GetHeight();

  if (image_size.GetWidth() * panel_size.GetHeight() >
      panel_size.GetWidth() * image_size.GetHeight()) {
    final_height = (panel_size.GetWidth() * image_size.GetHeight()) /
                   image_size.GetWidth();
    final_y = (panel_size.GetHeight() - final_height) / 2;
  } else {
    final_width = (image_size.GetWidth() * panel_size.GetHeight()) /
                  image_size.GetHeight();
    final_x = (panel_size.GetWidth() - final_width) / 2;
  }

  rendered_ = wxBitmap(
      map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL)
          .Size(panel_size, {final_x, final_y}, 0, 0, 0));

  wxMemoryDC dc;
  dc.SelectObject(rendered_);

  for (AreaIndicator &area : areas_) {
    const wxBrush *brush_color = wxGREY_BRUSH;

    const MapArea &map_area = GD_GetMapArea(area.area_id);
    if (!AP_IsLocationVisible(map_area.classification)) {
      area.active = false;
      continue;
    } else {
      area.active = true;
    }

    bool has_reachable_unchecked = false;
    bool has_unreachable_unchecked = false;
    for (const Location &section : map_area.locations) {
      if (AP_IsLocationVisible(section.classification) &&
          !AP_HasCheckedGameLocation(section.ap_location_id)) {
        if (IsLocationReachable(section.ap_location_id)) {
          has_reachable_unchecked = true;
        } else {
          has_unreachable_unchecked = true;
        }
      }
    }

    if (has_reachable_unchecked && has_unreachable_unchecked) {
      brush_color = wxYELLOW_BRUSH;
    } else if (has_reachable_unchecked) {
      brush_color = wxGREEN_BRUSH;
    } else if (has_unreachable_unchecked) {
      brush_color = wxRED_BRUSH;
    }

    int real_area_size =
        final_width * AREA_EFFECTIVE_SIZE / image_size.GetWidth();
    int actual_border_size =
        real_area_size * AREA_BORDER_SIZE / AREA_EFFECTIVE_SIZE;
    int real_area_x = final_x + (map_area.map_x - (AREA_EFFECTIVE_SIZE / 2)) *
                                    final_width / image_size.GetWidth();
    int real_area_y = final_y + (map_area.map_y - (AREA_EFFECTIVE_SIZE / 2)) *
                                    final_width / image_size.GetWidth();

    dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size));
    dc.SetBrush(*brush_color);
    dc.DrawRectangle({real_area_x, real_area_y},
                     {real_area_size, real_area_size});

    area.real_x1 = real_area_x;
    area.real_x2 = real_area_x + real_area_size;
    area.real_y1 = real_area_y;
    area.real_y2 = real_area_y + real_area_size;

    int popup_x =
        final_x + map_area.map_x * final_width / image_size.GetWidth();
    int popup_y =
        final_y + map_area.map_y * final_width / image_size.GetWidth();

    area.popup->SetMaxSize(panel_size);
    area.popup->GetSizer()->Fit(area.popup);

    if (popup_x + area.popup->GetSize().GetWidth() > panel_size.GetWidth()) {
      popup_x = panel_size.GetWidth() - area.popup->GetSize().GetWidth();
    }
    if (popup_y + area.popup->GetSize().GetHeight() > panel_size.GetHeight()) {
      popup_y = panel_size.GetHeight() - area.popup->GetSize().GetHeight();
    }
    area.popup->SetPosition({popup_x, popup_y});
  }
}