#include "subway_map.h" #include #include #include #include "ap_state.h" #include "game_data.h" #include "global.h" #include "tracker_state.h" constexpr int AREA_ACTUAL_SIZE = 21; constexpr int OWL_ACTUAL_SIZE = 32; enum class ItemDrawType { kNone, kBox, kOwl }; SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { SetBackgroundStyle(wxBG_STYLE_PAINT); map_image_ = wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG); if (!map_image_.IsOk()) { return; } owl_image_ = wxImage(GetAbsolutePath("assets/owl.png").c_str(), wxBITMAP_TYPE_PNG); if (!owl_image_.IsOk()) { return; } unchecked_eye_ = wxBitmap(wxImage(GetAbsolutePath("assets/unchecked.png").c_str(), wxBITMAP_TYPE_PNG) .Scale(32, 32)); checked_eye_ = wxBitmap( wxImage(GetAbsolutePath("assets/checked.png").c_str(), wxBITMAP_TYPE_PNG) .Scale(32, 32)); tree_ = std::make_unique>( quadtree::Box{0, 0, static_cast(map_image_.GetWidth()), static_cast(map_image_.GetHeight())}); for (const SubwayItem &subway_item : GD_GetSubwayItems()) { tree_->add(subway_item.id); } Redraw(); scroll_timer_ = new wxTimer(this); Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this); Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); Bind(wxEVT_MOUSEWHEEL, &SubwayMap::OnMouseScroll, this); Bind(wxEVT_LEAVE_WINDOW, &SubwayMap::OnMouseLeave, this); Bind(wxEVT_LEFT_DOWN, &SubwayMap::OnMouseClick, this); Bind(wxEVT_TIMER, &SubwayMap::OnTimer, this); zoom_slider_ = new wxSlider(this, wxID_ANY, 0, 0, 8, {15, 15}); zoom_slider_->Bind(wxEVT_SLIDER, &SubwayMap::OnZoomSlide, this); help_button_ = new wxButton(this, wxID_ANY, "Help"); help_button_->Bind(wxEVT_BUTTON, &SubwayMap::OnClickHelp, this); SetUpHelpButton(); } void SubwayMap::OnConnect() { networks_.Clear(); std::map> tagged; for (const SubwayItem &subway_item : GD_GetSubwayItems()) { if (AP_IsPaintingShuffle() && !subway_item.paintings.empty()) { continue; } for (const std::string &tag : subway_item.tags) { tagged[tag].push_back(subway_item.id); } if (!AP_IsSunwarpShuffle() && subway_item.sunwarp && subway_item.sunwarp->type != SubwaySunwarpType::kFinal) { std::ostringstream tag; tag << "sunwarp" << subway_item.sunwarp->dots; tagged[tag.str()].push_back(subway_item.id); } } for (const auto &[tag, items] : tagged) { // Pairwise connect all items with the same tag. for (auto tag_it1 = items.begin(); std::next(tag_it1) != items.end(); tag_it1++) { for (auto tag_it2 = std::next(tag_it1); tag_it2 != items.end(); tag_it2++) { networks_.AddLink(*tag_it1, *tag_it2); } } } checked_paintings_.clear(); } void SubwayMap::UpdateIndicators() { if (AP_IsPaintingShuffle()) { for (const std::string &painting_id : AP_GetCheckedPaintings()) { if (!checked_paintings_.count(painting_id)) { checked_paintings_.insert(painting_id); if (AP_GetPaintingMapping().count(painting_id)) { networks_.AddLink(GD_GetSubwayItemForPainting(painting_id), GD_GetSubwayItemForPainting( AP_GetPaintingMapping().at(painting_id))); } } } } Redraw(); } void SubwayMap::UpdateSunwarp(SubwaySunwarp from_sunwarp, SubwaySunwarp to_sunwarp) { networks_.AddLink(GD_GetSubwayItemForSunwarp(from_sunwarp), GD_GetSubwayItemForSunwarp(to_sunwarp)); } void SubwayMap::Zoom(bool in) { wxPoint focus_point; if (mouse_position_) { focus_point = *mouse_position_; } else { focus_point = {GetSize().GetWidth() / 2, GetSize().GetHeight() / 2}; } if (in) { if (zoom_ < 3.0) { SetZoom(zoom_ + 0.25, focus_point); } } else { if (zoom_ > 1.0) { SetZoom(zoom_ - 0.25, focus_point); } } } void SubwayMap::OnPaint(wxPaintEvent &event) { if (GetSize() != rendered_.GetSize()) { wxSize panel_size = GetSize(); wxSize image_size = map_image_.GetSize(); render_x_ = 0; render_y_ = 0; render_width_ = panel_size.GetWidth(); render_height_ = panel_size.GetHeight(); if (image_size.GetWidth() * panel_size.GetHeight() > panel_size.GetWidth() * image_size.GetHeight()) { render_height_ = (panel_size.GetWidth() * image_size.GetHeight()) / image_size.GetWidth(); render_y_ = (panel_size.GetHeight() - render_height_) / 2; } else { render_width_ = (image_size.GetWidth() * panel_size.GetHeight()) / image_size.G
#include "network_set.h"

void NetworkSet::Clear() {
  network_by_item_.clear();
}

void NetworkSet::AddLink(int id1, int id2, bool two_way) {
  if (two_way && id2 > id1) {
    std::swap(id1, id2);
  }

  if (!network_by_item_.count(id1)) {
    network_by_item_[id1] = {};
  }
  if (!network_by_item_.count(id2)) {
    network_by_item_[id2] = {};
  }

  NetworkNode node = {id1, id2, two_way};

  network_by_item_[id1].insert(node);
  network_by_item_[id2].insert(node);
}

void NetworkSet::AddLinkToNetwork(int network_id, int id1, int id2, bool two_way) {
  if (two_way && id2 > id1) {
    std::swap(id1, id2);
  }

  if (!network_by_item_.count(network_id)) {
    network_by_item_[network_id] = {};
  }

  NetworkNode node = {id1, id2, two_way};

  network_by_item_[network_id].insert(node);
}

bool NetworkSet::IsItemInNetwork(int id) const {
  return network_by_item_.count(id);
}

const std::set<NetworkNode>& NetworkSet::GetNetworkGraph(int id) const {
  return network_by_item_.at(id);
}

bool NetworkNode::operator<(const NetworkNode& rhs) const {
  if (entry != rhs.entry) return entry < rhs.entry;
  if (exit != rhs.exit) return exit < rhs.exit;
  if (two_way != rhs.two_way) return two_way < rhs.two_way;
  return false;
}