remove overlay window, add document overlay + over/under
This commit is contained in:
1 parent
e32e781b46
commit
a4b34cc0be
22 files changed
+261
-1381
No files matched your search
@@ -40,7 +40,6 @@ namespace anm2ed::imgui
|
||||
if (settings.windowIsLayers) window_update(layers, manager, settings, resources, dialog, clipboard);
|
||||
if (settings.windowIsNulls) window_update(nulls, manager, settings, resources, dialog, clipboard);
|
||||
if (settings.windowIsOnionskin) onionskin.update(manager, settings);
|
||||
if (settings.windowIsOverlays) window_update(overlays, manager, settings, resources, dialog, clipboard);
|
||||
if (settings.windowIsShaders) shaders.update(manager, settings, resources, dialog);
|
||||
if (settings.windowIsSounds) window_update(sounds, manager, settings, resources, dialog, clipboard);
|
||||
if (settings.windowIsSpritesheetEditor) spritesheetEditor.update(manager, settings, resources);
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace anm2ed::imgui
|
||||
Window layers{layers_window_register()};
|
||||
Window nulls{nulls_window_register()};
|
||||
Onionskin onionskin;
|
||||
Window overlays{overlays_window_register()};
|
||||
ShadersWindow shaders;
|
||||
SpritesheetEditor spritesheetEditor;
|
||||
Window spritesheets{spritesheets_window_register()};
|
||||
|
||||
+2
-27
@@ -181,7 +181,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto& document = manager.documents[i];
|
||||
auto isDocumentDirty = document.is_dirty() || document.isForceDirty;
|
||||
auto isSpritesheetDirty = document.spritesheet_any_dirty() || document.overlay_any_dirty();
|
||||
auto isSpritesheetDirty = document.spritesheet_any_dirty();
|
||||
auto isDirty = isDocumentDirty || isSpritesheetDirty;
|
||||
|
||||
if (!closePopup.is_open())
|
||||
@@ -278,7 +278,7 @@ namespace anm2ed::imgui
|
||||
|
||||
auto filename = path::to_utf8(closeDocument.filename_get());
|
||||
auto isDocumentDirty = closeDocument.is_dirty() || closeDocument.isForceDirty;
|
||||
auto isSpritesheetDirty = closeDocument.spritesheet_any_dirty() || closeDocument.overlay_any_dirty();
|
||||
auto isSpritesheetDirty = closeDocument.spritesheet_any_dirty();
|
||||
auto promptLabel =
|
||||
isDocumentDirty && isSpritesheetDirty
|
||||
? LABEL_DOCUMENT_AND_SPRITESHEETS_MODIFIED_PROMPT
|
||||
@@ -337,31 +337,6 @@ namespace anm2ed::imgui
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& overlay : spritesheet.children)
|
||||
{
|
||||
if (overlay.type != ElementType::OVERLAY) continue;
|
||||
auto overlayTexture = closeDocument.overlay_texture_get(overlay.id);
|
||||
if (!overlayTexture || !closeDocument.overlay_is_dirty(overlay.id)) continue;
|
||||
auto pathString = path::to_utf8(overlay.path);
|
||||
auto savePath = closeDocument.directory_get() / overlay.path;
|
||||
path::ensure_directory(savePath.parent_path());
|
||||
if (overlayTexture->write_png(savePath))
|
||||
{
|
||||
closeDocument.overlay_hash_set_saved(overlay.id);
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY),
|
||||
std::make_format_args(overlay.id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_SAVE_OVERLAY, anm2ed::ENGLISH),
|
||||
std::make_format_args(overlay.id, pathString)));
|
||||
}
|
||||
else
|
||||
{
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED),
|
||||
std::make_format_args(overlay.id, pathString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(overlay.id, pathString)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
@@ -41,6 +44,87 @@ namespace anm2ed::imgui
|
||||
constexpr auto TRIGGER_TEXT_COLOR_LIGHT = ImVec4(0.0f, 0.0f, 0.0f, 0.5f);
|
||||
namespace
|
||||
{
|
||||
struct OverlayAnimationOption
|
||||
{
|
||||
uint64_t documentId{};
|
||||
int animationIndex{-1};
|
||||
std::string label{};
|
||||
};
|
||||
|
||||
std::vector<OverlayAnimationOption> overlay_animation_options_get(Manager& manager)
|
||||
{
|
||||
std::vector<OverlayAnimationOption> options{{.label = std::string(localize.get(BASIC_NONE))}};
|
||||
|
||||
for (auto& document : manager.documents)
|
||||
{
|
||||
auto documentLabel = path::to_utf8(document.filename_get());
|
||||
int animationIndex{};
|
||||
if (auto animations = document.anm2.element_get(ElementType::ANIMATIONS))
|
||||
for (auto& animation : animations->children)
|
||||
{
|
||||
if (animation.type != ElementType::ANIMATION) continue;
|
||||
auto label = std::format("{} ({})", animation.name, documentLabel);
|
||||
options.push_back({.documentId = document.tabId, .animationIndex = animationIndex, .label = label});
|
||||
++animationIndex;
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
std::vector<const char*> overlay_animation_option_labels_get(std::vector<OverlayAnimationOption>& options)
|
||||
{
|
||||
std::vector<const char*> labels{};
|
||||
labels.reserve(options.size());
|
||||
for (auto& option : options)
|
||||
labels.push_back(option.label.c_str());
|
||||
return labels;
|
||||
}
|
||||
|
||||
int overlay_animation_option_index_get(const Document& document, const std::vector<OverlayAnimationOption>& options)
|
||||
{
|
||||
if (document.overlayIndex == -1) return 0;
|
||||
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
||||
for (int i = 1; i < (int)options.size(); ++i)
|
||||
if (options[i].documentId == documentId && options[i].animationIndex == document.overlayIndex) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
Document* overlay_animation_document_get(Manager& manager, const Document& document)
|
||||
{
|
||||
if (document.overlayIndex == -1) return nullptr;
|
||||
auto documentId = document.overlayDocumentId ? document.overlayDocumentId : document.tabId;
|
||||
for (auto& candidate : manager.documents)
|
||||
if (candidate.tabId == documentId) return &candidate;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::optional<vec4> animation_rects_merge(std::optional<vec4> rect, vec4 next)
|
||||
{
|
||||
if (next == vec4(-1.0f)) return rect;
|
||||
if (!rect) return next;
|
||||
|
||||
auto minPoint = glm::min(vec2(rect->x, rect->y), vec2(next.x, next.y));
|
||||
auto maxPoint = glm::max(vec2(rect->x + rect->z, rect->y + rect->w), vec2(next.x + next.z, next.y + next.w));
|
||||
return vec4(minPoint, maxPoint - minPoint);
|
||||
}
|
||||
|
||||
std::optional<vec4> animation_render_rect_get(Manager& manager, Document& document, Element* animation,
|
||||
bool isRootTransform)
|
||||
{
|
||||
std::optional<vec4> rect{};
|
||||
|
||||
if (animation)
|
||||
rect = animation_rects_merge(rect, document.anm2.animation_rect(*animation, isRootTransform));
|
||||
|
||||
if (auto overlayDocument = overlay_animation_document_get(manager, document))
|
||||
if (auto overlayAnimation = overlayDocument->anm2.element_get(ElementType::ANIMATION, document.overlayIndex))
|
||||
rect = animation_rects_merge(rect,
|
||||
overlayDocument->anm2.animation_rect(*overlayAnimation, isRootTransform));
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
std::filesystem::path render_destination_directory(const std::filesystem::path& path, int type)
|
||||
{
|
||||
if (type == render::PNGS) return path;
|
||||
@@ -188,6 +272,7 @@ namespace anm2ed::imgui
|
||||
auto& frameTime = document.frameTime;
|
||||
auto& zoom = document.previewZoom;
|
||||
auto& overlayIndex = document.overlayIndex;
|
||||
auto& overlayDocumentId = document.overlayDocumentId;
|
||||
auto& pan = document.previewPan;
|
||||
|
||||
auto stop_all_sounds = [&]()
|
||||
@@ -211,6 +296,7 @@ namespace anm2ed::imgui
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
overlayDocumentId = savedOverlayDocumentId;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
@@ -405,7 +491,9 @@ namespace anm2ed::imgui
|
||||
auto& gridOffset = settings.previewGridOffset;
|
||||
auto& isGrid = settings.previewIsGrid;
|
||||
auto& overlayTransparency = settings.previewOverlayTransparency;
|
||||
auto& overlayDrawOrder = settings.previewOverlayDrawOrder;
|
||||
auto& overlayIndex = document.overlayIndex;
|
||||
auto& overlayDocumentId = document.overlayDocumentId;
|
||||
auto& isRootTransform = settings.previewIsRootTransform;
|
||||
auto& isPivots = settings.previewIsPivots;
|
||||
auto& isAxes = settings.previewIsAxes;
|
||||
@@ -550,11 +638,48 @@ namespace anm2ed::imgui
|
||||
ImGui::ColorEdit4(localize.get(BASIC_COLOR), value_ptr(axesColor), ImGuiColorEditFlags_NoInputs);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_AXES_COLOR));
|
||||
|
||||
combo_negative_one_indexed(localize.get(LABEL_OVERLAY), &overlayIndex, document.animation.labels);
|
||||
auto overlayOptions = overlay_animation_options_get(manager);
|
||||
auto overlayLabels = overlay_animation_option_labels_get(overlayOptions);
|
||||
auto overlayOptionIndex = overlay_animation_option_index_get(document, overlayOptions);
|
||||
if (overlayOptionIndex == -1)
|
||||
{
|
||||
overlayIndex = -1;
|
||||
overlayDocumentId = 0;
|
||||
overlayOptionIndex = 0;
|
||||
}
|
||||
if (ImGui::Combo(localize.get(LABEL_OVERLAY), &overlayOptionIndex, overlayLabels.data(),
|
||||
(int)overlayLabels.size()))
|
||||
{
|
||||
auto& option = overlayOptions[overlayOptionIndex];
|
||||
overlayIndex = option.animationIndex;
|
||||
overlayDocumentId = overlayIndex == -1 ? 0 : option.documentId;
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY));
|
||||
|
||||
ImGui::DragFloat(localize.get(BASIC_ALPHA), &overlayTransparency, DRAG_SPEED, 0, 255, "%.0f");
|
||||
overlayDrawOrder = glm::clamp(overlayDrawOrder, (int)overlay_draw_order::OVER, (int)overlay_draw_order::UNDER);
|
||||
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
||||
auto orderIconSize = icon_size_get();
|
||||
auto orderButtonWidth = orderIconSize.x + ImGui::GetStyle().FramePadding.x * 2.0f;
|
||||
auto alphaWidth =
|
||||
std::max(ImGui::GetContentRegionAvail().x - (orderButtonWidth * 2.0f) -
|
||||
(ImGui::GetStyle().ItemSpacing.x * 2.0f),
|
||||
ImGui::GetFrameHeight());
|
||||
auto overlayIconTint = isLightTheme ? ImVec4(0.0f, 0.0f, 0.0f, 1.0f) : ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
ImGui::PushItemWidth(alphaWidth);
|
||||
ImGui::DragFloat("##Overlay Alpha", &overlayTransparency, DRAG_SPEED, 0, 100, "%.0f%%");
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_ALPHA));
|
||||
overlayTransparency = glm::clamp(overlayTransparency, 0.0f, 100.0f);
|
||||
|
||||
ImGui::SameLine();
|
||||
radio_button_icon("##Overlay Over", &overlayDrawOrder, overlay_draw_order::OVER, resources.icons[icon::OVER].id,
|
||||
orderIconSize, overlayIconTint);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_OVER));
|
||||
|
||||
ImGui::SameLine();
|
||||
radio_button_icon("##Overlay Under", &overlayDrawOrder, overlay_draw_order::UNDER,
|
||||
resources.icons[icon::UNDER].id, orderIconSize, overlayIconTint);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERLAY_UNDER));
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
@@ -600,6 +725,7 @@ namespace anm2ed::imgui
|
||||
if (isRenderPreviewOverridden)
|
||||
{
|
||||
savedOverlayIndex = overlayIndex;
|
||||
savedOverlayDocumentId = overlayDocumentId;
|
||||
savedZoom = zoom;
|
||||
savedPan = pan;
|
||||
}
|
||||
@@ -607,6 +733,7 @@ namespace anm2ed::imgui
|
||||
if (settings.renderIsUseIsolatedAnimation)
|
||||
{
|
||||
overlayIndex = -1;
|
||||
overlayDocumentId = 0;
|
||||
settings.animationPreviewTransparent = true;
|
||||
settings.timelineIsOnlyShowLayers = true;
|
||||
settings.previewIsAxes = false;
|
||||
@@ -619,12 +746,11 @@ namespace anm2ed::imgui
|
||||
|
||||
if (settings.renderIsUseAnimationBounds)
|
||||
{
|
||||
if (animation)
|
||||
if (auto rect = anm2.animation_rect(*animation, isRootTransform); rect != vec4(-1.0f))
|
||||
{
|
||||
size_set(vec2(rect.z, rect.w) * settings.renderScale);
|
||||
set_to_rect(zoom, pan, rect);
|
||||
}
|
||||
if (auto rect = animation_render_rect_get(manager, document, animation, isRootTransform))
|
||||
{
|
||||
size_set(vec2(rect->z, rect->w) * settings.renderScale);
|
||||
set_to_rect(zoom, pan, *rect);
|
||||
}
|
||||
|
||||
isSizeTrySet = false;
|
||||
}
|
||||
@@ -661,6 +787,7 @@ namespace anm2ed::imgui
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
overlayDocumentId = savedOverlayDocumentId;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
@@ -753,8 +880,9 @@ namespace anm2ed::imgui
|
||||
}
|
||||
|
||||
auto referenceItemType = static_cast<ItemType>(reference.itemType);
|
||||
auto is_layer_animation_selected = [&](int id)
|
||||
auto is_layer_animation_selected = [&](Document& sampleDocument, int id)
|
||||
{
|
||||
if (&sampleDocument != &document) return false;
|
||||
if (reference.animationIndex != -1 && referenceItemType == ItemType::LAYER && reference.itemID == id)
|
||||
return true;
|
||||
for (auto itemReference : document.items.references)
|
||||
@@ -768,9 +896,13 @@ namespace anm2ed::imgui
|
||||
return false;
|
||||
};
|
||||
|
||||
auto render = [&](Element* animation, float time, vec3 colorOffset = {}, float alphaOffset = {},
|
||||
auto render = [&](Document& sampleDocument, Element* animation, float time, vec3 colorOffset = {},
|
||||
float alphaOffset = {},
|
||||
const std::vector<OnionskinSample>* layeredOnions = nullptr, bool isIndexMode = false)
|
||||
{
|
||||
auto& sampleAnm2 = sampleDocument.anm2;
|
||||
bool isActiveDocument = &sampleDocument == &document;
|
||||
|
||||
auto sample_time_for_item = [&](Element& item, const OnionskinSample& sample) -> std::optional<float>
|
||||
{
|
||||
if (!isIndexMode)
|
||||
@@ -880,7 +1012,7 @@ namespace anm2ed::imgui
|
||||
math::percent_to_unit(rootFrame.scale), rootFrame.rotation);
|
||||
auto rootTransform = itemTransform * rootModel;
|
||||
|
||||
auto isSelected = referenceItemType == ItemType::ROOT && reference.groupType == groupType &&
|
||||
auto isSelected = isActiveDocument && referenceItemType == ItemType::ROOT && reference.groupType == groupType &&
|
||||
reference.groupId == group.id;
|
||||
vec4 color = isOnion ? vec4(sampleColor, sampleAlpha) : isSelected ? color::RED : ROOT_COLOR;
|
||||
auto icon = isAltIcons ? icon::TARGET_ALT : icon::TARGET;
|
||||
@@ -915,12 +1047,11 @@ namespace anm2ed::imgui
|
||||
return;
|
||||
|
||||
auto id = layerAnimation.layerId;
|
||||
auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, id);
|
||||
auto layer = sampleAnm2.element_get(ElementType::LAYER_ELEMENT, id);
|
||||
if (!layer) return;
|
||||
|
||||
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, layer->spritesheetId);
|
||||
auto textureInfo = document.texture_get(layer->spritesheetId);
|
||||
if (!spritesheet || !textureInfo || !textureInfo->is_valid()) return;
|
||||
auto textureInfo = sampleDocument.texture_get(layer->spritesheetId);
|
||||
if (!textureInfo || !textureInfo->is_valid()) return;
|
||||
|
||||
auto draw_layer = [&](float sampleTime, const glm::mat4& sampleTransform, vec3 sampleColor,
|
||||
float sampleAlpha, bool isOnion)
|
||||
@@ -933,7 +1064,7 @@ namespace anm2ed::imgui
|
||||
auto texSize = vec2(texture.size);
|
||||
if (texSize.x <= 0.0f || texSize.y <= 0.0f) return;
|
||||
|
||||
frame = anm2.frame_effective(id, frame);
|
||||
frame = sampleAnm2.frame_effective(id, frame);
|
||||
auto crop = frame.crop;
|
||||
auto size = frame.size;
|
||||
auto pivot = frame.pivot;
|
||||
@@ -966,40 +1097,15 @@ namespace anm2ed::imgui
|
||||
frameTint.a = std::max(0.0f, frameTint.a - (alphaOffset + sampleAlpha));
|
||||
|
||||
auto vertices = math::uv_vertices_get(uvMin, uvMax);
|
||||
auto customShader = document.shader_get(layer->spritesheetId);
|
||||
auto customShader = sampleDocument.shader_get(layer->spritesheetId);
|
||||
auto& layerShader = customShader ? *customShader : shaderTexture;
|
||||
|
||||
auto overlay_draw = [&](const Element& overlay)
|
||||
{
|
||||
if (overlay.type != ElementType::OVERLAY) return;
|
||||
if (!overlay.isVisible) return;
|
||||
auto overlayTexture = document.overlay_texture_get(overlay.id);
|
||||
if (!overlayTexture || !overlayTexture->is_valid()) return;
|
||||
|
||||
auto overlayTexSize = vec2(overlayTexture->size);
|
||||
if (overlayTexSize.x <= 0.0f || overlayTexSize.y <= 0.0f) return;
|
||||
|
||||
auto overlayUvMin = (crop - overlay.position) / overlayTexSize;
|
||||
auto overlayUvMax = (crop + size - overlay.position) / overlayTexSize;
|
||||
auto overlayVertices = math::uv_vertices_get(overlayUvMin, overlayUvMax);
|
||||
auto overlayTint = frameTint;
|
||||
overlayTint.a *= overlay.tint.a;
|
||||
texture_render(shaderTexture, overlayTexture->id, layerTransform, overlayTint, frameColorOffset,
|
||||
overlayVertices.data(), vec2(overlayTexture->size), sampleTime);
|
||||
};
|
||||
|
||||
for (auto& overlay : spritesheet->children)
|
||||
if (overlay.index == OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
|
||||
|
||||
texture_render(layerShader, texture.id, layerTransform, frameTint, frameColorOffset, vertices.data(),
|
||||
vec2(texture.size), sampleTime);
|
||||
|
||||
for (auto& overlay : spritesheet->children)
|
||||
if (overlay.index != OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
|
||||
|
||||
auto color = isOnion ? vec4(sampleColor, 1.0f - sampleAlpha)
|
||||
: is_layer_animation_selected(id) ? SELECTED_LAYER_BORDER_COLOR
|
||||
: color::RED;
|
||||
: is_layer_animation_selected(sampleDocument, id) ? SELECTED_LAYER_BORDER_COLOR
|
||||
: color::RED;
|
||||
|
||||
if (isBorder) rect_render(shaderLine, layerTransform, layerModel, color);
|
||||
|
||||
@@ -1055,7 +1161,7 @@ namespace anm2ed::imgui
|
||||
return;
|
||||
|
||||
auto id = nullAnimation.nullId;
|
||||
auto nulls = anm2.element_get(ElementType::NULLS);
|
||||
auto nulls = sampleAnm2.element_get(ElementType::NULLS);
|
||||
auto nullInfo = nulls ? element_child_id_get(*nulls, ElementType::NULL_ELEMENT, id) : nullptr;
|
||||
if (!nullInfo) return;
|
||||
auto isShowRect = nullInfo->isShowRect;
|
||||
@@ -1070,8 +1176,9 @@ namespace anm2ed::imgui
|
||||
|
||||
auto& size = isShowRect ? POINT_SIZE : TARGET_SIZE;
|
||||
auto color = isOnion ? vec4(sampleColor, 1.0f - sampleAlpha)
|
||||
: id == reference.itemID && referenceItemType == ItemType::NULL_ ? color::RED
|
||||
: NULL_COLOR;
|
||||
: isActiveDocument && id == reference.itemID && referenceItemType == ItemType::NULL_
|
||||
? color::RED
|
||||
: NULL_COLOR;
|
||||
|
||||
auto nullModel = math::quad_model_get(size, frame.position, size * 0.5f,
|
||||
math::percent_to_unit(frame.scale), frame.rotation);
|
||||
@@ -1109,12 +1216,19 @@ namespace anm2ed::imgui
|
||||
if (animation)
|
||||
{
|
||||
auto layeredOnions = settings.onionskinIsEnabled ? &onionskinSamples : nullptr;
|
||||
auto overlay_render = [&]()
|
||||
{
|
||||
if (auto overlayDocument = overlay_animation_document_get(manager, document))
|
||||
if (auto overlayAnimation = overlayDocument->anm2.element_get(ElementType::ANIMATION, overlayIndex))
|
||||
render(*overlayDocument, overlayAnimation, frameTime, {},
|
||||
1.0f - math::percent_to_unit(overlayTransparency), layeredOnions,
|
||||
settings.onionskinMode == (int)OnionskinMode::INDEX);
|
||||
};
|
||||
|
||||
render(animation, frameTime, {}, 0.0f, layeredOnions, settings.onionskinMode == (int)OnionskinMode::INDEX);
|
||||
|
||||
if (auto overlayAnimation = anm2.element_get(ElementType::ANIMATION, overlayIndex))
|
||||
render(overlayAnimation, frameTime, {}, 1.0f - math::uint8_to_float(overlayTransparency), layeredOnions,
|
||||
settings.onionskinMode == (int)OnionskinMode::INDEX);
|
||||
if (overlayDrawOrder == overlay_draw_order::UNDER) overlay_render();
|
||||
render(document, animation, frameTime, {}, 0.0f, layeredOnions,
|
||||
settings.onionskinMode == (int)OnionskinMode::INDEX);
|
||||
if (overlayDrawOrder == overlay_draw_order::OVER) overlay_render();
|
||||
}
|
||||
|
||||
if (manager.isRecording && renderFrameIndex < renderFrameCount)
|
||||
@@ -1136,6 +1250,7 @@ namespace anm2ed::imgui
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
overlayDocumentId = savedOverlayDocumentId;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
@@ -1569,6 +1684,7 @@ namespace anm2ed::imgui
|
||||
zoom = savedZoom;
|
||||
settings = savedSettings;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
overlayDocumentId = savedOverlayDocumentId;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
|
||||
#include "audio_stream.hpp"
|
||||
@@ -22,6 +23,7 @@ namespace anm2ed::imgui
|
||||
float savedZoom{};
|
||||
glm::vec2 savedPan{};
|
||||
int savedOverlayIndex{};
|
||||
uint64_t savedOverlayDocumentId{};
|
||||
glm::vec2 mousePos{};
|
||||
glm::vec2 checkerPan{};
|
||||
glm::vec2 checkerSyncPan{};
|
||||
|
||||
@@ -61,17 +61,11 @@ namespace anm2ed::imgui
|
||||
};
|
||||
if (auto selectedLayerSpritesheet = selected_layer_spritesheet_get();
|
||||
selectedLayerSpritesheet != -1 && document.editTarget != Document::EditTarget::REGION &&
|
||||
document.editTarget != Document::EditTarget::OVERLAY && document.editTarget != Document::EditTarget::SPRITESHEET)
|
||||
document.editTarget != Document::EditTarget::SPRITESHEET)
|
||||
referenceSpritesheet = selectedLayerSpritesheet;
|
||||
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, referenceSpritesheet);
|
||||
auto baseTexture = document.texture_get(referenceSpritesheet);
|
||||
auto activeOverlayId = -1;
|
||||
auto activeOverlay = document.editTarget == Document::EditTarget::OVERLAY ? document.overlay_get() : nullptr;
|
||||
if (activeOverlay && document.overlay_spritesheet_id_get(activeOverlay->id) == referenceSpritesheet)
|
||||
activeOverlayId = activeOverlay->id;
|
||||
else
|
||||
activeOverlay = nullptr;
|
||||
auto texture = activeOverlayId != -1 ? document.overlay_texture_get(activeOverlayId) : baseTexture;
|
||||
auto texture = baseTexture;
|
||||
auto& tool = settings.tool;
|
||||
auto& shaderGrid = resources.shaders[shader::GRID];
|
||||
auto& shaderTexture = resources.shaders[shader::TEXTURE];
|
||||
@@ -244,24 +238,8 @@ namespace anm2ed::imgui
|
||||
auto spritesheetModel = math::quad_model_get(viewTexture->size);
|
||||
auto spritesheetTransform = transform * spritesheetModel;
|
||||
|
||||
auto overlay_draw = [&](const Element& overlay)
|
||||
{
|
||||
if (overlay.type != ElementType::OVERLAY) return;
|
||||
if (!overlay.isVisible) return;
|
||||
auto overlayTexture = document.overlay_texture_get(overlay.id);
|
||||
if (!overlayTexture || !overlayTexture->is_valid()) return;
|
||||
auto overlayTransform = transform * math::quad_model_get(overlayTexture->size, overlay.position);
|
||||
texture_render(shaderTexture, overlayTexture->id, overlayTransform, vec4(1.0f, 1.0f, 1.0f, overlay.tint.a));
|
||||
};
|
||||
|
||||
for (auto& overlay : spritesheet->children)
|
||||
if (overlay.index == OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
|
||||
|
||||
if (baseTexture && baseTexture->is_valid()) texture_render(shaderTexture, baseTexture->id, spritesheetTransform);
|
||||
|
||||
for (auto& overlay : spritesheet->children)
|
||||
if (overlay.index != OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
|
||||
|
||||
if (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
|
||||
|
||||
if (isBorder)
|
||||
@@ -328,18 +306,6 @@ namespace anm2ed::imgui
|
||||
}
|
||||
}
|
||||
|
||||
if (activeOverlay)
|
||||
{
|
||||
auto overlayTexture = document.overlay_texture_get(activeOverlayId);
|
||||
if (overlayTexture && overlayTexture->is_valid())
|
||||
{
|
||||
auto overlayModel = math::quad_model_get(overlayTexture->size, activeOverlay->position);
|
||||
auto overlayTransform = transform * overlayModel;
|
||||
rect_render(dashedShader, overlayTransform, overlayModel, color::RED, BORDER_DASH_LENGTH, BORDER_DASH_GAP,
|
||||
BORDER_DASH_OFFSET);
|
||||
}
|
||||
}
|
||||
|
||||
bool isFrameOnSpritesheet = isReferenceLayerOnSpritesheet;
|
||||
if (isFrameOnSpritesheet && frame->regionId == -1)
|
||||
{
|
||||
@@ -429,11 +395,6 @@ namespace anm2ed::imgui
|
||||
mousePos = position_translate(zoom, pan, to_ivec2(ImGui::GetMousePos()) - to_ivec2(cursorScreenPos));
|
||||
auto textureMousePos = mousePos;
|
||||
auto previousTextureMousePos = previousMousePos;
|
||||
if (activeOverlay)
|
||||
{
|
||||
textureMousePos -= activeOverlay->position;
|
||||
previousTextureMousePos -= activeOverlay->position;
|
||||
}
|
||||
|
||||
auto snap_rect = [&](glm::vec2 minPoint, glm::vec2 maxPoint)
|
||||
{
|
||||
@@ -466,29 +427,6 @@ namespace anm2ed::imgui
|
||||
auto fraction = current - glm::floor(current);
|
||||
return glm::floor(value) + fraction;
|
||||
};
|
||||
auto overlayIsGridSnap = isGridSnap;
|
||||
auto overlayGridSize = gridSize;
|
||||
auto overlayGridOffset = gridOffset;
|
||||
auto overlay_position_snap =
|
||||
[overlayIsGridSnap, overlayGridSize, overlayGridOffset, clamp_vec2_to_int](vec2 value)
|
||||
{
|
||||
if (overlayIsGridSnap)
|
||||
{
|
||||
if (overlayGridSize.x != 0)
|
||||
{
|
||||
auto offsetX = (float)overlayGridOffset.x;
|
||||
auto sizeX = (float)overlayGridSize.x;
|
||||
value.x = std::round((value.x - offsetX) / sizeX) * sizeX + offsetX;
|
||||
}
|
||||
if (overlayGridSize.y != 0)
|
||||
{
|
||||
auto offsetY = (float)overlayGridOffset.y;
|
||||
auto sizeY = (float)overlayGridSize.y;
|
||||
value.y = std::round((value.y - offsetY) / sizeY) * sizeY + offsetY;
|
||||
}
|
||||
}
|
||||
return clamp_vec2_to_int(value);
|
||||
};
|
||||
auto frame_snapshot_push = [&](StringType messageType, const std::set<Reference>& frameReferences)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
@@ -506,12 +444,6 @@ namespace anm2ed::imgui
|
||||
[message, queuedSpritesheet, queuedRegionIds](Manager&, Document& document)
|
||||
{ document.regions_snapshot(message, queuedSpritesheet, queuedRegionIds); }});
|
||||
};
|
||||
auto overlay_snapshot_push = [&](StringType messageType)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
manager.command_push(
|
||||
{manager.selected, [message](Manager&, Document& document) { document.anm2_snapshot(message); }});
|
||||
};
|
||||
auto texture_snapshot_push = [&](StringType messageType)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
@@ -693,36 +625,12 @@ namespace anm2ed::imgui
|
||||
region.size = clamp_vec2_to_int(maxPoint - minPoint);
|
||||
});
|
||||
};
|
||||
auto overlay_update = [&](int id, auto update)
|
||||
{
|
||||
auto queuedSpritesheet = referenceSpritesheet;
|
||||
manager.command_push({manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
auto spritesheet =
|
||||
document.anm2.element_get(ElementType::SPRITESHEET, queuedSpritesheet);
|
||||
if (!spritesheet) return;
|
||||
auto overlay = element_child_id_get(*spritesheet, ElementType::OVERLAY, id);
|
||||
if (!overlay) return;
|
||||
update(*overlay);
|
||||
}});
|
||||
};
|
||||
auto overlay_position_set = [&](int id, vec2 position)
|
||||
{
|
||||
overlay_update(id, [=](Element& overlay) { overlay.position = overlay_position_snap(position); });
|
||||
};
|
||||
auto overlay_position_offset = [&](int id, vec2 delta)
|
||||
{
|
||||
overlay_update(id,
|
||||
[=](Element& overlay) { overlay.position = overlay_position_snap(overlay.position + delta); });
|
||||
};
|
||||
auto texture_line_apply = [&](ivec2 start, ivec2 end, vec4 color)
|
||||
{
|
||||
auto queuedSpritesheet = referenceSpritesheet;
|
||||
auto queuedOverlay = activeOverlayId;
|
||||
manager.command_push({manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
auto texture = queuedOverlay != -1 ? document.overlay_texture_get(queuedOverlay)
|
||||
: document.texture_get(queuedSpritesheet);
|
||||
auto texture = document.texture_get(queuedSpritesheet);
|
||||
if (!texture) return;
|
||||
texture->pixel_line(start, end, color);
|
||||
}});
|
||||
@@ -730,15 +638,9 @@ namespace anm2ed::imgui
|
||||
auto texture_change_push = [&]()
|
||||
{
|
||||
auto queuedSpritesheet = referenceSpritesheet;
|
||||
auto queuedOverlay = activeOverlayId;
|
||||
manager.command_push(
|
||||
{manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
if (queuedOverlay != -1)
|
||||
document.overlay_texture_change(queuedOverlay);
|
||||
else
|
||||
document.texture_change(queuedSpritesheet);
|
||||
}});
|
||||
{ document.texture_change(queuedSpritesheet); }});
|
||||
};
|
||||
|
||||
auto region_selection_set = [&](int id)
|
||||
@@ -801,9 +703,7 @@ namespace anm2ed::imgui
|
||||
auto& toolInfo = tool::INFO[useTool];
|
||||
auto& areaType = toolInfo.areaType;
|
||||
auto isRegionEditTarget = document.editTarget == Document::EditTarget::REGION;
|
||||
auto isOverlayEditTarget = document.editTarget == Document::EditTarget::OVERLAY && activeOverlayId != -1;
|
||||
auto selectedFrameToolReferences =
|
||||
isRegionEditTarget || isOverlayEditTarget ? std::set<Reference>{} : selectedFrameReferences;
|
||||
auto selectedFrameToolReferences = isRegionEditTarget ? std::set<Reference>{} : selectedFrameReferences;
|
||||
bool isAreaAllowed = areaType == tool::ALL || areaType == tool::SPRITESHEET_EDITOR;
|
||||
bool isFrameRequired =
|
||||
!(useTool == tool::PAN || useTool == tool::DRAW || useTool == tool::ERASE || useTool == tool::COLOR_PICKER);
|
||||
@@ -812,8 +712,7 @@ namespace anm2ed::imgui
|
||||
(useTool == tool::CROP || useTool == tool::MOVE);
|
||||
bool isFrameAvailable = !isFrameRequired || (frame && !isRegionInUse && !selectedFrameToolReferences.empty()) ||
|
||||
(useTool == tool::CROP && !regionSelection.empty()) ||
|
||||
(useTool == tool::MOVE && regionReference != -1) ||
|
||||
(useTool == tool::MOVE && isOverlayEditTarget);
|
||||
(useTool == tool::MOVE && regionReference != -1);
|
||||
bool isSpritesheetRequired = useTool == tool::DRAW || useTool == tool::ERASE || useTool == tool::COLOR_PICKER;
|
||||
bool isSpritesheetAvailable = !isSpritesheetRequired || (texture && texture->is_valid());
|
||||
auto cursor = (isAreaAllowed && isFrameAvailable && isSpritesheetAvailable) ? toolInfo.cursor
|
||||
@@ -848,34 +747,6 @@ namespace anm2ed::imgui
|
||||
if (isMouseDown || isMouseMiddleDown) pan += mouseDelta;
|
||||
break;
|
||||
case tool::MOVE:
|
||||
if (isOverlayEditTarget)
|
||||
{
|
||||
if (!activeOverlay) break;
|
||||
|
||||
if (isBegin) overlay_snapshot_push(EDIT_OVERLAY_MOVE);
|
||||
if (isMouseClicked) cropAnchor = mousePos - activeOverlay->position;
|
||||
if (isMouseDown) overlay_position_set(activeOverlayId, mousePos - cropAnchor);
|
||||
if (isLeftPressed) overlay_position_offset(activeOverlayId, vec2(-stepX, 0));
|
||||
if (isRightPressed) overlay_position_offset(activeOverlayId, vec2(stepX, 0));
|
||||
if (isUpPressed) overlay_position_offset(activeOverlayId, vec2(0, -stepY));
|
||||
if (isDownPressed) overlay_position_offset(activeOverlayId, vec2(0, stepY));
|
||||
|
||||
if (isDuring)
|
||||
{
|
||||
if (ImGui::BeginTooltip())
|
||||
{
|
||||
ImGui::TextUnformatted(
|
||||
std::vformat(localize.get(FORMAT_POSITION),
|
||||
std::make_format_args(activeOverlay->position.x, activeOverlay->position.y))
|
||||
.c_str());
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
if (isEnd) document_change_push(Document::SPRITESHEETS);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) && regionReference != -1)
|
||||
{
|
||||
if (!spritesheet) break;
|
||||
|
||||
+23
-725
@@ -543,6 +543,7 @@ namespace anm2ed::imgui
|
||||
auto& selection = document.animation.selection;
|
||||
auto& reference = document.reference;
|
||||
auto& overlayIndex = document.overlayIndex;
|
||||
auto& overlayDocumentId = document.overlayDocumentId;
|
||||
int merged{-1};
|
||||
|
||||
document.anm2_snapshot(localize.get(EDIT_MERGE_ANIMATIONS));
|
||||
@@ -550,7 +551,11 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto selected = quickSelection ? *quickSelection : std::set<int>(selection.begin(), selection.end());
|
||||
auto isQuickGroupMerge = quickGroupSelection && !quickGroupSelection->empty();
|
||||
if (selected.contains(overlayIndex)) overlayIndex = -1;
|
||||
if ((overlayDocumentId == 0 || overlayDocumentId == document.tabId) && selected.contains(overlayIndex))
|
||||
{
|
||||
overlayIndex = -1;
|
||||
overlayDocumentId = 0;
|
||||
}
|
||||
|
||||
if (selected.size() > 1)
|
||||
merged = anm2.animations_merge(*selected.begin(), selected);
|
||||
@@ -574,7 +579,11 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto mergeSelection = window_animation_merge_indices_get(document, options.selection, options.reference);
|
||||
if (mergeSelection.empty()) return -1;
|
||||
if (mergeSelection.contains(overlayIndex)) overlayIndex = -1;
|
||||
if ((overlayDocumentId == 0 || overlayDocumentId == document.tabId) && mergeSelection.contains(overlayIndex))
|
||||
{
|
||||
overlayIndex = -1;
|
||||
overlayDocumentId = 0;
|
||||
}
|
||||
merged = anm2.animations_merge(options.reference, mergeSelection, options.type, options.isDeleteAnimationsAfter);
|
||||
}
|
||||
|
||||
@@ -672,89 +681,6 @@ namespace anm2ed::imgui
|
||||
}
|
||||
}
|
||||
|
||||
void window_overlays_save(Document& document, const std::set<int>& ids)
|
||||
{
|
||||
if (ids.empty()) return;
|
||||
|
||||
for (auto& id : ids)
|
||||
{
|
||||
auto overlay = document.overlay_get(id);
|
||||
auto texture = document.overlay_texture_get(id);
|
||||
if (!overlay || !texture) continue;
|
||||
auto pathString = path::to_utf8(overlay->path);
|
||||
WorkingDirectory workingDirectory(document.directory_get());
|
||||
path::ensure_directory(overlay->path.parent_path());
|
||||
if (texture->write_png(overlay->path))
|
||||
{
|
||||
document.overlay_hash_set_saved(id);
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY), std::make_format_args(id, pathString)));
|
||||
logger.info(
|
||||
std::vformat(localize.get(TOAST_SAVE_OVERLAY, anm2ed::ENGLISH), std::make_format_args(id, pathString)));
|
||||
}
|
||||
else
|
||||
{
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED), std::make_format_args(id, pathString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int window_overlay_next_id_get(const Document& document)
|
||||
{
|
||||
int nextId{};
|
||||
if (auto spritesheets = document.anm2.element_get(ElementType::SPRITESHEETS))
|
||||
for (auto& spritesheet : spritesheets->children)
|
||||
{
|
||||
if (spritesheet.type != ElementType::SPRITESHEET) continue;
|
||||
for (auto& overlay : spritesheet.children)
|
||||
if (overlay.type == ElementType::OVERLAY) nextId = std::max(nextId, overlay.id + 1);
|
||||
}
|
||||
return nextId;
|
||||
}
|
||||
|
||||
void window_overlays_context_actions_add(Window& window, Manager& manager, Settings& settings, Document& document,
|
||||
Clipboard& clipboard, Actions& actions)
|
||||
{
|
||||
auto& selection = document.overlay.selection;
|
||||
actions_undo_redo_add(actions, manager, document);
|
||||
actions.separator();
|
||||
actions.add(ACTION_PROPERTIES, [&]() { return selection.size() == 1 && (bool)window.properties; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.properties); });
|
||||
actions.add(ACTION_OPEN_DIRECTORY, [&]() { return selection.size() == 1 && (bool)window.open; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.open); });
|
||||
actions.add(ACTION_SET_FILE_PATH, [&]() { return selection.size() == 1 && (bool)window.path_set; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.path_set); });
|
||||
actions.add(ACTION_ADD, [&]() { return (bool)window.add; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.add); });
|
||||
actions.add(ACTION_REMOVE, [&]() { return !selection.empty() && (bool)window.remove; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.remove); },
|
||||
TOOLTIP_REMOVE_OVERLAYS);
|
||||
actions.add(ACTION_RELOAD, [&]() { return !selection.empty() && (bool)window.reload; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.reload); },
|
||||
TOOLTIP_RELOAD_OVERLAYS);
|
||||
actions.add(ACTION_REPLACE, [&]() { return selection.size() == 1 && (bool)window.replace; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.replace); },
|
||||
TOOLTIP_REPLACE_OVERLAY);
|
||||
actions.add(ACTION_SAVE, [&]() { return !selection.empty(); },
|
||||
[&]()
|
||||
{
|
||||
if (settings.fileIsWarnOverwrite)
|
||||
{
|
||||
window.selection2 = selection;
|
||||
window.popup2.open();
|
||||
}
|
||||
else if (window.save)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.save);
|
||||
},
|
||||
TOOLTIP_SAVE_OVERLAYS);
|
||||
actions.separator();
|
||||
actions.add(ACTION_COPY, [&]() { return !selection.empty() && (bool)window.copy; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.copy); });
|
||||
actions.add(ACTION_PASTE, [&]() { return !clipboard.is_empty() && (bool)window.paste; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.paste); });
|
||||
}
|
||||
|
||||
int window_footer_button_count_get(const Window& window)
|
||||
{
|
||||
int count{};
|
||||
@@ -1622,6 +1548,7 @@ namespace anm2ed::imgui
|
||||
auto& selection = document.animation.selection;
|
||||
auto& reference = document.reference;
|
||||
auto& overlayIndex = document.overlayIndex;
|
||||
auto& overlayDocumentId = document.overlayDocumentId;
|
||||
auto groupSelection = window.selection;
|
||||
|
||||
auto behavior = [&]()
|
||||
@@ -1640,7 +1567,11 @@ namespace anm2ed::imgui
|
||||
auto i = *it;
|
||||
auto childIndex = window_animation_child_index_get(*items, i);
|
||||
if (childIndex == -1) continue;
|
||||
if (overlayIndex == i) overlayIndex = -1;
|
||||
if ((overlayDocumentId == 0 || overlayDocumentId == document.tabId) && overlayIndex == i)
|
||||
{
|
||||
overlayIndex = -1;
|
||||
overlayDocumentId = 0;
|
||||
}
|
||||
if (reference.animationIndex == i) reference.animationIndex = -1;
|
||||
items->children.erase(items->children.begin() + childIndex);
|
||||
}
|
||||
@@ -1797,7 +1728,12 @@ namespace anm2ed::imgui
|
||||
auto i = *it;
|
||||
auto childIndex = window_animation_child_index_get(*items, i);
|
||||
if (childIndex == -1) continue;
|
||||
if (document.overlayIndex == i) document.overlayIndex = -1;
|
||||
if ((document.overlayDocumentId == 0 || document.overlayDocumentId == document.tabId) &&
|
||||
document.overlayIndex == i)
|
||||
{
|
||||
document.overlayIndex = -1;
|
||||
document.overlayDocumentId = 0;
|
||||
}
|
||||
if (document.reference.animationIndex == i) document.reference.animationIndex = -1;
|
||||
items->children.erase(items->children.begin() + childIndex);
|
||||
}
|
||||
@@ -2726,644 +2662,6 @@ namespace anm2ed::imgui
|
||||
return window;
|
||||
}
|
||||
|
||||
Window overlays_window_register()
|
||||
{
|
||||
Window window{};
|
||||
window.title = LABEL_OVERLAYS_WINDOW;
|
||||
window.isOpen = &Settings::windowIsOverlays;
|
||||
window.changeType = Document::SPRITESHEETS;
|
||||
window.elementType = ElementType::OVERLAY;
|
||||
window.childLabel = "##Overlays Child";
|
||||
window.footerRows = 2;
|
||||
window.flags = 0;
|
||||
window.isChildPaddingZero = true;
|
||||
window.unavailableText = TEXT_SELECT_SPRITESHEET;
|
||||
window.editElement = element_make(ElementType::OVERLAY);
|
||||
window.popup = PopupHelper(LABEL_OVERLAY_PROPERTIES, POPUP_SMALL_NO_HEIGHT);
|
||||
window.popup2 = PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT);
|
||||
window.storage_get = [](Document& document) -> Storage& { return document.overlay; };
|
||||
window.is_available = [](Document& document)
|
||||
{ return document.anm2.element_get(ElementType::SPRITESHEET, document.spritesheet.reference); };
|
||||
window.add = [](Window& window, Manager&, Settings&, Document&, Clipboard&)
|
||||
{
|
||||
if (window.dialog) window.dialog->file_open(Dialog::OVERLAY_OPEN, true);
|
||||
};
|
||||
window.replace = [](Window& window, Manager&, Settings&, Document&, Clipboard&)
|
||||
{
|
||||
if (window.dialog) window.dialog->file_open(Dialog::OVERLAY_REPLACE);
|
||||
};
|
||||
window.path_set = [](Window& window, Manager&, Settings&, Document&, Clipboard&)
|
||||
{
|
||||
if (window.dialog) window.dialog->file_save(Dialog::OVERLAY_PATH_SET);
|
||||
};
|
||||
window.open = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
|
||||
{
|
||||
auto& selection = document.overlay.selection;
|
||||
if (selection.size() != 1 || !window.dialog) return;
|
||||
if (auto overlay = document.overlay_get(*selection.begin())) window_directory_open(*window.dialog, document, overlay->path);
|
||||
};
|
||||
window.properties = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
|
||||
{
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, document.spritesheet.reference);
|
||||
auto& selection = document.overlay.selection;
|
||||
if (!spritesheet || selection.size() != 1) return;
|
||||
auto id = *selection.begin();
|
||||
if (!element_child_id_get(*spritesheet, ElementType::OVERLAY, id)) return;
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
document.overlay.reference = id;
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
window.popup.open();
|
||||
};
|
||||
window.remove = [](Window& window, Manager&, Settings&, Document& document, Clipboard&)
|
||||
{
|
||||
auto selected = document.overlay.selection;
|
||||
if (selected.empty()) return;
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, document.spritesheet.reference);
|
||||
if (!spritesheet) return;
|
||||
|
||||
auto behavior = [&]()
|
||||
{
|
||||
for (auto id : selected)
|
||||
{
|
||||
auto overlay = element_child_id_get(*spritesheet, ElementType::OVERLAY, id);
|
||||
if (!overlay) continue;
|
||||
auto pathString = path::to_utf8(overlay->path);
|
||||
toasts.push(std::vformat(localize.get(TOAST_REMOVE_OVERLAY), std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_REMOVE_OVERLAY, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
element_child_id_erase(*spritesheet, ElementType::OVERLAY, id);
|
||||
}
|
||||
document.overlay.reference = -1;
|
||||
document.overlay.selection.clear();
|
||||
};
|
||||
|
||||
window_edit(window, document, localize.get(EDIT_REMOVE_OVERLAYS), behavior);
|
||||
};
|
||||
window.reload = [](Window&, Manager&, Settings&, Document& document, Clipboard&)
|
||||
{
|
||||
auto selected = document.overlay.selection;
|
||||
if (selected.empty()) return;
|
||||
document.textures_snapshot(localize.get(EDIT_RELOAD_OVERLAYS));
|
||||
for (auto id : selected)
|
||||
document.overlay_texture_reload(id);
|
||||
document.change(Document::TEXTURES);
|
||||
|
||||
for (auto id : selected)
|
||||
{
|
||||
auto overlay = document.overlay_get(id);
|
||||
if (!overlay) continue;
|
||||
document.overlay_hash_set_saved(id);
|
||||
auto pathString = path::to_utf8(overlay->path);
|
||||
toasts.push(std::vformat(localize.get(TOAST_RELOAD_OVERLAY), std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_RELOAD_OVERLAY, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
};
|
||||
window.save = [](Window&, Manager&, Settings&, Document& document, Clipboard&)
|
||||
{
|
||||
window_overlays_save(document, document.overlay.selection);
|
||||
};
|
||||
window.copy = [](Window&, Manager&, Settings&, Document& document, Clipboard& clipboard)
|
||||
{
|
||||
auto& selection = document.overlay.selection;
|
||||
if (selection.empty()) return;
|
||||
|
||||
std::string clipboardText{};
|
||||
for (auto id : selection)
|
||||
if (auto overlay = document.overlay_get(id)) clipboardText += element_to_string(*overlay);
|
||||
clipboard.set(clipboardText);
|
||||
};
|
||||
window.paste = [](Window& window, Manager&, Settings&, Document& document, Clipboard& clipboard)
|
||||
{
|
||||
if (clipboard.is_empty()) return;
|
||||
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, document.spritesheet.reference);
|
||||
if (!spritesheet) return;
|
||||
|
||||
tinyxml2::XMLDocument xmlDocument{};
|
||||
std::string errorString{};
|
||||
if (xmlDocument.Parse(clipboard.get().c_str()) != tinyxml2::XML_SUCCESS)
|
||||
{
|
||||
errorString = xmlDocument.ErrorStr();
|
||||
toasts.push(std::vformat(localize.get(TOAST_DESERIALIZE_OVERLAYS_FAILED), std::make_format_args(errorString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_DESERIALIZE_OVERLAYS_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(errorString)));
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<Element> pasted{};
|
||||
for (auto xmlElement = xmlDocument.FirstChildElement("Overlay"); xmlElement;
|
||||
xmlElement = xmlElement->NextSiblingElement("Overlay"))
|
||||
{
|
||||
auto overlay = element_read(xmlElement);
|
||||
if (overlay.type == ElementType::OVERLAY) pasted.push_back(std::move(overlay));
|
||||
}
|
||||
if (pasted.empty())
|
||||
{
|
||||
errorString = "No valid Overlay(s).";
|
||||
toasts.push(std::vformat(localize.get(TOAST_DESERIALIZE_OVERLAYS_FAILED), std::make_format_args(errorString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_DESERIALIZE_OVERLAYS_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(errorString)));
|
||||
return;
|
||||
}
|
||||
|
||||
auto behavior = [&]()
|
||||
{
|
||||
std::set<int> added{};
|
||||
for (auto overlay : pasted)
|
||||
{
|
||||
overlay.id = window_overlay_next_id_get(document);
|
||||
overlay.path = path::backslash_handle(overlay.path);
|
||||
added.insert(overlay.id);
|
||||
spritesheet->children.push_back(std::move(overlay));
|
||||
document.overlay_texture_reload(*added.rbegin());
|
||||
}
|
||||
|
||||
document.overlay.selection = added;
|
||||
document.overlay.reference = added.empty() ? -1 : *added.rbegin();
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
window.newElementId = document.overlay.reference;
|
||||
};
|
||||
|
||||
window_edit(window, document, localize.get(EDIT_PASTE_OVERLAYS), behavior);
|
||||
};
|
||||
window.rows_update =
|
||||
[](Window& window, Manager& manager, Settings& settings, Resources& resources, Clipboard& clipboard,
|
||||
Document& document, ImVec2)
|
||||
{
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, document.spritesheet.reference);
|
||||
if (!spritesheet) return;
|
||||
|
||||
auto& selection = document.overlay.selection;
|
||||
auto& reference = document.overlay.reference;
|
||||
auto style = ImGui::GetStyle();
|
||||
auto overlayChildSize = ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeightWithSpacing() * 4);
|
||||
bool isContextMenuQueued{};
|
||||
int contextMenuTargetId{-1};
|
||||
StringType visibilityTooltip{STRING_UNDEFINED};
|
||||
|
||||
std::vector<int> ids{};
|
||||
for (auto& overlay : spritesheet->children)
|
||||
if (overlay.type == ElementType::OVERLAY) ids.push_back(overlay.id);
|
||||
|
||||
if (reference != -1 && std::ranges::find(ids, reference) == ids.end())
|
||||
{
|
||||
reference = -1;
|
||||
selection.clear();
|
||||
}
|
||||
|
||||
selection.start((int)ids.size());
|
||||
if (ImGui::Shortcut(ImGuiMod_Ctrl | ImGuiKey_A, ImGuiInputFlags_RouteFocused))
|
||||
{
|
||||
selection.clear();
|
||||
for (auto id : ids)
|
||||
selection.insert(id);
|
||||
}
|
||||
if (ImGui::Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteFocused))
|
||||
{
|
||||
selection.clear();
|
||||
reference = -1;
|
||||
}
|
||||
|
||||
int scrollTargetId = -1;
|
||||
int arrowSelectionId = -1;
|
||||
if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) &&
|
||||
(ImGui::IsKeyPressed(ImGuiKey_UpArrow, true) || ImGui::IsKeyPressed(ImGuiKey_DownArrow, true)))
|
||||
{
|
||||
auto nextId = window_arrow_selection_get(ids, reference, selection);
|
||||
if (nextId != -1)
|
||||
{
|
||||
arrowSelectionId = nextId;
|
||||
scrollTargetId = nextId;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2());
|
||||
for (auto& overlay : spritesheet->children)
|
||||
{
|
||||
if (overlay.type != ElementType::OVERLAY) continue;
|
||||
auto id = overlay.id;
|
||||
auto isNewOverlay = window.newElementId == id;
|
||||
ImGui::PushID(id);
|
||||
|
||||
window_scroll_to_item(overlayChildSize.y, scrollTargetId == id);
|
||||
if (scrollTargetId == id) ImGui::SetNextWindowFocus();
|
||||
|
||||
if (ImGui::BeginChild("##Overlay Child", overlayChildSize, ImGuiChildFlags_Borders))
|
||||
{
|
||||
auto isSelected = selection.contains(id) || arrowSelectionId == id;
|
||||
auto isReferenced = id == reference || arrowSelectionId == id;
|
||||
auto cursorPos = ImGui::GetCursorPos();
|
||||
auto textureInfo = document.overlay_texture_get(id);
|
||||
bool isValid = textureInfo && textureInfo->is_valid();
|
||||
auto& texture = isValid ? *textureInfo : resources.icons[icon::NONE];
|
||||
auto tintColor = !isValid ? ImVec4(1.0f, 0.25f, 0.25f, 1.0f)
|
||||
: overlay.isVisible ? ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
: ImVec4(1.0f, 1.0f, 1.0f, 0.35f);
|
||||
auto pathString = path::to_utf8(overlay.path);
|
||||
auto pathCStr = pathString.c_str();
|
||||
auto visibleButtonSize = icon_size_get();
|
||||
|
||||
ImGui::SetNextItemSelectionUserData(id);
|
||||
ImGui::SetNextItemStorageID(id);
|
||||
if (scrollTargetId == id) ImGui::SetKeyboardFocusHere();
|
||||
auto isActivated =
|
||||
ImGui::Selectable("##Overlay Selectable", isSelected, ImGuiSelectableFlags_AllowOverlap,
|
||||
overlayChildSize);
|
||||
auto isRowRightClicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
|
||||
auto isClicked = ImGui::IsItemClicked(ImGuiMouseButton_Left) || isRowRightClicked;
|
||||
if (isActivated || isClicked)
|
||||
{
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
reference = id;
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
}
|
||||
if (isRowRightClicked)
|
||||
{
|
||||
isContextMenuQueued = true;
|
||||
contextMenuTargetId = id;
|
||||
}
|
||||
if (scrollTargetId == id) ImGui::SetItemDefaultFocus();
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && window.properties)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.properties);
|
||||
|
||||
auto imageSize = to_imvec2(vec2(overlayChildSize.y));
|
||||
auto aspectRatio = texture.size.y != 0 ? (float)texture.size.x / texture.size.y : 1.0f;
|
||||
if (imageSize.x / imageSize.y > aspectRatio)
|
||||
imageSize.x = imageSize.y * aspectRatio;
|
||||
else
|
||||
imageSize.y = imageSize.x / aspectRatio;
|
||||
|
||||
ImGui::SetCursorPos(cursorPos);
|
||||
ImGui::ImageWithBg(texture.id, imageSize, ImVec2(), ImVec2(1, 1), ImVec4(), tintColor);
|
||||
|
||||
ImGui::SetCursorPos(
|
||||
ImVec2(overlayChildSize.y + style.ItemSpacing.x,
|
||||
overlayChildSize.y - overlayChildSize.y / 2 - ImGui::GetTextLineHeight() / 2));
|
||||
|
||||
if (isReferenced) ImGui::PushFont(resources.fonts[font::ITALICS].get(), font::SIZE);
|
||||
auto overlayLabel = std::vformat(localize.get(FORMAT_OVERLAY), std::make_format_args(id, pathCStr));
|
||||
if (document.overlay_is_dirty(id))
|
||||
overlayLabel =
|
||||
std::vformat(localize.get(FORMAT_SPRITESHEET_NOT_SAVED), std::make_format_args(overlayLabel));
|
||||
ImGui::TextUnformatted(overlayLabel.c_str());
|
||||
if (isReferenced) ImGui::PopFont();
|
||||
|
||||
auto visibleIcon = overlay.isVisible ? icon::VISIBLE : icon::INVISIBLE;
|
||||
auto visibleButtonPos =
|
||||
ImVec2(overlayChildSize.x - visibleButtonSize.x - style.ItemSpacing.x,
|
||||
overlayChildSize.y * 0.5f - visibleButtonSize.y * 0.5f);
|
||||
ImGui::SetCursorPos(visibleButtonPos);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4());
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2());
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameBorderSize, 0.0f);
|
||||
if (ImGui::ImageButton("##Overlay Visible Toggle", resources.icons[visibleIcon].id, visibleButtonSize))
|
||||
{
|
||||
auto queuedId = id;
|
||||
manager.command_push({manager.selected,
|
||||
[queuedId](Manager&, Document& document)
|
||||
{
|
||||
auto behavior = [&]()
|
||||
{
|
||||
auto overlay = document.overlay_get(queuedId);
|
||||
if (!overlay) return;
|
||||
overlay->isVisible = !overlay->isVisible;
|
||||
};
|
||||
window_edit(document, Document::SPRITESHEETS,
|
||||
localize.get(EDIT_TOGGLE_ITEM_VISIBILITY), behavior);
|
||||
}});
|
||||
}
|
||||
auto isVisibleButtonHovered = ImGui::IsItemHovered();
|
||||
auto isVisibleButtonRightClicked = ImGui::IsItemClicked(ImGuiMouseButton_Right);
|
||||
if (isVisibleButtonRightClicked)
|
||||
{
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
reference = id;
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
isContextMenuQueued = true;
|
||||
contextMenuTargetId = id;
|
||||
}
|
||||
ImGui::PopStyleVar(2);
|
||||
ImGui::PopStyleColor(3);
|
||||
if (isVisibleButtonHovered)
|
||||
visibilityTooltip =
|
||||
overlay.isVisible ? TOOLTIP_ITEM_VISIBILITY_SHOWN : TOOLTIP_ITEM_VISIBILITY_HIDDEN;
|
||||
}
|
||||
|
||||
ImGui::EndChild();
|
||||
|
||||
if (isNewOverlay)
|
||||
{
|
||||
ImGui::SetScrollHereY(0.5f);
|
||||
window.newElementId = -1;
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (visibilityTooltip != STRING_UNDEFINED)
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, window.tooltipWindowPadding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, window.tooltipItemSpacing);
|
||||
ImGui::SetTooltip("%s", localize.get(visibilityTooltip));
|
||||
ImGui::PopStyleVar(2);
|
||||
}
|
||||
|
||||
selection.finish();
|
||||
if (contextMenuTargetId != -1)
|
||||
{
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
if (!selection.contains(contextMenuTargetId)) selection = {contextMenuTargetId};
|
||||
reference = contextMenuTargetId;
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
}
|
||||
if (arrowSelectionId != -1)
|
||||
{
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
selection = {arrowSelectionId};
|
||||
reference = arrowSelectionId;
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
}
|
||||
if (shortcut(manager.chords[SHORTCUT_CONFIRM], shortcut::FOCUSED) && reference != -1 && window.dialog)
|
||||
if (auto overlay = document.overlay_get(reference)) window_directory_open(*window.dialog, document, overlay->path);
|
||||
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup) &&
|
||||
ImGui::IsMouseReleased(ImGuiMouseButton_Right) && !ImGui::IsAnyItemHovered())
|
||||
isContextMenuQueued = true;
|
||||
if (isContextMenuQueued) ImGui::OpenPopup("##Overlay Context Menu");
|
||||
|
||||
Actions actions{};
|
||||
window_overlays_context_actions_add(window, manager, settings, document, clipboard, actions);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, window.tooltipWindowPadding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, window.tooltipItemSpacing);
|
||||
actions_popup_draw("##Overlay Context Menu", actions, settings);
|
||||
ImGui::PopStyleVar(2);
|
||||
};
|
||||
window.context_update =
|
||||
[](Window&, Manager&, Settings&, Resources&, Clipboard&, Document&) {};
|
||||
window.footer_update =
|
||||
[](Window& window, Manager& manager, Settings& settings, Resources&, Clipboard& clipboard, Document& document)
|
||||
{
|
||||
auto& selection = document.overlay.selection;
|
||||
|
||||
auto rowOneWidgetSize = widget_size_with_row_get(3);
|
||||
Actions rowOneActions{};
|
||||
rowOneActions.add(ACTION_ADD, [&]() { return (bool)window.add; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.add); },
|
||||
TOOLTIP_ADD_OVERLAY);
|
||||
rowOneActions.add(ACTION_RELOAD, [&]() { return !selection.empty() && (bool)window.reload; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.reload); },
|
||||
TOOLTIP_RELOAD_OVERLAYS);
|
||||
rowOneActions.add(ACTION_REPLACE, [&]() { return selection.size() == 1 && (bool)window.replace; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.replace); },
|
||||
TOOLTIP_REPLACE_OVERLAY);
|
||||
|
||||
bool isSameLine{};
|
||||
for (auto& action : rowOneActions.items)
|
||||
action_button_draw(action, manager, settings, rowOneWidgetSize, isSameLine);
|
||||
|
||||
if (window.dialog && window.dialog->is_selected(Dialog::OVERLAY_OPEN))
|
||||
{
|
||||
auto paths = window.dialog->paths;
|
||||
manager.command_push({manager.selected, [&window, paths](Manager&, Document& document)
|
||||
{
|
||||
document.overlays_add(document.spritesheet.reference, paths);
|
||||
document.region.reference = -1;
|
||||
document.region.selection.clear();
|
||||
window.newElementId = document.overlay.reference;
|
||||
}});
|
||||
window.dialog->reset();
|
||||
}
|
||||
|
||||
if (window.dialog && window.dialog->is_selected(Dialog::OVERLAY_REPLACE))
|
||||
{
|
||||
if (selection.size() == 1 && !window.dialog->path.empty())
|
||||
{
|
||||
auto id = *selection.begin();
|
||||
auto dialogPath = window.dialog->path;
|
||||
manager.command_push({manager.selected, [id, dialogPath](Manager&, Document& document)
|
||||
{
|
||||
auto behavior = [&]()
|
||||
{
|
||||
auto overlay = document.overlay_get(id);
|
||||
if (!overlay) return;
|
||||
overlay->path = window_asset_path_get(document, dialogPath);
|
||||
document.overlay_texture_reload(id);
|
||||
};
|
||||
|
||||
window_edit(document, Document::SPRITESHEETS, localize.get(EDIT_REPLACE_OVERLAY),
|
||||
behavior);
|
||||
if (auto overlay = document.overlay_get(id))
|
||||
{
|
||||
document.overlay_hash_set_saved(id);
|
||||
auto pathString = path::to_utf8(overlay->path);
|
||||
toasts.push(std::vformat(localize.get(TOAST_REPLACE_OVERLAY),
|
||||
std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_REPLACE_OVERLAY, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
}});
|
||||
}
|
||||
window.dialog->reset();
|
||||
}
|
||||
|
||||
if (window.dialog && window.dialog->is_selected(Dialog::OVERLAY_PATH_SET))
|
||||
{
|
||||
if (selection.size() == 1 && !window.dialog->path.empty())
|
||||
{
|
||||
auto id = *selection.begin();
|
||||
auto dialogPath = window.dialog->path;
|
||||
manager.command_push({manager.selected, [id, dialogPath](Manager&, Document& document)
|
||||
{
|
||||
auto behavior = [&]()
|
||||
{
|
||||
auto overlay = document.overlay_get(id);
|
||||
auto texture = document.overlay_texture_get(id);
|
||||
if (!overlay || !texture) return;
|
||||
auto newPath = window_asset_path_get(document, dialogPath);
|
||||
auto pathString = path::to_utf8(newPath);
|
||||
WorkingDirectory workingDirectory(document.directory_get());
|
||||
path::ensure_directory(newPath.parent_path());
|
||||
if (!texture->write_png(newPath))
|
||||
{
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED),
|
||||
std::make_format_args(id, pathString)));
|
||||
logger.error(
|
||||
std::vformat(localize.get(TOAST_SAVE_OVERLAY_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
return;
|
||||
}
|
||||
overlay->path = newPath;
|
||||
document.overlayTexturePaths[id] = overlay->path;
|
||||
document.overlay_hash_set_saved(id);
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_OVERLAY),
|
||||
std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_SAVE_OVERLAY, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
};
|
||||
|
||||
window_edit(document, Document::SPRITESHEETS, localize.get(EDIT_SET_OVERLAY_FILE_PATH),
|
||||
behavior);
|
||||
}});
|
||||
}
|
||||
window.dialog->reset();
|
||||
}
|
||||
|
||||
auto rowTwoWidgetSize = widget_size_with_row_get(2);
|
||||
Actions rowTwoActions{};
|
||||
rowTwoActions.add(ACTION_REMOVE, [&]() { return !selection.empty() && (bool)window.remove; },
|
||||
[&]() { window_command_run(window, manager, settings, document, clipboard, window.remove); },
|
||||
TOOLTIP_REMOVE_OVERLAYS);
|
||||
rowTwoActions.add(ACTION_SAVE, [&]() { return !selection.empty(); },
|
||||
[&]()
|
||||
{
|
||||
if (settings.fileIsWarnOverwrite)
|
||||
{
|
||||
window.selection2 = selection;
|
||||
window.popup2.open();
|
||||
}
|
||||
else if (window.save)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.save);
|
||||
},
|
||||
TOOLTIP_SAVE_OVERLAYS);
|
||||
|
||||
isSameLine = false;
|
||||
for (auto& action : rowTwoActions.items)
|
||||
action_button_draw(action, manager, settings, rowTwoWidgetSize, isSameLine);
|
||||
|
||||
if (shortcut(manager.chords[SHORTCUT_ADD], shortcut::FOCUSED) && window.add)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.add);
|
||||
if (shortcut(manager.chords[SHORTCUT_REMOVE], shortcut::FOCUSED) && window.remove)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.remove);
|
||||
if (shortcut(manager.chords[SHORTCUT_COPY], shortcut::FOCUSED) && window.copy)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.copy);
|
||||
if (shortcut(manager.chords[SHORTCUT_PASTE], shortcut::FOCUSED) && window.paste)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.paste);
|
||||
};
|
||||
window.popup_update =
|
||||
[](Window& window, Manager& manager, Settings&, Resources&, Clipboard&, Document& document)
|
||||
{
|
||||
window.popup.trigger();
|
||||
if (ImGui::BeginPopupModal(window.popup.label(), &window.popup.isOpen, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
auto spritesheetReference = document.spritesheet.reference;
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, spritesheetReference);
|
||||
auto targetOverlay = document.overlay.reference == -1
|
||||
? nullptr
|
||||
: spritesheet ? element_child_id_get(*spritesheet, ElementType::OVERLAY,
|
||||
document.overlay.reference)
|
||||
: nullptr;
|
||||
bool isOverlayInvalid = !spritesheet || !targetOverlay;
|
||||
if (isOverlayInvalid)
|
||||
window.popup.close();
|
||||
else
|
||||
{
|
||||
if (window.popup.isJustOpened) window.editElement = *targetOverlay;
|
||||
|
||||
auto& overlay = window.editElement;
|
||||
auto childSize = child_size_get(4);
|
||||
if (ImGui::BeginChild("##Child", childSize, ImGuiChildFlags_Borders))
|
||||
{
|
||||
ImGui::DragFloat2(localize.get(BASIC_OFFSET), value_ptr(overlay.position), DRAG_SPEED, 0.0f, 0.0f,
|
||||
math::vec2_format_get(overlay.position));
|
||||
|
||||
int alpha = std::clamp(math::float_to_uint8(overlay.tint.a), 0, 255);
|
||||
if (ImGui::SliderInt(localize.get(BASIC_ALPHA), &alpha, 0, 255))
|
||||
overlay.tint.a = math::uint8_to_float(alpha);
|
||||
|
||||
int drawOrder = overlay.index == OVERLAY_DRAW_ORDER_BELOW ? OVERLAY_DRAW_ORDER_BELOW
|
||||
: OVERLAY_DRAW_ORDER_ABOVE;
|
||||
ImGui::SeparatorText(localize.get(LABEL_OVERLAY_DRAW_ORDER));
|
||||
ImGui::RadioButton(localize.get(LABEL_OVERLAY_DRAW_ORDER_BELOW), &drawOrder, OVERLAY_DRAW_ORDER_BELOW);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton(localize.get(LABEL_OVERLAY_DRAW_ORDER_ABOVE), &drawOrder, OVERLAY_DRAW_ORDER_ABOVE);
|
||||
overlay.index = drawOrder;
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
||||
if (ImGui::Button(localize.get(BASIC_CONFIRM), widgetSize))
|
||||
{
|
||||
auto editedOverlay = overlay;
|
||||
auto editedReference = document.overlay.reference;
|
||||
auto editedSpritesheetReference = spritesheetReference;
|
||||
manager.command_push({manager.selected, [&window, editedOverlay, editedReference,
|
||||
editedSpritesheetReference](Manager&, Document& document) mutable
|
||||
{
|
||||
auto spritesheet =
|
||||
document.anm2.element_get(ElementType::SPRITESHEET, editedSpritesheetReference);
|
||||
if (!spritesheet) return;
|
||||
auto target =
|
||||
element_child_id_get(*spritesheet, ElementType::OVERLAY, editedReference);
|
||||
if (!target) return;
|
||||
|
||||
auto set = [&]()
|
||||
{
|
||||
target->position = editedOverlay.position;
|
||||
target->tint.a = editedOverlay.tint.a;
|
||||
target->index = editedOverlay.index == OVERLAY_DRAW_ORDER_BELOW
|
||||
? OVERLAY_DRAW_ORDER_BELOW
|
||||
: OVERLAY_DRAW_ORDER_ABOVE;
|
||||
document.overlay.reference = editedReference;
|
||||
document.overlay.selection = {editedReference};
|
||||
document.editTarget = Document::EditTarget::OVERLAY;
|
||||
};
|
||||
|
||||
window_edit(window, document, localize.get(EDIT_SET_OVERLAY_PROPERTIES), set);
|
||||
}});
|
||||
window.popup.close();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
||||
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) window.popup.close();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
window.popup.end();
|
||||
|
||||
window.popup2.trigger();
|
||||
if (ImGui::BeginPopupModal(window.popup2.label(), &window.popup2.isOpen, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
ImGui::TextUnformatted(localize.get(LABEL_OVERWRITE_CONFIRMATION));
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
if (ImGui::Button(localize.get(BASIC_YES), widgetSize))
|
||||
{
|
||||
auto queuedSelection = window.selection2;
|
||||
manager.command_push({manager.selected, [queuedSelection](Manager&, Document& document) mutable
|
||||
{ window_overlays_save(document, queuedSelection); }});
|
||||
window.selection2.clear();
|
||||
window.popup2.close();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
||||
{
|
||||
window.selection2.clear();
|
||||
window.popup2.close();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
window.popup2.end();
|
||||
};
|
||||
return window;
|
||||
}
|
||||
|
||||
Window spritesheets_window_register()
|
||||
{
|
||||
Window window{};
|
||||
|
||||
@@ -139,6 +139,5 @@ namespace anm2ed::imgui
|
||||
Window layers_window_register();
|
||||
Window nulls_window_register();
|
||||
Window events_window_register();
|
||||
Window overlays_window_register();
|
||||
void window_update(Window&, Manager&, Settings&, Resources&, Dialog&, Clipboard&);
|
||||
}
|
||||
Reference in new issue
Block a user