about summary refs log tree commit diff stats
path: root/src/paintings_pane.cpp
blob: 352533f8c21d03b8721111b18ca68a1f339f9dfa (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
54
55
56
57
58
59
60
61
#include "paintings_pane.h"

#include <map>
#include <set>

#include <fmt/core.h>
#include <wx/dataview.h>

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

namespace {

std::string GetPaintingDisplayName(const std::string& id) {
  const PaintingExit& painting = GD_GetPaintingExit(GD_GetPaintingByName(id));
  const MapArea& map_area = GD_GetMapArea(painting.map_area);

  return fmt::format("{} - {}", map_area.name, painting.display_name);
}

}  // namespace

PaintingsPane::PaintingsPane(wxWindow* parent)
    : wxPanel(parent, wxID_ANY) {
  wxStaticText* label = new wxStaticText(this, wxID_ANY, "Shuffled paintings grouped by destination:");
  tree_ctrl_ = new wxDataViewTreeCtrl(this, wxID_ANY);

  wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
  top_sizer->Add(label, wxSizerFlags().Border());
  top_sizer->Add(tree_ctrl_, wxSizerFlags().Expand().Proportion(1));

  SetSizerAndFit(top_sizer);
}

void PaintingsPane::UpdateIndicators() {
  tree_ctrl_->DeleteAllItems();

  if (!AP_IsPaintingShuffle()) {
    return;
  }

  std::map<std::string, std::set<std::string>> grouped_paintings;

  for (const auto& [from, to] : AP_GetPaintingMapping()) {
    if (IsPaintingReachable(GD_GetPaintingByName(from)) &&
        AP_IsPaintingChecked(from)) {
      grouped_paintings[GetPaintingDisplayName(to)].insert(
          GetPaintingDisplayName(from));
    }
  }

  for (const auto& [to, froms] : grouped_paintings) {
    wxDataViewItem tree_branch =
        tree_ctrl_->AppendContainer(wxDataViewItem(0), to);

    for (const std::string& from : froms) {
      tree_ctrl_->AppendItem(tree_branch, from);
    }
  }
}