From ea16cff14ff4faf5782da8ff684a6ec412b7b6ac Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sun, 12 May 2024 17:48:02 -0400 Subject: Started making subway map --- src/game_data.cpp | 62 ++++++++++++++++++++++++++++++++++- src/game_data.h | 25 +++++++++++++++ src/subway_map.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/subway_map.h | 35 ++++++++++++++++++++ src/tracker_frame.cpp | 13 ++++++-- src/tracker_frame.h | 2 ++ src/tracker_state.cpp | 20 ++++++++++++ src/tracker_state.h | 2 ++ 8 files changed, 244 insertions(+), 4 deletions(-) create mode 100644 src/subway_map.cpp create mode 100644 src/subway_map.h (limited to 'src') diff --git a/src/game_data.cpp b/src/game_data.cpp index c98f532..4348967 100644 --- a/src/game_data.cpp +++ b/src/game_data.cpp @@ -44,6 +44,7 @@ struct GameData { std::vector doors_; std::vector panels_; std::vector map_areas_; + std::vector subway_items_; std::map room_by_id_; std::map door_by_id_; @@ -606,6 +607,56 @@ struct GameData { errstr << "Area data not found for: " << area; TrackerLog(errstr.str()); } + + // Read in subway items. + YAML::Node subway_config = + YAML::LoadFile(GetAbsolutePath("assets/subway.yaml")); + for (const auto &subway_it : subway_config) { + SubwayItem subway_item; + subway_item.id = subway_items_.size(); + subway_item.x = subway_it["pos"][0].as(); + subway_item.y = subway_it["pos"][1].as(); + + if (subway_it["door"]) { + subway_item.door = AddOrGetDoor(subway_it["room"].as(), + subway_it["door"].as()); + } + + if (subway_it["paintings"]) { + for (const auto &painting_it : subway_it["paintings"]) { + subway_item.paintings.push_back(painting_it.as()); + } + } + + if (subway_it["tags"]) { + for (const auto &tag_it : subway_it["tags"]) { + subway_item.tags.push_back(tag_it.as()); + } + } + + if (subway_it["sunwarp"]) { + SubwaySunwarp sunwarp; + sunwarp.dots = subway_it["sunwarp"]["dots"].as(); + + std::string sunwarp_type = + subway_it["sunwarp"]["type"].as(); + if (sunwarp_type == "final") { + sunwarp.type = SubwaySunwarpType::kFinal; + } else if (sunwarp_type == "exit") { + sunwarp.type = SubwaySunwarpType::kExit; + } else { + sunwarp.type = SubwaySunwarpType::kEnter; + } + + subway_item.sunwarp = sunwarp; + } + + if (subway_it["special"]) { + subway_item.special = subway_it["special"].as(); + } + + subway_items_.push_back(subway_item); + } } int AddOrGetRoom(std::string room) { @@ -621,8 +672,9 @@ struct GameData { std::string full_name = room + " - " + door; if (!door_by_id_.count(full_name)) { + int door_id = doors_.size(); door_by_id_[full_name] = doors_.size(); - doors_.push_back({.room = AddOrGetRoom(room), .name = door}); + doors_.push_back({.id = door_id, .room = AddOrGetRoom(room), .name = door}); } return door_by_id_[full_name]; @@ -704,3 +756,11 @@ const std::vector &GD_GetSunwarpDoors() { int GD_GetRoomForSunwarp(int index) { return GetState().room_by_sunwarp_.at(index); } + +const std::vector &GD_GetSubwayItems() { + return GetState().subway_items_; +} + +const SubwayItem &GD_GetSubwayItem(int id) { + return GetState().subway_items_.at(id); +} diff --git a/src/game_data.h b/src/game_data.h index cd09627..37d1eb3 100644 --- a/src/game_data.h +++ b/src/game_data.h @@ -62,6 +62,7 @@ struct ProgressiveRequirement { }; struct Door { + int id; int room; std::string name; std::string location_name; @@ -118,6 +119,28 @@ struct MapArea { bool hunt = false; }; +enum class SubwaySunwarpType { + kEnter, + kExit, + kFinal +}; + +struct SubwaySunwarp { + int dots; + SubwaySunwarpType type; +}; + +struct SubwayItem { + int id; + int x; + int y; + std::optional door; + std::vector paintings; + std::vector tags; + std::optional sunwarp; + std::optional special; +}; + const std::vector& GD_GetMapAreas(); const MapArea& GD_GetMapArea(int id); int GD_GetRoomByName(const std::string& name); @@ -131,5 +154,7 @@ const std::vector& GD_GetAchievementPanels(); int GD_GetItemIdForColor(LingoColor color); const std::vector& GD_GetSunwarpDoors(); int GD_GetRoomForSunwarp(int index); +const std::vector& GD_GetSubwayItems(); +const SubwayItem& GD_GetSubwayItem(int id); #endif /* end of include guard: GAME_DATA_H_9C42AC51 */ diff --git a/src/subway_map.cpp b/src/subway_map.cpp new file mode 100644 index 0000000..c58b2d1 --- /dev/null +++ b/src/subway_map.cpp @@ -0,0 +1,89 @@ +#include "subway_map.h" + +#include "game_data.h" +#include "global.h" +#include "tracker_state.h" + +constexpr int AREA_ACTUAL_SIZE = 21; + +SubwayMap::SubwayMap(wxWindow *parent) : wxPanel(parent, wxID_ANY) { + map_image_ = + wxImage(GetAbsolutePath("assets/subway.png").c_str(), wxBITMAP_TYPE_PNG); + if (!map_image_.IsOk()) { + return; + } + + Redraw(); + Resize(); + + Bind(wxEVT_PAINT, &SubwayMap::OnPaint, this); + Bind(wxEVT_MOTION, &SubwayMap::OnMouseMove, this); +} + +void SubwayMap::UpdateIndicators() { + Redraw(); + Resize(); +} + +void SubwayMap::OnPaint(wxPaintEvent &event) { + if (GetSize() != resized_.GetSize()) { + Resize(); + } + + wxPaintDC dc(this); + dc.DrawBitmap(resized_, 0, 0); + + event.Skip(); +} + +void SubwayMap::OnMouseMove(wxMouseEvent &event) { + event.Skip(); +} + +void SubwayMap::Redraw() { + rendered_ = wxBitmap(map_image_); + + wxMemoryDC dc; + dc.SelectObject(rendered_); + + for (const SubwayItem &subway_item : GD_GetSubwayItems()) { + const wxBrush *brush_color = wxGREY_BRUSH; + if (subway_item.door) { + if (IsDoorOpen(*subway_item.door)) { + brush_color = wxGREEN_BRUSH; + } else { + brush_color = wxRED_BRUSH; + } + } + + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 1)); + dc.SetBrush(*brush_color); + dc.DrawRectangle({subway_item.x, subway_item.y}, + {AREA_ACTUAL_SIZE, AREA_ACTUAL_SIZE}); + } +} + +void SubwayMap::Resize() { + wxSize panel_size = GetSize(); + wxSize image_size = rendered_.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.GetHeight(); + render_x_ = (panel_size.GetWidth() - render_width_) / 2; + } + + resized_ = wxBitmap(rendered_.ConvertToImage() + .Scale(render_width_, render_height_, wxIMAGE_QUALITY_BILINEAR) + .Size(panel_size, {render_x_, render_y_}, 0, 0, 0)); +} diff --git a/src/subway_map.h b/src/subway_map.h new file mode 100644 index 0000000..dc67867 --- /dev/null +++ b/src/subway_map.h @@ -0,0 +1,35 @@ +#ifndef SUBWAY_MAP_H_BD2D843E +#define SUBWAY_MAP_H_BD2D843E + +#include + +#ifndef WX_PRECOMP +#include +#endif + +#include + +class SubwayMap : public wxPanel { + public: + SubwayMap(wxWindow *parent); + + void UpdateIndicators(); + + private: + void OnPaint(wxPaintEvent &event); + void OnMouseMove(wxMouseEvent &event); + + void Redraw(); + void Resize(); + + wxImage map_image_; + wxBitmap rendered_; + wxBitmap resized_; + int render_x_ = 0; + int render_y_ = 0; + int render_width_ = 0; + int render_height_ = 0; + +}; + +#endif /* end of include guard: SUBWAY_MAP_H_BD2D843E */ diff --git a/src/tracker_frame.cpp b/src/tracker_frame.cpp index 8a0c764..70fee2d 100644 --- a/src/tracker_frame.cpp +++ b/src/tracker_frame.cpp @@ -11,6 +11,7 @@ #include "ap_state.h" #include "connection_dialog.h" #include "settings_dialog.h" +#include "subway_map.h" #include "tracker_config.h" #include "tracker_panel.h" #include "version.h" @@ -58,15 +59,20 @@ TrackerFrame::TrackerFrame() Bind(STATE_CHANGED, &TrackerFrame::OnStateChanged, this); Bind(STATUS_CHANGED, &TrackerFrame::OnStatusChanged, this); - wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY); achievements_pane_ = new AchievementsPane(this); + + wxChoicebook *choicebook = new wxChoicebook(this, wxID_ANY); choicebook->AddPage(achievements_pane_, "Achievements"); - tracker_panel_ = new TrackerPanel(this); + wxNotebook *rightpane = new wxNotebook(this, wxID_ANY); + tracker_panel_ = new TrackerPanel(rightpane); + subway_map_ = new SubwayMap(rightpane); + rightpane->AddPage(tracker_panel_, "Map"); + rightpane->AddPage(subway_map_, "Subway"); wxBoxSizer *top_sizer = new wxBoxSizer(wxHORIZONTAL); top_sizer->Add(choicebook, wxSizerFlags().Expand().Proportion(1)); - top_sizer->Add(tracker_panel_, wxSizerFlags().Expand().Proportion(3)); + top_sizer->Add(rightpane, wxSizerFlags().Expand().Proportion(3)); SetSizerAndFit(top_sizer); SetSize(1280, 728); @@ -165,6 +171,7 @@ void TrackerFrame::OnCheckForUpdates(wxCommandEvent &event) { void TrackerFrame::OnStateChanged(wxCommandEvent &event) { tracker_panel_->UpdateIndicators(); achievements_pane_->UpdateIndicators(); + subway_map_->UpdateIndicators(); Refresh(); } diff --git a/src/tracker_frame.h b/src/tracker_frame.h index e5bf97e..c7c6772 100644 --- a/src/tracker_frame.h +++ b/src/tracker_frame.h @@ -8,6 +8,7 @@ #endif class AchievementsPane; +class SubwayMap; class TrackerPanel; wxDECLARE_EVENT(STATE_CHANGED, wxCommandEvent); @@ -35,6 +36,7 @@ class TrackerFrame : public wxFrame { TrackerPanel *tracker_panel_; AchievementsPane *achievements_pane_; + SubwayMap *subway_map_; }; #endif /* end of include guard: TRACKER_FRAME_H_86BD8DFB */ diff --git a/src/tracker_state.cpp b/src/tracker_state.cpp index 640a159..5588c7f 100644 --- a/src/tracker_state.cpp +++ b/src/tracker_state.cpp @@ -14,6 +14,7 @@ namespace { struct TrackerState { std::map reachability; + std::set reachable_doors; std::mutex reachability_mutex; }; @@ -156,6 +157,11 @@ class StateCalculator { flood_boundary = new_boundary; panel_boundary = new_panel_boundary; } + + // Now that we know the full reachable area, let's make sure all doors are evaluated. + for (const Door& door : GD_GetDoors()) { + int discard = IsDoorReachable(door.id); + } } const std::set& GetReachableRooms() const { return reachable_rooms_; } @@ -422,9 +428,17 @@ void RecalculateReachability() { } } + std::set new_reachable_doors; + for (const auto& [door_id, decision] : state_calculator.GetDoorDecisions()) { + if (decision == kYes) { + new_reachable_doors.insert(door_id); + } + } + { std::lock_guard reachability_guard(GetState().reachability_mutex); std::swap(GetState().reachability, new_reachability); + std::swap(GetState().reachable_doors, new_reachable_doors); } } @@ -437,3 +451,9 @@ bool IsLocationReachable(int location_id) { return false; } } + +bool IsDoorOpen(int door_id) { + std::lock_guard reachability_guard(GetState().reachability_mutex); + + return GetState().reachable_doors.count(door_id); +} diff --git a/src/tracker_state.h b/src/tracker_state.h index e73607f..119b3b5 100644 --- a/src/tracker_state.h +++ b/src/tracker_state.h @@ -5,4 +5,6 @@ void RecalculateReachability(); bool IsLocationReachable(int location_id); +bool IsDoorOpen(int door_id); + #endif /* end of include guard: TRACKER_STATE_H_8639BC90 */ -- cgit 1.4.1