yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_context_actions.cc
Go to the documentation of this file.
2
7#include "util/i18n/tr.h"
9
10namespace yaze::editor {
11
13 const ImVec2& screen_position) {
14 auto& canvas = editor_->ow_map_canvas_;
15 canvas.ClearContextMenuItems();
17 return false;
18 }
19 // Select tool: plain right-click. Paint tools: right-click samples, so
20 // only Shift+right-click opens the menu.
21 const bool menu_gesture =
22 editor_->current_mode == EditingMode::MOUSE || ImGui::GetIO().KeyShift;
23 if (!editor_->rom_ || !editor_->rom_->is_loaded() ||
25 !menu_gesture ||
27 editor_->entity_renderer_->hovered_entity() != nullptr)) {
28 return false;
29 }
31 editor_->current_world_, editor_->game_state_, screen_position,
32 canvas.zero_point(), canvas.scrolling(), canvas.global_scale());
33 if (!target) {
34 return false;
35 }
36 const auto* map = editor_->overworld_.overworld_map(target->map_id);
37 if (!map) {
38 return false;
39 }
40 target->parent_map_id =
41 map->parent() == 0xFF ? target->map_id : map->parent();
42 if (!target->valid()) {
43 return false;
44 }
45 const auto* tiles = editor_->overworld_.mutable_map_tiles();
46 const auto& world_tiles = target->world == 0 ? tiles->light_world
47 : target->world == 1 ? tiles->dark_world
48 : tiles->special_world;
49 const int x = static_cast<int>(target->world_position.x) / 16;
50 const int y = static_cast<int>(target->world_position.y) / 16;
51 if (x < static_cast<int>(world_tiles.size()) &&
52 y < static_cast<int>(world_tiles[x].size())) {
53 target->tile16_id = world_tiles[x][y];
54 }
55 editor_->map_properties_system_->SetupCanvasContextMenu(
56 canvas, *target, editor_->current_map_lock_,
59 return true;
60}
61
63 const std::string& entity_type, const OverworldContextTarget& target) {
64 if (!target.valid()) {
65 return;
66 }
67 if (entity_type == "item") {
69 return;
70 }
72 OverworldEntityInsertionRequest{entity_type, target, 0};
73}
74
76 const OverworldContextTarget& target) {
77 if (!target.valid() || !overworld_.is_loaded() || !map_blockset_loaded_ ||
78 target.tile16_id < 0 ||
79 target.tile16_id >= static_cast<int>(overworld_.tiles16().size())) {
80 return false;
81 }
82 // Use the existing switch guard so pending Tile16 edits are preserved.
85 return true;
86}
87
89 const OverworldContextTarget& target) {
90 if (!target.valid() || !overworld_.is_loaded() || target.tile16_id < 0 ||
91 target.tile16_id >= static_cast<int>(overworld_.tiles16().size())) {
92 return absl::InvalidArgumentError("The clicked Tile16 is unavailable");
93 }
94 // Explicit source navigation uses the clicked screen even when another map
95 // is pinned. The context target was captured before menu hover can change it.
96 const int previous_map = current_map_;
97 SelectMapForEditing(target.map_id, /*respect_pin=*/false);
98 if (!status_.ok()) {
99 const auto failure = status_;
100 SelectMapForEditing(previous_map, /*respect_pin=*/false);
101 return failure;
102 }
103 const int quadrant =
104 (static_cast<int>(target.world_position.x) % 16 >= 8 ? 1 : 0) +
105 (static_cast<int>(target.world_position.y) % 16 >= 8 ? 2 : 0);
106 const auto result = OpenGraphicsForTile16Quadrant(target.tile16_id, quadrant);
107 if (!result.ok()) {
108 // A floating paste or unsupported source must not leave navigation on the
109 // clicked map when the Graphics editor refused the new context.
110 SelectMapForEditing(previous_map, /*respect_pin=*/false);
111 }
112 return result;
113}
114
116 const std::optional<OverworldContextTarget>& target) {
117 item_insert_target_ = target;
119}
120
123 ImGui::OpenPopup("Insert Item");
125 }
126 if (!ImGui::BeginPopup("Insert Item")) {
127 return;
128 }
129 ImGui::TextUnformatted(tr("Choose an item"));
130 ImGui::BeginChild("##ItemInsertList", ImVec2(220.0f, 220.0f),
131 ImGuiChildFlags_Borders);
132 for (size_t i = 0; i < zelda3::kSecretItemNames.size(); ++i) {
133 if (ImGui::Selectable(zelda3::kSecretItemNames[i].c_str())) {
134 const auto item_id = static_cast<uint8_t>(i);
137 "item", *item_insert_target_, item_id};
138 item_placement_armed_ = false;
139 } else {
140 armed_item_id_ = item_id;
143 }
144 item_insert_target_.reset();
145 ImGui::CloseCurrentPopup();
146 }
147 }
148 ImGui::EndChild();
149 if (!item_insert_target_) {
150 ImGui::TextDisabled(tr("Click the map to place the item."));
151 }
152 ImGui::EndPopup();
153}
154
157 !ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
159 return false;
160 }
161 if (entity_renderer_ && entity_renderer_->hovered_entity() != nullptr) {
162 return false;
163 }
164 const float scale = ow_map_canvas_.global_scale() > 0.0f
166 : 1.0f;
167 auto target = ResolveOverworldContextTarget(
169 ImVec2(0.0f, 0.0f), ImVec2(0.0f, 0.0f), scale);
170 if (!target) {
171 return false;
172 }
173 const auto* map = overworld_.overworld_map(target->map_id);
174 if (!map) {
175 return false;
176 }
177 target->parent_map_id =
178 map->parent() == 0xFF ? target->map_id : map->parent();
179 if (!target->valid()) {
180 return false;
181 }
184 item_placement_armed_ = false;
185 return true;
186}
187
201
202} // namespace yaze::editor
bool is_loaded() const
Definition rom.h:187
EditorDependencies dependencies_
Definition editor.h:370
OverworldEditor * editor_
Non-owning pointer to the parent editor.
bool PrepareContextMenu(const ImVec2 &screen_position)
std::unique_ptr< MapPropertiesSystem > map_properties_system_
void RequestItemInsertPopup(const std::optional< OverworldContextTarget > &target)
void HandleEntityInsertion(const std::string &entity_type, const OverworldContextTarget &target)
Handle entity insertion from context menu.
bool SampleContextTile16(const OverworldContextTarget &target)
std::optional< OverworldContextTarget > item_insert_target_
void HandleTile16Edit(const OverworldContextTarget &target)
Handle tile16 editing from context menu (MOUSE mode) Opens the Tile16 captured at menu-open through t...
std::unique_ptr< OverworldEntityRenderer > entity_renderer_
std::optional< OverworldEntityInsertionRequest > pending_entity_insertion_
absl::Status OpenGraphicsForTile16Quadrant(int tile16_id, int quadrant)
absl::Status OpenGraphicsForContextTile16(const OverworldContextTarget &target)
void ScrollBlocksetCanvasToCurrentTile()
Scroll the blockset canvas to show the current selected tile16.
void SelectMapForEditing(int map_id, bool respect_pin=true)
void SetEntityEditMode(EntityEditMode mode)
Entity focus (entrances/exits/items/sprites); NONE = all entities.
bool OpenWindowFloating(size_t session_id, const std::string &base_window_id)
void MarkWindowRecentlyUsed(const std::string &window_id)
auto global_scale() const
Definition canvas.h:413
auto hover_mouse_pos() const
Definition canvas.h:476
void ClearContextMenuItems()
Definition canvas.cc:994
bool IsMouseHovering() const
Definition canvas.h:354
const std::vector< gfx::Tile16 > & tiles16() const
Definition overworld.h:751
bool is_lyra_preview() const
Definition overworld.h:430
auto is_loaded() const
Definition overworld.h:803
auto overworld_map(int i) const
Definition overworld.h:737
Editors are the view controllers for the application.
std::optional< OverworldContextTarget > ResolveOverworldContextTarget(int world, int game_state, ImVec2 screen_position, ImVec2 canvas_origin, ImVec2 scrolling, float scale, int map_count=zelda3::kNumOverworldMaps)
const std::vector< std::string > kSecretItemNames
project::YazeProject * project
Definition editor.h:174
SharedClipboard * shared_clipboard
Definition editor.h:187
WorkspaceWindowManager * window_manager
Definition editor.h:182
bool valid(int map_count=zelda3::kNumOverworldMaps) const
static constexpr const char * kTile16Editor