From 9f25878acfe1c7281a96f83742349516510c5b6d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 2 May 2023 10:07:25 -0400 Subject: Added areas to map --- CMakeLists.txt | 1 + area_window.cpp | 39 +++++++++++++++++ area_window.h | 30 +++++++++++++ assets/areas.yaml | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ game_data.cpp | 25 +++++++++++ game_data.h | 10 ++++- tracker_panel.cpp | 20 +++++++++ tracker_panel.h | 4 ++ 8 files changed, 257 insertions(+), 1 deletion(-) create mode 100644 area_window.cpp create mode 100644 area_window.h create mode 100755 assets/areas.yaml diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e4ece5..9000583 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ add_executable(lingo_ap_tracker tracker_frame.cpp tracker_panel.cpp game_data.cpp + area_window.cpp ) set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD 17) set_property(TARGET lingo_ap_tracker PROPERTY CXX_STANDARD_REQUIRED ON) diff --git a/area_window.cpp b/area_window.cpp new file mode 100644 index 0000000..b142525 --- /dev/null +++ b/area_window.cpp @@ -0,0 +1,39 @@ +#include "area_window.h" + +#include + +#include "game_data.h" + +AreaWindow::AreaWindow(wxWindow* parent, int area_id) + : wxWindow(parent, wxID_ANY), area_id_(area_id) { + SetSize(EFFECTIVE_SIZE, EFFECTIVE_SIZE); + + Redraw(); + + Bind(wxEVT_PAINT, &AreaWindow::OnPaint, this); + Bind(wxEVT_ENTER_WINDOW, &AreaWindow::OnEnterWindow, this); +} + +void AreaWindow::OnPaint(wxPaintEvent& event) { + if (GetSize() != rendered_.GetSize()) { + Redraw(); + } + + wxPaintDC dc(this); + dc.DrawBitmap(rendered_, 0, 0); +} + +void AreaWindow::OnEnterWindow(wxMouseEvent& event) { + std::cout << GetGameData().GetMapArea(area_id_).name << std::endl; +} + +void AreaWindow::Redraw() { + int actual_border_size = GetSize().GetWidth() * BORDER_SIZE / EFFECTIVE_SIZE; + + rendered_ = wxBitmap(GetSize()); + wxMemoryDC dc; + dc.SelectObject(rendered_); + dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, actual_border_size)); + dc.SetBrush(*wxGREEN_BRUSH); + dc.DrawRectangle({0, 0}, GetSize()); +} diff --git a/area_window.h b/area_window.h new file mode 100644 index 0000000..0806da4 --- /dev/null +++ b/area_window.h @@ -0,0 +1,30 @@ +#ifndef AREA_WINDOW_H_C2653ACF +#define AREA_WINDOW_H_C2653ACF + +#include + +#ifndef WX_PRECOMP +#include +#endif + +class AreaWindow : public wxWindow { + public: + static constexpr int ACTUAL_SIZE = 64; + static constexpr int BORDER_SIZE = 5; + static constexpr int EFFECTIVE_SIZE = ACTUAL_SIZE + BORDER_SIZE * 2; + + AreaWindow(wxWindow* parent, int area_id); + + int GetAreaId() const { return area_id_; } + + private: + void OnPaint(wxPaintEvent& event); + void OnEnterWindow(wxMouseEvent& event); + + void Redraw(); + + int area_id_; + wxBitmap rendered_; +}; + +#endif /* end of include guard: AREA_WINDOW_H_C2653ACF */ diff --git a/assets/areas.yaml b/assets/areas.yaml new file mode 100755 index 0000000..423ecd1 --- /dev/null +++ b/assets/areas.yaml @@ -0,0 +1,129 @@ +--- + Starting Room: + map: [1589, 1192] + Hidden Room: + map: [1725, 1236] + The Seeker: + map: [1686, 1361] + Second Room: + map: [1589, 1029] + Hub Room: + map: [1589, 924] + Pilgrim Room: + map: [1493, 1564] + Crossroads: + map: [1294, 720] + Amen Name Area: + fold_into: Crossroads + The Tenacious: + map: [1589, 780] + Warts Straw Area: + fold_into: Outside The Agreeable + Leaf Feel Area: + fold_into: Outside The Agreeable + Outside The Agreeable: + map: [1766, 700] + Hallway Room: + map: [573, 1631] + Dread Hallway: + fold_into: Outside The Agreeable + The Agreeable: + map: [1909, 699] + Hedge Maze: + map: [2102, 600] + The Perceptive: + map: [2251, 600] + The Fearless: + map: [1790, 2220] + The Observant: + map: [2252, 193] + The Incomparable: + map: [2642, 872] + Orange Tower First Floor: + map: [1285, 928] + Color Hunt: + map: [1790, 2079] + Orange Tower Third Floor: + map: [1935, 1575] + Orange Tower Fourth Floor: + map: [1365, 394] + Orange Tower Fifth Floor: + map: [1252, 1259] + Orange Tower Seventh Floor: + map: [1587, 1900] + Courtyard: + map: [863, 387] + The Colorful: + map: [863, 200] + Welcome Back Area: + map: [1472, 1233] + Owl Hallway: + map: [2080, 886] + Outside The Initiated: + map: [2282, 1483] + The Initiated: + map: [2294, 1174] + The Traveled: + map: [1964, 994] + Outside The Bold: + map: [2325, 1927] + The Bold: + map: [2297, 2053] + The Red: + map: [2352, 2053] + Outside The Undeterred: + map: [657, 1315] + The Undeterred: + map: [618, 1456] + Number Hunt: + map: [1108, 1315] + Directional Gallery: + map: [943, 1169] + Champion's Rest: + map: [1845, 1883] + The Bearer: + map: [2155, 1764] + The Steady: + map: [2121, 2182] + Knight Night Room: + map: [1990, 1322] + The Artistic: + map: [1151, 1793] + The Artistic (Smiley): + fold_into: The Artistic + The Discerning: + map: [1098, 807] + The Ecstatic: + map: [972, 805] + The Eyes They See: + map: [955, 933] + Outside The Wondrous: + map: [691, 524] + The Wondrous: + map: [648, 338] + Elements Area: + map: [908, 1632] + Wanderlust Tutorial: + map: [1587, 1765] + Rhyme Room (Smiley): + fold_into: Rhyme Room + Rhyme Room (Cross): + fold_into: Rhyme Room + Rhyme Room: + map: [1587, 1492] + Rhyme Room (Target): + fold_into: Rhyme Room + Room Room: + map: [2553, 2153] + Outside The Wise: + map: [1087, 1986] + The Wise: + map: [759, 1986] + Outside The Scientific: + map: [510, 2271] + The Scientific: + map: [1368, 2103] + Art Gallery: + map: [2474, 1366] + Challenge Room: + map: [1486, 1357] diff --git a/game_data.cpp b/game_data.cpp index 0ae5468..f377e0b 100644 --- a/game_data.cpp +++ b/game_data.cpp @@ -217,6 +217,21 @@ GameData::GameData() { } } } + + map_areas_.reserve(areas_config.size()); + + std::map fold_areas; + for (const auto &area_it : areas_config) { + if (area_it.second["map"]) { + int area_id = AddOrGetArea(area_it.first.as()); + MapArea &area_obj = map_areas_[area_id]; + area_obj.map_x = area_it.second["map"][0].as(); + area_obj.map_y = area_it.second["map"][1].as(); + } else if (area_it.second["fold_into"]) { + fold_areas[area_it.first.as()] = + AddOrGetArea(area_it.second["fold_into"].as()); + } + } } int GameData::AddOrGetRoom(std::string room) { @@ -250,6 +265,16 @@ int GameData::AddOrGetPanel(std::string room, std::string panel) { return panel_by_id_[full_name]; } +int GameData::AddOrGetArea(std::string area) { + if (!area_by_id_.count(area)) { + area_by_id_[area] = map_areas_.size(); + map_areas_.push_back( + {.id = static_cast(map_areas_.size()), .name = area}); + } + + return area_by_id_[area]; +} + const GameData &GetGameData() { static GameData *instance = new GameData(); return *instance; diff --git a/game_data.h b/game_data.h index 761b233..91b48a5 100644 --- a/game_data.h +++ b/game_data.h @@ -57,6 +57,7 @@ struct Location { }; struct MapArea { + int id; std::string name; std::vector locations; int map_x; @@ -67,20 +68,27 @@ class GameData { public: GameData(); + const std::vector& GetMapAreas() const { return map_areas_; } + + const MapArea& GetMapArea(int id) const { return map_areas_.at(id); } + private: int AddOrGetRoom(std::string room); int AddOrGetDoor(std::string room, std::string door); int AddOrGetPanel(std::string room, std::string panel); + int AddOrGetArea(std::string area); std::vector rooms_; std::vector doors_; std::vector panels_; + std::vector map_areas_; std::map room_by_id_; std::map door_by_id_; std::map panel_by_id_; + std::map area_by_id_; }; -const GameData &GetGameData(); +const GameData& GetGameData(); #endif /* end of include guard: GAME_DATA_H_9C42AC51 */ diff --git a/tracker_panel.cpp b/tracker_panel.cpp index 38d7c86..0cd65cc 100644 --- a/tracker_panel.cpp +++ b/tracker_panel.cpp @@ -1,11 +1,17 @@ #include "tracker_panel.h" +#include "game_data.h" + 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 : GetGameData().GetMapAreas()) { + area_windows_.push_back(new AreaWindow(this, map_area.id)); + } + Redraw(); Bind(wxEVT_PAINT, &TrackerPanel::OnPaint, this); @@ -43,4 +49,18 @@ void TrackerPanel::Redraw() { rendered_ = wxBitmap( map_image_.Scale(final_width, final_height, wxIMAGE_QUALITY_NORMAL) .Size(panel_size, {final_x, final_y}, 0, 0, 0)); + + for (AreaWindow *area_window : area_windows_) { + const MapArea &map_area = + GetGameData().GetMapArea(area_window->GetAreaId()); + int real_area_size = + final_width * AreaWindow::EFFECTIVE_SIZE / image_size.GetWidth(); + area_window->SetSize({real_area_size, real_area_size}); + area_window->SetPosition({ + final_x + (map_area.map_x - (AreaWindow::EFFECTIVE_SIZE / 2)) * + final_width / image_size.GetWidth(), + final_y + (map_area.map_y - (AreaWindow::EFFECTIVE_SIZE / 2)) * + final_width / image_size.GetWidth(), + }); + } } diff --git a/tracker_panel.h b/tracker_panel.h index 32f7537..ae15271 100644 --- a/tracker_panel.h +++ b/tracker_panel.h @@ -7,6 +7,8 @@ #include #endif +#include "area_window.h" + class TrackerPanel : public wxPanel { public: TrackerPanel(wxWindow *parent); @@ -18,6 +20,8 @@ class TrackerPanel : public wxPanel { wxImage map_image_; wxBitmap rendered_; + + std::vector area_windows_; }; #endif /* end of include guard: TRACKER_PANEL_H_D675A54D */ -- cgit 1.4.1