diff --git a/src/document.cpp b/src/document.cpp index 6350aab..e9d1db3 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -45,6 +45,30 @@ namespace anm2ed::document return count; } + std::string region_name_get(const std::string& format, int number) + { + try + { + return std::vformat(format, std::make_format_args(number)); + } + catch (const std::format_error&) + { + return format; + } + } + + Element* frame_region_match_get(Element& spritesheet, const Element& frame) + { + auto frameCrop = glm::ivec2(frame.crop); + auto frameSize = glm::ivec2(frame.size); + auto framePivot = glm::ivec2(frame.pivot); + for (auto& region : spritesheet.children) + if (region.type == ElementType::REGION && glm::ivec2(region.crop) == frameCrop && + glm::ivec2(region.size) == frameSize && glm::ivec2(region.pivot) == framePivot) + return ®ion; + return nullptr; + } + int frame_count_get(const Element& item) { auto frameType = item.type == ElementType::TRIGGERS ? ElementType::TRIGGER : ElementType::FRAME; @@ -569,6 +593,109 @@ namespace anm2ed return isChanged; } + bool Document::regions_generate_from_animations(const std::set& animationIndices, const std::string& format, + RegionFrameMapping mapping) + { + if (animationIndices.empty()) return false; + + int regionNumber{}; + bool isChanged{}; + for (auto animationIndex : animationIndices) + { + auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex); + if (!animation) continue; + + auto layerAnimations = element_child_first_get(*animation, ElementType::LAYER_ANIMATIONS); + if (!layerAnimations) continue; + + auto layer_animation_regions_generate = [&](auto&& self, Element& layerAnimation) -> void + { + if (layerAnimation.type == ElementType::GROUP) + { + for (auto& child : layerAnimation.children) + self(self, child); + return; + } + if (layerAnimation.type != ElementType::LAYER_ANIMATION) return; + + auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, layerAnimation.layerId); + auto spritesheet = layer ? anm2.element_get(ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; + if (!spritesheet) return; + + for (auto& frame : layerAnimation.children) + { + if (frame.type != ElementType::FRAME) continue; + + auto region = document::frame_region_match_get(*spritesheet, frame); + if (!region) + { + auto generated = element_make(ElementType::REGION); + generated.id = element_child_next_id_get(*spritesheet, ElementType::REGION); + generated.name = document::region_name_get(format, regionNumber++); + generated.crop = frame.crop; + generated.size = frame.size; + generated.pivot = frame.pivot; + generated.origin = Origin::CUSTOM; + spritesheet->children.push_back(generated); + region = &spritesheet->children.back(); + isChanged = true; + } + if (mapping == RegionFrameMapping::SET && frame.regionId != region->id) + { + frame.regionId = region->id; + isChanged = true; + } + } + }; + + for (auto& layerAnimation : layerAnimations->children) + layer_animation_regions_generate(layer_animation_regions_generate, layerAnimation); + } + + return isChanged; + } + + bool Document::regions_generate_from_frames(const std::set& frameReferences, const std::string& format, + RegionFrameMapping mapping) + { + int regionNumber{}; + bool isChanged{}; + for (auto frameReference : frameReferences) + { + if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) continue; + + auto frame = anm2.element_get(frameReference.animationIndex, ItemType::LAYER, frameReference.itemID, + frameReference.frameIndex); + if (!frame || frame->type != ElementType::FRAME || frame->regionId != -1) continue; + + auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, frameReference.itemID); + auto spritesheet = layer ? anm2.element_get(ElementType::SPRITESHEET, layer->spritesheetId) : nullptr; + if (!spritesheet) continue; + + auto region = document::frame_region_match_get(*spritesheet, *frame); + if (!region) + { + auto generated = element_make(ElementType::REGION); + generated.id = element_child_next_id_get(*spritesheet, ElementType::REGION); + generated.name = document::region_name_get(format, regionNumber++); + generated.crop = frame->crop; + generated.size = frame->size; + generated.pivot = frame->pivot; + generated.origin = Origin::CUSTOM; + spritesheet->children.push_back(generated); + region = &spritesheet->children.back(); + isChanged = true; + } + if (mapping == RegionFrameMapping::SET && frame->regionId != region->id) + { + frame->regionId = region->id; + isChanged = true; + } + } + + return isChanged; + } + bool Document::spritesheet_pack(int id, int padding) { struct RectI diff --git a/src/document.hpp b/src/document.hpp index 0fc0a76..830a189 100644 --- a/src/document.hpp +++ b/src/document.hpp @@ -52,6 +52,12 @@ namespace anm2ed SPRITESHEET }; + enum class RegionFrameMapping + { + PRESERVE, + SET + }; + std::filesystem::path path{}; uint64_t tabId{}; @@ -116,6 +122,8 @@ namespace anm2ed resource::Audio* sound_get(int); const resource::Audio* sound_get(int) const; bool regions_trim(int, const std::set&); + bool regions_generate_from_animations(const std::set&, const std::string&, RegionFrameMapping); + bool regions_generate_from_frames(const std::set&, const std::string&, RegionFrameMapping); bool spritesheet_pack(int, int); bool spritesheets_merge(const std::set&, bool, bool, bool, origin::Type); void scan_and_set_regions(); diff --git a/src/imgui/taskbar.cpp b/src/imgui/taskbar.cpp index c7fadbd..0106506 100644 --- a/src/imgui/taskbar.cpp +++ b/src/imgui/taskbar.cpp @@ -13,6 +13,7 @@ #include "strings.hpp" #include "toast.hpp" #include "types.hpp" +#include "util/imgui/input.hpp" #include "util/imgui/layout.hpp" #include "util/imgui/shortcut.hpp" @@ -23,6 +24,9 @@ using namespace glm; namespace anm2ed::imgui { + constexpr auto GENERATE_REGIONS_TARGET_SELECTION = 0; + constexpr auto GENERATE_REGIONS_TARGET_ALL = 1; + Options save_options_get(Settings& settings) { Flags flags{}; @@ -173,12 +177,9 @@ namespace anm2ed::imgui generatePopup.open(); ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_GENERATE_ANIMATION_FROM_GRID)); - bool isChangeAllFramesAvailable = frames && !frames->selection.empty() && itemType != ItemType::TRIGGER; - bool isChangeAllAnimationsAvailable = document && !document->animation.selection.empty(); - if (ImGui::MenuItem(localize.get(LABEL_CHANGE_ALL_FRAME_PROPERTIES), nullptr, false, - isChangeAllFramesAvailable || isChangeAllAnimationsAvailable)) - changePopup.open(); - ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_CHANGE_ALL_FRAME_PROPERTIES)); + if (ImGui::MenuItem(localize.get(LABEL_TASKBAR_GENERATE_REGIONS_FROM_ANIMATIONS), nullptr, false, document)) + generateRegionsPopup.open(); + ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_GENERATE_REGIONS_FROM_ANIMATIONS)); if (ImGui::MenuItem(localize.get(LABEL_SCAN_AND_SET_REGIONS), nullptr, false, document && hasRegions)) { @@ -196,6 +197,15 @@ namespace anm2ed::imgui ImGui::Separator(); + bool isChangeAllFramesAvailable = frames && !frames->selection.empty() && itemType != ItemType::TRIGGER; + bool isChangeAllAnimationsAvailable = document && !document->animation.selection.empty(); + if (ImGui::MenuItem(localize.get(LABEL_CHANGE_ALL_FRAME_PROPERTIES), nullptr, false, + isChangeAllFramesAvailable || isChangeAllAnimationsAvailable)) + changePopup.open(); + ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_WIZARD_CHANGE_ALL_FRAME_PROPERTIES)); + + ImGui::Separator(); + if (ImGui::MenuItem(localize.get(LABEL_TASKBAR_RENDER_ANIMATION), nullptr, false, animation && manager.isAbleToRecord)) renderPopup.open(); @@ -253,6 +263,62 @@ namespace anm2ed::imgui ImGui::EndPopup(); } + generateRegionsPopup.trigger(); + if (ImGui::BeginPopupModal(generateRegionsPopup.label(), &generateRegionsPopup.isOpen, ImGuiWindowFlags_NoResize)) + { + if (document) + { + ImGui::RadioButton(localize.get(LABEL_CURRENT_SELECTION), &generateRegionsTarget, + GENERATE_REGIONS_TARGET_SELECTION); + ImGui::SameLine(); + ImGui::RadioButton(localize.get(LABEL_ALL), &generateRegionsTarget, GENERATE_REGIONS_TARGET_ALL); + + input_text_string(localize.get(LABEL_FORMAT), &settings.generateRegionNameFormat); + ImGui::Checkbox(localize.get(LABEL_MAP_FRAMES_TO_REGIONS), &isGenerateRegionsMapFrames); + + auto widgetSize = widget_size_with_row_get(2); + if (ImGui::Button(localize.get(LABEL_GENERATE), widgetSize)) + { + std::set animationIndices{}; + if (generateRegionsTarget == GENERATE_REGIONS_TARGET_ALL) + { + if (auto animations = document->anm2.element_get(ElementType::ANIMATIONS)) + for (auto [i, animation] : std::views::enumerate(animations->children)) + if (animation.type == ElementType::ANIMATION) animationIndices.insert((int)i); + } + else + { + animationIndices.insert(document->animation.selection.begin(), document->animation.selection.end()); + if (animationIndices.empty() && document->reference.animationIndex >= 0) + animationIndices.insert(document->reference.animationIndex); + } + + auto queuedAnimationIndices = animationIndices; + auto queuedFormat = settings.generateRegionNameFormat; + auto queuedMapping = isGenerateRegionsMapFrames ? Document::RegionFrameMapping::SET + : Document::RegionFrameMapping::PRESERVE; + manager.command_push({manager.selected, + [=](Manager&, Document& document) + { + if (queuedAnimationIndices.empty()) return; + document.snapshot(localize.get(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS)); + if (document.regions_generate_from_animations(queuedAnimationIndices, queuedFormat, + queuedMapping)) + document.anm2_change(queuedMapping == Document::RegionFrameMapping::SET + ? Document::ALL + : Document::SPRITESHEETS); + }}); + generateRegionsPopup.close(); + } + + ImGui::SameLine(); + + if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) generateRegionsPopup.close(); + } + ImGui::EndPopup(); + } + generateRegionsPopup.end(); + changePopup.trigger(); if (ImGui::BeginPopupModal(changePopup.label(), &changePopup.isOpen, ImGuiWindowFlags_NoResize)) diff --git a/src/imgui/taskbar.hpp b/src/imgui/taskbar.hpp index 11d6e84..74604a9 100644 --- a/src/imgui/taskbar.hpp +++ b/src/imgui/taskbar.hpp @@ -35,12 +35,16 @@ namespace anm2ed::imgui Canvas generate; PopupHelper generatePopup{PopupHelper(LABEL_TASKBAR_GENERATE_ANIMATION_FROM_GRID)}; + PopupHelper generateRegionsPopup{ + PopupHelper(LABEL_TASKBAR_GENERATE_REGIONS_FROM_ANIMATIONS, imgui::POPUP_SMALL_NO_HEIGHT)}; PopupHelper changePopup{PopupHelper(LABEL_CHANGE_ALL_FRAME_PROPERTIES, imgui::POPUP_NORMAL_NO_HEIGHT)}; PopupHelper overwritePopup{PopupHelper(LABEL_TASKBAR_OVERWRITE_FILE, imgui::POPUP_SMALL_NO_HEIGHT)}; PopupHelper renderPopup{PopupHelper(LABEL_TASKBAR_RENDER_ANIMATION, imgui::POPUP_SMALL_NO_HEIGHT)}; PopupHelper configurePopup{PopupHelper(LABEL_TASKBAR_CONFIGURE)}; PopupHelper aboutPopup{PopupHelper(LABEL_TASKBAR_ABOUT)}; Settings editSettings{}; + int generateRegionsTarget{}; + bool isGenerateRegionsMapFrames{true}; bool isQuittingMode{}; bool save_execute(Manager&, Settings&, const PendingSave&); diff --git a/src/imgui/window/timeline.cpp b/src/imgui/window/timeline.cpp index 5b0661c..3175345 100644 --- a/src/imgui/window/timeline.cpp +++ b/src/imgui/window/timeline.cpp @@ -1807,6 +1807,24 @@ namespace anm2ed::imgui }); }; + auto make_many_regions = [&]() + { + auto targetFrames = frame_references_for_current_get(); + std::erase_if(targetFrames, + [&](const Reference& frameReference) + { + if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) return true; + auto item = item_get(frameReference.itemType, frameReference.itemID); + auto frame = item ? track_frame_get(*item, frameReference.frameIndex) : nullptr; + auto layer = layer_get(frameReference.itemID); + return !frame || frame->regionId != -1 || !layer || !spritesheet_get(layer->spritesheetId); + }); + if (targetFrames.size() < 2) return; + + makeManyRegionReferences = targetFrames; + makeManyRegionsPopup.open(); + }; + auto item = item_get(reference.itemType, reference.itemID); auto frame = frame_get(); auto selectedFrames = frame_references_for_current_get(); @@ -1814,6 +1832,17 @@ namespace anm2ed::imgui std::erase_if(selectedBakeFrames, [](const Reference& frameReference) { return frameReference.itemType == TRIGGER; }); auto isReverseFrames = is_frames_reverse_available(selectedFrames); + auto selectedRegionFrames = selectedFrames; + std::erase_if(selectedRegionFrames, + [&](const Reference& frameReference) + { + if (frameReference.itemType != LAYER || frameReference.frameIndex < 0) return true; + auto item = item_get(frameReference.itemType, frameReference.itemID); + auto frame = item ? track_frame_get(*item, frameReference.frameIndex) : nullptr; + auto layer = layer_get(frameReference.itemID); + return !frame || frame->regionId != -1 || !layer || !spritesheet_get(layer->spritesheetId); + }); + bool isMakeManyRegions = selectedRegionFrames.size() > 1; auto selectedRootFrames = selected_root_frame_references_get(); bool isMakeRegion = frame && reference.itemType == LAYER && reference.itemID != -1 && frame->regionId == -1 && layer_get(reference.itemID) && spritesheet_get(layer_get(reference.itemID)->spritesheetId); @@ -1848,10 +1877,16 @@ namespace anm2ed::imgui .isEnabled = [&]() { return animation && animation->frameNum != animation_length_get(*animation); }, .run = [&]() { fit_animation_length(); }}); actions.separator(); - actions.add({.label = LABEL_MAKE_REGION, + actions.add({.label = isMakeManyRegions ? LABEL_MAKE_MANY_REGIONS : LABEL_MAKE_REGION, .shortcut = -1, - .isEnabled = [&]() { return isMakeRegion; }, - .run = [&]() { make_region(); }}); + .isEnabled = [=]() { return isMakeManyRegions || isMakeRegion; }, + .run = [&]() + { + if (isMakeManyRegions) + make_many_regions(); + else + make_region(); + }}); actions.separator(); actions.add({.label = LABEL_DELETE, .shortcut = SHORTCUT_REMOVE, @@ -3717,6 +3752,33 @@ namespace anm2ed::imgui if (itemProperties.update(manager, settings, document, reference)) group_selection_reset_for(document); group_properties_update(); + makeManyRegionsPopup.trigger(); + if (ImGui::BeginPopupModal(makeManyRegionsPopup.label(), &makeManyRegionsPopup.isOpen, ImGuiWindowFlags_NoResize)) + { + input_text_string(localize.get(LABEL_FORMAT), &settings.generateRegionNameFormat); + ImGui::Checkbox(localize.get(LABEL_MAP_FRAMES_TO_REGIONS), &isMakeManyRegionsMapFrames); + + auto widgetSize = widget_size_with_row_get(2); + if (ImGui::Button(localize.get(LABEL_MAKE_MANY_REGIONS), widgetSize)) + { + auto targetFrames = makeManyRegionReferences; + auto format = settings.generateRegionNameFormat; + auto mapping = isMakeManyRegionsMapFrames ? Document::RegionFrameMapping::SET + : Document::RegionFrameMapping::PRESERVE; + edit_command_push(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, Document::ALL, + [=](Manager&, Document& document) mutable + { document.regions_generate_from_frames(targetFrames, format, mapping); }); + makeManyRegionsPopup.close(); + } + + ImGui::SameLine(); + + if (ImGui::Button(localize.get(BASIC_CANCEL), widgetSize)) makeManyRegionsPopup.close(); + + ImGui::EndPopup(); + } + makeManyRegionsPopup.end(); + bakePopup.trigger(); if (ImGui::BeginPopupModal(bakePopup.label(), &bakePopup.isOpen, ImGuiWindowFlags_NoResize)) diff --git a/src/imgui/window/timeline.hpp b/src/imgui/window/timeline.hpp index 068e1f8..ac0d211 100644 --- a/src/imgui/window/timeline.hpp +++ b/src/imgui/window/timeline.hpp @@ -58,9 +58,12 @@ namespace anm2ed::imgui popup::ItemProperties itemProperties{}; PopupHelper bakePopup{PopupHelper(LABEL_TIMELINE_BAKE_POPUP, POPUP_SMALL_NO_HEIGHT)}; PopupHelper bakeIntoOtherFramesPopup{PopupHelper(LABEL_BAKE_INTO_OTHER_FRAMES, POPUP_SMALL_NO_HEIGHT)}; + PopupHelper makeManyRegionsPopup{PopupHelper(LABEL_MAKE_MANY_REGIONS, POPUP_SMALL_NO_HEIGHT)}; BakeIntoOtherFramesTarget bakeIntoOtherFramesTarget{BakeIntoOtherFramesTarget::CURRENT_SELECTION}; bool isBakeIntoOtherFramesLayers{true}; bool isBakeIntoOtherFramesNulls{true}; + bool isMakeManyRegionsMapFrames{true}; + std::set makeManyRegionReferences{}; int hoveredTime{}; bool isFrameBoxPending{}; bool isFrameBoxSelecting{}; diff --git a/src/imgui/window/window.cpp b/src/imgui/window/window.cpp index 857134d..5f6ddbf 100644 --- a/src/imgui/window/window.cpp +++ b/src/imgui/window/window.cpp @@ -600,10 +600,30 @@ namespace anm2ed::imgui auto container = window_container_get(window, document.anm2); auto& storage = window.storage_get(document); auto& selection = storage.selection; - auto count = window_element_count_get(window, container); + std::vector ids{}; + if (container) + for (auto& element : container->children) + if (element.type == window.elementType) + { + auto key = window.element_key_get ? window.element_key_get(element, (int)ids.size()) : element.id; + ids.push_back(key); + } + auto count = (int)ids.size(); int index{}; + int scrollTargetId = -1; + int arrowSelectionId = -1; selection.start(count); + if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && + (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true) || ImGui::IsKeyPressed(ImGuiKey_DownArrow, true))) + { + auto nextId = window_arrow_selection_get(ids, storage.reference, selection); + if (nextId != -1) + { + arrowSelectionId = nextId; + scrollTargetId = nextId; + } + } if (container) { @@ -611,8 +631,9 @@ namespace anm2ed::imgui { if (element.type != window.elementType) continue; auto key = window.element_key_get ? window.element_key_get(element, index) : element.id; - auto isSelected = selection.contains(key); - auto isReferenced = window_flag_has(window.flags, WINDOW_REFERENCE_ITALIC) && storage.reference == key; + auto isSelected = selection.contains(key) || arrowSelectionId == key; + auto isReferenced = window_flag_has(window.flags, WINDOW_REFERENCE_ITALIC) && + (storage.reference == key || arrowSelectionId == key); auto font = window.row_font_get ? window.row_font_get(document, element, key) : isReferenced ? resource::font::ITALICS : resource::font::REGULAR; @@ -622,6 +643,7 @@ namespace anm2ed::imgui ImGui::SetNextItemSelectionUserData(key); auto label = window.row_label_get ? window.row_label_get(document, element) : element.name; if (isFontPushed) ImGui::PushFont(resources.fonts[font].get(), resource::font::SIZE); + if (scrollTargetId == key) ImGui::SetKeyboardFocusHere(); if (window_flag_has(window.flags, WINDOW_RENAME)) { @@ -658,7 +680,7 @@ namespace anm2ed::imgui if (isFontPushed) ImGui::PopFont(); - if (window.newElementId == key || window.scrollQueued == key) + if (window.newElementId == key || window.scrollQueued == key || scrollTargetId == key) { ImGui::SetScrollHereY(0.5f); if (window.newElementId == key) window.newElementId = -1; @@ -693,6 +715,15 @@ namespace anm2ed::imgui } selection.finish(); + if (arrowSelectionId != -1) + { + selection = {arrowSelectionId}; + storage.reference = arrowSelectionId; + if (window.row_select) window.row_select(window, document, arrowSelectionId); + } + if (shortcut(manager.chords[SHORTCUT_CONFIRM], shortcut::FOCUSED) && + window_flag_has(window.flags, WINDOW_PROPERTIES) && selection.size() == 1) + window_properties(window, manager, *selection.begin()); } void window_update(Window& window, Manager& manager, Settings& settings, Resources& resources, Dialog& dialog, @@ -1407,17 +1438,14 @@ namespace anm2ed::imgui } int scrollTargetId = -1; + int arrowSelectionId = -1; if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true) || ImGui::IsKeyPressed(ImGuiKey_DownArrow, true))) { auto nextId = window_arrow_selection_get(window.order, reference, selection); if (nextId != -1) { - selection = {nextId}; - reference = nextId; - document.reference = {document.reference.animationIndex}; - frame.reference = -1; - frame.selection.clear(); + arrowSelectionId = nextId; scrollTargetId = nextId; } } @@ -1436,12 +1464,13 @@ namespace anm2ed::imgui if (!region) continue; auto isNewRegion = window.newElementId == id; auto nameCStr = region->name.c_str(); - auto isSelected = selection.contains(id); - auto isReferenced = id == reference; + auto isSelected = selection.contains(id) || arrowSelectionId == id; + auto isReferenced = id == reference || arrowSelectionId == id; ImGui::PushID(id); window_scroll_to_item(regionChildSize.y, scrollTargetId == id); + if (scrollTargetId == id) ImGui::SetNextWindowFocus(); if (ImGui::BeginChild("##Region Child", regionChildSize, ImGuiChildFlags_Borders)) { @@ -1452,6 +1481,7 @@ namespace anm2ed::imgui ImGui::SetNextItemSelectionUserData(i); ImGui::SetNextItemStorageID(id); + if (scrollTargetId == id) ImGui::SetKeyboardFocusHere(); if (ImGui::Selectable("##Region Selectable", isSelected, 0, regionChildSize)) { document.editTarget = Document::EditTarget::REGION; @@ -1666,6 +1696,15 @@ namespace anm2ed::imgui ImGui::PopStyleVar(); selection.finish(); selection.set_index_map(nullptr); + if (arrowSelectionId != -1) + { + document.editTarget = Document::EditTarget::REGION; + selection = {arrowSelectionId}; + reference = arrowSelectionId; + document.reference = {document.reference.animationIndex}; + frame.reference = -1; + frame.selection.clear(); + } if (shortcut(manager.chords[SHORTCUT_ADD], shortcut::FOCUSED) && window.add) window_command_run(window, manager, settings, document, clipboard, window.add); @@ -1675,6 +1714,8 @@ namespace anm2ed::imgui window_command_run(window, manager, settings, document, clipboard, window.copy); if (shortcut(manager.chords[SHORTCUT_PASTE], shortcut::FOCUSED) && window.paste) window_command_run(window, manager, settings, document, clipboard, window.paste); + if (shortcut(manager.chords[SHORTCUT_CONFIRM], shortcut::FOCUSED) && selection.size() == 1 && window.properties) + window_command_run(window, manager, settings, document, clipboard, window.properties); }; window.context_update = [](Window& window, Manager& manager, Settings& settings, Resources&, Clipboard& clipboard, Document& document) @@ -2028,7 +2069,7 @@ namespace anm2ed::imgui } }; window.rows_update = - [](Window& window, Manager&, Settings&, Resources& resources, Clipboard&, Document& document, ImVec2) + [](Window& window, Manager& manager, Settings&, Resources& resources, Clipboard&, Document& document, ImVec2) { auto& selection = document.spritesheet.selection; auto& reference = document.spritesheet.reference; @@ -2065,16 +2106,14 @@ namespace anm2ed::imgui } int scrollTargetId = -1; + int arrowSelectionId = -1; if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true) || ImGui::IsKeyPressed(ImGuiKey_DownArrow, true))) { auto nextId = window_arrow_selection_get(ids, reference, selection); if (nextId != -1) { - selection = {nextId}; - reference = nextId; - region.reference = -1; - region.selection.clear(); + arrowSelectionId = nextId; scrollTargetId = nextId; } } @@ -2089,11 +2128,12 @@ namespace anm2ed::imgui ImGui::PushID(id); window_scroll_to_item(spritesheetChildSize.y, scrollTargetId == id); + if (scrollTargetId == id) ImGui::SetNextWindowFocus(); if (ImGui::BeginChild("##Spritesheet Child", spritesheetChildSize, ImGuiChildFlags_Borders)) { - auto isSelected = selection.contains(id); - auto isReferenced = id == reference; + auto isSelected = selection.contains(id) || arrowSelectionId == id; + auto isReferenced = id == reference || arrowSelectionId == id; auto cursorPos = ImGui::GetCursorPos(); auto textureInfo = document.texture_get(id); bool isValid = textureInfo && textureInfo->is_valid(); @@ -2104,6 +2144,7 @@ namespace anm2ed::imgui ImGui::SetNextItemSelectionUserData(id); ImGui::SetNextItemStorageID(id); + if (scrollTargetId == id) ImGui::SetKeyboardFocusHere(); if (ImGui::Selectable("##Spritesheet Selectable", isSelected, 0, spritesheetChildSize)) { document.editTarget = Document::EditTarget::SPRITESHEET; @@ -2207,6 +2248,17 @@ namespace anm2ed::imgui ImGui::PopStyleVar(); selection.finish(); + if (arrowSelectionId != -1) + { + document.editTarget = Document::EditTarget::SPRITESHEET; + selection = {arrowSelectionId}; + reference = arrowSelectionId; + region.reference = -1; + region.selection.clear(); + } + if (shortcut(manager.chords[SHORTCUT_CONFIRM], shortcut::FOCUSED) && reference != -1 && window.dialog) + if (auto spritesheet = document.anm2.element_get(ElementType::SPRITESHEET, reference)) + window_directory_open(*window.dialog, document, spritesheet->path); }; window.context_update = [](Window& window, Manager& manager, Settings& settings, Resources&, Clipboard& clipboard, Document& document) @@ -2704,14 +2756,14 @@ namespace anm2ed::imgui if (ImGui::Shortcut(ImGuiKey_Escape, ImGuiInputFlags_RouteFocused)) selection.clear(); int scrollTargetId = -1; + int arrowSelectionId = -1; if (ImGui::IsWindowFocused(ImGuiFocusedFlags_RootAndChildWindows) && (ImGui::IsKeyPressed(ImGuiKey_UpArrow, true) || ImGui::IsKeyPressed(ImGuiKey_DownArrow, true))) { auto nextId = window_arrow_selection_get(ids, reference, selection); if (nextId != -1) { - selection = {nextId}; - reference = nextId; + arrowSelectionId = nextId; scrollTargetId = nextId; } } @@ -2726,10 +2778,11 @@ namespace anm2ed::imgui ImGui::PushID(id); window_scroll_to_item(soundChildSize.y, scrollTargetId == id); + if (scrollTargetId == id) ImGui::SetNextWindowFocus(); if (ImGui::BeginChild("##Sound Child", soundChildSize, ImGuiChildFlags_Borders)) { - auto isSelected = selection.contains(id); + auto isSelected = selection.contains(id) || arrowSelectionId == id; auto cursorPos = ImGui::GetCursorPos(); auto audio = document.sound_get(id); bool isValid = audio && audio->is_valid(); @@ -2739,6 +2792,7 @@ namespace anm2ed::imgui ImGui::SetNextItemSelectionUserData(id); ImGui::SetNextItemStorageID(id); + if (scrollTargetId == id) ImGui::SetKeyboardFocusHere(); if (ImGui::Selectable("##Sound Selectable", isSelected, 0, soundChildSize)) { reference = id; @@ -2799,6 +2853,14 @@ namespace anm2ed::imgui ImGui::PopStyleVar(); selection.finish(); + if (arrowSelectionId != -1) + { + selection = {arrowSelectionId}; + reference = arrowSelectionId; + } + if (shortcut(manager.chords[SHORTCUT_CONFIRM], shortcut::FOCUSED) && reference != -1 && window.dialog) + if (auto sound = document.anm2.element_get(ElementType::SOUND_ELEMENT, reference)) + window_directory_open(*window.dialog, document, sound->path); if (shortcut(manager.chords[SHORTCUT_ADD], shortcut::FOCUSED) && window.add) window_command_run(window, manager, settings, document, clipboard, window.add); diff --git a/src/resource/strings.hpp b/src/resource/strings.hpp index 27a8160..b4ed9ec 100644 --- a/src/resource/strings.hpp +++ b/src/resource/strings.hpp @@ -144,6 +144,7 @@ namespace anm2ed X(EDIT_FRAME_TINT, "Frame Tint", "Matiz de Frame", "Оттенок кадра", "帧色调", "프레임 색조") \ X(EDIT_FRAME_VISIBILITY, "Frame Visibility", "Visibilidad de Frame", "Видимость кадра", "帧可见", "프레임 표시") \ X(EDIT_GENERATE_ANIMATION_FROM_GRID, "Generate Animation from Grid", "Generar Animacion Desde Cuadricula", "Создать анимацию с сетки", "从网格转换为动画", "격자로 애니메이션 생성") \ + X(EDIT_GENERATE_REGIONS_FROM_ANIMATIONS, "Generate Regions from Animations", "Generar regiones desde animaciones", "Создать регионы из анимаций", "从动画生成区域", "애니메이션에서 영역 생성") \ X(EDIT_INSERT_FRAME, "Insert Frame", "Insertar Frame", "Вставить кадр", "插入帧", "프레임 삽입하기") \ X(EDIT_LOOP, "Loop", "Loop", "Цикл", "循环", "반복") \ X(EDIT_MERGE_ANIMATIONS, "Merge Animations", "Combinar Animaciones", "Соединить анимации", "合并多个动画", "애니메이션 병합") \ @@ -296,6 +297,7 @@ namespace anm2ed X(LABEL_GENERATE_COUNT, "Count", "Conteo", "Кол-во", "数量", "프레임 수") \ X(LABEL_GENERATE_FRAME_SIZE, "Frame Size", "Tamaño de Frame", "Размер кадра", "单帧大小", "프레임 크기") \ X(LABEL_GENERATE_MAKE_REGIONS, "Make Regions", "Crear Regiones", "Создать регионы", "创建区域", "영역 만들기") \ + X(LABEL_GENERATE_REGIONS_FROM_ANIMATIONS, "Generate Regions from Animations", "Generar regiones desde animaciones", "Создать регионы из анимаций", "从动画生成区域", "애니메이션에서 영역 생성") \ X(LABEL_GENERATE_ROWS, "Rows", "Filas", "Ряды", "行", "행") \ X(LABEL_GENERATE_START_POSITION, "Start Position", "Poscicion de Inicio", "Начальная позиция", "起始位置", "시작 위치") \ X(LABEL_ALL, "All", "Todo", "Все", "全部", "전체") \ @@ -315,6 +317,8 @@ namespace anm2ed X(LABEL_ITEMS, "Items", "Items", "Предметы", "物品", "항목") \ X(LABEL_LOCALIZATION, "Localization", "Localizacion", "Локализация", "本地化", "현지화") \ X(LABEL_MAKE_REGION, "Make Region", "Crear Región", "Создать регион", "创建区域", "영역 만들기") \ + X(LABEL_MAKE_MANY_REGIONS, "Make Many Regions", "Crear varias regiones", "Создать несколько регионов", "创建多个区域", "여러 영역 만들기") \ + X(LABEL_MAP_FRAMES_TO_REGIONS, "Set frames to use generated regions", "Configurar frames para usar regiones generadas", "Настроить кадры на использование созданных регионов", "设置帧使用生成的区域", "프레임이 생성된 영역을 사용하도록 설정") \ X(LABEL_LOOP, "Loop", "Loop", "Цикл", "循环", "반복") \ X(LABEL_MANAGER_ANM2_DRAG_DROP, "Anm2 Drag Drop", "Arrastrar y Soltar Anm2", "Anm2 Drag Drop", "Anm2 拖放", "Anm2 드래그 앤 드롭") \ X(LABEL_GROUP_PROPERTIES, "Group Properties", "Propiedades de grupo", "Свойства группы", "组属性", "그룹 속성") \ @@ -384,6 +388,7 @@ namespace anm2ed X(LABEL_TASKBAR_ABOUT, "About", "Sobre", "О", "关于", "정보") \ X(LABEL_TASKBAR_CONFIGURE, "Configure", "Configurar", "Конфигурация", "配置", "구성 설정") \ X(LABEL_TASKBAR_GENERATE_ANIMATION_FROM_GRID, "Generate Animation from Grid", "Generar Animacion desde Cuadricula", "Создать анимацию с сетки", "从网格转换为动画", "격자로 애니메이션 생성") \ + X(LABEL_TASKBAR_GENERATE_REGIONS_FROM_ANIMATIONS, "Generate Regions from Animations", "Generar regiones desde animaciones", "Создать регионы из анимаций", "从动画生成区域", "애니메이션에서 영역 생성") \ X(LABEL_TASKBAR_OVERWRITE_FILE, "Overwrite File", "Sobreescribir Archivo", "Перезапись файла", "覆盖文件", "파일 덮어쓰기") \ X(LABEL_TASKBAR_RENDER_ANIMATION, "Render Animation", "Renderizar Animacion", "Рендер анимации", "生成动画", "애니메이션 렌더링") \ X(LABEL_THEME, "Theme", "Tema", "Тема", "主题", "테마") \ @@ -703,6 +708,7 @@ namespace anm2ed X(TOOLTIP_UNUSED_ITEMS_SHOWN, "Unused layers/nulls are shown. Press to hide them.", "Las capas/nulls no utilizados estan visibles. Presiona para ocultarlos", "Неиспользуемые слои/нули видимы. Нажмите, чтобы их скрыть.", "正在显示未使用的动画层/Null. 点击以隐藏它们.", "사용되지 않는 레이어/Null이 표시되어 있습니다. 숨기려면 누르세요.") \ X(TOOLTIP_USE_DEFAULT_SETTINGS, "Reset the settings to their defaults.", "Reinicia las configuraciones a sus predeterminados.", "Сбросить настройки на настройки по умолчанию.", "重设所有设置为默认.", "설정을 기본값으로 재설정합니다.") \ X(TOOLTIP_WIZARD_GENERATE_ANIMATION_FROM_GRID, "Generate frames in the current selected animation item from grid values.", "Genera frames en el item de animacion seleccionado actualmente a partir de valores de la cuadricula.", "Создает кадры в текущем выбранном элементе анимации на основе значений сетки.", "根据网格值在当前选中的动画项目中生成帧。", "현재 선택된 애니메이션 항목에서 그리드 값으로 프레임을 생성합니다.") \ + X(TOOLTIP_WIZARD_GENERATE_REGIONS_FROM_ANIMATIONS, "Create spritesheet regions from layer frames in selected animations.", "Crea regiones de spritesheet desde frames de capas en las animaciones seleccionadas.", "Создает регионы спрайт-листа из кадров слоев выбранных анимаций.", "从所选动画的图层帧创建图集区域。", "선택한 애니메이션의 레이어 프레임에서 스프라이트 시트 영역을 만듭니다.") \ X(TOOLTIP_WIZARD_CHANGE_ALL_FRAME_PROPERTIES, "Change certain properties of selected frames.\n(Note: this will also appear in Frame Properties when multiselecting frames.)", "Cambia ciertas propiedades de los frames seleccionados.\n(Nota: esto tambien aparecera en Propiedades de Frame al seleccionar multiples frames.)", "Изменить некоторые свойства выбранных кадров.\n(Примечание: это также появится в \"Свойствах кадра\" при выборе нескольких кадров.)", "更改所选帧的某些属性。\n(注意:在多选帧时,这也会显示在“帧属性”中。)", "선택한 프레임의 일부 속성을 변경합니다.\n(참고: 프레임을 여러 개 선택하면 프레임 속성에도 표시됩니다.)") \ X(TOOLTIP_WIZARD_RENDER_ANIMATION, "Render the animation into a media format.\n(Note: this requires FFmpeg!)", "Renderiza la animacion a un formato multimedia.\n(Nota: esto requiere FFmpeg!)", "Рендерит анимацию в медиаформат.\n(Примечание: требуется FFmpeg!)", "将动画渲染为媒体格式。\n(注意:需要 FFmpeg!)", "애니메이션을 미디어 형식으로 렌더링합니다.\n(참고: FFmpeg가 필요합니다!)") \ X(TOOLTIP_WIZARD_SCAN_AND_SET_REGIONS, "Match all regionless frames in all animations in the document to a region, if a matching region exists and matches the frame's relevant values.", "Empareja todos los frames sin region de todas las animaciones del documento con una region, si existe una region coincidente y coincide con los valores relevantes del frame.", "Сопоставляет все кадры без региона во всех анимациях документа с регионом, если существует подходящий регион и его релевантные значения совпадают со значениями кадра.", "将文档中所有动画里无区域的帧与区域进行匹配;若存在匹配区域且其相关值与帧一致,则进行设置。", "문서의 모든 애니메이션에서 영역이 없는 프레임을 영역과 매칭합니다. 일치하는 영역이 있고 프레임의 관련 값이 일치하면 설정합니다.") \ diff --git a/workshop/metadata.xml b/workshop/metadata.xml index bef6451..92684c3 100644 --- a/workshop/metadata.xml +++ b/workshop/metadata.xml @@ -53,6 +53,6 @@ Alternatively, if you have subscribed to the mod, you can find the latest releas [h3]Happy animating![/h3] [img]https://files.catbox.moe/4auc1c.gif[/img] - 2.24 + 2.25 Public