Skip to content

Commit

Permalink
Mission map widget for overlay, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
3vcloud committed Oct 15, 2024
1 parent b367e8b commit 0152a6f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Dependencies/GWCA
3 changes: 2 additions & 1 deletion GWToolboxdll/Modules/ToolboxSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include <Widgets/EffectsMonitorWidget.h>
#include <Widgets/LatencyWidget.h>
#include <Widgets/ActiveQuestWidget.h>
#include <Widgets/MissionMapWidget.h>
#include "ToolboxSettings.h"


Expand Down Expand Up @@ -223,7 +224,7 @@ void ToolboxSettings::LoadModules(ToolboxIni* ini)
GWToolbox::ToggleModule(StringDecoderWindow::Instance());
GWToolbox::ToggleModule(DoorMonitorWindow::Instance());
GWToolbox::ToggleModule(SkillListingWindow::Instance());
GWToolbox::ToggleModule(TargetInfoWindow::Instance());
GWToolbox::ToggleModule(MissionMapWidget::Instance());
#endif

GWToolbox::ToggleModule(VendorFix::Instance());
Expand Down
59 changes: 59 additions & 0 deletions GWToolboxdll/Widgets/MissionMapWidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "stdafx.h"

#include "MissionMapWidget.h"

#include <GWCA/Context/MapContext.h>
#include <GWCA/Context/GameplayContext.h>

#include <GWCA/Managers/MapMgr.h>
#include <GWCA/Managers/UIMgr.h>

#include <Widgets/Minimap/Minimap.h>
#include <Utils/ToolboxUtils.h>

namespace {

}

void MissionMapWidget::Draw(IDirect3DDevice9*)
{
const auto mission_map_context = GW::Map::GetMissionMapContext();
const auto mission_map_frame = mission_map_context ? GW::UI::GetFrameById(mission_map_context->frame_id) : nullptr;
if (!(mission_map_frame && mission_map_frame->IsVisible()))
return;

const auto root = GW::UI::GetRootFrame();
const auto mission_map_top_left = mission_map_frame->position.GetContentTopLeft(root);
const auto mission_map_bottom_right = mission_map_frame->position.GetContentBottomRight(root);

const auto viewport = ImGui::GetMainViewport();
const auto& viewport_offset = viewport->Pos;
const auto draw_list = ImGui::GetBackgroundDrawList(viewport);

const auto& lines = Minimap::Instance().custom_renderer.GetLines();

// TODO: Look at the minimap widget and world map widget; use translations and other bollocks to draw lines into the mission map.

const auto gameplay_context = GW::GetGameplayContext();
const auto& mission_map_zoom = gameplay_context->mission_map_zoom; // e.g. scroll wheel in/out
const auto& mission_map_center_pos = mission_map_context->player_mission_map_pos; // e.g. player position in the world (this could change depending on observing etc)
const auto& mission_map_last_click_location = mission_map_context->last_mouse_location; // e.g. when you drag on the mission map
const auto& current_pan_offset = mission_map_context->h003c->mission_map_pan_offset;

(viewport_offset, lines, draw_list, mission_map_zoom, mission_map_center_pos, mission_map_last_click_location);

// Might need to rip off GamePosToWorldMap etc from world map widget

// Bounds for mission map:
draw_list->AddRect({ mission_map_top_left.x, mission_map_top_left.y }, { mission_map_bottom_right.x, mission_map_bottom_right.y }, IM_COL32_WHITE);
float y = mission_map_top_left.y;
draw_list->AddText({ mission_map_top_left.x, y }, IM_COL32_WHITE, "TODO: Look at the minimap widget and world map widget.\nUse translations and other bollocks to draw lines into the mission map.");
y += 48.f;
draw_list->AddText({ mission_map_top_left.x, y }, IM_COL32_WHITE, std::format("Mission Map rect: {}, {}, {}, {}\nZoom level: {}\nCenter pos (player):{}, {}\nPan:{}, {}",
mission_map_top_left.x, mission_map_top_left.y, mission_map_bottom_right.x, mission_map_bottom_right.y,
mission_map_zoom,
mission_map_center_pos.x, mission_map_center_pos.y,
current_pan_offset.x, current_pan_offset.y).c_str());

// RENDER ME!!
}
20 changes: 20 additions & 0 deletions GWToolboxdll/Widgets/MissionMapWidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <ToolboxWidget.h>

class MissionMapWidget : public ToolboxWidget {
MissionMapWidget() = default;
~MissionMapWidget() override = default;

public:
static MissionMapWidget& Instance()
{
static MissionMapWidget w;
return w;
}
bool HasSettings() override { return false; }
[[nodiscard]] const char* Name() const override { return "Mission Map"; }
[[nodiscard]] const char* Icon() const override { return ICON_FA_GLOBE; }

void Draw(IDirect3DDevice9* pDevice) override;
};
37 changes: 16 additions & 21 deletions GWToolboxdll/Windows/InfoWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <Logger.h>
#include <GWToolbox.h>
#include <Utils/TextUtils.h>
#include <GWCA/Context/GameplayContext.h>

namespace {

Expand Down Expand Up @@ -642,7 +643,13 @@ namespace {
}
}


void HighlightFrame(GW::UI::Frame* frame) {
const auto root = GW::UI::GetRootFrame();
const auto top_left = frame->position.GetTopLeftOnScreen(root);
const auto bottom_right = frame->position.GetBottomRightOnScreen(root);
const auto draw_list = ImGui::GetBackgroundDrawList();
draw_list->AddRect({ top_left.x, top_left.y }, { bottom_right.x, bottom_right.y }, IM_COL32_WHITE);
}


void PostDraw() {
Expand Down Expand Up @@ -769,32 +776,20 @@ namespace {
[[maybe_unused]] const GW::Chat::ChatBuffer* log = GW::Chat::GetChatLog();
[[maybe_unused]] const GW::AreaInfo* ai = GW::Map::GetMapInfo(GW::Map::GetMapID());
[[maybe_unused]] const auto ac = me_player ? GW::AccountMgr::GetAvailableCharacter(me_player->name) : nullptr;
[[maybe_unused]] const auto gpc = GW::GetGameplayContext();


[[maybe_unused]] const auto mission_map_context = GW::Map::GetMissionMapContext();
[[maybe_unused]] const auto mission_map_frame = mission_map_context ? GW::UI::GetFrameById(mission_map_context->frame_id) : nullptr;
[[maybe_unused]] const auto world_map_context = GW::Map::GetWorldMapContext();

[[maybe_unused]] const auto campaign = ac ? ac->campaign() : 0;
[[maybe_unused]] const auto level = ac ? ac->level() : 0;
[[maybe_unused]] const auto primary = ac ? ac->primary() : 0;
[[maybe_unused]] const auto secondary = ac ? ac->secondary() : 0;

#ifdef _DEBUG
const auto frame = GW::UI::GetFrameByLabel(L"NPCInteract");
if (frame && frame->IsVisible()) {
auto dialog_buttons_frame = GW::UI::GetChildFrame(frame, 2); // Scrollable frame
dialog_buttons_frame = GW::UI::GetChildFrame(dialog_buttons_frame, 0);
dialog_buttons_frame = GW::UI::GetChildFrame(dialog_buttons_frame, 0);
dialog_buttons_frame = GW::UI::GetChildFrame(dialog_buttons_frame, 1);
if (dialog_buttons_frame) {
for (auto& sibling : dialog_buttons_frame->relation.siblings) {
const auto button_frame = sibling.GetFrame();
if (button_frame->child_offset_id != 0x1)
continue; // Not a button frame
const auto top_left = button_frame->position.GetTopLeftOnScreen(frame);
const auto bottom_right = button_frame->position.GetBottomRightOnScreen(frame);
const auto label = std::to_string(button_frame->field100_0x1a8);
const auto draw_list = ImGui::GetBackgroundDrawList();
draw_list->AddRect({ top_left.x, top_left.y }, { bottom_right.x, bottom_right.y }, IM_COL32_WHITE);
draw_list->AddText({ top_left.x, top_left.y }, IM_COL32_WHITE, label.c_str());
}
}
}
//HighlightFrame(mission_map_frame);
#endif
}
}
Expand Down

0 comments on commit 0152a6f

Please sign in to comment.