yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_entity_renderer.cc
Go to the documentation of this file.
2
3#include "absl/strings/str_format.h"
4#include "app/core/features.h"
6#include "app/gui/canvas.h"
7#include "app/zelda3/common.h"
8#include "util/hex.h"
9#include "imgui/imgui.h"
10
11namespace yaze {
12namespace editor {
13
14using namespace ImGui;
15
16// Entity colors - solid with good visibility
17namespace {
18ImVec4 GetEntranceColor() { return ImVec4{1.0f, 1.0f, 0.0f, 1.0f}; } // Solid yellow (#FFFF00FF, fully opaque)
19ImVec4 GetExitColor() { return ImVec4{1.0f, 1.0f, 1.0f, 1.0f}; } // Solid white (#FFFFFFFF, fully opaque)
20ImVec4 GetItemColor() { return ImVec4{1.0f, 0.0f, 0.0f, 1.0f}; } // Solid red (#FF0000FF, fully opaque)
21ImVec4 GetSpriteColor() { return ImVec4{1.0f, 0.0f, 1.0f, 1.0f}; } // Solid magenta (#FF00FFFF, fully opaque)
22} // namespace
23
24void OverworldEntityRenderer::DrawEntrances(ImVec2 canvas_p0, ImVec2 scrolling,
25 int current_world,
26 int current_mode) {
27 hovered_entity_ = nullptr;
28 int i = 0;
29 for (auto& each : overworld_->entrances()) {
30 if (each.map_id_ < 0x40 + (current_world * 0x40) &&
31 each.map_id_ >= (current_world * 0x40) && !each.deleted) {
32 // Use theme-aware color with proper transparency
33 ImVec4 entrance_color = GetEntranceColor();
34 if (each.is_hole_) {
35 // Holes are more opaque for visibility
36 entrance_color.w = 0.78f; // 200/255 alpha
37 }
38 canvas_->DrawRect(each.x_, each.y_, 16, 16, entrance_color);
39 if (IsMouseHoveringOverEntity(each, canvas_p0, scrolling)) {
40 hovered_entity_ = &each;
41 }
42 std::string str = util::HexByte(each.entrance_id_);
43
44
45
46
47
48 canvas_->DrawText(str, each.x_, each.y_);
49 }
50 i++;
51 }
52
53
54}
55
56void OverworldEntityRenderer::DrawExits(ImVec2 canvas_p0, ImVec2 scrolling,
57 int current_world,
58 int current_mode) {
59 int i = 0;
60 for (auto& each : *overworld_->mutable_exits()) {
61 if (each.map_id_ < 0x40 + (current_world * 0x40) &&
62 each.map_id_ >= (current_world * 0x40) && !each.deleted_) {
63 canvas_->DrawRect(each.x_, each.y_, 16, 16, GetExitColor());
64 if (IsMouseHoveringOverEntity(each, canvas_p0, scrolling)) {
65 hovered_entity_ = &each;
66 }
67 each.entity_id_ = i;
68
69
70
71 std::string str = util::HexByte(i);
72 canvas_->DrawText(str, each.x_, each.y_);
73 }
74 i++;
75 }
76
77
78}
79
80void OverworldEntityRenderer::DrawItems(int current_world, int current_mode) {
81 int i = 0;
82 for (auto& item : *overworld_->mutable_all_items()) {
83 // Get the item's bitmap and real X and Y positions
84 if (item.room_map_id_ < 0x40 + (current_world * 0x40) &&
85 item.room_map_id_ >= (current_world * 0x40) && !item.deleted) {
86 canvas_->DrawRect(item.x_, item.y_, 16, 16, GetItemColor());
87
89 canvas_->scrolling())) {
90 hovered_entity_ = &item;
91 }
92
93
94 std::string item_name = "";
95 if (item.id_ < zelda3::kSecretItemNames.size()) {
96 item_name = zelda3::kSecretItemNames[item.id_];
97 } else {
98 item_name = absl::StrFormat("0x%02X", item.id_);
99 }
100 canvas_->DrawText(item_name, item.x_, item.y_);
101 }
102 i++;
103 }
104
105
106}
107
108void OverworldEntityRenderer::DrawSprites(int current_world, int game_state,
109 int current_mode) {
110 int i = 0;
111 for (auto& sprite : *overworld_->mutable_sprites(game_state)) {
112 // Filter sprites by current world - only show sprites for the current world
113 if (!sprite.deleted() && sprite.map_id() < 0x40 + (current_world * 0x40) &&
114 sprite.map_id() >= (current_world * 0x40)) {
115 // Sprites are already stored with global coordinates (realX, realY from
116 // ROM loading) So we can use sprite.x_ and sprite.y_ directly
117 int sprite_x = sprite.x_;
118 int sprite_y = sprite.y_;
119
120 // Temporarily update sprite coordinates for entity interaction
121 int original_x = sprite.x_;
122 int original_y = sprite.y_;
123
124 canvas_->DrawRect(sprite_x, sprite_y, 16, 16, GetSpriteColor());
126 canvas_->scrolling())) {
127 hovered_entity_ = &sprite;
128 }
129
130
132 if ((*sprite_previews_)[sprite.id()].is_active()) {
133 canvas_->DrawBitmap((*sprite_previews_)[sprite.id()], sprite_x,
134 sprite_y, 2.0f);
135 }
136 }
137
138 canvas_->DrawText(absl::StrFormat("%s", sprite.name()), sprite_x,
139 sprite_y);
140
141 // Restore original coordinates
142 sprite.x_ = original_x;
143 sprite.y_ = original_y;
144 }
145 i++;
146 }
147
148
149}
150
151} // namespace editor
152} // namespace yaze
153
static Flags & get()
Definition features.h:79
void DrawEntrances(ImVec2 canvas_p0, ImVec2 scrolling, int current_world, int current_mode)
void DrawSprites(int current_world, int game_state, int current_mode)
void DrawItems(int current_world, int current_mode)
void DrawExits(ImVec2 canvas_p0, ImVec2 scrolling, int current_world, int current_mode)
void DrawBitmap(Bitmap &bitmap, int border_offset, float scale)
Definition canvas.cc:1062
void DrawRect(int x, int y, int w, int h, ImVec4 color)
Definition canvas.cc:1329
auto zero_point() const
Definition canvas.h:310
auto scrolling() const
Definition canvas.h:311
void DrawText(const std::string &text, int x, int y)
Definition canvas.cc:1334
auto mutable_sprites(int state)
Definition overworld.h:266
const std::vector< OverworldEntrance > & entrances() const
Definition overworld.h:270
Definition input.cc:20
bool IsMouseHoveringOverEntity(const zelda3::GameEntity &entity, ImVec2 canvas_p0, ImVec2 scrolling)
Definition entity.cc:21
std::string HexByte(uint8_t byte, HexStringParams params)
Definition hex.cc:30
const std::vector< std::string > kSecretItemNames
Main namespace for the application.
struct yaze::core::FeatureFlags::Flags::Overworld overworld