#include "subway_map.h" #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_TIMER, &SubwayMap::OnTimer, this); } 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::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()) /
extends "res://scripts/player.gd"


func _solving():
	._solving()

	var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects")
	effects_node.enter_solve_mode()


func _solvingEnd():
	._solvingEnd()

	var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects")
	effects_node.exit_solve_mode()


func _unhandled_input(event):
	._unhandled_input(event)

	if event is InputEventKey:
		if event.pressed and event.scancode == KEY_P:
			var effects_node = get_tree().get_root().get_node("Spatial/AP_Effects")
			effects_node.skip_puzzle()
xPoint real_area_pos = {subway_item.x, subway_item.y}; int real_area_size = (draw_type == ItemDrawType::kOwl ? OWL_ACTUAL_SIZE : AREA_ACTUAL_SIZE); if (draw_type == ItemDrawType::kBox) { dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); dc.SetBrush(*brush_color); dc.DrawRectangle(real_area_pos, {real_area_size, real_area_size}); } else if (draw_type == ItemDrawType::kOwl) { wxBitmap owl_bitmap = wxBitmap(owl_image_.Scale( real_area_size, real_area_size, wxIMAGE_QUALITY_BILINEAR)); dc.DrawBitmap(owl_bitmap, real_area_pos); } } } wxPoint SubwayMap::MapPosToRenderPos(wxPoint pos) const { return {static_cast(pos.x * render_width_ * zoom_ / map_image_.GetSize().GetWidth() + zoom_x_), static_cast(pos.y * render_width_ * zoom_ / map_image_.GetSize().GetWidth() + zoom_y_)}; } wxPoint SubwayMap::MapPosToVirtualPos(wxPoint pos) const { return {static_cast(pos.x * render_width_ * zoom_ / map_image_.GetSize().GetWidth()), static_cast(pos.y * render_width_ * zoom_ / map_image_.GetSize().GetWidth())}; } wxPoint SubwayMap::RenderPosToMapPos(wxPoint pos) const { return { std::clamp(static_cast((pos.x - zoom_x_) * map_image_.GetWidth() / render_width_ / zoom_), 0, map_image_.GetWidth() - 1), std::clamp(static_cast((pos.y - zoom_y_) * map_image_.GetWidth() / render_width_ / zoom_), 0, map_image_.GetHeight() - 1)}; } void SubwayMap::SetZoomPos(wxPoint pos) { if (render_width_ * zoom_ <= GetSize().GetWidth()) { zoom_x_ = (GetSize().GetWidth() - render_width_ * zoom_) / 2; } else { zoom_x_ = std::clamp( pos.x, GetSize().GetWidth() - static_cast(render_width_ * zoom_), 0); } if (render_height_ * zoom_ <= GetSize().GetHeight()) { zoom_y_ = (GetSize().GetHeight() - render_height_ * zoom_) / 2; } else { zoom_y_ = std::clamp( pos.y, GetSize().GetHeight() - static_cast(render_height_ * zoom_), 0); } } void SubwayMap::SetScrollSpeed(int scroll_x, int scroll_y) { bool should_timer = (scroll_x != 0 || scroll_y != 0); if (should_timer != scroll_timer_->IsRunning()) { if (should_timer) { scroll_timer_->Start(1000 / 60); } else { scroll_timer_->Stop(); } } scroll_x_ = scroll_x; scroll_y_ = scroll_y; } quadtree::Box SubwayMap::GetItemBox::operator()(const int &id) const { const SubwayItem &subway_item = GD_GetSubwayItem(id); return {static_cast(subway_item.x), static_cast(subway_item.y), AREA_ACTUAL_SIZE, AREA_ACTUAL_SIZE}; }