Libraries window, animation layers and child playback
A Libraries window (docked with Spritesheets and Sounds) links other .anm2 files: cards list each one's animations, open it as a tab, and reload when it changes on disk. A layer's Source is a spritesheet or an animation, from this file or a library; the preview, renders and CLI draw the child in the layer's frame. Animation-layer keyframes set the child's animation, mode (loop, once, hold), start frame (or random) and restart; Child is also a copyable frame property. All of it is editor-only and counted by the Isaac warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6edf5f0e5b
commit
d1a6d89d14
44 files changed
+873
-81
No files matched your search
@@ -30,6 +30,7 @@ namespace anm2ed::imgui
|
||||
X(ACTION_REPLACE, BASIC_REPLACE, -1) \
|
||||
X(ACTION_SAVE, BASIC_SAVE, -1) \
|
||||
X(ACTION_EXPORT, BASIC_EXPORT, -1) \
|
||||
X(ACTION_OPEN, BASIC_OPEN, -1) \
|
||||
X(ACTION_OPEN_DIRECTORY, BASIC_OPEN_DIRECTORY, -1) \
|
||||
X(ACTION_SET_FILE_PATH, BASIC_SET_FILE_PATH, -1) \
|
||||
X(ACTION_PACK, BASIC_PACK, -1) \
|
||||
|
||||
@@ -9,12 +9,16 @@ namespace anm2ed::imgui
|
||||
if (auto document = manager.get(); document)
|
||||
if (settings.windowIsAnimationPreview) animationPreview.tick(manager, settings, deltaSeconds);
|
||||
|
||||
if (!settings.fileIsAutoReloadSpritesheets) return;
|
||||
spritesheetReloadTime += deltaSeconds;
|
||||
if (spritesheetReloadTime < AUTO_RELOAD_INTERVAL) return;
|
||||
spritesheetReloadTime = 0.0f;
|
||||
// Files changed on disk are picked up every few seconds: libraries always, spritesheets when set to.
|
||||
reloadTime += deltaSeconds;
|
||||
if (reloadTime < AUTO_RELOAD_INTERVAL) return;
|
||||
reloadTime = 0.0f;
|
||||
for (auto& document : manager.documents)
|
||||
{
|
||||
document.libraries_reload();
|
||||
if (!settings.fileIsAutoReloadSpritesheets) continue;
|
||||
if (auto ids = document.spritesheets_changed_get(); !ids.empty()) document.spritesheets_reload(ids);
|
||||
}
|
||||
}
|
||||
|
||||
void Dockspace::update(Taskbar& taskbar, Documents& documents, Manager& manager, Settings& settings,
|
||||
@@ -68,6 +72,7 @@ namespace anm2ed::imgui
|
||||
shaders_update(panel, shaders);
|
||||
}
|
||||
if (settings.windowIsSounds) panel_update(sounds, sounds_update);
|
||||
if (settings.windowIsLibraries) panel_update(libraries, libraries_update);
|
||||
if (settings.windowIsSpritesheetEditor) spritesheetEditor.update(manager, settings, resources);
|
||||
if (settings.windowIsSpritesheets)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
AnimationPreview animationPreview;
|
||||
bool isCanvasFocused{};
|
||||
float spritesheetReloadTime{};
|
||||
float reloadTime{};
|
||||
AnimationsPanel animations{};
|
||||
RegionsPanel regions{};
|
||||
PanelState events{};
|
||||
@@ -26,6 +26,7 @@ namespace anm2ed::imgui
|
||||
SpritesheetEditor spritesheetEditor;
|
||||
SpritesheetsPanel spritesheets{};
|
||||
PanelState sounds{};
|
||||
PanelState libraries{};
|
||||
Timeline timeline;
|
||||
PopupHelper toolsColorEditPopup{PopupHelper(LABEL_TOOLS_COLOR_EDIT_POPUP, POPUP_TO_CONTENT, POPUP_BY_ITEM)};
|
||||
AutosaveRestore autosaveRestore;
|
||||
|
||||
@@ -387,7 +387,8 @@ namespace anm2ed::imgui
|
||||
{issues.skewFrames, FORMAT_ISAAC_SKEW_FRAMES},
|
||||
{issues.shaderFrames, FORMAT_ISAAC_SHADER_FRAMES},
|
||||
{issues.depthFrames, FORMAT_ISAAC_DEPTH_FRAMES},
|
||||
{issues.triggerSounds, FORMAT_ISAAC_TRIGGER_SOUNDS}})
|
||||
{issues.triggerSounds, FORMAT_ISAAC_TRIGGER_SOUNDS},
|
||||
{issues.animationLayers, FORMAT_ISAAC_ANIMATION_LAYERS}})
|
||||
if (count > 0) ImGui::BulletText("%s", localize_format(format, count).c_str());
|
||||
}
|
||||
ImGui::TextWrapped("%s", localize.get(TEXT_ISAAC_EDITOR_COPY));
|
||||
|
||||
@@ -111,12 +111,14 @@ namespace anm2ed::imgui
|
||||
std::optional<vec4> rect{};
|
||||
|
||||
if (animation)
|
||||
rect = animation_rects_merge(rect, model::animation_rect(document.model, *animation, isRootTransform));
|
||||
rect = animation_rects_merge(
|
||||
rect, model::animation_rect(document.model, *animation, isRootTransform, document.library_resolver_get()));
|
||||
|
||||
if (auto overlayDocument = overlay_animation_document_get(manager, document))
|
||||
if (auto overlayAnimation = overlayDocument->model.animation_get(document.overlayIndex))
|
||||
rect = animation_rects_merge(rect,
|
||||
model::animation_rect(overlayDocument->model, *overlayAnimation, isRootTransform));
|
||||
model::animation_rect(overlayDocument->model, *overlayAnimation, isRootTransform,
|
||||
overlayDocument->library_resolver_get()));
|
||||
|
||||
return rect;
|
||||
}
|
||||
@@ -296,7 +298,9 @@ namespace anm2ed::imgui
|
||||
|
||||
auto fit_view = [&]()
|
||||
{
|
||||
if (animation) set_to_rect(zoom, pan, model::animation_rect(model, *animation, isRootTransform));
|
||||
if (animation)
|
||||
set_to_rect(zoom, pan,
|
||||
model::animation_rect(model, *animation, isRootTransform, document.library_resolver_get()));
|
||||
};
|
||||
|
||||
manager.isAbleToRecord = false;
|
||||
@@ -677,7 +681,9 @@ namespace anm2ed::imgui
|
||||
auto isActiveDocument = &sampleDocument == &document;
|
||||
auto& sampleModel = sampleDocument.model;
|
||||
auto targetIcon = resources.icon_id_get(isAltIcons && !isIsolated ? icon::TARGET_ALT : icon::TARGET);
|
||||
for (const auto& draw : model::animation_draws_get(sampleModel, sampleAnimation, drawOptions))
|
||||
auto sampleOptions = drawOptions;
|
||||
sampleOptions.library_get = sampleDocument.library_resolver_get();
|
||||
for (const auto& draw : model::animation_draws_get(sampleModel, sampleAnimation, sampleOptions))
|
||||
{
|
||||
auto isOnion = draw.sample != -1;
|
||||
if (isOnion && isOnlySelected && !(isActiveDocument && is_draw_selected(draw))) continue;
|
||||
@@ -709,8 +715,7 @@ namespace anm2ed::imgui
|
||||
}
|
||||
else if (draw.type == model::DrawType::LAYER)
|
||||
{
|
||||
auto layer = model::item_get(sampleModel.content.layers, draw.id);
|
||||
auto layerTexture = sampleDocument.texture_get(layer->spritesheetId);
|
||||
auto layerTexture = sampleDocument.draw_image_get(draw);
|
||||
if (!layerTexture || !layerTexture->is_valid() || layerTexture->size.x <= 0 || layerTexture->size.y <= 0)
|
||||
continue;
|
||||
auto textureSize = vec2(layerTexture->size);
|
||||
@@ -769,8 +774,10 @@ namespace anm2ed::imgui
|
||||
pivotPathsKey = key;
|
||||
pivotPaths.clear();
|
||||
for (int time = 0; time < animation->frameNum; ++time)
|
||||
for (const auto& draw : model::animation_draws_get(
|
||||
model, *animation, {.time = (float)time, .isRootTransform = isRootTransform}))
|
||||
for (const auto& draw : model::animation_draws_get(model, *animation,
|
||||
{.time = (float)time,
|
||||
.isRootTransform = isRootTransform,
|
||||
.library_get = document.library_resolver_get()}))
|
||||
{
|
||||
auto path = std::ranges::find_if(pivotPaths,
|
||||
[&](const PivotPath& path)
|
||||
|
||||
@@ -208,13 +208,17 @@ namespace anm2ed::imgui
|
||||
}
|
||||
else
|
||||
{
|
||||
auto layer = type == LAYER ? model::item_get(model.content.layers, reference.itemID) : nullptr;
|
||||
auto isAnimationLayer = layer && layer->is_animation();
|
||||
bool isRegionSet = frame && displayFrame.regionId != -1 && displayFrame.crop == frame->crop &&
|
||||
displayFrame.size == frame->size && displayFrame.pivot == frame->pivot;
|
||||
for (auto& field : VEC2_FIELDS)
|
||||
{
|
||||
const auto& source = field.isRegionField ? displayFrame : useFrame;
|
||||
auto value = frame ? source.*field.member : vec2();
|
||||
ImGui::BeginDisabled(field.isRegionField && (type == ROOT || type == NULL_ || isRegionSet));
|
||||
// An animation layer's pivot is where its child's origin goes; it has no crop or size.
|
||||
ImGui::BeginDisabled(field.isRegionField && (type == ROOT || type == NULL_ || isRegionSet ||
|
||||
(isAnimationLayer && field.member != &model::Frame::pivot)));
|
||||
auto state =
|
||||
drag_float2_persistent(localize.get(field.label), frame ? &value : &dummy_value<vec2>(), DRAG_SPEED,
|
||||
0.0f, 0.0f, frame ? vec2_format_get(source.*field.member) : "");
|
||||
@@ -273,7 +277,7 @@ namespace anm2ed::imgui
|
||||
const Reference&) { frame.colorOffset = colorOffset; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_COLOR_OFFSET));
|
||||
|
||||
ImGui::BeginDisabled(type != LAYER);
|
||||
ImGui::BeginDisabled(type != LAYER || isAnimationLayer);
|
||||
if (combo_id_mapped(localize.get(BASIC_REGION), frame ? &useFrame.regionId : &dummy_value_negative<int>(),
|
||||
regions.ids, regions.labels) &&
|
||||
frame)
|
||||
@@ -301,7 +305,7 @@ namespace anm2ed::imgui
|
||||
{ frame.interpolation = static_cast<Interpolation>(interpolationValue); });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FRAME_INTERPOLATION));
|
||||
|
||||
ImGui::BeginDisabled(type != LAYER);
|
||||
ImGui::BeginDisabled(type != LAYER || isAnimationLayer);
|
||||
if (combo_id_mapped(localize.get(BASIC_SHADER), frame ? &useFrame.shaderId : &dummy_value_negative<int>(),
|
||||
shaders.ids, shaders.labels) &&
|
||||
frame)
|
||||
@@ -324,6 +328,44 @@ namespace anm2ed::imgui
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FRAME_VISIBILITY));
|
||||
|
||||
if (isAnimationLayer && frame)
|
||||
{
|
||||
ImGui::SeparatorText(localize.get(LABEL_CHILD));
|
||||
auto values = document.animation_names_get(layer->libraryId);
|
||||
auto labels = values;
|
||||
values.insert(values.begin(), std::string{});
|
||||
labels.insert(labels.begin(), localize.get(TEXT_LAYER_ANIMATION));
|
||||
bool isChildChanged =
|
||||
combo_string_mapped(localize.get(LABEL_ANIMATION), &useFrame.childAnimation, values, labels);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_ANIMATION));
|
||||
|
||||
const char* modeLabels[] = {localize.get(LABEL_LOOP), localize.get(LABEL_ONCE), localize.get(LABEL_HOLD)};
|
||||
auto mode = (int)useFrame.childMode;
|
||||
if (ImGui::Combo(localize.get(BASIC_MODE), &mode, modeLabels, (int)std::size(modeLabels)))
|
||||
{
|
||||
useFrame.childMode = (ChildMode)mode;
|
||||
isChildChanged = true;
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_MODE));
|
||||
|
||||
ImGui::BeginDisabled(useFrame.isChildStartRandom);
|
||||
isChildChanged |= input_int_range(localize.get(LABEL_START_FRAME), useFrame.childStart, 0, FRAME_NUM_MAX,
|
||||
STEP, STEP_FAST);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_START));
|
||||
ImGui::EndDisabled();
|
||||
|
||||
isChildChanged |= ImGui::Checkbox(localize.get(LABEL_RANDOM), &useFrame.isChildStartRandom);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_START_RANDOM));
|
||||
ImGui::SameLine();
|
||||
isChildChanged |= ImGui::Checkbox(localize.get(LABEL_RESTART), &useFrame.isChildRestart);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHILD_RESTART));
|
||||
|
||||
if (isChildChanged)
|
||||
frame_edit(edit_state::COMPLETE, EDIT_FRAME_CHILD,
|
||||
[child = useFrame](Document&, model::Frame& frame, model::Track*, const Reference&)
|
||||
{ edit::frame_property_copy(frame, child, edit::FrameProperty::CHILD); });
|
||||
}
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
for (int axis = 0; axis < (int)std::size(FLIP_BUTTONS); ++axis)
|
||||
|
||||
@@ -9,7 +9,8 @@ using namespace anm2ed::types;
|
||||
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
constexpr int ITEM_PROPERTIES_ROWS = 2;
|
||||
constexpr int NULL_PROPERTIES_ROWS = 2;
|
||||
constexpr int LAYER_PROPERTIES_ROWS = 4;
|
||||
|
||||
auto& layers_get(model::Model& model) { return model.content.layers; }
|
||||
auto& nulls_get(model::Model& model) { return model.content.nulls; }
|
||||
@@ -23,7 +24,7 @@ namespace anm2ed::imgui
|
||||
|
||||
// The layer/null properties popup: adds a new item (id -1) or replaces the edited one, then selects it.
|
||||
template <class Item, class ItemsGet, class FieldsDraw>
|
||||
void item_properties_update(Panel& panel, int popupIndex, SelectionKind kind, StringType nameTooltip,
|
||||
void item_properties_update(Panel& panel, int popupIndex, int rows, SelectionKind kind, StringType nameTooltip,
|
||||
StringType addEdit, StringType propertiesEdit, ItemsGet items_get,
|
||||
FieldsDraw&& fields_draw)
|
||||
{
|
||||
@@ -34,7 +35,7 @@ namespace anm2ed::imgui
|
||||
popup.trigger();
|
||||
if (ImGui::BeginPopupModal(popup.label(), &popup.isOpen, ImGuiWindowFlags_NoResize))
|
||||
{
|
||||
if (ImGui::BeginChild("##Child", child_size_get(ITEM_PROPERTIES_ROWS), ImGuiChildFlags_Borders))
|
||||
if (ImGui::BeginChild("##Child", child_size_get(rows), ImGuiChildFlags_Borders))
|
||||
{
|
||||
if (popup.isJustOpened) ImGui::SetKeyboardFocusHere();
|
||||
input_text_string(localize.get(BASIC_NAME), &edit.name);
|
||||
@@ -49,6 +50,12 @@ namespace anm2ed::imgui
|
||||
Item item{.name = edit.name};
|
||||
if constexpr (requires { item.spritesheetId; }) item.spritesheetId = edit.spritesheetId;
|
||||
if constexpr (requires { item.isShowRect; }) item.isShowRect = edit.isShowRect;
|
||||
if constexpr (requires { item.animation; })
|
||||
if (edit.isAnimation)
|
||||
{
|
||||
item.libraryId = edit.libraryId;
|
||||
item.animation = edit.animation;
|
||||
}
|
||||
auto& state = panel.state;
|
||||
command_push(panel,
|
||||
[&state, item, id = edit.id, kind, addEdit, propertiesEdit, items_get](Document& document)
|
||||
@@ -115,6 +122,9 @@ namespace anm2ed::imgui
|
||||
[&](int id)
|
||||
{
|
||||
auto layer = model::item_get(layers, id);
|
||||
if (layer->is_animation())
|
||||
return std::vformat(localize.get(FORMAT_LAYER_ANIMATION),
|
||||
std::make_format_args(layer->id, layer->name, layer->animation));
|
||||
return std::vformat(localize.get(FORMAT_LAYER),
|
||||
std::make_format_args(layer->id, layer->name, layer->spritesheetId));
|
||||
},
|
||||
@@ -133,12 +143,37 @@ namespace anm2ed::imgui
|
||||
ImGui::End();
|
||||
|
||||
item_properties_update<model::Layer>(
|
||||
panel, 0, SelectionKind::LAYERS, TOOLTIP_ITEM_NAME, EDIT_ADD_LAYER, EDIT_SET_LAYER_PROPERTIES, layers_get,
|
||||
panel, 0, LAYER_PROPERTIES_ROWS, SelectionKind::LAYERS, TOOLTIP_ITEM_NAME, EDIT_ADD_LAYER,
|
||||
EDIT_SET_LAYER_PROPERTIES, layers_get,
|
||||
[&](Manager::ItemEdit& layer)
|
||||
{
|
||||
auto spritesheets = document.choices_get(SelectionKind::SPRITESHEETS);
|
||||
combo_id_mapped(localize.get(LABEL_SPRITESHEET), &layer.spritesheetId, spritesheets.ids, spritesheets.labels);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
||||
ImGui::TextUnformatted(localize.get(LABEL_LAYER_SOURCE));
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SOURCE));
|
||||
for (auto [label, isAnimation] : {std::pair{LABEL_SPRITESHEET, false}, std::pair{LABEL_ANIMATION, true}})
|
||||
{
|
||||
ImGui::SameLine();
|
||||
if (ImGui::RadioButton(localize.get(label), layer.isAnimation == isAnimation))
|
||||
layer.isAnimation = isAnimation;
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SOURCE));
|
||||
}
|
||||
|
||||
if (!layer.isAnimation)
|
||||
{
|
||||
auto spritesheets = document.choices_get(SelectionKind::SPRITESHEETS);
|
||||
combo_id_mapped(localize.get(LABEL_SPRITESHEET), &layer.spritesheetId, spritesheets.ids,
|
||||
spritesheets.labels);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_SPRITESHEET));
|
||||
return;
|
||||
}
|
||||
|
||||
auto libraries = document.choices_get(SelectionKind::LIBRARIES);
|
||||
libraries.labels.front() = localize.get(TEXT_THIS_FILE);
|
||||
combo_id_mapped(localize.get(LABEL_LIBRARY), &layer.libraryId, libraries.ids, libraries.labels);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_LIBRARY));
|
||||
auto names = document.animation_names_get(layer.libraryId);
|
||||
if (layer.animation.empty() && !names.empty()) layer.animation = names.front();
|
||||
combo_string_mapped(localize.get(LABEL_ANIMATION), &layer.animation, names, names);
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_LAYER_ANIMATION));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -166,8 +201,8 @@ namespace anm2ed::imgui
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
item_properties_update<model::Null>(panel, 1, SelectionKind::NULLS, TOOLTIP_NULL_NAME, EDIT_ADD_NULL,
|
||||
EDIT_SET_NULL_PROPERTIES, nulls_get,
|
||||
item_properties_update<model::Null>(panel, 1, NULL_PROPERTIES_ROWS, SelectionKind::NULLS, TOOLTIP_NULL_NAME,
|
||||
EDIT_ADD_NULL, EDIT_SET_NULL_PROPERTIES, nulls_get,
|
||||
[](Manager::ItemEdit& null)
|
||||
{
|
||||
ImGui::Checkbox(localize.get(LABEL_RECT), &null.isShowRect);
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
#include "panel.hpp"
|
||||
|
||||
#include <format>
|
||||
|
||||
#include "path.hpp"
|
||||
|
||||
using namespace anm2ed::resource;
|
||||
using namespace anm2ed::types;
|
||||
using namespace anm2ed::util;
|
||||
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
constexpr int LIBRARY_CARD_LINES = 2;
|
||||
|
||||
auto& libraries_get(model::Model& model) { return model.content.libraries; }
|
||||
|
||||
void libraries_update(Panel& panel)
|
||||
{
|
||||
auto& [manager, settings, resources, dialog, clipboard, document, state] = panel;
|
||||
auto& libraries = document.model.content.libraries;
|
||||
auto selection = document.selected_ids_get(SelectionKind::LIBRARIES);
|
||||
|
||||
if (dialog.is_selected(Dialog::LIBRARY_OPEN))
|
||||
{
|
||||
command_push(panel,
|
||||
[&state, paths = dialog.paths](Document& document)
|
||||
{
|
||||
document.libraries_add(paths);
|
||||
state.newId = document.focused_id_get(SelectionKind::LIBRARIES);
|
||||
});
|
||||
dialog.reset();
|
||||
}
|
||||
|
||||
if (ImGui::Begin(localize.get(LABEL_LIBRARIES_WINDOW), &settings.windowIsLibraries))
|
||||
{
|
||||
auto isOne = [selection]() { return selection.size() == 1; };
|
||||
auto loaded_get = [&](int id) { return document.library_get(document.model, id); };
|
||||
// Opens the library as its own tab, or switches to it when it already is one.
|
||||
auto open = [&](int id)
|
||||
{
|
||||
manager.command_push({.runManager = [path = document.library_path_get(id)](Manager& manager)
|
||||
{
|
||||
for (int i = 0; i < (int)manager.documents.size(); ++i)
|
||||
{
|
||||
std::error_code ec{};
|
||||
if (!std::filesystem::equivalent(manager.documents[i].path, path, ec)) continue;
|
||||
manager.pendingSelected = i;
|
||||
return manager.set(i);
|
||||
}
|
||||
manager.open(path);
|
||||
}});
|
||||
};
|
||||
|
||||
Actions actions{};
|
||||
actions.add(ACTION_OPEN, isOne, [&]() { open(*selection.begin()); }, TOOLTIP_LIBRARY_OPEN);
|
||||
actions.add(ACTION_OPEN_DIRECTORY, isOne,
|
||||
[&]() { directory_open(dialog, document, model::item_get(libraries, *selection.begin())->path); });
|
||||
actions.add(ACTION_ADD, {}, [&]() { dialog.file_open(Dialog::LIBRARY_OPEN, true); }, TOOLTIP_LIBRARY_ADD);
|
||||
actions.add(
|
||||
ACTION_REMOVE_UNUSED, {},
|
||||
[&]() { items_unused_remove(panel, ElementType::LIBRARY, EDIT_REMOVE_UNUSED_LIBRARIES, libraries_get); },
|
||||
TOOLTIP_REMOVE_UNUSED_LIBRARIES);
|
||||
actions.add(
|
||||
ACTION_RELOAD, [selection]() { return !selection.empty(); },
|
||||
[&]()
|
||||
{
|
||||
command_push(panel,
|
||||
[selection](Document& document)
|
||||
{
|
||||
for (auto id : selection)
|
||||
if (auto library = model::item_get(document.model.content.libraries, id))
|
||||
{
|
||||
document.library_reload(id);
|
||||
toast_log(Level::INFO, TOAST_RELOAD_LIBRARY, id, path::to_utf8(library->path));
|
||||
}
|
||||
});
|
||||
},
|
||||
TOOLTIP_RELOAD_LIBRARIES);
|
||||
items_clipboard_actions_add<model::Library>(actions, panel, SelectionKind::LIBRARIES, EDIT_PASTE_LIBRARIES,
|
||||
TOAST_DESERIALIZE_LIBRARIES_FAILED, libraries_get);
|
||||
|
||||
ListRows rows{.label_get =
|
||||
[&](int id)
|
||||
{
|
||||
auto pathString = path::to_utf8(model::item_get(libraries, id)->path);
|
||||
return std::vformat(localize.get(FORMAT_SOUND), std::make_format_args(id, pathString));
|
||||
},
|
||||
.tooltip_draw =
|
||||
[&](int id)
|
||||
{
|
||||
auto loaded = loaded_get(id);
|
||||
tooltip_name_draw(resources, path::to_utf8(model::item_get(libraries, id)->path));
|
||||
ImGui::Text("%s: %d", localize.get(BASIC_ID), id);
|
||||
if (loaded && loaded->model.isValid)
|
||||
ImGui::TextUnformatted(localize.get(TOOLTIP_LIBRARY_OPEN));
|
||||
else
|
||||
{
|
||||
ImGui::Spacing();
|
||||
ImGui::TextWrapped("%s", localize.get(TOOLTIP_LIBRARY_INVALID));
|
||||
}
|
||||
},
|
||||
.image_get =
|
||||
[&](int id)
|
||||
{
|
||||
auto loaded = loaded_get(id);
|
||||
auto isValid = loaded && loaded->model.isValid;
|
||||
auto& texture = resources.icons[isValid ? icon::ANIMATION : icon::NONE];
|
||||
return CardImage{.texture = &texture, .size = glm::vec2(texture.size), .isValid = isValid};
|
||||
},
|
||||
.activate = open,
|
||||
.children_draw =
|
||||
[&](int id)
|
||||
{
|
||||
auto loaded = loaded_get(id);
|
||||
if (!loaded || !loaded->model.isValid) return;
|
||||
auto animations = loaded->model.animations_get();
|
||||
auto count = animations.size();
|
||||
auto label = std::vformat(localize.get(FORMAT_LIBRARY_ANIMATIONS), std::make_format_args(count));
|
||||
ImGui::PushID(id);
|
||||
if (ImGui::TreeNodeEx(label.c_str(), ImGuiTreeNodeFlags_SpanAvailWidth))
|
||||
{
|
||||
for (auto [index, animation] : animations)
|
||||
ImGui::BulletText("%s", animation->name.c_str());
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::PopID();
|
||||
},
|
||||
.cardLines = LIBRARY_CARD_LINES};
|
||||
list_panel_draw(
|
||||
panel, actions, {{ACTION_ADD, ACTION_REMOVE_UNUSED, ACTION_RELOAD, ACTION_OPEN}},
|
||||
[&]() { content_list_draw(panel, SelectionKind::LIBRARIES, item_ids_get(libraries), rows); }, true);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
||||
@@ -254,6 +254,7 @@ namespace anm2ed::imgui
|
||||
else
|
||||
isBreak = row_draw(panel, selection, focus, rows, keys[i], i, arrowKey);
|
||||
if (isBreak) break;
|
||||
if (rows.children_draw) rows.children_draw(keys[i]);
|
||||
}
|
||||
if (isCards) ImGui::PopStyleVar();
|
||||
list_select_end(panel, selection, focus, rows, arrowKey);
|
||||
|
||||
@@ -64,7 +64,8 @@ namespace anm2ed::imgui
|
||||
PanelState& state;
|
||||
};
|
||||
|
||||
// How a list shows its keys; only `label_get` is required. With `image_get` the rows are cards.
|
||||
// How a list shows its keys; only `label_get` is required. With `image_get` the rows are cards; `children_draw` draws
|
||||
// under a key.
|
||||
struct ListRows
|
||||
{
|
||||
std::function<std::string(int)> label_get{};
|
||||
@@ -76,6 +77,7 @@ namespace anm2ed::imgui
|
||||
std::function<void(int)> select{};
|
||||
std::function<void(int)> activate{};
|
||||
std::function<bool(int, int)> drag_drop_update{};
|
||||
std::function<void(int)> children_draw{};
|
||||
int cardLines{};
|
||||
bool isFocusItalic{};
|
||||
};
|
||||
@@ -147,6 +149,7 @@ namespace anm2ed::imgui
|
||||
void nulls_update(Panel&);
|
||||
void events_update(Panel&);
|
||||
void sounds_update(Panel&);
|
||||
void libraries_update(Panel&);
|
||||
void spritesheets_update(Panel&, SpritesheetsPanel&);
|
||||
void regions_update(Panel&, RegionsPanel&);
|
||||
void frame_properties_update(Manager&, Settings&, FramePropertiesPanel&);
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
constexpr StringType FRAME_PROPERTY_LABELS[] = {
|
||||
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SKEW, BASIC_PIVOT, BASIC_CROP,
|
||||
BASIC_POSITION, BASIC_SCALE, BASIC_ROTATION, BASIC_SKEW, BASIC_PIVOT, BASIC_CROP,
|
||||
BASIC_SIZE, BASIC_REGION, BASIC_TINT, BASIC_COLOR_OFFSET, BASIC_VISIBLE, BASIC_INTERPOLATED,
|
||||
BASIC_DURATION, BASIC_SHADER, BASIC_DEPTH, BASIC_EVENT, LABEL_SOUNDS};
|
||||
BASIC_DURATION, BASIC_SHADER, BASIC_DEPTH, LABEL_CHILD, BASIC_EVENT, LABEL_SOUNDS};
|
||||
static_assert(std::size(FRAME_PROPERTY_LABELS) == (std::size_t)edit::FrameProperty::COUNT);
|
||||
|
||||
void TimelineContext::frame_begin()
|
||||
|
||||
@@ -253,9 +253,9 @@ namespace anm2ed::imgui::wizard
|
||||
|
||||
state.canvas->layers_render(resources.shaders[shader::TEXTURE], state.model, *animation,
|
||||
{.time = state.time, .isRootTransform = true}, state.canvas->transform_get(zoom, pan),
|
||||
[&](int id)
|
||||
[&](const model::Draw& draw)
|
||||
{
|
||||
auto texture = state.textures.find(id);
|
||||
auto texture = state.textures.find(draw.spritesheetId);
|
||||
return texture == state.textures.end() ? nullptr : &texture->second;
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user