fix merge window, fix hash slowness (again), touch up overlays (still not sure about them)
This commit is contained in:
1 parent
98f87c9d46
commit
ff76932555
13 files changed
+494
-94
No files matched your search
+54
-4
@@ -95,6 +95,8 @@ namespace anm2ed
|
||||
"", "", "EaseIn", "EaseOut", "EaseInOut"};
|
||||
|
||||
constexpr std::array<std::string_view, (std::size_t)Origin::COUNT> ORIGIN_VALUES = {"", "TopLeft", "Center"};
|
||||
constexpr std::array<std::string_view, (std::size_t)OverlayDrawOrder::COUNT> OVERLAY_DRAW_ORDER_VALUES = {"Below",
|
||||
"Above"};
|
||||
constexpr std::string_view ANM2ED_GROUP_FRAME_BACKUP_TAG = "FrameRestore";
|
||||
constexpr std::string_view SOURCE_DOCUMENT_TAG = "SourceDocument";
|
||||
|
||||
@@ -232,6 +234,7 @@ namespace anm2ed
|
||||
Element element{};
|
||||
element.type = type;
|
||||
element.tag = std::string(element_tag_get(type));
|
||||
if (type == ElementType::OVERLAY) element.index = OVERLAY_DRAW_ORDER_ABOVE;
|
||||
return element;
|
||||
}
|
||||
|
||||
@@ -451,6 +454,29 @@ namespace anm2ed
|
||||
|
||||
int color_write(float value) { return math::float_to_uint8(value); }
|
||||
|
||||
int overlay_draw_order_get(const Element& element)
|
||||
{
|
||||
return element.index == OVERLAY_DRAW_ORDER_BELOW ? OVERLAY_DRAW_ORDER_BELOW : OVERLAY_DRAW_ORDER_ABOVE;
|
||||
}
|
||||
|
||||
void overlay_draw_order_read(Element& out, const XMLElement* element)
|
||||
{
|
||||
if (out.type != ElementType::OVERLAY) return;
|
||||
out.index = OVERLAY_DRAW_ORDER_ABOVE;
|
||||
if (element)
|
||||
{
|
||||
element->QueryFloatAttribute("XOffset", &out.position.x);
|
||||
element->QueryFloatAttribute("YOffset", &out.position.y);
|
||||
}
|
||||
out.tint.a = color_read(element, "Alpha", out.tint.a);
|
||||
|
||||
auto value = element ? element->Attribute("DrawOrder") : nullptr;
|
||||
if (!value) return;
|
||||
|
||||
for (std::size_t i = 0; i < OVERLAY_DRAW_ORDER_VALUES.size(); ++i)
|
||||
if (OVERLAY_DRAW_ORDER_VALUES[i] == value) out.index = (int)i;
|
||||
}
|
||||
|
||||
Interpolation interpolation_read(const XMLElement* element, const char* attribute)
|
||||
{
|
||||
bool isFallback{};
|
||||
@@ -526,6 +552,7 @@ namespace anm2ed
|
||||
|
||||
out.interpolation = interpolation_read(element);
|
||||
out.origin = origin_read(element);
|
||||
overlay_draw_order_read(out, element);
|
||||
if (out.type == ElementType::REGION && out.origin == Origin::TOP_LEFT) out.pivot = {};
|
||||
if (out.type == ElementType::REGION && out.origin == Origin::CENTER) out.pivot = out.size * 0.5f;
|
||||
}
|
||||
@@ -686,7 +713,18 @@ namespace anm2ed
|
||||
{
|
||||
out->SetAttribute("Id", element.id);
|
||||
path_set(out, "Path", element.path);
|
||||
if (element.type == ElementType::OVERLAY && !element.isVisible) out->SetAttribute("Visible", element.isVisible);
|
||||
if (element.type == ElementType::OVERLAY)
|
||||
{
|
||||
if (!element.isVisible) out->SetAttribute("Visible", element.isVisible);
|
||||
if (element.position != glm::vec2())
|
||||
{
|
||||
out->SetAttribute("XOffset", element.position.x);
|
||||
out->SetAttribute("YOffset", element.position.y);
|
||||
}
|
||||
if (color_write(element.tint.a) != 255) out->SetAttribute("Alpha", color_write(element.tint.a));
|
||||
if (overlay_draw_order_get(element) == OVERLAY_DRAW_ORDER_BELOW)
|
||||
out->SetAttribute("DrawOrder", OVERLAY_DRAW_ORDER_VALUES[OVERLAY_DRAW_ORDER_BELOW].data());
|
||||
}
|
||||
}
|
||||
else if (element.type == ElementType::SHADER)
|
||||
{
|
||||
@@ -1015,6 +1053,17 @@ namespace anm2ed
|
||||
hash_path_attr_append(hash, "Path", element.path);
|
||||
if (element.type == ElementType::OVERLAY && !element.isVisible)
|
||||
hash_attr_append(hash, "Visible", element.isVisible);
|
||||
if (element.type == ElementType::OVERLAY)
|
||||
{
|
||||
if (element.position != glm::vec2())
|
||||
{
|
||||
hash_attr_append(hash, "XOffset", element.position.x);
|
||||
hash_attr_append(hash, "YOffset", element.position.y);
|
||||
}
|
||||
if (color_write(element.tint.a) != 255) hash_attr_append(hash, "Alpha", color_write(element.tint.a));
|
||||
if (overlay_draw_order_get(element) == OVERLAY_DRAW_ORDER_BELOW)
|
||||
hash_attr_append(hash, "DrawOrder", OVERLAY_DRAW_ORDER_VALUES[OVERLAY_DRAW_ORDER_BELOW]);
|
||||
}
|
||||
}
|
||||
else if (element.type == ElementType::SHADER)
|
||||
{
|
||||
@@ -2436,10 +2485,9 @@ namespace anm2ed
|
||||
|
||||
std::uint64_t Anm2::hash(Options options) const
|
||||
{
|
||||
auto serialized = to_string(options);
|
||||
auto hash = ANM2_HASH_OFFSET;
|
||||
for (auto c : serialized)
|
||||
hash_byte_append(hash, (unsigned char)c);
|
||||
hash_byte_append(hash, options.isExtendedFormat ? 'E' : 'A');
|
||||
element_hash_append(hash, root, ElementType::UNKNOWN, SERIALIZE_ANM2ED_DEFAULT);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -2756,6 +2804,8 @@ namespace anm2ed
|
||||
tracks_each(*layerAnimations, ElementType::LAYER_ANIMATION,
|
||||
[&](const Element& layerAnimation)
|
||||
{
|
||||
auto layer = element_get(ElementType::LAYER_ELEMENT, layerAnimation.layerId);
|
||||
if (!layer || layer->spritesheetId != parentId) return;
|
||||
for (const auto& frame : layerAnimation.children)
|
||||
if (frame.type == ElementType::FRAME && frame.regionId != -1) used.insert(frame.regionId);
|
||||
});
|
||||
|
||||
@@ -110,6 +110,16 @@ namespace anm2ed
|
||||
inline constexpr int APPEND_RIGHT = (int)SpritesheetMergeOrigin::APPEND_RIGHT;
|
||||
inline constexpr int APPEND_BOTTOM = (int)SpritesheetMergeOrigin::APPEND_BOTTOM;
|
||||
|
||||
enum class OverlayDrawOrder
|
||||
{
|
||||
BELOW,
|
||||
ABOVE,
|
||||
COUNT
|
||||
};
|
||||
|
||||
inline constexpr int OVERLAY_DRAW_ORDER_BELOW = (int)OverlayDrawOrder::BELOW;
|
||||
inline constexpr int OVERLAY_DRAW_ORDER_ABOVE = (int)OverlayDrawOrder::ABOVE;
|
||||
|
||||
inline const glm::vec4 ROOT_COLOR = glm::vec4(0.140f, 0.310f, 0.560f, 1.000f);
|
||||
inline const glm::vec4 ROOT_COLOR_ACTIVE = glm::vec4(0.240f, 0.520f, 0.880f, 1.000f);
|
||||
inline const glm::vec4 ROOT_COLOR_HOVERED = glm::vec4(0.320f, 0.640f, 1.000f, 1.000f);
|
||||
|
||||
@@ -2581,6 +2581,12 @@ namespace anm2ed
|
||||
snapshots.anm2_push(current, message);
|
||||
}
|
||||
|
||||
void Document::tracks_snapshot(const std::string& message, const std::set<Reference>& trackReferences)
|
||||
{
|
||||
this->message = message;
|
||||
snapshots.tracks_push(current, message, trackReferences);
|
||||
}
|
||||
|
||||
void Document::frames_snapshot(const std::string& message, const std::set<Reference>& frameReferences)
|
||||
{
|
||||
this->message = message;
|
||||
|
||||
@@ -202,6 +202,7 @@ namespace anm2ed
|
||||
std::filesystem::path path_from_autosave_get(const std::filesystem::path&);
|
||||
|
||||
void anm2_snapshot(const std::string& message);
|
||||
void tracks_snapshot(const std::string& message, const std::set<Reference>&);
|
||||
void frames_snapshot(const std::string& message, const std::set<Reference>&);
|
||||
void regions_snapshot(const std::string& message, int, const std::set<int>&);
|
||||
void textures_snapshot(const std::string& message);
|
||||
|
||||
@@ -432,9 +432,11 @@ namespace anm2ed::imgui
|
||||
|
||||
for (int preset = 0; preset < Document::FILE_MERGE_PRESET_COUNT; ++preset)
|
||||
{
|
||||
ImGui::PushID(preset);
|
||||
ImGui::RadioButton(localize.get(ANM2_DRAG_DROP_MERGE_PRESET_LABELS[preset]),
|
||||
&manager.anm2DragDropMergePreset, preset);
|
||||
ImGui::SetItemTooltip("%s", localize.get(ANM2_DRAG_DROP_MERGE_PRESET_TOOLTIPS[preset]));
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
@@ -969,25 +969,33 @@ namespace anm2ed::imgui
|
||||
auto customShader = document.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.type != ElementType::OVERLAY) continue;
|
||||
if (!overlay.isVisible) continue;
|
||||
auto overlayTexture = document.overlay_texture_get(overlay.id);
|
||||
if (!overlayTexture || !overlayTexture->is_valid()) continue;
|
||||
|
||||
auto overlayTexSize = vec2(overlayTexture->size);
|
||||
if (overlayTexSize.x <= 0.0f || overlayTexSize.y <= 0.0f) continue;
|
||||
|
||||
auto overlayUvMin = crop / overlayTexSize;
|
||||
auto overlayUvMax = (crop + size) / overlayTexSize;
|
||||
auto overlayVertices = math::uv_vertices_get(overlayUvMin, overlayUvMax);
|
||||
texture_render(shaderTexture, overlayTexture->id, layerTransform, frameTint, frameColorOffset,
|
||||
overlayVertices.data(), vec2(overlayTexture->size), sampleTime);
|
||||
}
|
||||
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
|
||||
|
||||
@@ -111,8 +111,9 @@ namespace anm2ed::imgui
|
||||
|
||||
auto fit_view = [&]()
|
||||
{
|
||||
if (texture && texture->is_valid())
|
||||
set_to_rect(zoom, pan, {0, 0, (float)texture->size.x, (float)texture->size.y});
|
||||
auto fitTexture = baseTexture && baseTexture->is_valid() ? baseTexture : texture;
|
||||
if (fitTexture && fitTexture->is_valid())
|
||||
set_to_rect(zoom, pan, {0, 0, (float)fitTexture->size.x, (float)fitTexture->size.y});
|
||||
};
|
||||
|
||||
auto zoom_adjust = [&](int levelDelta)
|
||||
@@ -243,17 +244,23 @@ 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.type != ElementType::OVERLAY) continue;
|
||||
if (!overlay.isVisible) continue;
|
||||
auto overlayTexture = document.overlay_texture_get(overlay.id);
|
||||
if (!overlayTexture || !overlayTexture->is_valid()) continue;
|
||||
auto overlayTransform = transform * math::quad_model_get(overlayTexture->size);
|
||||
texture_render(shaderTexture, overlayTexture->id, overlayTransform);
|
||||
}
|
||||
if (overlay.index != OVERLAY_DRAW_ORDER_BELOW) overlay_draw(overlay);
|
||||
|
||||
if (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
|
||||
|
||||
@@ -321,6 +328,18 @@ 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)
|
||||
{
|
||||
@@ -408,6 +427,13 @@ namespace anm2ed::imgui
|
||||
auto stepY = isGridSnap ? step * gridSize.y : step;
|
||||
previousMousePos = mousePos;
|
||||
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)
|
||||
{
|
||||
@@ -440,6 +466,29 @@ 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));
|
||||
@@ -457,6 +506,12 @@ 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));
|
||||
@@ -638,6 +693,28 @@ 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;
|
||||
@@ -724,7 +801,9 @@ namespace anm2ed::imgui
|
||||
auto& toolInfo = tool::INFO[useTool];
|
||||
auto& areaType = toolInfo.areaType;
|
||||
auto isRegionEditTarget = document.editTarget == Document::EditTarget::REGION;
|
||||
auto selectedFrameToolReferences = isRegionEditTarget ? std::set<Reference>{} : selectedFrameReferences;
|
||||
auto isOverlayEditTarget = document.editTarget == Document::EditTarget::OVERLAY && activeOverlayId != -1;
|
||||
auto selectedFrameToolReferences =
|
||||
isRegionEditTarget || isOverlayEditTarget ? 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);
|
||||
@@ -733,7 +812,8 @@ 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 && regionReference != -1) ||
|
||||
(useTool == tool::MOVE && isOverlayEditTarget);
|
||||
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
|
||||
@@ -768,6 +848,34 @@ 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;
|
||||
@@ -929,7 +1037,7 @@ namespace anm2ed::imgui
|
||||
if (!texture) break;
|
||||
auto color = useTool == tool::DRAW ? toolColor : vec4();
|
||||
if (isMouseClicked) texture_snapshot_push(useTool == tool::DRAW ? EDIT_DRAW : EDIT_ERASE);
|
||||
if (isMouseDown) texture_line_apply(ivec2(previousMousePos), ivec2(mousePos), color);
|
||||
if (isMouseDown) texture_line_apply(ivec2(previousTextureMousePos), ivec2(textureMousePos), color);
|
||||
if (isMouseReleased) texture_change_push();
|
||||
break;
|
||||
}
|
||||
@@ -937,7 +1045,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
if (texture && isDuring)
|
||||
{
|
||||
toolColor = texture->pixel_read(mousePos);
|
||||
toolColor = texture->pixel_read(textureMousePos);
|
||||
if (ImGui::BeginTooltip())
|
||||
{
|
||||
ImGui::ColorButton("##Color Picker Button", to_imvec4(toolColor));
|
||||
@@ -1043,7 +1151,8 @@ namespace anm2ed::imgui
|
||||
actions_undo_redo_add(actions, manager, document);
|
||||
actions.separator();
|
||||
actions.add(ACTION_CENTER_VIEW, []() { return true; }, center_view);
|
||||
actions.add(ACTION_FIT_VIEW, [&]() { return texture && texture->is_valid(); }, fit_view);
|
||||
actions.add(ACTION_FIT_VIEW, [&]()
|
||||
{ return (baseTexture && baseTexture->is_valid()) || (texture && texture->is_valid()); }, fit_view);
|
||||
actions.separator();
|
||||
actions.add(ACTION_ZOOM_IN, []() { return true; }, zoom_in);
|
||||
actions.add(ACTION_ZOOM_OUT, []() { return true; }, zoom_out);
|
||||
|
||||
+103
-50
@@ -473,12 +473,23 @@ namespace anm2ed::imgui
|
||||
manager.command_push({manager.selected,
|
||||
[run](Manager& manager, Document& document) mutable { run(manager, document); }});
|
||||
};
|
||||
auto snapshot_command_push = [&](StringType messageType)
|
||||
auto track_references_from_frame_references_get = [](std::set<Reference> frameReferences)
|
||||
{
|
||||
std::set<Reference> result{};
|
||||
for (auto frameReference : frameReferences)
|
||||
{
|
||||
frameReference.frameIndex = -1;
|
||||
result.insert(frameReference);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
auto tracks_snapshot_command_push = [&](StringType messageType, const std::set<Reference>& trackReferences)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
auto queuedTrackReferences = trackReferences;
|
||||
manager.command_push({manager.selected,
|
||||
[message](Manager&, Document& document)
|
||||
{ document.anm2_snapshot(message); }});
|
||||
[message, queuedTrackReferences](Manager&, Document& document)
|
||||
{ document.tracks_snapshot(message, queuedTrackReferences); }});
|
||||
};
|
||||
auto frames_snapshot_command_push = [&](StringType messageType, const std::set<Reference>& frameReferences)
|
||||
{
|
||||
@@ -488,6 +499,34 @@ namespace anm2ed::imgui
|
||||
[message, queuedFrameReferences](Manager&, Document& document)
|
||||
{ document.frames_snapshot(message, queuedFrameReferences); }});
|
||||
};
|
||||
auto frames_edit_command_push = [&](StringType messageType, Document::ChangeType changeType,
|
||||
const std::set<Reference>& frameReferences, auto run)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
auto queuedFrameReferences = frameReferences;
|
||||
manager.command_push({manager.selected,
|
||||
[=](Manager& manager, Document& document) mutable
|
||||
{
|
||||
(void)changeType;
|
||||
document.frames_snapshot(message, queuedFrameReferences);
|
||||
run(manager, document);
|
||||
document.anm2_change(changeType);
|
||||
}});
|
||||
};
|
||||
auto tracks_edit_command_push = [&](StringType messageType, Document::ChangeType changeType,
|
||||
const std::set<Reference>& trackReferences, auto run)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
auto queuedTrackReferences = trackReferences;
|
||||
manager.command_push({manager.selected,
|
||||
[=](Manager& manager, Document& document) mutable
|
||||
{
|
||||
(void)changeType;
|
||||
document.tracks_snapshot(message, queuedTrackReferences);
|
||||
run(manager, document);
|
||||
document.anm2_change(changeType);
|
||||
}});
|
||||
};
|
||||
auto edit_command_push = [&](StringType messageType, Document::ChangeType changeType, auto run)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
@@ -572,9 +611,9 @@ namespace anm2ed::imgui
|
||||
if (!animation || !command_item_reference_get(document, targetReference))
|
||||
return;
|
||||
|
||||
edit_command_push(EDIT_INSERT_FRAME, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
tracks_edit_command_push(EDIT_INSERT_FRAME, Document::FRAMES, {targetReference},
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto animation = command_animation_get(document, targetReference.animationIndex);
|
||||
auto item = command_item_reference_get(document, targetReference);
|
||||
if (!animation || !item) return;
|
||||
@@ -620,7 +659,7 @@ namespace anm2ed::imgui
|
||||
frames_selection_set_reference_for(document);
|
||||
if (newReference.itemType != TRIGGER)
|
||||
document.frameTime = frame_time_from_index_get(*item, newReference.frameIndex);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto frames_delete_for = [=](Document& document, std::set<Reference> selectedFrames) mutable
|
||||
@@ -660,9 +699,10 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto selectedFrames = frame_references_for_current_get();
|
||||
if (selectedFrames.empty()) return;
|
||||
edit_command_push(EDIT_DELETE_FRAMES, Document::FRAMES,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{ frames_delete_for(document, selectedFrames); });
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedFrames);
|
||||
tracks_edit_command_push(EDIT_DELETE_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{ frames_delete_for(document, selectedFrames); });
|
||||
};
|
||||
|
||||
auto frames_duplicate = [&]()
|
||||
@@ -672,9 +712,10 @@ namespace anm2ed::imgui
|
||||
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
|
||||
if (selectedFrames.empty()) return;
|
||||
|
||||
edit_command_push(EDIT_DUPLICATE_FRAMES, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedFrames);
|
||||
tracks_edit_command_push(EDIT_DUPLICATE_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : selectedFrames)
|
||||
{
|
||||
@@ -734,7 +775,7 @@ namespace anm2ed::imgui
|
||||
isFrameSelectionLocked = false;
|
||||
frameFocusIndex = document.reference.frameIndex;
|
||||
frameFocusRequested = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto is_frames_reverse_available = [&](std::set<Reference> selectedFrames)
|
||||
@@ -757,9 +798,10 @@ namespace anm2ed::imgui
|
||||
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
|
||||
if (!is_frames_reverse_available(selectedFrames)) return;
|
||||
|
||||
edit_command_push(EDIT_REVERSE_FRAMES, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedFrames);
|
||||
tracks_edit_command_push(EDIT_REVERSE_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : selectedFrames)
|
||||
{
|
||||
@@ -827,7 +869,7 @@ namespace anm2ed::imgui
|
||||
isFrameSelectionLocked = false;
|
||||
frameFocusIndex = document.reference.frameIndex;
|
||||
frameFocusRequested = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto frames_bake = [&]()
|
||||
@@ -840,9 +882,10 @@ namespace anm2ed::imgui
|
||||
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
|
||||
if (selectedFrames.empty()) return;
|
||||
|
||||
edit_command_push(EDIT_BAKE_FRAMES, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedFrames);
|
||||
tracks_edit_command_push(EDIT_BAKE_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : selectedFrames)
|
||||
{
|
||||
@@ -892,7 +935,7 @@ namespace anm2ed::imgui
|
||||
}
|
||||
else
|
||||
frames_selection_reset_for(document);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto selected_root_frame_references_get = [&]()
|
||||
@@ -983,6 +1026,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto selectedRootFrames = selected_root_frame_references_get();
|
||||
if (selectedRootFrames.empty()) return;
|
||||
if (!animation) return;
|
||||
auto target = bakeIntoOtherFramesTarget;
|
||||
auto isLayers = isBakeIntoOtherFramesLayers;
|
||||
auto isNulls = isBakeIntoOtherFramesNulls;
|
||||
@@ -990,9 +1034,13 @@ namespace anm2ed::imgui
|
||||
auto isRoundRotation = settings.bakeIsRoundRotation;
|
||||
auto isMatchRootInterpolation = settings.bakeIsMatchRootInterpolation;
|
||||
auto isUseRootPivot = settings.bakeIsUseRootPivot;
|
||||
edit_command_push(EDIT_BAKE_INTO_OTHER_FRAMES, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto targetItems = item_references_for_bake_into_other_frames_get(
|
||||
document, *animation, target, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls);
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedRootFrames);
|
||||
trackReferences.insert(targetItems.begin(), targetItems.end());
|
||||
tracks_edit_command_push(EDIT_BAKE_INTO_OTHER_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto animation = command_animation_get(document, document.reference.animationIndex);
|
||||
if (!animation) return;
|
||||
auto rootItemReference = item_reference_from_frame_get(*selectedRootFrames.begin());
|
||||
@@ -1122,7 +1170,7 @@ namespace anm2ed::imgui
|
||||
isFrameSelectionLocked = false;
|
||||
frameFocusIndex = document.reference.frameIndex;
|
||||
frameFocusRequested = true;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
std::optional<int> frameSplitTimeAtCursor;
|
||||
@@ -1135,9 +1183,9 @@ namespace anm2ed::imgui
|
||||
auto splitTime = frameSplitTimeAtCursor.value_or((int)std::floor(playback.time));
|
||||
if (targetReference.itemType == TRIGGER) return;
|
||||
|
||||
edit_command_push(EDIT_SPLIT_FRAME, Document::FRAMES,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{
|
||||
tracks_edit_command_push(EDIT_SPLIT_FRAME, Document::FRAMES, {targetReference},
|
||||
[=](Manager&, Document& document) mutable
|
||||
{
|
||||
if (targetReference.itemType == TRIGGER) return;
|
||||
|
||||
auto item = command_item_reference_get(document, targetReference);
|
||||
@@ -1193,7 +1241,7 @@ namespace anm2ed::imgui
|
||||
item->children.insert(item->children.begin() + insertIndex, splitFrame);
|
||||
document.reference = targetReference;
|
||||
frames_selection_set_reference_for(document);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
auto reference_clear = [&]()
|
||||
@@ -1824,9 +1872,10 @@ namespace anm2ed::imgui
|
||||
auto selectedFrames = frame_references_for_current_get();
|
||||
if (selectedFrames.empty()) return;
|
||||
frame_references_copy(selectedFrames);
|
||||
edit_command_push(EDIT_CUT_FRAMES, Document::FRAMES,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{ frames_delete_for(document, selectedFrames); });
|
||||
auto trackReferences = track_references_from_frame_references_get(selectedFrames);
|
||||
tracks_edit_command_push(EDIT_CUT_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{ frames_delete_for(document, selectedFrames); });
|
||||
};
|
||||
|
||||
auto paste = [&]()
|
||||
@@ -1839,11 +1888,11 @@ namespace anm2ed::imgui
|
||||
auto message = std::string(localize.get(EDIT_PASTE_FRAMES));
|
||||
command_push([=](Manager&, Document& document) mutable
|
||||
{
|
||||
document.anm2_snapshot(message);
|
||||
auto animation = command_animation_get(document, targetReference.animationIndex);
|
||||
if (!animation) return;
|
||||
if (auto item = command_item_reference_get(document, targetReference))
|
||||
{
|
||||
document.tracks_snapshot(message, {targetReference});
|
||||
std::set<int> indices{};
|
||||
std::string errorString{};
|
||||
int insertIndex = (int)item->children.size();
|
||||
@@ -1898,6 +1947,7 @@ namespace anm2ed::imgui
|
||||
}
|
||||
else
|
||||
{
|
||||
document.snapshots.pendingStep.reset();
|
||||
toasts.push(
|
||||
std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED), errorString));
|
||||
logger.error(std::format("{} {}", localize.get(TOAST_DESERIALIZE_FRAMES_FAILED,
|
||||
@@ -2861,9 +2911,12 @@ namespace anm2ed::imgui
|
||||
{ return frameReference.itemType == TRIGGER || frameReference.frameIndex < 0; });
|
||||
if (drag.references.empty()) return;
|
||||
|
||||
edit_command_push(EDIT_MOVE_FRAMES, Document::FRAMES,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto trackReferences = track_references_from_frame_references_get(
|
||||
std::set<Reference>(drag.references.begin(), drag.references.end()));
|
||||
trackReferences.insert({drag.animationIndex, targetType, targetID, -1, targetGroupType, targetGroupId});
|
||||
tracks_edit_command_push(EDIT_MOVE_FRAMES, Document::FRAMES, trackReferences,
|
||||
[=, this](Manager&, Document& document) mutable
|
||||
{
|
||||
auto targetItem =
|
||||
command_item_get(document, drag.animationIndex, targetType, targetID, targetGroupType,
|
||||
targetGroupId);
|
||||
@@ -2935,7 +2988,7 @@ namespace anm2ed::imgui
|
||||
if (targetType == LAYER)
|
||||
if (auto layer = command_layer_get(document, targetID))
|
||||
document.spritesheet.reference = layer->spritesheetId;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
float playheadLineCenterX{};
|
||||
@@ -3328,15 +3381,15 @@ namespace anm2ed::imgui
|
||||
if (ImGui::IsKeyDown(ImGuiMod_Alt))
|
||||
{
|
||||
auto targetReference = frameReference;
|
||||
edit_command_push(EDIT_FRAME_INTERPOLATION, Document::FRAMES,
|
||||
[=](Manager&, Document& document)
|
||||
{
|
||||
auto frame = command_frame_get(document, targetReference);
|
||||
if (!frame) return;
|
||||
frame->interpolation = frame->interpolation == Interpolation::NONE
|
||||
? Interpolation::LINEAR
|
||||
: Interpolation::NONE;
|
||||
});
|
||||
frames_edit_command_push(EDIT_FRAME_INTERPOLATION, Document::FRAMES, {targetReference},
|
||||
[=](Manager&, Document& document)
|
||||
{
|
||||
auto frame = command_frame_get(document, targetReference);
|
||||
if (!frame) return;
|
||||
frame->interpolation = frame->interpolation == Interpolation::NONE
|
||||
? Interpolation::LINEAR
|
||||
: Interpolation::NONE;
|
||||
});
|
||||
}
|
||||
|
||||
document.frameTime = frameTime;
|
||||
@@ -3544,7 +3597,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
isDraggedFrameSnapshot = true;
|
||||
if (draggedFrameType == TRIGGER)
|
||||
snapshot_command_push(EDIT_TRIGGER_AT_FRAME);
|
||||
tracks_snapshot_command_push(EDIT_TRIGGER_AT_FRAME, {item_reference_from_frame_get(draggedFrameReference)});
|
||||
else
|
||||
{
|
||||
std::set<Reference> draggedFrameReferences{};
|
||||
@@ -4126,7 +4179,6 @@ namespace anm2ed::imgui
|
||||
static bool isShortenChordHeld = false;
|
||||
auto isShortenFrame = shortcut(manager.chords[SHORTCUT_SHORTEN_FRAME], shortcut::GLOBAL);
|
||||
|
||||
if (isShortenFrame && !isShortenChordHeld) snapshot_command_push(EDIT_SHORTEN_FRAME);
|
||||
if (isShortenFrame)
|
||||
{
|
||||
|
||||
@@ -4135,6 +4187,7 @@ namespace anm2ed::imgui
|
||||
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
|
||||
if (!selectedFrames.empty())
|
||||
{
|
||||
if (!isShortenChordHeld) frames_snapshot_command_push(EDIT_SHORTEN_FRAME, selectedFrames);
|
||||
command_push([=](Manager&, Document& document)
|
||||
{
|
||||
for (auto frameReference : selectedFrames)
|
||||
@@ -4151,7 +4204,6 @@ namespace anm2ed::imgui
|
||||
|
||||
static bool isExtendChordHeld = false;
|
||||
auto isExtendFrame = shortcut(manager.chords[SHORTCUT_EXTEND_FRAME], shortcut::GLOBAL);
|
||||
if (isExtendFrame && !isExtendChordHeld) snapshot_command_push(EDIT_EXTEND_FRAME);
|
||||
if (isExtendFrame)
|
||||
{
|
||||
|
||||
@@ -4160,6 +4212,7 @@ namespace anm2ed::imgui
|
||||
[](const Reference& frameReference) { return frameReference.itemType == TRIGGER; });
|
||||
if (!selectedFrames.empty())
|
||||
{
|
||||
if (!isExtendChordHeld) frames_snapshot_command_push(EDIT_EXTEND_FRAME, selectedFrames);
|
||||
command_push([=](Manager&, Document& document)
|
||||
{
|
||||
for (auto frameReference : selectedFrames)
|
||||
|
||||
+111
-9
@@ -719,6 +719,8 @@ namespace anm2ed::imgui
|
||||
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; },
|
||||
@@ -740,7 +742,7 @@ namespace anm2ed::imgui
|
||||
if (settings.fileIsWarnOverwrite)
|
||||
{
|
||||
window.selection2 = selection;
|
||||
window.popup.open();
|
||||
window.popup2.open();
|
||||
}
|
||||
else if (window.save)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.save);
|
||||
@@ -2104,6 +2106,8 @@ namespace anm2ed::imgui
|
||||
return;
|
||||
}
|
||||
if (layerAnimation.type != ElementType::LAYER_ANIMATION) return;
|
||||
auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, layerAnimation.layerId);
|
||||
if (!layer || layer->spritesheetId != spritesheetReference) return;
|
||||
for (auto& frame : layerAnimation.children)
|
||||
if (frame.type == ElementType::FRAME && frame.regionId == id) frame.regionId = -1;
|
||||
};
|
||||
@@ -2734,7 +2738,9 @@ namespace anm2ed::imgui
|
||||
window.flags = 0;
|
||||
window.isChildPaddingZero = true;
|
||||
window.unavailableText = TEXT_SELECT_SPRITESHEET;
|
||||
window.popup = PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, POPUP_SMALL_NO_HEIGHT);
|
||||
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); };
|
||||
@@ -2756,6 +2762,19 @@ namespace anm2ed::imgui
|
||||
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;
|
||||
@@ -2967,8 +2986,8 @@ namespace anm2ed::imgui
|
||||
contextMenuTargetId = id;
|
||||
}
|
||||
if (scrollTargetId == id) ImGui::SetItemDefaultFocus();
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left) && window.dialog)
|
||||
window_directory_open(*window.dialog, document, overlay.path);
|
||||
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;
|
||||
@@ -3208,7 +3227,7 @@ namespace anm2ed::imgui
|
||||
if (settings.fileIsWarnOverwrite)
|
||||
{
|
||||
window.selection2 = selection;
|
||||
window.popup.open();
|
||||
window.popup2.open();
|
||||
}
|
||||
else if (window.save)
|
||||
window_command_run(window, manager, settings, document, clipboard, window.save);
|
||||
@@ -3229,10 +3248,93 @@ namespace anm2ed::imgui
|
||||
window_command_run(window, manager, settings, document, clipboard, window.paste);
|
||||
};
|
||||
window.popup_update =
|
||||
[](Window& window, Manager& manager, Settings&, Resources&, Clipboard&, Document&)
|
||||
[](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));
|
||||
|
||||
@@ -3244,7 +3346,7 @@ namespace anm2ed::imgui
|
||||
manager.command_push({manager.selected, [queuedSelection](Manager&, Document& document) mutable
|
||||
{ window_overlays_save(document, queuedSelection); }});
|
||||
window.selection2.clear();
|
||||
window.popup.close();
|
||||
window.popup2.close();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
@@ -3252,12 +3354,12 @@ namespace anm2ed::imgui
|
||||
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
||||
{
|
||||
window.selection2.clear();
|
||||
window.popup.close();
|
||||
window.popup2.close();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
window.popup.end();
|
||||
window.popup2.end();
|
||||
};
|
||||
return window;
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ namespace anm2ed
|
||||
imgui::PopupHelper anm2DragDropPopup{
|
||||
imgui::PopupHelper(LABEL_MANAGER_ANM2_DRAG_DROP, imgui::POPUP_NORMAL, imgui::POPUP_BY_CURSOR)};
|
||||
imgui::PopupHelper anm2DragDropMergePopup{
|
||||
imgui::PopupHelper(LABEL_DOCUMENTS_MERGE_INTO_CURRENT, imgui::POPUP_NORMAL_NO_HEIGHT)};
|
||||
imgui::PopupHelper(LABEL_DOCUMENTS_MERGE_INTO_CURRENT, imgui::POPUP_SMALL_NO_HEIGHT)};
|
||||
|
||||
std::filesystem::path spritesheetDragDropPath{};
|
||||
bool isSpritesheetDragDrop{};
|
||||
|
||||
@@ -187,6 +187,7 @@ namespace anm2ed
|
||||
X(EDIT_REPLACE_OVERLAY, "Replace Overlay", "Replace Overlay", "Replace Overlay", "Replace Overlay", "Replace Overlay") \
|
||||
X(EDIT_REPLACE_SOUND, "Replace Sound", "Reemplazar Sonido", "Заменить звук", "替换声音", "사운드 교체") \
|
||||
X(EDIT_SET_OVERLAY_FILE_PATH, "Set Overlay File Path", "Set Overlay File Path", "Set Overlay File Path", "Set Overlay File Path", "Set Overlay File Path") \
|
||||
X(EDIT_SET_OVERLAY_PROPERTIES, "Set Overlay Properties", "Set Overlay Properties", "Set Overlay Properties", "Set Overlay Properties", "Set Overlay Properties") \
|
||||
X(EDIT_SET_SPRITESHEET_FILE_PATH, "Set Spritesheet File Path", "Set Spritesheet File Path", "Set Spritesheet File Path", "Set Spritesheet File Path", "Set Spritesheet File Path") \
|
||||
X(EDIT_SET_LAYER_PROPERTIES, "Set Layer Properties", "Establecer Propiedades de Capa", "Установить свойства слоя", "更改动画层属性", "레이어 속성 설정") \
|
||||
X(EDIT_SET_REGION_PROPERTIES, "Set Region Properties", "Establecer propiedades de región", "Установить свойства региона", "更改区域属性", "영역 속성 설정") \
|
||||
@@ -195,6 +196,7 @@ namespace anm2ed
|
||||
X(EDIT_SCAN_AND_SET_REGIONS, "Scan and Set Regions", "Escanear y establecer regiones", "Сканировать и установить регионы", "扫描并设置区域", "영역 스캔 및 설정") \
|
||||
X(EDIT_REGION_CROP, "Region Crop", "Recorte de región", "Обрезка региона", "区域裁剪", "영역 자르기") \
|
||||
X(EDIT_REGION_MOVE, "Region Pivot", "Pivote de región", "Пивот региона", "区域枢轴", "영역 피벗") \
|
||||
X(EDIT_OVERLAY_MOVE, "Overlay Offset", "Overlay Offset", "Overlay Offset", "Overlay Offset", "Overlay Offset") \
|
||||
X(EDIT_SPLIT_FRAME, "Split Frame", "Dividir Frame", "Разделить кадр", "拆分帧", "프레임 분할") \
|
||||
X(EDIT_SHORTEN_FRAME, "Shorten Frame", "Acortar Frame", "Укоротить кадр", "缩短帧时长", "프레임 단축") \
|
||||
X(EDIT_TOGGLE_ITEM_VISIBILITY, "Toggle Item Visibility", "Alternar Visibilidad de item", "Переключить видимость предмета", "物品可见", "항목 표시/숨기기") \
|
||||
@@ -364,6 +366,10 @@ namespace anm2ed
|
||||
X(LABEL_OUTPUT_DIRECTORY, "Directory", "Directorio", "Директория", "目录", "디렉터리") \
|
||||
X(LABEL_OUTPUT_PATH, "Path", "Ruta", "Путь", "路径", "경로") \
|
||||
X(LABEL_OVERLAY, "Overlay", "Overlay", "Наложение", "动画叠加", "오버레이") \
|
||||
X(LABEL_OVERLAY_DRAW_ORDER, "Draw Order", "Draw Order", "Draw Order", "Draw Order", "Draw Order") \
|
||||
X(LABEL_OVERLAY_DRAW_ORDER_ABOVE, "Above", "Above", "Above", "Above", "Above") \
|
||||
X(LABEL_OVERLAY_DRAW_ORDER_BELOW, "Below", "Below", "Below", "Below", "Below") \
|
||||
X(LABEL_OVERLAY_PROPERTIES, "Overlay Properties", "Overlay Properties", "Overlay Properties", "Overlay Properties", "Overlay Properties") \
|
||||
X(LABEL_OVERLAYS_WINDOW, "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays", "Overlays###Overlays") \
|
||||
X(LABEL_OVERWRITE_CONFIRMATION, "Are you sure? This will overwrite the existing file.", "¿Estas Seguro? Esto sobreescribira el archivo existente.", "Вы уверены? Это перезапишет существующий файл.", "你确定吗? 这样会覆盖原本的文件.", "저장하시겠습니까? 기존 파일을 덮어쓰게 됩니다.") \
|
||||
X(LABEL_OVERWRITE_WARNING, "Overwrite Warning", "Alerta de Sobreescribir", "Предупреждение о перезаписи", "覆盖提醒", "덮어쓰기 경고") \
|
||||
|
||||
@@ -173,6 +173,17 @@ namespace anm2ed::snapshots
|
||||
return path;
|
||||
}
|
||||
|
||||
std::optional<std::vector<int>> track_path_get(const Anm2& anm2, Reference trackReference)
|
||||
{
|
||||
trackReference.frameIndex = -1;
|
||||
auto track = anm2.element_get(trackReference);
|
||||
if (!track) return std::nullopt;
|
||||
|
||||
std::vector<int> path{};
|
||||
if (!element_path_get(anm2.root, track, path)) return std::nullopt;
|
||||
return path;
|
||||
}
|
||||
|
||||
std::optional<std::vector<int>> region_path_get(const Anm2& anm2, int spritesheetId, int regionId)
|
||||
{
|
||||
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, spritesheetId);
|
||||
@@ -208,6 +219,20 @@ namespace anm2ed::snapshots
|
||||
return step;
|
||||
}
|
||||
|
||||
void tracks_step_add(SnapshotStep& step, const Snapshot& snapshot, Reference trackReference)
|
||||
{
|
||||
trackReference.frameIndex = -1;
|
||||
auto path = track_path_get(snapshot.anm2, trackReference);
|
||||
if (!path) return;
|
||||
for (auto& elementStep : step.anm2.elements)
|
||||
if (elementStep.path == *path) return;
|
||||
|
||||
auto track = snapshot.anm2.element_get(trackReference);
|
||||
if (!track) return;
|
||||
|
||||
step.anm2.elements.push_back({std::move(*path), *track, {}});
|
||||
}
|
||||
|
||||
void frames_step_add(SnapshotStep& step, const Snapshot& snapshot, Reference frameReference)
|
||||
{
|
||||
auto path = frame_path_get(snapshot.anm2, frameReference);
|
||||
@@ -246,6 +271,13 @@ namespace anm2ed::snapshots
|
||||
return step;
|
||||
}
|
||||
|
||||
bool is_anm2_step_seeded(const SnapshotStep& step)
|
||||
{
|
||||
return step.anm2.elements.size() == 1 && step.anm2.elements.front().path.empty() &&
|
||||
step.anm2.elements.front().redo.type == ElementType::UNKNOWN &&
|
||||
step.anm2.elements.front().redo.children.empty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace anm2ed
|
||||
@@ -335,6 +367,18 @@ namespace anm2ed
|
||||
pendingStep = snapshots::step_anm2_seed(snapshot, message);
|
||||
}
|
||||
|
||||
void Snapshots::tracks_push(const Snapshot& snapshot, const std::string& message,
|
||||
const std::set<Reference>& trackReferences)
|
||||
{
|
||||
SnapshotStep step{};
|
||||
step.message = message;
|
||||
for (auto trackReference : trackReferences)
|
||||
snapshots::tracks_step_add(step, snapshot, trackReference);
|
||||
snapshots::step_state_seed(step, snapshot);
|
||||
|
||||
pendingStep = step.is_empty() ? std::nullopt : std::optional<SnapshotStep>(std::move(step));
|
||||
}
|
||||
|
||||
void Snapshots::frames_push(const Snapshot& snapshot, const std::string& message,
|
||||
const std::set<Reference>& frameReferences)
|
||||
{
|
||||
@@ -379,6 +423,14 @@ namespace anm2ed
|
||||
auto step = std::move(*pendingStep);
|
||||
pendingStep.reset();
|
||||
|
||||
if (snapshots::is_anm2_step_seeded(step))
|
||||
{
|
||||
Anm2 before{};
|
||||
before.isValid = step.anm2.isValid ? step.anm2.isValid->undo : snapshot.anm2.isValid;
|
||||
before.root = std::move(step.anm2.elements.front().undo);
|
||||
step.anm2 = snapshots::anm2_step_make(before, snapshot.anm2);
|
||||
}
|
||||
|
||||
if (step.anm2.isValid)
|
||||
{
|
||||
step.anm2.isValid->redo = snapshot.anm2.isValid;
|
||||
|
||||
@@ -142,6 +142,7 @@ namespace anm2ed
|
||||
|
||||
Snapshot* get();
|
||||
void anm2_push(const Snapshot&, const std::string&);
|
||||
void tracks_push(const Snapshot&, const std::string&, const std::set<Reference>&);
|
||||
void frames_push(const Snapshot&, const std::string&, const std::set<Reference>&);
|
||||
void regions_push(const Snapshot&, const std::string&, int, const std::set<int>&);
|
||||
void textures_push(const Snapshot&, const std::string&);
|
||||
|
||||
Reference in new issue
Block a user