Overlays, Shaders, Group Roots, Serialization Changes. Legalize Nuclear Bombs
This commit is contained in:
1 parent
555caf9f4f
commit
5792dd25a2
40 files changed
+6099
-747
No files matched your search
@@ -79,7 +79,11 @@ namespace anm2ed::imgui
|
||||
|
||||
bool actions_context_window_draw(const char* label, Actions& actions, Settings& settings, ImGuiPopupFlags flags)
|
||||
{
|
||||
if (!ImGui::BeginPopupContextWindow(label, flags)) return false;
|
||||
auto mouseButton = flags & ImGuiPopupFlags_MouseButtonMask_;
|
||||
if (ImGui::IsMouseReleased(mouseButton) && ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
||||
if (!(flags & ImGuiPopupFlags_NoOpenOverItems) || !ImGui::IsAnyItemHovered()) ImGui::OpenPopup(label, flags);
|
||||
|
||||
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false;
|
||||
actions_menu_draw(actions, settings);
|
||||
ImGui::EndPopup();
|
||||
return true;
|
||||
@@ -87,7 +91,7 @@ namespace anm2ed::imgui
|
||||
|
||||
bool actions_popup_draw(const char* label, Actions& actions, Settings& settings)
|
||||
{
|
||||
if (!ImGui::BeginPopup(label)) return false;
|
||||
if (!ImGui::BeginPopup(label, ImGuiWindowFlags_NoMove)) return false;
|
||||
actions_menu_draw(actions, settings);
|
||||
ImGui::EndPopup();
|
||||
return true;
|
||||
|
||||
@@ -40,6 +40,8 @@ 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);
|
||||
if (settings.windowIsSpritesheets)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "window/animation_preview.hpp"
|
||||
#include "window/frame_properties.hpp"
|
||||
#include "window/onionskin.hpp"
|
||||
#include "window/shaders.hpp"
|
||||
#include "window/spritesheet_editor.hpp"
|
||||
#include "window/timeline.hpp"
|
||||
#include "window/tools.hpp"
|
||||
@@ -25,6 +26,8 @@ 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()};
|
||||
Window sounds{sounds_window_register()};
|
||||
|
||||
+127
-31
@@ -1,5 +1,6 @@
|
||||
#include "documents.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <format>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
@@ -26,17 +27,46 @@ namespace anm2ed::imgui
|
||||
uint64_t documentId{};
|
||||
};
|
||||
|
||||
#define ANM2_DRAG_DROP_MERGE_PRESETS \
|
||||
X(FILE_MERGE_PRESET_MERGE_BY_NAME, BASIC_MERGE, TOOLTIP_MERGE_PRESET_MERGE_BY_NAME) \
|
||||
X(FILE_MERGE_PRESET_APPEND_AS_NEW, BASIC_APPEND, TOOLTIP_MERGE_PRESET_APPEND_AS_NEW) \
|
||||
X(FILE_MERGE_PRESET_REPLACE_MATCHING, BASIC_REPLACE, TOOLTIP_MERGE_PRESET_REPLACE_MATCHING)
|
||||
|
||||
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_LABELS[Document::FILE_MERGE_PRESET_COUNT] = {
|
||||
#define X(preset, label, tooltip) label,
|
||||
ANM2_DRAG_DROP_MERGE_PRESETS
|
||||
#undef X
|
||||
};
|
||||
|
||||
constexpr StringType ANM2_DRAG_DROP_MERGE_PRESET_TOOLTIPS[Document::FILE_MERGE_PRESET_COUNT] = {
|
||||
#define X(preset, label, tooltip) tooltip,
|
||||
ANM2_DRAG_DROP_MERGE_PRESETS
|
||||
#undef X
|
||||
};
|
||||
|
||||
#undef ANM2_DRAG_DROP_MERGE_PRESETS
|
||||
|
||||
Options save_options_get(const Settings& settings)
|
||||
{
|
||||
Flags flags{};
|
||||
if (settings.fileIsSerializeGroups) flags |= SERIALIZE_GROUPS;
|
||||
if (settings.fileIsSerializeRegions) flags |= SERIALIZE_REGIONS;
|
||||
if (settings.fileIsSerializeSounds) flags |= SERIALIZE_SOUNDS;
|
||||
Flags flags{SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS};
|
||||
if (settings.fileIsKeepRedundantFrameRegionValues) flags |= SERIALIZE_REDUNDANT_FRAME_REGION_VALUES;
|
||||
if (settings.fileIsBakeSpecialInterpolatedFrames) flags |= SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES;
|
||||
if (settings.isFileBakeGroupFrames) flags |= SERIALIZE_BAKE_GROUP_FRAMES;
|
||||
return {.flags = flags};
|
||||
}
|
||||
|
||||
void anm2_drag_drop_merge_queue(Manager& manager, const std::vector<std::filesystem::path>& paths,
|
||||
Document::FileMergePreset preset)
|
||||
{
|
||||
manager.command_push({manager.selected,
|
||||
[paths, preset](Manager&, Document& document)
|
||||
{
|
||||
document.anm2_snapshot(localize.get(EDIT_MERGE_ANM2));
|
||||
for (auto& path : paths) document.file_merge(path, preset);
|
||||
document.change(Document::ALL);
|
||||
}});
|
||||
}
|
||||
|
||||
void Documents::pending_document_order_apply(Manager& manager)
|
||||
{
|
||||
if (pendingDocumentTabIds.size() != manager.documents.size())
|
||||
@@ -161,7 +191,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto& document = manager.documents[i];
|
||||
auto isDocumentDirty = document.is_dirty() || document.isForceDirty;
|
||||
auto isSpritesheetDirty = document.spritesheet_any_dirty();
|
||||
auto isSpritesheetDirty = document.spritesheet_any_dirty() || document.overlay_any_dirty();
|
||||
auto isDirty = isDocumentDirty || isSpritesheetDirty;
|
||||
|
||||
if (!closePopup.is_open())
|
||||
@@ -258,7 +288,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();
|
||||
auto isSpritesheetDirty = closeDocument.spritesheet_any_dirty() || closeDocument.overlay_any_dirty();
|
||||
auto promptLabel =
|
||||
isDocumentDirty && isSpritesheetDirty
|
||||
? LABEL_DOCUMENT_AND_SPRITESHEETS_MODIFIED_PROMPT
|
||||
@@ -296,24 +326,51 @@ namespace anm2ed::imgui
|
||||
if (spritesheet.type != ElementType::SPRITESHEET) continue;
|
||||
auto id = spritesheet.id;
|
||||
auto texture = closeDocument.texture_get(id);
|
||||
if (!texture || !closeDocument.spritesheet_is_dirty(id)) continue;
|
||||
auto pathString = path::to_utf8(spritesheet.path);
|
||||
auto savePath = closeDocument.directory_get() / spritesheet.path;
|
||||
path::ensure_directory(savePath.parent_path());
|
||||
if (texture->write_png(savePath))
|
||||
if (texture && closeDocument.spritesheet_is_dirty(id))
|
||||
{
|
||||
closeDocument.spritesheet_hash_set_saved(id);
|
||||
toasts.push(
|
||||
std::vformat(localize.get(TOAST_SAVE_SPRITESHEET), std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
auto pathString = path::to_utf8(spritesheet.path);
|
||||
auto savePath = closeDocument.directory_get() / spritesheet.path;
|
||||
path::ensure_directory(savePath.parent_path());
|
||||
if (texture->write_png(savePath))
|
||||
{
|
||||
closeDocument.spritesheet_hash_set_saved(id);
|
||||
toasts.push(
|
||||
std::vformat(localize.get(TOAST_SAVE_SPRITESHEET), std::make_format_args(id, pathString)));
|
||||
logger.info(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
else
|
||||
{
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED),
|
||||
std::make_format_args(id, pathString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
for (auto& overlay : spritesheet.children)
|
||||
{
|
||||
toasts.push(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED),
|
||||
std::make_format_args(id, pathString)));
|
||||
logger.error(std::vformat(localize.get(TOAST_SAVE_SPRITESHEET_FAILED, anm2ed::ENGLISH),
|
||||
std::make_format_args(id, pathString)));
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,17 +423,62 @@ namespace anm2ed::imgui
|
||||
manager.isAnm2DragDrop = false;
|
||||
manager.anm2DragDropPaths.clear();
|
||||
manager.anm2DragDropPopup.close();
|
||||
manager.anm2DragDropMergePopup.close();
|
||||
manager.anm2DragDropMergePreset = Document::FILE_MERGE_PRESET_MERGE_BY_NAME;
|
||||
};
|
||||
|
||||
if (manager.anm2DragDropPaths.empty())
|
||||
drag_drop_reset();
|
||||
else if (manager.anm2DragDropMergePopup.is_open())
|
||||
{
|
||||
manager.anm2DragDropMergePopup.trigger();
|
||||
|
||||
if (ImGui::BeginPopupModal(manager.anm2DragDropMergePopup.label(), &manager.anm2DragDropMergePopup.isOpen,
|
||||
ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
auto document = manager.get();
|
||||
manager.anm2DragDropMergePreset =
|
||||
std::clamp(manager.anm2DragDropMergePreset, 0, Document::FILE_MERGE_PRESET_COUNT - 1);
|
||||
|
||||
for (int preset = 0; preset < Document::FILE_MERGE_PRESET_COUNT; ++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]));
|
||||
}
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
shortcut(manager.chords[SHORTCUT_CONFIRM]);
|
||||
ImGui::BeginDisabled(!document);
|
||||
if (ImGui::Button(localize.get(BASIC_MERGE), widgetSize))
|
||||
{
|
||||
auto paths = manager.anm2DragDropPaths;
|
||||
auto preset = (Document::FileMergePreset)manager.anm2DragDropMergePreset;
|
||||
anm2_drag_drop_merge_queue(manager, paths, preset);
|
||||
drag_drop_reset();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
shortcut(manager.chords[SHORTCUT_CANCEL]);
|
||||
if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) drag_drop_reset();
|
||||
|
||||
manager.anm2DragDropMergePopup.end();
|
||||
ImGui::EndPopup();
|
||||
|
||||
if (manager.isAnm2DragDrop && !manager.anm2DragDropMergePopup.is_open()) drag_drop_reset();
|
||||
}
|
||||
else if (!ImGui::IsPopupOpen(manager.anm2DragDropMergePopup.label()))
|
||||
drag_drop_reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!manager.anm2DragDropPopup.is_open()) manager.anm2DragDropPopup.open();
|
||||
|
||||
manager.anm2DragDropPopup.trigger();
|
||||
|
||||
if (ImGui::BeginPopupContextWindow(manager.anm2DragDropPopup.label(), ImGuiPopupFlags_None))
|
||||
if (ImGui::BeginPopup(manager.anm2DragDropPopup.label(), ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
auto document = manager.get();
|
||||
if (ImGui::MenuItem(manager.anm2DragDropPaths.size() > 1 ? localize.get(LABEL_DOCUMENTS_OPEN_MANY)
|
||||
@@ -396,15 +498,9 @@ namespace anm2ed::imgui
|
||||
{
|
||||
if (document)
|
||||
{
|
||||
auto paths = manager.anm2DragDropPaths;
|
||||
manager.command_push({manager.selected,
|
||||
[paths](Manager&, Document& document)
|
||||
{
|
||||
document.snapshot(localize.get(EDIT_MERGE_ANM2));
|
||||
for (auto& path : paths) document.file_merge(path);
|
||||
document.change(Document::ALL);
|
||||
}});
|
||||
drag_drop_reset();
|
||||
manager.anm2DragDropPopup.close();
|
||||
manager.anm2DragDropMergePopup.open();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace anm2ed::imgui::popup
|
||||
{
|
||||
int addId{-1};
|
||||
|
||||
document.snapshot(localize.get(EDIT_ADD_ITEM));
|
||||
document.anm2_snapshot(localize.get(EDIT_ADD_ITEM));
|
||||
if (queuedType == LAYER)
|
||||
addId = document.anm2.layer_animation_add(
|
||||
queuedAnimationIndex, queuedAddItemID, queuedInsertBeforeID, queuedAddItemName,
|
||||
|
||||
@@ -29,12 +29,10 @@ namespace anm2ed::imgui
|
||||
|
||||
Options save_options_get(Settings& settings)
|
||||
{
|
||||
Flags flags{};
|
||||
if (settings.fileIsSerializeGroups) flags |= SERIALIZE_GROUPS;
|
||||
if (settings.fileIsSerializeRegions) flags |= SERIALIZE_REGIONS;
|
||||
if (settings.fileIsSerializeSounds) flags |= SERIALIZE_SOUNDS;
|
||||
Flags flags{SERIALIZE_GROUPS | SERIALIZE_REGIONS | SERIALIZE_SOUNDS};
|
||||
if (settings.fileIsKeepRedundantFrameRegionValues) flags |= SERIALIZE_REDUNDANT_FRAME_REGION_VALUES;
|
||||
if (settings.fileIsBakeSpecialInterpolatedFrames) flags |= SERIALIZE_BAKE_SPECIAL_INTERPOLATED_FRAMES;
|
||||
if (settings.isFileBakeGroupFrames) flags |= SERIALIZE_BAKE_GROUP_FRAMES;
|
||||
return {.flags = flags};
|
||||
}
|
||||
|
||||
@@ -186,7 +184,7 @@ namespace anm2ed::imgui
|
||||
manager.command_push({manager.selected,
|
||||
[](Manager&, Document& document)
|
||||
{
|
||||
document.snapshot(localize.get(EDIT_SCAN_AND_SET_REGIONS));
|
||||
document.anm2_snapshot(localize.get(EDIT_SCAN_AND_SET_REGIONS));
|
||||
document.scan_and_set_regions();
|
||||
document.change(Document::FRAMES);
|
||||
}});
|
||||
@@ -301,7 +299,7 @@ namespace anm2ed::imgui
|
||||
[=](Manager&, Document& document)
|
||||
{
|
||||
if (queuedAnimationIndices.empty()) return;
|
||||
document.snapshot(localize.get(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS));
|
||||
document.anm2_snapshot(localize.get(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS));
|
||||
if (document.regions_generate_from_animations(queuedAnimationIndices, queuedFormat,
|
||||
queuedMapping))
|
||||
document.anm2_change(queuedMapping == Document::RegionFrameMapping::SET
|
||||
|
||||
@@ -198,6 +198,19 @@ namespace anm2ed::imgui
|
||||
auto pathString = path::to_utf8(path);
|
||||
auto& type = settings.renderType;
|
||||
auto renderFrameRate = std::max(settings.playbackTickRate, 1);
|
||||
auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation;
|
||||
auto render_preview_restore = [&]()
|
||||
{
|
||||
if (!isRenderPreviewOverridden) return;
|
||||
|
||||
settings = savedSettings;
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
};
|
||||
|
||||
if (playback.time >= (float)end + 1.0f || playback.isFinished)
|
||||
{
|
||||
@@ -223,6 +236,9 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto& rows = settings.renderRows;
|
||||
auto& columns = settings.renderColumns;
|
||||
auto layout = render::spritesheet_layout_get(rows, columns, (int)renderTempFrames.size());
|
||||
rows = layout.rows;
|
||||
columns = layout.columns;
|
||||
|
||||
if (renderTempFrames.empty())
|
||||
{
|
||||
@@ -324,17 +340,7 @@ namespace anm2ed::imgui
|
||||
renderFrameSoundIDs.clear();
|
||||
}
|
||||
|
||||
if (settings.renderIsRawAnimation)
|
||||
{
|
||||
settings = savedSettings;
|
||||
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
}
|
||||
render_preview_restore();
|
||||
|
||||
playback.isPlaying = false;
|
||||
playback.isFinished = false;
|
||||
@@ -349,8 +355,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto soundTime = (int)std::floor(playback.time);
|
||||
auto animation = anm2.element_get(ElementType::ANIMATION, document.reference.animationIndex);
|
||||
if (soundTime != renderFrameSoundTimePrev && animation &&
|
||||
(!settings.timelineIsOnlyShowLayers || manager.isRecording))
|
||||
if (soundTime != renderFrameSoundTimePrev && animation)
|
||||
frameSoundID = trigger_sound_id_get(animation, playback.time);
|
||||
renderFrameSoundTimePrev = soundTime;
|
||||
}
|
||||
@@ -358,7 +363,7 @@ namespace anm2ed::imgui
|
||||
|
||||
bind();
|
||||
auto pixels = pixels_get();
|
||||
if (settings.renderIsRawAnimation) pixels_unpremultiply_alpha(pixels);
|
||||
if (isRenderPreviewOverridden) pixels_unpremultiply_alpha(pixels);
|
||||
auto frameIndex = (int)renderTempFrames.size();
|
||||
auto framePath = renderTempDirectory / render_frame_filename(settings.renderFormat, frameIndex);
|
||||
if (Texture::write_pixels_png(framePath, size, pixels.data()))
|
||||
@@ -376,6 +381,7 @@ namespace anm2ed::imgui
|
||||
if (type != render::PNGS) render_temp_cleanup(renderTempDirectory, renderTempFrames);
|
||||
renderTempFrameDurations.clear();
|
||||
renderFrameSoundIDs.clear();
|
||||
render_preview_restore();
|
||||
playback.isPlaying = false;
|
||||
playback.isFinished = false;
|
||||
manager.isRecording = false;
|
||||
@@ -388,7 +394,6 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto animation = anm2.element_get(ElementType::ANIMATION, document.reference.animationIndex);
|
||||
auto& isSound = settings.timelineIsSound;
|
||||
auto& isOnlyShowLayers = settings.timelineIsOnlyShowLayers;
|
||||
|
||||
if (!animation)
|
||||
{
|
||||
@@ -400,9 +405,8 @@ namespace anm2ed::imgui
|
||||
{
|
||||
if (!manager.isRecording && !document.sounds.empty() && isSound)
|
||||
{
|
||||
if (!isOnlyShowLayers || manager.isRecording)
|
||||
if (auto soundID = trigger_sound_id_get(animation, playback.time); soundID != -1)
|
||||
if (auto sound = document.sound_get(soundID)) sound->play(false, mixer);
|
||||
if (auto soundID = trigger_sound_id_get(animation, playback.time); soundID != -1)
|
||||
if (auto sound = document.sound_get(soundID)) sound->play(false, mixer);
|
||||
}
|
||||
|
||||
auto info = element_first_get(anm2.root, ElementType::INFO);
|
||||
@@ -628,12 +632,29 @@ namespace anm2ed::imgui
|
||||
{
|
||||
savedSettings = settings;
|
||||
|
||||
if (settings.renderIsRawAnimation)
|
||||
auto isRenderPreviewOverridden = settings.renderIsUseAnimationBounds || settings.renderIsUseIsolatedAnimation;
|
||||
if (isRenderPreviewOverridden)
|
||||
{
|
||||
savedOverlayIndex = overlayIndex;
|
||||
savedZoom = zoom;
|
||||
savedPan = pan;
|
||||
}
|
||||
|
||||
if (settings.renderIsUseIsolatedAnimation)
|
||||
{
|
||||
overlayIndex = -1;
|
||||
settings.animationPreviewTransparent = true;
|
||||
settings.timelineIsOnlyShowLayers = true;
|
||||
settings.previewIsAxes = false;
|
||||
settings.previewIsGrid = false;
|
||||
settings.previewIsPivots = false;
|
||||
settings.previewIsAltIcons = false;
|
||||
settings.previewIsBorder = false;
|
||||
settings.onionskinIsEnabled = false;
|
||||
}
|
||||
|
||||
if (settings.renderIsUseAnimationBounds)
|
||||
{
|
||||
if (animation)
|
||||
if (auto rect = anm2.animation_rect(*animation, isRootTransform); rect != vec4(-1.0f))
|
||||
{
|
||||
@@ -665,6 +686,17 @@ namespace anm2ed::imgui
|
||||
}
|
||||
if (renderTempDirectory.empty())
|
||||
{
|
||||
if (isRenderPreviewOverridden)
|
||||
{
|
||||
settings = savedSettings;
|
||||
pan = savedPan;
|
||||
zoom = savedZoom;
|
||||
overlayIndex = savedOverlayIndex;
|
||||
isSizeTrySet = true;
|
||||
hasPendingZoomPanAdjust = false;
|
||||
isCheckerPanInitialized = false;
|
||||
}
|
||||
|
||||
auto pathString = path::to_utf8(settings.renderPath);
|
||||
toasts.push(
|
||||
std::vformat(localize.get(TOAST_EXPORT_RENDERED_ANIMATION_FAILED), std::make_format_args(pathString)));
|
||||
@@ -795,6 +827,27 @@ namespace anm2ed::imgui
|
||||
return true;
|
||||
};
|
||||
|
||||
auto group_root_frame_get = [](const Element& container, const Element& track, float t) -> std::optional<Element>
|
||||
{
|
||||
if (track.groupId == -1) return std::nullopt;
|
||||
auto group = element_child_id_get(container, ElementType::GROUP, track.groupId);
|
||||
auto root = group ? element_child_first_get(*group, ElementType::ROOT_ANIMATION) : nullptr;
|
||||
if (!root) return std::nullopt;
|
||||
return frame_generate(*root, t);
|
||||
};
|
||||
|
||||
auto group_transform_for_time = [&](const Element& container, const Element& track, float t,
|
||||
const glm::mat4& sampleTransform)
|
||||
{
|
||||
auto itemTransform = sampleTransform;
|
||||
if (isRootTransform)
|
||||
if (auto groupRootFrame = group_root_frame_get(container, track, t))
|
||||
itemTransform *= math::quad_model_parent_get(groupRootFrame->position, {},
|
||||
math::percent_to_unit(groupRootFrame->scale),
|
||||
groupRootFrame->rotation);
|
||||
return itemTransform;
|
||||
};
|
||||
|
||||
auto draw_root =
|
||||
[&](float sampleTime, const glm::mat4& sampleTransform, vec3 sampleColor, float sampleAlpha, bool isOnion)
|
||||
{
|
||||
@@ -824,12 +877,52 @@ namespace anm2ed::imgui
|
||||
|
||||
draw_root(time, transform, {}, 0.0f, false);
|
||||
|
||||
auto draw_group_root = [&](Element& group, int groupType, float sampleTime,
|
||||
const glm::mat4& sampleTransform, vec3 sampleColor, float sampleAlpha,
|
||||
bool isOnion)
|
||||
{
|
||||
auto groupRoot = element_child_first_get(group, ElementType::ROOT_ANIMATION);
|
||||
if (!groupRoot) return;
|
||||
auto rootFrame = frame_generate(*groupRoot, sampleTime);
|
||||
if (isOnlyShowLayers || !rootFrame.isVisible || !groupRoot->isVisible) return;
|
||||
|
||||
auto itemTransform = sampleTransform;
|
||||
if (isRootTransform)
|
||||
itemTransform *= math::quad_model_parent_get(rootFrame.position, {}, math::percent_to_unit(rootFrame.scale),
|
||||
rootFrame.rotation);
|
||||
|
||||
auto rootModel = isRootTransform
|
||||
? math::quad_model_get(TARGET_SIZE, {}, TARGET_SIZE * 0.5f)
|
||||
: math::quad_model_get(TARGET_SIZE, rootFrame.position, TARGET_SIZE * 0.5f,
|
||||
math::percent_to_unit(rootFrame.scale), rootFrame.rotation);
|
||||
auto rootTransform = itemTransform * rootModel;
|
||||
|
||||
auto isSelected = 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;
|
||||
texture_render(shaderTexture, resources.icons[icon].id, rootTransform, color);
|
||||
};
|
||||
|
||||
if (auto layerAnimations = element_child_first_get(*animation, ElementType::LAYER_ANIMATIONS))
|
||||
{
|
||||
auto layer_animation_draw = [&](auto&& self, Element& layerAnimation, bool isParentVisible = true) -> void
|
||||
{
|
||||
if (layerAnimation.type == ElementType::GROUP)
|
||||
{
|
||||
if (isParentVisible && layerAnimation.isVisible)
|
||||
{
|
||||
auto groupRoot = element_child_first_get(layerAnimation, ElementType::ROOT_ANIMATION);
|
||||
if (layeredOnions && groupRoot)
|
||||
for (auto& sample : *layeredOnions)
|
||||
if (auto sampleTime = sample_time_for_item(*groupRoot, sample))
|
||||
{
|
||||
auto sampleTransform = transform_for_time(*sampleTime);
|
||||
draw_group_root(layerAnimation, LAYER, *sampleTime, sampleTransform, sample.colorOffset,
|
||||
sample.alphaOffset, true);
|
||||
}
|
||||
draw_group_root(layerAnimation, LAYER, time, transform, {}, 0.0f, false);
|
||||
}
|
||||
for (auto& child : layerAnimation.children)
|
||||
self(self, child, isParentVisible && layerAnimation.isVisible);
|
||||
return;
|
||||
@@ -864,7 +957,9 @@ namespace anm2ed::imgui
|
||||
|
||||
auto layerModel =
|
||||
math::quad_model_get(size, frame.position, pivot, math::percent_to_unit(frame.scale), frame.rotation);
|
||||
auto layerTransform = sampleTransform * layerModel;
|
||||
auto itemTransform = group_transform_for_time(*layerAnimations, layerAnimation, sampleTime,
|
||||
sampleTransform);
|
||||
auto layerTransform = itemTransform * layerModel;
|
||||
|
||||
auto uvMin = crop / texSize;
|
||||
auto uvMax = (crop + size) / texSize;
|
||||
@@ -878,12 +973,38 @@ namespace anm2ed::imgui
|
||||
frameColorOffset += rootFrame.colorOffset;
|
||||
frameTint *= rootFrame.tint;
|
||||
}
|
||||
if (isRootTransform)
|
||||
if (auto groupRootFrame = group_root_frame_get(*layerAnimations, layerAnimation, sampleTime))
|
||||
{
|
||||
frameColorOffset += groupRootFrame->colorOffset;
|
||||
frameTint *= groupRootFrame->tint;
|
||||
}
|
||||
|
||||
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& layerShader = customShader ? *customShader : shaderTexture;
|
||||
|
||||
texture_render(shaderTexture, texture.id, layerTransform, frameTint, frameColorOffset, vertices.data());
|
||||
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);
|
||||
}
|
||||
|
||||
auto color = isOnion ? vec4(sampleColor, 1.0f - sampleAlpha)
|
||||
: is_layer_animation_selected(id) ? SELECTED_LAYER_BORDER_COLOR
|
||||
@@ -895,7 +1016,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto pivotModel = math::quad_model_get(PIVOT_SIZE, frame.position, PIVOT_SIZE * 0.5f,
|
||||
math::percent_to_unit(frame.scale), frame.rotation);
|
||||
auto pivotTransform = sampleTransform * pivotModel;
|
||||
auto pivotTransform = itemTransform * pivotModel;
|
||||
|
||||
texture_render(shaderTexture, resources.icons[icon::PIVOT].id, pivotTransform, color);
|
||||
}
|
||||
@@ -921,6 +1042,19 @@ namespace anm2ed::imgui
|
||||
{
|
||||
if (nullAnimation.type == ElementType::GROUP)
|
||||
{
|
||||
if (isParentVisible && nullAnimation.isVisible)
|
||||
{
|
||||
auto groupRoot = element_child_first_get(nullAnimation, ElementType::ROOT_ANIMATION);
|
||||
if (layeredOnions && groupRoot)
|
||||
for (auto& sample : *layeredOnions)
|
||||
if (auto sampleTime = sample_time_for_item(*groupRoot, sample))
|
||||
{
|
||||
auto sampleTransform = transform_for_time(*sampleTime);
|
||||
draw_group_root(nullAnimation, NULL_, *sampleTime, sampleTransform, sample.colorOffset,
|
||||
sample.alphaOffset, true);
|
||||
}
|
||||
draw_group_root(nullAnimation, NULL_, time, transform, {}, 0.0f, false);
|
||||
}
|
||||
for (auto& child : nullAnimation.children)
|
||||
self(self, child, isParentVisible && nullAnimation.isVisible);
|
||||
return;
|
||||
@@ -950,7 +1084,9 @@ namespace anm2ed::imgui
|
||||
|
||||
auto nullModel = math::quad_model_get(size, frame.position, size * 0.5f,
|
||||
math::percent_to_unit(frame.scale), frame.rotation);
|
||||
auto nullTransform = sampleTransform * nullModel;
|
||||
auto itemTransform = group_transform_for_time(*nullAnimations, nullAnimation, sampleTime,
|
||||
sampleTransform);
|
||||
auto nullTransform = itemTransform * nullModel;
|
||||
|
||||
texture_render(shaderTexture, resources.icons[icon].id, nullTransform, color);
|
||||
|
||||
@@ -958,7 +1094,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto rectModel =
|
||||
math::quad_model_get(frame.scale, frame.position, frame.scale * 0.5f, vec2(1.0f), frame.rotation);
|
||||
auto rectTransform = sampleTransform * rectModel;
|
||||
auto rectTransform = itemTransform * rectModel;
|
||||
|
||||
rect_render(shaderLine, rectTransform, rectModel, color);
|
||||
}
|
||||
@@ -1074,9 +1210,10 @@ namespace anm2ed::imgui
|
||||
editItemType = static_cast<ItemType>(editReference.itemType);
|
||||
}
|
||||
|
||||
auto frame =
|
||||
anm2.element_get(editReference.animationIndex, editItemType, editReference.frameIndex, editReference.itemID);
|
||||
auto item = anm2.element_get(editReference.animationIndex, editItemType, editReference.itemID);
|
||||
auto frame = anm2.element_get(editReference);
|
||||
auto editItemReference = editReference;
|
||||
editItemReference.frameIndex = -1;
|
||||
auto item = anm2.element_get(editItemReference);
|
||||
auto nulls = anm2.element_get(ElementType::NULLS);
|
||||
auto selectedNull = editItemType == ItemType::NULL_ && nulls
|
||||
? element_child_id_get(*nulls, ElementType::NULL_ELEMENT, editReference.itemID)
|
||||
@@ -1105,8 +1242,10 @@ namespace anm2ed::imgui
|
||||
|
||||
auto frame_snapshot = [&](auto message)
|
||||
{
|
||||
auto queuedFrameReferences = selectedFrameReferences;
|
||||
manager.command_push({manager.selected,
|
||||
[message](Manager&, Document& document) { document.snapshot(localize.get(message)); }});
|
||||
[message, queuedFrameReferences](Manager&, Document& document)
|
||||
{ document.frames_snapshot(localize.get(message), queuedFrameReferences); }});
|
||||
};
|
||||
auto frame_change_apply = [&](FrameChange frameChange, ChangeType changeType = ChangeType::ADJUST)
|
||||
{
|
||||
@@ -1116,15 +1255,16 @@ namespace anm2ed::imgui
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : queuedFrameReferences)
|
||||
groupedFrames[{frameReference.animationIndex, frameReference.itemType,
|
||||
frameReference.itemID, -1}]
|
||||
.insert(frameReference.frameIndex);
|
||||
{
|
||||
auto itemReference = frameReference;
|
||||
itemReference.frameIndex = -1;
|
||||
groupedFrames[itemReference].insert(frameReference.frameIndex);
|
||||
}
|
||||
|
||||
for (auto& [itemReference, itemFrames] : groupedFrames)
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(itemReference.itemType);
|
||||
auto item = document.anm2.element_get(itemReference.animationIndex, itemType,
|
||||
itemReference.itemID);
|
||||
auto item = document.anm2.element_get(itemReference);
|
||||
if (!item) continue;
|
||||
frames_change(*item, frameChange, itemType, changeType, itemFrames);
|
||||
}
|
||||
|
||||
@@ -36,29 +36,26 @@ namespace anm2ed::imgui
|
||||
auto& anm2 = document.anm2;
|
||||
auto& reference = document.reference;
|
||||
auto& type = reference.itemType;
|
||||
auto itemType = static_cast<ItemType>(type);
|
||||
auto frame = anm2.element_get(reference.animationIndex, itemType, reference.frameIndex, reference.itemID);
|
||||
auto frame = reference.frameIndex >= 0 ? anm2.element_get(reference) : nullptr;
|
||||
|
||||
auto frame_edit = [&](auto message, auto behavior)
|
||||
{
|
||||
auto queuedReference = reference;
|
||||
manager.command_push({manager.selected,
|
||||
auto frame_edit = [&](auto message, auto behavior)
|
||||
{
|
||||
auto queuedReference = reference;
|
||||
manager.command_push({manager.selected,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(queuedReference.itemType);
|
||||
auto frame = document.anm2.element_get(queuedReference.animationIndex, itemType,
|
||||
queuedReference.frameIndex,
|
||||
queuedReference.itemID);
|
||||
auto item =
|
||||
document.anm2.element_get(queuedReference.animationIndex, itemType,
|
||||
queuedReference.itemID);
|
||||
if (queuedReference.frameIndex < 0) return;
|
||||
auto frame = document.anm2.element_get(queuedReference);
|
||||
auto itemReference = queuedReference;
|
||||
itemReference.frameIndex = -1;
|
||||
auto item = document.anm2.element_get(itemReference);
|
||||
if (!frame) return;
|
||||
|
||||
document.snapshot(localize.get(message));
|
||||
document.frames_snapshot(localize.get(message), {queuedReference});
|
||||
behavior(document, *frame, item, queuedReference);
|
||||
document.anm2_change(Document::FRAMES);
|
||||
}});
|
||||
};
|
||||
};
|
||||
|
||||
auto persistent_edit = [&](auto state, auto message, auto behavior)
|
||||
{
|
||||
@@ -68,20 +65,18 @@ namespace anm2ed::imgui
|
||||
manager.command_push({manager.selected,
|
||||
[=](Manager&, Document& document) mutable
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(queuedReference.itemType);
|
||||
auto frame = document.anm2.element_get(queuedReference.animationIndex, itemType,
|
||||
queuedReference.frameIndex,
|
||||
queuedReference.itemID);
|
||||
auto item =
|
||||
document.anm2.element_get(queuedReference.animationIndex, itemType,
|
||||
queuedReference.itemID);
|
||||
if (queuedReference.frameIndex < 0) return;
|
||||
auto frame = document.anm2.element_get(queuedReference);
|
||||
auto itemReference = queuedReference;
|
||||
itemReference.frameIndex = -1;
|
||||
auto item = document.anm2.element_get(itemReference);
|
||||
if (!frame) return;
|
||||
|
||||
if (state == edit::START) document.snapshot(localize.get(message));
|
||||
if (state == edit::START) document.frames_snapshot(localize.get(message), {queuedReference});
|
||||
behavior(document, *frame, item, queuedReference);
|
||||
if (state == edit::END) document.anm2_change(Document::FRAMES);
|
||||
}});
|
||||
};
|
||||
};
|
||||
|
||||
auto regionLabelsString = std::vector<std::string>{localize.get(BASIC_NONE)};
|
||||
auto regionLabels = std::vector<const char*>{regionLabelsString[0].c_str()};
|
||||
|
||||
@@ -0,0 +1,430 @@
|
||||
#include "shaders.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
#include "path.hpp"
|
||||
#include "strings.hpp"
|
||||
#include "util/imgui/input.hpp"
|
||||
#include "util/imgui/layout.hpp"
|
||||
|
||||
using namespace anm2ed::resource;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
#define SHADER_UNIFORM_BINDING_COMBO_VALUES \
|
||||
X(resource::shader::UNIFORM_BINDING_IGNORE) \
|
||||
X(resource::shader::UNIFORM_BINDING_MANUAL) \
|
||||
X(resource::shader::UNIFORM_BINDING_COLOR_OFFSET) \
|
||||
X(resource::shader::UNIFORM_BINDING_FRAME_TINT) \
|
||||
X(resource::shader::UNIFORM_BINDING_MAIN_TEXTURE) \
|
||||
X(resource::shader::UNIFORM_BINDING_COMPONENTS) \
|
||||
X(resource::shader::UNIFORM_BINDING_PLAYBACK_TIME) \
|
||||
X(resource::shader::UNIFORM_BINDING_TEXTURE_SIZE) \
|
||||
X(resource::shader::UNIFORM_BINDING_TRANSFORM)
|
||||
|
||||
inline constexpr resource::shader::UniformBinding SHADER_UNIFORM_BINDING_COMBO_ORDER[] = {
|
||||
#define X(binding) binding,
|
||||
SHADER_UNIFORM_BINDING_COMBO_VALUES
|
||||
#undef X
|
||||
};
|
||||
#undef SHADER_UNIFORM_BINDING_COMBO_VALUES
|
||||
|
||||
std::filesystem::path shader_absolute_path_get(Document& document, const std::filesystem::path& shaderPath)
|
||||
{
|
||||
auto loadPath = path::backslash_handle(shaderPath);
|
||||
if (loadPath.empty() || loadPath.is_absolute()) return loadPath;
|
||||
return document.directory_get() / loadPath;
|
||||
}
|
||||
|
||||
bool is_shader_reload_needed(Document& document, Element& spritesheet, Element* shader)
|
||||
{
|
||||
if (!shader || !shader->isEnabled || shader->fragment.empty()) return false;
|
||||
if (!document.shader_get(spritesheet.id)) return true;
|
||||
if (!document.shaderVertexPaths.contains(spritesheet.id) || !document.shaderFragmentPaths.contains(spritesheet.id))
|
||||
return true;
|
||||
return document.shaderVertexPaths.at(spritesheet.id) != shader->vertex ||
|
||||
document.shaderFragmentPaths.at(spritesheet.id) != shader->fragment;
|
||||
}
|
||||
|
||||
Element* shader_spritesheet_get(Document& document)
|
||||
{
|
||||
if (document.spritesheet.selection.size() == 1)
|
||||
return document.anm2.element_get(ElementType::SPRITESHEET, *document.spritesheet.selection.begin());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Element* shader_element_get(Element& spritesheet, bool isCreate)
|
||||
{
|
||||
if (auto shader = element_child_first_get(spritesheet, ElementType::SHADER)) return shader;
|
||||
if (!isCreate) return nullptr;
|
||||
|
||||
spritesheet.children.push_back(element_make(ElementType::SHADER));
|
||||
return &spritesheet.children.back();
|
||||
}
|
||||
|
||||
void shader_enabled_set(Document& document, Element& spritesheet, bool isEnabled)
|
||||
{
|
||||
if (auto shader = shader_element_get(spritesheet, true))
|
||||
{
|
||||
shader->isEnabled = isEnabled;
|
||||
document.change(Document::SPRITESHEETS);
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path shader_asset_path_get(Document& document, const std::filesystem::path& path)
|
||||
{
|
||||
auto loadPath = path::backslash_handle(path);
|
||||
return path::backslash_replace(path::make_relative(loadPath, document.directory_get()));
|
||||
}
|
||||
|
||||
void shader_path_edit(Document& document, Element& spritesheet, std::filesystem::path Element::* member,
|
||||
const std::filesystem::path& value)
|
||||
{
|
||||
if (auto shader = shader_element_get(spritesheet, true))
|
||||
{
|
||||
shader->*member = path::backslash_replace(value);
|
||||
document.change(Document::SPRITESHEETS);
|
||||
}
|
||||
}
|
||||
|
||||
void shader_dialog_update(ShadersWindow& window, Manager& manager, Dialog& dialog, Dialog::Type type,
|
||||
std::filesystem::path Element::* member)
|
||||
{
|
||||
if (!dialog.is_selected(type)) return;
|
||||
|
||||
auto dialogPath = dialog.path;
|
||||
auto spritesheetId = window.dialogSpritesheetId;
|
||||
manager.command_push({manager.selected,
|
||||
[dialogPath, spritesheetId, member](Manager&, Document& document)
|
||||
{
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, spritesheetId);
|
||||
if (!spritesheet) return;
|
||||
shader_path_edit(document, *spritesheet, member,
|
||||
shader_asset_path_get(document, dialogPath));
|
||||
}});
|
||||
window.dialogSpritesheetId = -1;
|
||||
dialog.reset();
|
||||
}
|
||||
|
||||
void shader_path_row_update(ShadersWindow& window, Document& document, Resources& resources, Dialog& dialog,
|
||||
Element* spritesheet, std::filesystem::path Element::* member, Dialog::Type dialogType,
|
||||
StringType label)
|
||||
{
|
||||
auto shader = spritesheet ? shader_element_get(*spritesheet, false) : nullptr;
|
||||
auto shaderPath = shader ? shader->*member : std::filesystem::path{};
|
||||
auto isDefault = shaderPath.empty();
|
||||
auto displayPath = isDefault ? path::from_utf8(localize.get(BASIC_DEFAULT)) : shaderPath;
|
||||
|
||||
if (ImGui::ImageButton(std::format("##{} Path Set", localize.get(label)).c_str(),
|
||||
resources.icons[icon::FOLDER].id, icon_size_get()))
|
||||
{
|
||||
if (spritesheet)
|
||||
{
|
||||
window.dialogSpritesheetId = spritesheet->id;
|
||||
dialog.file_open(dialogType);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
auto labelWidth = ImGui::CalcTextSize(localize.get(label)).x;
|
||||
auto inputWidth = ImGui::GetContentRegionAvail().x - labelWidth - ImGui::GetStyle().ItemSpacing.x;
|
||||
if (inputWidth < ImGui::GetFrameHeight()) inputWidth = ImGui::GetFrameHeight();
|
||||
ImGui::SetNextItemWidth(inputWidth);
|
||||
ImGui::BeginDisabled(isDefault);
|
||||
auto isEdited = input_text_path(std::format("##{} Path", localize.get(label)).c_str(), &displayPath);
|
||||
ImGui::EndDisabled();
|
||||
if (isEdited && spritesheet)
|
||||
shader_path_edit(document, *spritesheet, member, displayPath);
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::TextUnformatted(localize.get(label));
|
||||
}
|
||||
|
||||
void shader_uniform_config_save(Document& document, Element& shaderElement, const resource::shader::Uniform& uniform)
|
||||
{
|
||||
auto config = shader_uniform_get(shaderElement, uniform.name, true);
|
||||
if (!config) return;
|
||||
|
||||
config->binding = std::string(resource::shader::uniform_binding_value_get(uniform.binding));
|
||||
config->value = resource::shader::uniform_value_string_get(uniform);
|
||||
if (uniform.binding == resource::shader::UNIFORM_BINDING_COMPONENTS)
|
||||
{
|
||||
for (int index = 0; index < (int)uniform.components.size(); ++index)
|
||||
{
|
||||
auto component = shader_uniform_component_get(*config, index, true);
|
||||
if (!component) continue;
|
||||
component->binding = std::string(resource::shader::uniform_binding_value_get(uniform.components[index].binding));
|
||||
component->value = std::format("{:.6g}", uniform.components[index].value);
|
||||
}
|
||||
}
|
||||
else
|
||||
std::erase_if(config->children, [](const Element& child) { return child.type == ElementType::COMPONENT; });
|
||||
document.change(Document::SPRITESHEETS);
|
||||
}
|
||||
|
||||
int shader_uniform_component_count_get(resource::shader::UniformValueType type)
|
||||
{
|
||||
if (type == resource::shader::UNIFORM_VALUE_VEC2) return 2;
|
||||
if (type == resource::shader::UNIFORM_VALUE_VEC3) return 3;
|
||||
if (type == resource::shader::UNIFORM_VALUE_VEC4) return 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void shader_uniform_components_from_value_set(resource::shader::Uniform& uniform)
|
||||
{
|
||||
uniform.components[0].value = uniform.value.x;
|
||||
uniform.components[1].value = uniform.value.y;
|
||||
uniform.components[2].value = uniform.value.z;
|
||||
uniform.components[3].value = uniform.value.w;
|
||||
}
|
||||
|
||||
void shader_uniform_value_from_components_set(resource::shader::Uniform& uniform)
|
||||
{
|
||||
uniform.value.x = uniform.components[0].value;
|
||||
uniform.value.y = uniform.components[1].value;
|
||||
uniform.value.z = uniform.components[2].value;
|
||||
uniform.value.w = uniform.components[3].value;
|
||||
}
|
||||
|
||||
bool shader_uniform_value_update(resource::shader::Uniform& uniform)
|
||||
{
|
||||
ImGui::SetNextItemWidth(-1.0f);
|
||||
switch (uniform.valueType)
|
||||
{
|
||||
case resource::shader::UNIFORM_VALUE_FLOAT:
|
||||
return ImGui::DragFloat("##Value", &uniform.value.x, 0.01f);
|
||||
case resource::shader::UNIFORM_VALUE_INT:
|
||||
case resource::shader::UNIFORM_VALUE_SAMPLER2D:
|
||||
return ImGui::InputInt("##Value", &uniform.intValue);
|
||||
case resource::shader::UNIFORM_VALUE_VEC2:
|
||||
return ImGui::DragFloat2("##Value", &uniform.value.x, 0.01f);
|
||||
case resource::shader::UNIFORM_VALUE_VEC3:
|
||||
return ImGui::DragFloat3("##Value", &uniform.value.x, 0.01f);
|
||||
case resource::shader::UNIFORM_VALUE_VEC4:
|
||||
return ImGui::DragFloat4("##Value", &uniform.value.x, 0.01f);
|
||||
default:
|
||||
ImGui::TextUnformatted(localize.get(BASIC_NONE));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool shader_uniform_component_binding_update(resource::shader::Uniform::Component& component)
|
||||
{
|
||||
auto bindingLabel = resource::shader::uniform_binding_label_get(component.binding);
|
||||
ImGui::SetNextItemWidth(ImGui::GetFrameHeight() * 5.0f);
|
||||
if (!ImGui::BeginCombo("##Component Binding", bindingLabel.data())) return false;
|
||||
|
||||
bool isChanged{};
|
||||
constexpr resource::shader::UniformBinding bindings[] = {resource::shader::UNIFORM_BINDING_MANUAL,
|
||||
resource::shader::UNIFORM_BINDING_PLAYBACK_TIME};
|
||||
for (auto binding : bindings)
|
||||
{
|
||||
auto isSelected = component.binding == binding;
|
||||
auto label = resource::shader::uniform_binding_label_get(binding);
|
||||
if (ImGui::Selectable(label.data(), isSelected))
|
||||
{
|
||||
component.binding = binding;
|
||||
isChanged = true;
|
||||
}
|
||||
if (isSelected) ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
bool shader_uniform_components_update(resource::shader::Uniform& uniform)
|
||||
{
|
||||
bool isChanged{};
|
||||
constexpr const char* labels[] = {"X", "Y", "Z", "W"};
|
||||
auto componentCount = shader_uniform_component_count_get(uniform.valueType);
|
||||
|
||||
for (int index = 0; index < componentCount; ++index)
|
||||
{
|
||||
auto& component = uniform.components[index];
|
||||
ImGui::PushID(index);
|
||||
if (index > 0) ImGui::Spacing();
|
||||
ImGui::TextUnformatted(labels[index]);
|
||||
ImGui::SameLine();
|
||||
if (shader_uniform_component_binding_update(component)) isChanged = true;
|
||||
ImGui::SameLine();
|
||||
ImGui::BeginDisabled(component.binding != resource::shader::UNIFORM_BINDING_MANUAL);
|
||||
ImGui::SetNextItemWidth(-1.0f);
|
||||
if (ImGui::DragFloat("##Component Value", &component.value, 0.01f)) isChanged = true;
|
||||
ImGui::EndDisabled();
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
if (isChanged) shader_uniform_value_from_components_set(uniform);
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
void shader_uniforms_update(Document& document, Element* shaderElement, resource::Shader* runtime)
|
||||
{
|
||||
if (!shaderElement || !runtime) return;
|
||||
|
||||
if (runtime->uniforms.empty())
|
||||
{
|
||||
ImGui::TextUnformatted(localize.get(BASIC_NONE));
|
||||
return;
|
||||
}
|
||||
|
||||
auto flags = ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_BordersOuterH | ImGuiTableFlags_RowBg |
|
||||
ImGuiTableFlags_Resizable | ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_ScrollY;
|
||||
auto tableSize = ImGui::GetContentRegionAvail();
|
||||
if (tableSize.y < ImGui::GetFrameHeight()) tableSize.y = ImGui::GetFrameHeight();
|
||||
if (!ImGui::BeginTable("##Shader Uniforms", 4, flags, tableSize)) return;
|
||||
|
||||
ImGui::TableSetupColumn(localize.get(BASIC_NAME));
|
||||
ImGui::TableSetupColumn(localize.get(LABEL_TYPE));
|
||||
ImGui::TableSetupColumn(localize.get(LABEL_BINDING));
|
||||
ImGui::TableSetupColumn(localize.get(LABEL_VALUE_COLUMN));
|
||||
ImGui::TableSetupScrollFreeze(0, 1);
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (auto& uniform : runtime->uniforms)
|
||||
{
|
||||
ImGui::PushID(uniform.name.c_str());
|
||||
ImGui::TableNextRow();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(uniform.name.c_str());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(resource::shader::uniform_value_type_label_get(uniform.valueType).data());
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
auto bindingLabel = resource::shader::uniform_binding_label_get(uniform.binding);
|
||||
ImGui::SetNextItemWidth(-1.0f);
|
||||
if (ImGui::BeginCombo("##Binding", bindingLabel.data()))
|
||||
{
|
||||
for (auto binding : SHADER_UNIFORM_BINDING_COMBO_ORDER)
|
||||
{
|
||||
if (!resource::shader::is_uniform_binding_valid(binding, uniform.valueType)) continue;
|
||||
auto isSelected = uniform.binding == binding;
|
||||
auto label = resource::shader::uniform_binding_label_get(binding);
|
||||
if (ImGui::Selectable(label.data(), isSelected))
|
||||
{
|
||||
uniform.binding = binding;
|
||||
if (uniform.binding == resource::shader::UNIFORM_BINDING_COMPONENTS)
|
||||
shader_uniform_components_from_value_set(uniform);
|
||||
shader_uniform_config_save(document, *shaderElement, uniform);
|
||||
}
|
||||
if (isSelected) ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (uniform.binding == resource::shader::UNIFORM_BINDING_COMPONENTS)
|
||||
{
|
||||
if (shader_uniform_components_update(uniform)) shader_uniform_config_save(document, *shaderElement, uniform);
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::BeginDisabled(uniform.binding != resource::shader::UNIFORM_BINDING_MANUAL);
|
||||
if (shader_uniform_value_update(uniform))
|
||||
{
|
||||
shader_uniform_components_from_value_set(uniform);
|
||||
shader_uniform_config_save(document, *shaderElement, uniform);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
|
||||
void ShadersWindow::update(Manager& manager, Settings& settings, Resources& resources, Dialog& dialog)
|
||||
{
|
||||
if (ImGui::Begin(localize.get(LABEL_SHADERS_WINDOW), &settings.windowIsShaders))
|
||||
{
|
||||
auto document = manager.get();
|
||||
auto spritesheet = document ? shader_spritesheet_get(*document) : nullptr;
|
||||
auto shader = spritesheet ? shader_element_get(*spritesheet, false) : nullptr;
|
||||
auto isShaderEnabled = !shader || shader->isEnabled;
|
||||
auto isReloadNeeded = document && spritesheet && is_shader_reload_needed(*document, *spritesheet, shader);
|
||||
|
||||
shader_dialog_update(*this, manager, dialog, Dialog::SHADER_VERTEX_PATH_SET, &Element::vertex);
|
||||
shader_dialog_update(*this, manager, dialog, Dialog::SHADER_FRAGMENT_PATH_SET, &Element::fragment);
|
||||
|
||||
if (!spritesheet)
|
||||
{
|
||||
ImGui::TextUnformatted(localize.get(TEXT_SELECT_SPRITESHEET));
|
||||
ImGui::End();
|
||||
return;
|
||||
}
|
||||
|
||||
auto contentSize = size_without_footer_get();
|
||||
if (contentSize.y < ImGui::GetFrameHeight()) contentSize.y = ImGui::GetFrameHeight();
|
||||
if (ImGui::BeginChild("##Shaders Child", contentSize, ImGuiChildFlags_Borders))
|
||||
{
|
||||
ImGui::BeginDisabled(!isShaderEnabled);
|
||||
if (ImGui::BeginTabBar("##Shaders Tabs"))
|
||||
{
|
||||
if (ImGui::BeginTabItem(localize.get(LABEL_FILES)))
|
||||
{
|
||||
if (document)
|
||||
{
|
||||
shader_path_row_update(*this, *document, resources, dialog, spritesheet, &Element::vertex,
|
||||
Dialog::SHADER_VERTEX_PATH_SET, LABEL_VERTEX);
|
||||
shader_path_row_update(*this, *document, resources, dialog, spritesheet, &Element::fragment,
|
||||
Dialog::SHADER_FRAGMENT_PATH_SET, LABEL_FRAGMENT);
|
||||
}
|
||||
|
||||
if (isReloadNeeded) ImGui::TextWrapped("%s", localize.get(LABEL_SHADER_RELOAD_NEEDED));
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
auto consoleSize = ImGui::GetContentRegionAvail();
|
||||
if (consoleSize.y < ImGui::GetFrameHeight()) consoleSize.y = ImGui::GetFrameHeight();
|
||||
if (ImGui::BeginChild("##Shaders Console", consoleSize, ImGuiChildFlags_Borders))
|
||||
ImGui::TextWrapped("%s", status.c_str());
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem(localize.get(LABEL_UNIFORMS)))
|
||||
{
|
||||
shader_uniforms_update(*document, shader, document->shader_get(spritesheet->id));
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
ImGui::EndTabBar();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
if (ImGui::Button(localize.get(isShaderEnabled ? BASIC_ENABLED : BASIC_DISABLED), widgetSize))
|
||||
{
|
||||
auto spritesheetId = spritesheet->id;
|
||||
auto isNextEnabled = !isShaderEnabled;
|
||||
manager.command_push({manager.selected,
|
||||
[spritesheetId, isNextEnabled](Manager&, Document& document)
|
||||
{
|
||||
auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, spritesheetId);
|
||||
if (spritesheet) shader_enabled_set(document, *spritesheet, isNextEnabled);
|
||||
}});
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::BeginDisabled(!isShaderEnabled || !document);
|
||||
if (ImGui::Button(localize.get(BASIC_RELOAD), widgetSize) && document)
|
||||
{
|
||||
status.clear();
|
||||
document->shader_reload(spritesheet->id, &status);
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include "dialog.hpp"
|
||||
#include "manager.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
class ShadersWindow
|
||||
{
|
||||
public:
|
||||
std::string status{};
|
||||
int dialogSpritesheetId{-1};
|
||||
void update(Manager&, Settings&, Resources&, Dialog&);
|
||||
};
|
||||
}
|
||||
@@ -36,7 +36,6 @@ namespace anm2ed::imgui
|
||||
auto& anm2 = document.anm2;
|
||||
auto& reference = document.reference;
|
||||
auto& referenceSpritesheet = document.spritesheet.reference;
|
||||
auto referenceItemType = static_cast<ItemType>(reference.itemType);
|
||||
auto& pan = document.editorPan;
|
||||
auto& zoom = document.editorZoom;
|
||||
auto& backgroundColor = settings.editorBackgroundColor;
|
||||
@@ -62,10 +61,17 @@ namespace anm2ed::imgui
|
||||
};
|
||||
if (auto selectedLayerSpritesheet = selected_layer_spritesheet_get();
|
||||
selectedLayerSpritesheet != -1 && document.editTarget != Document::EditTarget::REGION &&
|
||||
document.editTarget != Document::EditTarget::SPRITESHEET)
|
||||
document.editTarget != Document::EditTarget::OVERLAY && document.editTarget != Document::EditTarget::SPRITESHEET)
|
||||
referenceSpritesheet = selectedLayerSpritesheet;
|
||||
auto spritesheet = anm2.element_get(ElementType::SPRITESHEET, referenceSpritesheet);
|
||||
auto texture = document.texture_get(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& tool = settings.tool;
|
||||
auto& shaderGrid = resources.shaders[shader::GRID];
|
||||
auto& shaderTexture = resources.shaders[shader::TEXTURE];
|
||||
@@ -226,17 +232,28 @@ namespace anm2ed::imgui
|
||||
viewport_set();
|
||||
clear(isTransparent ? vec4(0) : vec4(backgroundColor, 1.0f));
|
||||
|
||||
auto frame =
|
||||
anm2.element_get(reference.animationIndex, referenceItemType, reference.frameIndex, reference.itemID);
|
||||
auto frame = reference.frameIndex >= 0 ? anm2.element_get(reference) : nullptr;
|
||||
|
||||
if (spritesheet && texture && texture->is_valid())
|
||||
auto viewTexture = baseTexture && baseTexture->is_valid() ? baseTexture : texture;
|
||||
|
||||
if (spritesheet && viewTexture && viewTexture->is_valid())
|
||||
{
|
||||
auto transform = transform_get(zoom, pan);
|
||||
|
||||
auto spritesheetModel = math::quad_model_get(texture->size);
|
||||
auto spritesheetModel = math::quad_model_get(viewTexture->size);
|
||||
auto spritesheetTransform = transform * spritesheetModel;
|
||||
|
||||
texture_render(shaderTexture, texture->id, spritesheetTransform);
|
||||
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 (isGrid) grid_render(shaderGrid, zoom, pan, gridSize, gridOffset, gridColor);
|
||||
|
||||
@@ -376,10 +393,10 @@ namespace anm2ed::imgui
|
||||
auto editReference = reference;
|
||||
if (!selectedFrameReferences.contains(reference) && !selectedFrameReferences.empty())
|
||||
editReference = *selectedFrameReferences.begin();
|
||||
auto editReferenceItemType = static_cast<ItemType>(editReference.itemType);
|
||||
auto frame = anm2.element_get(editReference.animationIndex, editReferenceItemType, editReference.frameIndex,
|
||||
editReference.itemID);
|
||||
auto item = anm2.element_get(editReference.animationIndex, editReferenceItemType, editReference.itemID);
|
||||
auto frame = editReference.frameIndex >= 0 ? anm2.element_get(editReference) : nullptr;
|
||||
auto itemReference = editReference;
|
||||
itemReference.frameIndex = -1;
|
||||
auto item = anm2.element_get(itemReference);
|
||||
auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, editReference.itemID);
|
||||
bool isReferenceLayerOnSpritesheet =
|
||||
frame && editReference.itemID > -1 && layer && layer->spritesheetId == referenceSpritesheet;
|
||||
@@ -423,11 +440,28 @@ namespace anm2ed::imgui
|
||||
auto fraction = current - glm::floor(current);
|
||||
return glm::floor(value) + fraction;
|
||||
};
|
||||
auto snapshot_push = [&](StringType messageType)
|
||||
auto frame_snapshot_push = [&](StringType messageType, const std::set<Reference>& frameReferences)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
auto queuedFrameReferences = frameReferences;
|
||||
manager.command_push({manager.selected,
|
||||
[message, queuedFrameReferences](Manager&, Document& document)
|
||||
{ document.frames_snapshot(message, queuedFrameReferences); }});
|
||||
};
|
||||
auto region_snapshot_push = [&](StringType messageType, const std::set<int>& regionIds)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
auto queuedSpritesheet = referenceSpritesheet;
|
||||
auto queuedRegionIds = regionIds;
|
||||
manager.command_push({manager.selected,
|
||||
[message, queuedSpritesheet, queuedRegionIds](Manager&, Document& document)
|
||||
{ document.regions_snapshot(message, queuedSpritesheet, queuedRegionIds); }});
|
||||
};
|
||||
auto texture_snapshot_push = [&](StringType messageType)
|
||||
{
|
||||
auto message = std::string(localize.get(messageType));
|
||||
manager.command_push(
|
||||
{manager.selected, [message](Manager&, Document& document) { document.snapshot(message); }});
|
||||
{manager.selected, [message](Manager&, Document& document) { document.textures_snapshot(message); }});
|
||||
};
|
||||
auto document_change_push = [&](Document::ChangeType changeType)
|
||||
{
|
||||
@@ -443,13 +477,16 @@ namespace anm2ed::imgui
|
||||
{
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : queuedFrameReferences)
|
||||
groupedFrames[{frameReference.animationIndex, frameReference.itemType, frameReference.itemID, -1}]
|
||||
.insert(frameReference.frameIndex);
|
||||
{
|
||||
auto itemReference = frameReference;
|
||||
itemReference.frameIndex = -1;
|
||||
groupedFrames[itemReference].insert(frameReference.frameIndex);
|
||||
}
|
||||
|
||||
for (auto& [itemReference, itemFrames] : groupedFrames)
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(itemReference.itemType);
|
||||
auto item = document.anm2.element_get(itemReference.animationIndex, itemType, itemReference.itemID);
|
||||
auto item = document.anm2.element_get(itemReference);
|
||||
if (!item) continue;
|
||||
frames_change(*item, frameChange, itemType, changeType, itemFrames);
|
||||
}
|
||||
@@ -461,24 +498,26 @@ namespace anm2ed::imgui
|
||||
ChangeType changeType = ChangeType::ADJUST)
|
||||
{
|
||||
auto queuedReference = editReference;
|
||||
auto queuedReferenceItemType = editReferenceItemType;
|
||||
auto queuedFrameReferences = frameReferences;
|
||||
manager.command_push(
|
||||
{manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
auto frame = document.anm2.element_get(queuedReference.animationIndex, queuedReferenceItemType,
|
||||
queuedReference.frameIndex, queuedReference.itemID);
|
||||
if (queuedReference.frameIndex < 0) return;
|
||||
auto frame = document.anm2.element_get(queuedReference);
|
||||
if (!frame) return;
|
||||
|
||||
std::map<Reference, std::set<int>> groupedFrames{};
|
||||
for (auto frameReference : queuedFrameReferences)
|
||||
groupedFrames[{frameReference.animationIndex, frameReference.itemType, frameReference.itemID, -1}]
|
||||
.insert(frameReference.frameIndex);
|
||||
{
|
||||
auto itemReference = frameReference;
|
||||
itemReference.frameIndex = -1;
|
||||
groupedFrames[itemReference].insert(frameReference.frameIndex);
|
||||
}
|
||||
|
||||
for (auto& [itemReference, itemFrames] : groupedFrames)
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(itemReference.itemType);
|
||||
auto item = document.anm2.element_get(itemReference.animationIndex, itemType, itemReference.itemID);
|
||||
auto item = document.anm2.element_get(itemReference);
|
||||
if (!item) continue;
|
||||
frames_change(*item, frameChangeGet(*frame), itemType, changeType, itemFrames);
|
||||
}
|
||||
@@ -602,9 +641,11 @@ namespace anm2ed::imgui
|
||||
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 = document.texture_get(queuedSpritesheet);
|
||||
auto texture = queuedOverlay != -1 ? document.overlay_texture_get(queuedOverlay)
|
||||
: document.texture_get(queuedSpritesheet);
|
||||
if (!texture) return;
|
||||
texture->pixel_line(start, end, color);
|
||||
}});
|
||||
@@ -612,8 +653,15 @@ namespace anm2ed::imgui
|
||||
auto texture_change_push = [&]()
|
||||
{
|
||||
auto queuedSpritesheet = referenceSpritesheet;
|
||||
auto queuedOverlay = activeOverlayId;
|
||||
manager.command_push(
|
||||
{manager.selected, [=](Manager&, Document& document) { document.texture_change(queuedSpritesheet); }});
|
||||
{manager.selected, [=](Manager&, Document& document)
|
||||
{
|
||||
if (queuedOverlay != -1)
|
||||
document.overlay_texture_change(queuedOverlay);
|
||||
else
|
||||
document.texture_change(queuedSpritesheet);
|
||||
}});
|
||||
};
|
||||
|
||||
auto region_selection_set = [&](int id)
|
||||
@@ -701,7 +749,7 @@ namespace anm2ed::imgui
|
||||
region_selection_set(hoveredRegionId);
|
||||
if (isReferenceLayerOnSpritesheet)
|
||||
{
|
||||
snapshot_push(EDIT_FRAME_REGION);
|
||||
frame_snapshot_push(EDIT_FRAME_REGION, selectedFrameReferences);
|
||||
FrameChange change{};
|
||||
change.regionId = hoveredRegionId;
|
||||
if (auto region = region_get(hoveredRegionId))
|
||||
@@ -726,7 +774,7 @@ namespace anm2ed::imgui
|
||||
auto region = region_get(regionReference);
|
||||
if (!region) break;
|
||||
|
||||
if (isBegin) snapshot_push(EDIT_REGION_MOVE);
|
||||
if (isBegin) region_snapshot_push(EDIT_REGION_MOVE, {regionReference});
|
||||
if (isMouseDown) region_pivot_set(regionReference, pivot_snap(mousePos - region->crop, region->pivot));
|
||||
if (isLeftPressed) region_pivot_offset(regionReference, vec2(-step, 0));
|
||||
if (isRightPressed) region_pivot_offset(regionReference, vec2(step, 0));
|
||||
@@ -749,7 +797,7 @@ namespace anm2ed::imgui
|
||||
}
|
||||
|
||||
if (!item || !frame || selectedFrameToolReferences.empty() || isRegionInUse) break;
|
||||
if (isBegin) snapshot_push(EDIT_FRAME_PIVOT);
|
||||
if (isBegin) frame_snapshot_push(EDIT_FRAME_PIVOT, selectedFrameToolReferences);
|
||||
if (isMouseDown)
|
||||
{
|
||||
auto pivot = pivot_snap(mousePos - frame->crop, frame->pivot);
|
||||
@@ -784,7 +832,7 @@ namespace anm2ed::imgui
|
||||
if ((isRegionEditTarget || isRegionInUse || selectedFrameToolReferences.empty()) && !regionSelection.empty())
|
||||
{
|
||||
if (!spritesheet || regionSelection.empty()) break;
|
||||
if (isBegin) snapshot_push(EDIT_REGION_CROP);
|
||||
if (isBegin) region_snapshot_push(EDIT_REGION_CROP, regionSelection);
|
||||
|
||||
if (isMouseClicked)
|
||||
{
|
||||
@@ -825,7 +873,7 @@ namespace anm2ed::imgui
|
||||
}
|
||||
|
||||
if (!item || !frame || selectedFrameToolReferences.empty() || isRegionInUse) break;
|
||||
if (isBegin) snapshot_push(EDIT_FRAME_CROP);
|
||||
if (isBegin) frame_snapshot_push(EDIT_FRAME_CROP, selectedFrameToolReferences);
|
||||
|
||||
if (isMouseClicked)
|
||||
{
|
||||
@@ -880,7 +928,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
if (!texture) break;
|
||||
auto color = useTool == tool::DRAW ? toolColor : vec4();
|
||||
if (isMouseClicked) snapshot_push(useTool == tool::DRAW ? EDIT_DRAW : EDIT_ERASE);
|
||||
if (isMouseClicked) texture_snapshot_push(useTool == tool::DRAW ? EDIT_DRAW : EDIT_ERASE);
|
||||
if (isMouseDown) texture_line_apply(ivec2(previousMousePos), ivec2(mousePos), color);
|
||||
if (isMouseReleased) texture_change_push();
|
||||
break;
|
||||
|
||||
+337
-152
File diff suppressed because it is too large.
Load diff
@@ -21,6 +21,8 @@ namespace anm2ed::imgui
|
||||
int type{NONE};
|
||||
int id{-1};
|
||||
int index{-1};
|
||||
int groupType{NONE};
|
||||
int groupId{-1};
|
||||
bool isGroup{};
|
||||
|
||||
auto operator<=>(const TimelineRowReference&) const = default;
|
||||
@@ -31,6 +33,8 @@ namespace anm2ed::imgui
|
||||
int type{NONE};
|
||||
int itemID{-1};
|
||||
int animationIndex{-1};
|
||||
int groupType{NONE};
|
||||
int groupId{-1};
|
||||
int frameIndex{-1};
|
||||
int duration{1};
|
||||
std::vector<int> indices{};
|
||||
|
||||
+1448
-92
File diff suppressed because it is too large.
Load diff
@@ -29,7 +29,8 @@ namespace anm2ed::imgui
|
||||
WINDOW_PASTE = 1 << 8,
|
||||
WINDOW_RENAME = 1 << 9,
|
||||
WINDOW_PROPERTIES = 1 << 10,
|
||||
WINDOW_REFERENCE_ITALIC = 1 << 11
|
||||
WINDOW_REFERENCE_ITALIC = 1 << 11,
|
||||
WINDOW_GROUP = 1 << 12
|
||||
};
|
||||
|
||||
using WindowFlags = int;
|
||||
@@ -108,6 +109,7 @@ namespace anm2ed::imgui
|
||||
Command duplicate{};
|
||||
Command merge{};
|
||||
Command merge_open{};
|
||||
Command group{};
|
||||
Command default_set{};
|
||||
Command cut{};
|
||||
Command copy{};
|
||||
@@ -137,5 +139,6 @@ 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&);
|
||||
}
|
||||
@@ -84,7 +84,11 @@ namespace anm2ed::imgui::wizard
|
||||
{
|
||||
std::set<Reference> result = itemReferences;
|
||||
if (result.empty() && document.reference.itemType != NONE)
|
||||
result.insert({document.reference.animationIndex, document.reference.itemType, document.reference.itemID});
|
||||
{
|
||||
auto itemReference = document.reference;
|
||||
itemReference.frameIndex = -1;
|
||||
result.insert(itemReference);
|
||||
}
|
||||
std::erase_if(result, [&](const Reference& reference) { return !is_item_reference_changeable(reference); });
|
||||
return result;
|
||||
};
|
||||
@@ -396,12 +400,10 @@ namespace anm2ed::imgui::wizard
|
||||
groupedFrames[itemReference].insert(frameReference.frameIndex);
|
||||
}
|
||||
|
||||
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
for (auto& [itemReference, selection] : groupedFrames)
|
||||
{
|
||||
auto item = anm2.element_get(itemReference.animationIndex,
|
||||
static_cast<ItemType>(itemReference.itemType),
|
||||
itemReference.itemID);
|
||||
auto item = anm2.element_get(itemReference);
|
||||
if (!item) continue;
|
||||
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
|
||||
changeType, selection);
|
||||
@@ -412,13 +414,12 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
if (queuedIsItemsDestination)
|
||||
{
|
||||
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
for (auto itemReference : queuedItemReferences)
|
||||
{
|
||||
if (itemReference.itemType == TRIGGER) continue;
|
||||
auto item = anm2.element_get(itemReference.animationIndex,
|
||||
static_cast<ItemType>(itemReference.itemType),
|
||||
itemReference.itemID);
|
||||
itemReference.frameIndex = -1;
|
||||
auto item = anm2.element_get(itemReference);
|
||||
if (!item) continue;
|
||||
auto selection = all_frames_selection(*item);
|
||||
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
|
||||
@@ -428,7 +429,7 @@ namespace anm2ed::imgui::wizard
|
||||
return;
|
||||
}
|
||||
|
||||
document.snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
document.anm2_snapshot(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
|
||||
for (auto animationIndex : queuedAnimations)
|
||||
{
|
||||
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
|
||||
|
||||
@@ -69,15 +69,6 @@ namespace anm2ed::imgui::wizard
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_STACK_SIZE));
|
||||
|
||||
ImGui::SeparatorText(localize.get(LABEL_SERIALIZATION));
|
||||
ImGui::Checkbox(localize.get(LABEL_GROUPS), &temporary.fileIsSerializeGroups);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SERIALIZE_GROUPS));
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox(localize.get(LABEL_REGIONS), &temporary.fileIsSerializeRegions);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SERIALIZE_REGIONS));
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox(localize.get(LABEL_SOUNDS), &temporary.fileIsSerializeSounds);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SERIALIZE_SOUNDS));
|
||||
|
||||
ImGui::Checkbox(localize.get(LABEL_KEEP_REDUNDANT_FRAME_REGION_VALUES),
|
||||
&temporary.fileIsKeepRedundantFrameRegionValues);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_KEEP_REDUNDANT_FRAME_REGION_VALUES));
|
||||
@@ -86,6 +77,9 @@ namespace anm2ed::imgui::wizard
|
||||
&temporary.fileIsBakeSpecialInterpolatedFrames);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_SPECIAL_INTERPOLATED_FRAMES_ON_SAVE));
|
||||
|
||||
ImGui::Checkbox(localize.get(LABEL_BAKE_GROUP_FRAMES_ON_SAVE), &temporary.isFileBakeGroupFrames);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_BAKE_GROUP_FRAMES_ON_SAVE));
|
||||
|
||||
ImGui::SeparatorText(localize.get(LABEL_OPTIONS));
|
||||
ImGui::Checkbox(localize.get(LABEL_OVERWRITE_WARNING), &temporary.fileIsWarnOverwrite);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_OVERWRITE_WARNING));
|
||||
|
||||
@@ -162,8 +162,7 @@ namespace anm2ed::imgui::wizard
|
||||
bool isRegionsChanged{};
|
||||
for (auto queuedReference : queuedLayerReferences)
|
||||
{
|
||||
auto item = document.anm2.element_get(queuedReference.animationIndex, ItemType::LAYER,
|
||||
queuedReference.itemID);
|
||||
auto item = document.anm2.element_get(queuedReference);
|
||||
auto animation =
|
||||
document.anm2.element_get(ElementType::ANIMATION, queuedReference.animationIndex);
|
||||
auto layer = document.anm2.element_get(ElementType::LAYER_ELEMENT,
|
||||
@@ -175,7 +174,7 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
if (!isChanged)
|
||||
{
|
||||
document.snapshot(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
|
||||
document.anm2_snapshot(localize.get(EDIT_GENERATE_ANIMATION_FROM_GRID));
|
||||
isChanged = true;
|
||||
}
|
||||
auto frameIndexStart = (int)item->children.size();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "render_animation.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <set>
|
||||
#include <string>
|
||||
@@ -34,12 +35,14 @@ namespace anm2ed::imgui::wizard
|
||||
[&](const Reference& frameReference)
|
||||
{
|
||||
return frameReference.animationIndex != reference.animationIndex ||
|
||||
frameReference.itemType != reference.itemType || frameReference.itemID != reference.itemID;
|
||||
frameReference.itemType != reference.itemType || frameReference.itemID != reference.itemID ||
|
||||
frameReference.groupType != reference.groupType || frameReference.groupId != reference.groupId;
|
||||
});
|
||||
if (!frameReferences.empty())
|
||||
{
|
||||
auto itemType = static_cast<ItemType>(reference.itemType);
|
||||
if (auto item = document.anm2.element_get(reference.animationIndex, itemType, reference.itemID))
|
||||
auto itemReference = reference;
|
||||
itemReference.frameIndex = -1;
|
||||
if (auto item = document.anm2.element_get(itemReference))
|
||||
{
|
||||
int duration{};
|
||||
int frameIndex{};
|
||||
@@ -74,7 +77,8 @@ namespace anm2ed::imgui::wizard
|
||||
auto& path = settings.renderPath;
|
||||
auto& format = settings.renderFormat;
|
||||
auto& scale = settings.renderScale;
|
||||
auto& isRaw = settings.renderIsRawAnimation;
|
||||
auto& isUseAnimationBounds = settings.renderIsUseAnimationBounds;
|
||||
auto& isUseIsolatedAnimation = settings.renderIsUseIsolatedAnimation;
|
||||
auto& type = settings.renderType;
|
||||
auto& start = manager.recordingStart;
|
||||
auto& end = manager.recordingEnd;
|
||||
@@ -83,6 +87,11 @@ namespace anm2ed::imgui::wizard
|
||||
auto& isRange = manager.isRecordingRange;
|
||||
auto& reference = document.reference;
|
||||
auto& frameNum = animation->frameNum;
|
||||
auto animationFrameNum = std::max(frameNum, 1);
|
||||
auto frameMax = animationFrameNum - 1;
|
||||
start = std::clamp(start, 0, frameMax);
|
||||
end = std::clamp(end, start, frameMax);
|
||||
auto renderFrameNum = isRange ? render::frame_count_get(start, end) : animationFrameNum;
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
@@ -154,10 +163,10 @@ namespace anm2ed::imgui::wizard
|
||||
}
|
||||
else if (type == render::SPRITESHEET)
|
||||
{
|
||||
input_int_range(localize.get(LABEL_GENERATE_ROWS), rows, 1, frameNum - 1);
|
||||
input_int_range(localize.get(LABEL_GENERATE_ROWS), rows, 1, renderFrameNum);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROWS));
|
||||
|
||||
input_int_range(localize.get(LABEL_GENERATE_COLUMNS), columns, 1, frameNum - 1);
|
||||
input_int_range(localize.get(LABEL_GENERATE_COLUMNS), columns, 1, renderFrameNum);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_COLUMNS));
|
||||
}
|
||||
|
||||
@@ -181,19 +190,32 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
ImGui::BeginDisabled(!isRange);
|
||||
{
|
||||
input_int_range(localize.get(LABEL_START), start, 0, frameNum - 1);
|
||||
input_int_range(localize.get(LABEL_START), start, 0, frameMax);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_START));
|
||||
input_int_range(localize.get(LABEL_END), end, start, frameNum - 1);
|
||||
input_int_range(localize.get(LABEL_END), end, start, frameMax);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_END));
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
renderFrameNum = isRange ? render::frame_count_get(start, end) : animationFrameNum;
|
||||
|
||||
if (type == render::SPRITESHEET)
|
||||
{
|
||||
auto layout = render::spritesheet_layout_get(rows, columns, renderFrameNum);
|
||||
rows = layout.rows;
|
||||
columns = layout.columns;
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::Checkbox(localize.get(LABEL_RAW), &isRaw);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_RAW));
|
||||
ImGui::Checkbox(localize.get(LABEL_USE_ANIMATION_BOUNDS), &isUseAnimationBounds);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_USE_ANIMATION_BOUNDS));
|
||||
|
||||
ImGui::BeginDisabled(!isRaw);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::Checkbox(localize.get(LABEL_USE_ISOLATED_ANIMATION), &isUseIsolatedAnimation);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_USE_ISOLATED_ANIMATION));
|
||||
|
||||
ImGui::BeginDisabled(!isUseAnimationBounds);
|
||||
{
|
||||
input_float_range(localize.get(BASIC_SCALE), scale, 0.1f, 100.0f, 1.0f, STEP_FAST, "%.1fx");
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SCALE_OUTPUT));
|
||||
|
||||
Reference in new issue
Block a user