Skip to content

Commit

Permalink
Merge pull request #1191 from AlexMacocian/alexmacocian/colored-quest…
Browse files Browse the repository at this point in the history
…-markers

Colored quest markers
  • Loading branch information
DubbleClick authored Jul 28, 2024
2 parents 2c3ad55 + 46af1f4 commit e371394
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 3 deletions.
8 changes: 8 additions & 0 deletions GWToolboxdll/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ namespace Colors {
i[3] = static_cast<int>(color >> IM_COL32_B_SHIFT & 0xFF);
}

static void ConvertU32ToFloat4RGBA(const Color color, float* i)
{
i[0] = static_cast<float>(color >> IM_COL32_R_SHIFT & 0xFF) / 255.0f;
i[1] = static_cast<float>(color >> IM_COL32_G_SHIFT & 0xFF) / 255.0f;
i[2] = static_cast<float>(color >> IM_COL32_B_SHIFT & 0xFF) / 255.0f;
i[3] = static_cast<float>(color >> IM_COL32_A_SHIFT & 0xFF) / 255.0f;
}

static Color ConvertInt4ToU32(const int* i)
{
return static_cast<Color>((i[0] & 0xFF) << IM_COL32_A_SHIFT) |
Expand Down
4 changes: 2 additions & 2 deletions GWToolboxdll/Modules/QuestModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace {
Colors::Yellow(), Colors::Amber(), Colors::Orange(),
Colors::DeepOrange(), Colors::Green(), Colors::Lime(),
Colors::Magenta(), Colors::Gold(), Colors::BlueGrey(),
Colors::Grey(), Colors::White(), Colors::MaterialBlue(),
Colors::MaterialGreen(), Colors::MaterialRed(), Colors::MaterialYellow()
Colors::White(), Colors::MaterialBlue(), Colors::MaterialGreen(),
Colors::MaterialRed(), Colors::MaterialYellow()
};

bool draw_quest_path_on_terrain = true;
Expand Down
9 changes: 9 additions & 0 deletions GWToolboxdll/Widgets/Minimap/Shaders/constant_colour_ps.hlsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cbuffer cbPerFrame : register(c0)
{
float4 color : register(c0);
};

float4 main() : SV_TARGET
{
return color;
}
39 changes: 39 additions & 0 deletions GWToolboxdll/Widgets/Minimap/SymbolsRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@

#include <ImGuiAddons.h>

#include <Color.h>

#include <GWCA/Managers/QuestMgr.h>
#include <Widgets/Minimap/Minimap.h>
#include <Widgets/Minimap/SymbolsRenderer.h>
#include <Modules/QuestModule.h>

// Note: these two files are autogenerated by CMake!
#include "Shaders/constant_colour_ps.h"

namespace {
IDirect3DPixelShader9* pshader = nullptr;
bool need_configure_pipeline = true;
}

void SymbolsRenderer::LoadSettings(const ToolboxIni* ini, const char* section)
{
Expand Down Expand Up @@ -157,6 +168,12 @@ void SymbolsRenderer::Render(IDirect3DDevice9* device)
{
Initialize(device);

if (need_configure_pipeline) {
if (!ConfigureProgrammablePipeline(device)) {
return;
}
}

const GW::Agent* me = GW::Agents::GetObservingAgent();
if (me == nullptr) {
return;
Expand Down Expand Up @@ -191,6 +208,11 @@ void SymbolsRenderer::Render(IDirect3DDevice9* device)
if (ImColor(is_current_quest ? color_quest : color_other_quests).Value.w == 0.0f) {
return;
}

const auto quest_im_color = QuestModule::GetQuestColor(quest.quest_id);
float quest_color[4];
Colors::ConvertU32ToFloat4RGBA(quest_im_color, quest_color);
device->SetPixelShaderConstantF(0, quest_color, 1);
const GW::Vec2f qpos = { quest.marker.x, quest.marker.y };
if (std::ranges::contains(markers_drawn, qpos))
return; // Don't draw more than 1 marker for a position
Expand Down Expand Up @@ -222,6 +244,11 @@ void SymbolsRenderer::Render(IDirect3DDevice9* device)
};

if (const auto quest_log = GW::QuestMgr::GetQuestLog()) {
if (pshader == nullptr || device->SetPixelShader(pshader) != D3D_OK) {
Log::Error("SymbolsRenderer: unable to SetPixelShader, aborting render.");
return;
}

// draw active quest first
const auto active_quest_id = GW::QuestMgr::GetActiveQuestId();
if (auto* quest = GW::QuestMgr::GetQuest(active_quest_id)) {
Expand All @@ -232,10 +259,22 @@ void SymbolsRenderer::Render(IDirect3DDevice9* device)
})) {
draw_quest_marker(quest);
}

device->SetPixelShader(nullptr);
}

translate = DirectX::XMMatrixTranslation(me->pos.x, me->pos.y + 5000.0f, 0);
world = translate;
device->SetTransform(D3DTS_WORLD, reinterpret_cast<const D3DMATRIX*>(&world));
device->DrawPrimitive(type, north_offset, north_ntriangles);
}

bool SymbolsRenderer::ConfigureProgrammablePipeline(IDirect3DDevice9* device)
{
if (device->CreatePixelShader(reinterpret_cast<const DWORD*>(&g_ps20_main), &pshader) != D3D_OK) {
// Log::Error("SymbolsRenderer: unable to CreateVertexShader");
return false;
}
need_configure_pipeline = false;
return true;
}
2 changes: 1 addition & 1 deletion GWToolboxdll/Widgets/Minimap/SymbolsRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SymbolsRenderer : public VBuffer {

private:
void Initialize(IDirect3DDevice9* device) override;

bool ConfigureProgrammablePipeline(IDirect3DDevice9* device);
Color color_quest = 0;
Color color_other_quests = 0;
Color color_north = 0;
Expand Down

0 comments on commit e371394

Please sign in to comment.