yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_entity_interaction.cc
Go to the documentation of this file.
1// Related header
3
4// Third-party library headers
5#include "imgui/imgui.h"
6
7// Project headers
9
10namespace yaze::editor {
11
13 zelda3::GameEntity* hovered_entity) {
14 if (!ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
15 return;
16 }
17
18 if (!hovered_entity) {
19 return;
20 }
21
22 current_entity_ = hovered_entity;
23 switch (hovered_entity->entity_type_) {
25 current_exit_ = *static_cast<zelda3::OverworldExit*>(hovered_entity);
26 ImGui::OpenPopup(
27 gui::MakePopupId(gui::EditorNames::kOverworld, "Exit Editor").c_str());
28 break;
31 *static_cast<zelda3::OverworldEntrance*>(hovered_entity);
32 ImGui::OpenPopup(
34 .c_str());
35 break;
37 current_item_ = *static_cast<zelda3::OverworldItem*>(hovered_entity);
38 ImGui::OpenPopup(
39 gui::MakePopupId(gui::EditorNames::kOverworld, "Item Editor").c_str());
40 break;
42 current_sprite_ = *static_cast<zelda3::Sprite*>(hovered_entity);
43 ImGui::OpenPopup(
45 .c_str());
46 break;
47 default:
48 break;
49 }
50}
51
53 zelda3::GameEntity* hovered_entity) {
54 if (!hovered_entity || !ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
55 return -1;
56 }
57
59 return static_cast<zelda3::OverworldExit*>(hovered_entity)->room_id_;
60 } else if (hovered_entity->entity_type_ ==
62 return static_cast<zelda3::OverworldEntrance*>(hovered_entity)
63 ->entrance_id_;
64 }
65 return -1;
66}
67
69 zelda3::GameEntity* hovered_entity, ImVec2 mouse_delta) {
70 // Start drag if clicking on an entity
71 if (!is_dragging_ && hovered_entity &&
72 ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {
73 dragged_entity_ = hovered_entity;
74 is_dragging_ = true;
77 }
78
79 // Update drag position
81 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
82 // Apply movement delta to entity position
83 dragged_entity_->x_ += static_cast<uint16_t>(mouse_delta.x);
84 dragged_entity_->y_ += static_cast<uint16_t>(mouse_delta.y);
85
86 // Mark ROM as dirty
87 if (rom_) {
88 rom_->set_dirty(true);
89 }
90 return true;
91 }
92
93 // End drag on mouse release
94 if (is_dragging_ && ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
95 FinishDrag();
96 }
97
98 return is_dragging_;
99}
100
102 is_dragging_ = false;
103 free_movement_ = false;
104 dragged_entity_ = nullptr;
105}
106
107} // namespace yaze::editor
108
void set_dirty(bool dirty)
Definition rom.h:130
void FinishDrag()
Finish an active drag operation.
int HandleDoubleClick(zelda3::GameEntity *hovered_entity)
Handle double-click actions on entities.
void HandleContextMenus(zelda3::GameEntity *hovered_entity)
Handle entity context menus on right-click.
bool HandleDragDrop(zelda3::GameEntity *hovered_entity, ImVec2 mouse_delta)
Handle entity drag-and-drop operations.
Base class for all overworld and dungeon entities.
Definition common.h:31
enum yaze::zelda3::GameEntity::EntityType entity_type_
Represents an overworld exit that transitions from dungeon to overworld.
A class for managing sprites in the overworld and underworld.
Definition sprite.h:35
Editors are the view controllers for the application.
Definition agent_chat.cc:23
constexpr const char * kOverworld
Definition popup_id.h:53
std::string MakePopupId(size_t session_id, const std::string &editor_name, const std::string &popup_name)
Generate session-aware popup IDs to prevent conflicts in multi-editor layouts.
Definition popup_id.h:23