53 if (ImGui::BeginPopup(
"Reorder source colors")) {
54 ImGui::CloseCurrentPopup();
59 const float width = ImGui::CalcTextSize(tr(
"Reorder")).x +
60 ImGui::GetStyle().FramePadding.x * 2;
62 ImGui::GetCursorScreenPos().x + ImGui::GetContentRegionAvail().x;
63 if (ImGui::GetItemRectMax().x + width + ImGui::GetStyle().ItemSpacing.x <=
68 if (ImGui::Button(tr(
"Reorder"))) {
70 ImGui::OpenPopup(
"Reorder source colors");
74 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled)) {
75 ImGui::SetTooltip(
"%s", busy
76 ? tr(
"Finish the pixel stroke first")
77 : tr(
"Reorder colors and remap source pixels"));
80 ImGui::SetNextWindowSizeConstraints(
81 ImVec2(25 * ImGui::GetFontSize(), 0),
82 ImVec2(29 * ImGui::GetFontSize(), ImGui::GetIO().DisplaySize.y * 0.85f));
83 if (!ImGui::BeginPopup(
"Reorder source colors"))
85 ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + 25 * ImGui::GetFontSize());
88 ImGui::TextWrapped(
"%s", tr(
"Source changed. Close and reopen Reorder."));
90 ImGui::TextUnformatted(tr(
"Remap pixels in:"));
98 ImGui::TextWrapped(
"%s", tr(
"Click two colors below to swap their slots. "
99 "Slot 0 stays transparent."));
100 const auto& palette =
source_->targets[
source_->selected_target].palette;
101 const float size = ImGui::GetFrameHeight();
102 for (
int row = 0; row < 2; ++row) {
103 ImGui::TextUnformatted(row == 0 ? tr(
"Before") : tr(
"After"));
104 for (
int slot = 0; slot < 8 && palette.size() == 8; ++slot) {
108 palette[row == 0 ? slot :
order_[slot]]);
109 color.w = slot == 0 ? 0.0f : 1.0f;
110 ImGui::PushID(row * 8 + slot);
111 const bool clicked = ImGui::ColorButton(
113 ImGuiColorEditFlags_NoTooltip | ImGuiColorEditFlags_AlphaPreview,
116 "color", absl::StrFormat(
"Reorder %s slot %d",
117 row == 0 ?
"before" :
"after", slot));
118 if (clicked && row == 1 && slot != 0) {
128 ImGui::GetWindowDrawList()->AddRect(
129 ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),
130 ImGui::GetColorU32(ImGuiCol_Text), 0, 0, 2);
132 if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled))
133 ImGui::SetTooltip(tr(
"Slot %d"), slot);
137 if (ImGui::SmallButton(tr(
"Reset order"))) {
138 order_ = {0, 1, 2, 3, 4, 5, 6, 7};
144 std::vector<size_t> targets{
source_->selected_target};
146 targets.resize(
source_->targets.size());
147 std::iota(targets.begin(), targets.end(), 0);
150 for (
int slot = 0; slot < 8; ++slot)
151 permutation[
order_[slot]] = slot;
154 const bool supported =
source_->resolve_live_source && plan.ok();
156 ImGui::Text(tr(
"%zu source tiles; %zu changed colors"),
157 plan->physical_tiles, plan->colors.size());
158 ImGui::TextWrapped(
"%s", tr(
"Selected artwork keeps its appearance. "
159 "Other uses of these shared tiles or "
160 "palette slots can change."));
163 "%s", plan.ok() ? tr(
"This source cannot resolve live edits.")
164 : std::string(plan.status().message()).c_str());
167 ImGui::TextWrapped(
"%s",
error_.c_str());
170 (plan->colors.empty() && plan->sheets.empty()));
171 if (ImGui::Button(tr(
"Apply"))) {
172 const auto status = apply(targets, permutation);
174 ImGui::CloseCurrentPopup();
176 error_ = std::string(status.message());
180 ImGui::EndDisabled();
183 if (ImGui::Button(tr(
"Cancel")))
184 ImGui::CloseCurrentPopup();
186 ImGui::PopTextWrapPos();