yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project_graphics_import_ui.cc
Go to the documentation of this file.
2
3#include <cstdio>
4
5#include "core/project.h"
6#include "imgui/imgui.h"
7#include "util/file_util.h"
8
9namespace yaze::editor {
11 if (!ImGui::CollapsingHeader("Import graphics pack",
12 ImGuiTreeNodeFlags_DefaultOpen))
13 return;
14 bool changed =
15 ImGui::InputText("Logical pack JSON", graphics_import_path_.data(),
17 ImGui::SameLine();
18 if (ImGui::Button("Browse pack")) {
20 if (!path.empty()) {
21 std::snprintf(graphics_import_path_.data(), graphics_import_path_.size(),
22 "%s", path.c_str());
23 changed = true;
24 }
25 }
26 if (ImGui::Button("Load pack")) {
27 const auto asset = LoadProjectGraphicsImport(graphics_import_path_.data());
28 graphics_source_status_ = asset.status();
29 if (asset.ok()) {
34 asset->width * asset->height;
35 for (size_t i = 0; i < asset->palettes.size(); ++i)
37 {asset->palettes[i].id, static_cast<int>(5 + i), -1,
38 static_cast<int>(asset->palettes[i].characters.size() / 32 + 32)});
39 changed = true;
40 }
41 }
43 return;
44 const auto* resource = graphics_source_->selected_resource();
45 if (!resource)
46 return;
47 auto& binding = graphics_import_bindings_;
48 binding.target_resource = resource->pending_bytes;
49 binding.resource_first_character = -1;
50 for (const auto& slice : resource->slices)
51 if (slice.profile_id == graphics_source_->profile_id() &&
52 slice.source_offset == 0 &&
53 slice.byte_count == resource->pending_bytes.size())
54 binding.resource_first_character = slice.first_character();
55 ImGui::Text("Pack: %d x %d Tile16 cells", graphics_import_asset_->width,
57 ImGui::TextWrapped(
58 "Choose destination ranges you own. Unreferenced characters and tiles "
59 "are not automatically allocated.");
60 for (auto& palette : binding.palettes) {
61 ImGui::PushID(palette.palette.c_str());
62 ImGui::Text("%s", palette.palette.c_str());
63 changed |= ImGui::InputInt("BG palette row", &palette.bg_row);
64 changed |= ImGui::InputScalar("First BG character (hex)", ImGuiDataType_S32,
65 &palette.first_character, nullptr, nullptr,
66 "%03X", ImGuiInputTextFlags_CharsHexadecimal);
67 changed |= ImGui::InputInt("Owned character count",
68 &palette.owned_character_count);
69 ImGui::PopID();
70 }
71 changed |= ImGui::InputScalar("First Tile16 (hex)", ImGuiDataType_S32,
72 &binding.first_tile16, nullptr, nullptr, "%03X",
73 ImGuiInputTextFlags_CharsHexadecimal);
74 changed |= ImGui::InputInt("Owned Tile16 count", &binding.owned_tile16_count);
75 changed |= ImGui::InputInt("Area anchor X (Tile16)", &binding.anchor_x);
76 changed |= ImGui::InputInt("Area anchor Y (Tile16)", &binding.anchor_y);
77 if (changed) {
80 }
81 if (ImGui::Button("Preview import")) {
82 auto plan =
84 graphics_source_status_ = plan.status();
85 if (plan.ok())
86 graphics_import_plan_ = std::move(*plan);
87 }
89 const auto& plan = *graphics_import_plan_;
90 ImGui::Text("%zu characters, %zu Tile16 definitions, %zu palette colors",
91 plan.replacements.size(), plan.definitions.size(),
92 plan.palette_changes.size());
93 for (const auto& note : plan.notes)
94 ImGui::TextWrapped("%s", note.c_str());
95 if (ImGui::TreeNode("Palette records to replace")) {
96 for (const auto& color : plan.palette_changes)
97 ImGui::Text("%s[%d][%d]: $%04X -> $%04X", color.group_name.c_str(),
98 color.palette_index, color.color_index,
99 color.original_color.snes(), color.new_color.snes());
100 ImGui::TreePop();
101 }
102 ImGui::Checkbox(
103 "I reviewed the destination ranges and shared palette records",
105 ImGui::BeginDisabled(!graphics_import_ranges_reviewed_);
106 if (ImGui::Button("Import graphics and Tile16"))
109 ImGui::EndDisabled();
110 }
112 if (ImGui::Button("Place at area anchor")) {
113 const int parent = graphics_source_->parent_map();
115 (parent % 8) * 32 + binding.anchor_x,
116 ((parent % 64) / 8) * 32 + binding.anchor_y);
117 }
118 ImGui::TextWrapped(
119 "Use the main Undo/Redo for imported graphics and placement. Publish "
120 "graphics before Save ROM.");
121 }
122 ImGui::Separator();
123}
124} // namespace yaze::editor
std::array< char, 1024 > graphics_import_path_
absl::Status ApplyProjectGraphicsImport(const std::string &pack, const ProjectGraphicsImportBindings &bindings)
absl::StatusOr< ProjectGraphicsImportPlan > PreviewProjectGraphicsImport(const std::string &pack, const ProjectGraphicsImportBindings &bindings)
std::shared_ptr< ProjectGraphicsSource > graphics_source_
std::optional< ProjectGraphicsImportPlan > graphics_import_plan_
absl::Status PlaceProjectGraphicsImport(int world_x, int world_y)
ProjectGraphicsImportBindings graphics_import_bindings_
std::optional< ProjectGraphicsImportAsset > graphics_import_asset_
static std::string ShowOpenFileDialog()
ShowOpenFileDialog opens a file dialog and returns the selected filepath. Uses global feature flag to...
Editors are the view controllers for the application.
absl::StatusOr< ProjectGraphicsImportAsset > LoadProjectGraphicsImport(const std::filesystem::path &logical_pack)
std::vector< ProjectImportPaletteBinding > palettes