Frame properties: one field table for change-all, shared widgets

- FRAME_CHANGE_SCALARS generates FrameChange fields, the frames_change apply step and change-all population
- Change-all draws component rows from tables instead of five widget lambdas and 46 aliases
- Frame properties uses one edit path (edit::COMPLETE), a vec2 field table and an X/Y flip loop
- Shared INTERPOLATION_LABELS and Document::layer_regions_get

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shweetandClaude Opus 5.5 committed 2026-10-03 13:44:14 -04:00
1 parent 30ea363c39
commit a4638a422d
9 files changed
+421 -744

No files matched your search

+269 -495
View File
@@ -1,7 +1,7 @@
#include "change_all_frame_properties.hpp"
#include <algorithm>
#include <map>
#include <ranges>
#include <set>
#include <string>
#include <vector>
@@ -15,6 +15,9 @@ using namespace glm;
namespace anm2ed::imgui::wizard
{
constexpr int CHANGE_TYPE_COUNT = 5;
constexpr const char* COLOR_COMPONENT_FORMATS[] = {"R:%d", "G:%d", "B:%d", "A:%d"};
enum ChangeDestination
{
CHANGE_DESTINATION_FRAMES,
@@ -22,86 +25,92 @@ namespace anm2ed::imgui::wizard
CHANGE_DESTINATION_ITEMS,
};
struct ChangeButton
{
StringType label;
StringType tooltip;
ChangeType type;
};
constexpr ChangeButton CHANGE_BUTTONS[CHANGE_TYPE_COUNT] = {
{LABEL_ADJUST, TOOLTIP_ADJUST, ChangeType::ADJUST},
{BASIC_ADD, TOOLTIP_ADD_VALUES, ChangeType::ADD},
{LABEL_SUBTRACT, TOOLTIP_SUBTRACT_VALUES, ChangeType::SUBTRACT},
{LABEL_MULTIPLY, TOOLTIP_MULTIPLY_VALUES, ChangeType::MULTIPLY},
{LABEL_DIVIDE, TOOLTIP_DIVIDE_VALUES, ChangeType::DIVIDE}};
struct ComponentRow
{
StringType label;
std::vector<bool*> isEnabled;
float* values;
bool isLayerOnly;
};
void property_toggle_begin(bool& isEnabled)
{
ImGui::Checkbox("##Is Enabled", &isEnabled);
ImGui::SameLine();
ImGui::BeginDisabled(!isEnabled);
}
void components_draw(const ComponentRow& row, bool isColor)
{
auto count = (int)row.isEnabled.size();
auto label = localize.get(row.label);
auto& style = ImGui::GetStyle();
auto width = (ImGui::CalcItemWidth() - (ImGui::GetFrameHeightWithSpacing() + style.ItemSpacing.x) * (count - 1) -
(isColor ? ImGui::GetFrameHeight() : 0.0f)) /
count;
ImGui::PushItemWidth(width);
for (int i = 0; i < count; ++i)
{
ImGui::PushID(i);
if (i > 0) ImGui::SameLine();
property_toggle_begin(*row.isEnabled[i]);
auto valueLabel = !isColor && i == count - 1 ? label : "##Value";
if (isColor)
{
auto value = float_to_uint8(row.values[i]);
if (ImGui::DragInt(valueLabel, &value, DRAG_SPEED, 0, 0, COLOR_COMPONENT_FORMATS[i]))
row.values[i] = uint8_to_float(value);
}
else
ImGui::DragFloat(valueLabel, &row.values[i], DRAG_SPEED, 0.0f, 0.0f, float_format_get(row.values[i]));
ImGui::EndDisabled();
ImGui::PopID();
}
ImGui::PopItemWidth();
if (!isColor) return;
ImVec4 buttonColor{0.0f, 0.0f, 0.0f, 1.0f};
for (int i = 0; i < count; ++i)
if (*row.isEnabled[i]) (&buttonColor.x)[i] = glm::clamp(row.values[i], 0.0f, 1.0f);
ImGui::SameLine();
ImGui::ColorButton(label, buttonColor);
ImGui::SameLine();
ImGui::TextUnformatted(label);
}
void ChangeAllFrameProperties::update(Manager& manager, Document& document, Settings& settings, bool isFromWizard)
{
isChanged = false;
auto& anm2 = document.anm2;
auto& itemReferences = document.items.references;
auto& animations = document.animation.selection;
auto& isCropX = settings.changeIsCropX;
auto& isCropY = settings.changeIsCropY;
auto& isSizeX = settings.changeIsSizeX;
auto& isSizeY = settings.changeIsSizeY;
auto& isPositionX = settings.changeIsPositionX;
auto& isPositionY = settings.changeIsPositionY;
auto& isPivotX = settings.changeIsPivotX;
auto& isPivotY = settings.changeIsPivotY;
auto& isScaleX = settings.changeIsScaleX;
auto& isScaleY = settings.changeIsScaleY;
auto& isShearX = settings.changeIsShearX;
auto& isShearY = settings.changeIsShearY;
auto& isRotation = settings.changeIsRotation;
auto& isDuration = settings.changeIsDuration;
auto& isTintR = settings.changeIsTintR;
auto& isTintG = settings.changeIsTintG;
auto& isTintB = settings.changeIsTintB;
auto& isTintA = settings.changeIsTintA;
auto& isColorOffsetR = settings.changeIsColorOffsetR;
auto& isColorOffsetG = settings.changeIsColorOffsetG;
auto& isColorOffsetB = settings.changeIsColorOffsetB;
auto& isVisibleSet = settings.changeIsVisibleSet;
auto& isInterpolationSet = settings.changeIsInterpolationSet;
auto& isFlipXSet = settings.changeIsFlipXSet;
auto& isFlipYSet = settings.changeIsFlipYSet;
auto& isRegion = settings.changeIsRegion;
auto& isShader = settings.changeIsShader;
auto& crop = settings.changeCrop;
auto& size = settings.changeSize;
auto& position = settings.changePosition;
auto& pivot = settings.changePivot;
auto& scale = settings.changeScale;
auto& shear = settings.changeShear;
auto& rotation = settings.changeRotation;
auto& duration = settings.changeDuration;
auto& tint = settings.changeTint;
auto& colorOffset = settings.changeColorOffset;
auto& destination = settings.changeDestination;
auto& regionId = document.changeAllFramePropertiesRegionId;
auto& shaderId = document.changeAllFramePropertiesShaderId;
auto& isVisible = settings.changeIsVisible;
auto& interpolation = settings.changeInterpolation;
auto& isFlipX = settings.changeIsFlipX;
auto& isFlipY = settings.changeIsFlipY;
auto& destination = settings.changeDestination;
auto& isRoot = settings.changeIsRoot;
auto& isLayers = settings.changeIsLayers;
auto& isNulls = settings.changeIsNulls;
auto is_frame_reference_changeable = [](const Reference& reference) { return reference.itemType != TRIGGER; };
auto is_item_reference_changeable = [](const Reference& reference) { return reference.itemType != TRIGGER; };
auto selected_frame_references_get = [&]()
{
std::set<Reference> result = document.frame_references_get(Document::FrameReferenceFallback::NONE);
std::erase_if(result, [&](const Reference& reference) { return !is_frame_reference_changeable(reference); });
return result;
};
auto selected_item_references_get = [&]()
{
std::set<Reference> result = itemReferences;
if (result.empty() && document.reference.itemType != NONE)
{
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;
};
auto selectedFrameReferences = selected_frame_references_get();
auto selectedItemReferences = selected_item_references_get();
auto selectedFrameReferences = document.frame_references_get(Document::FrameReferenceFallback::NONE);
std::erase_if(selectedFrameReferences, [](const Reference& reference) { return reference.itemType == TRIGGER; });
auto selectedItemReferences = document.items.references;
if (selectedItemReferences.empty() && document.reference.itemType != NONE)
selectedItemReferences.insert({document.reference.animationIndex, document.reference.itemType,
document.reference.itemID, -1, document.reference.groupType,
document.reference.groupId});
std::erase_if(selectedItemReferences, [](const Reference& reference) { return reference.itemType == TRIGGER; });
bool isFramesDestination = !isFromWizard || destination == CHANGE_DESTINATION_FRAMES;
bool isItemsDestination = isFromWizard && destination == CHANGE_DESTINATION_ITEMS;
bool isSelectedFramesAvailable = !selectedFrameReferences.empty();
bool isSelectedItemsAvailable = !selectedItemReferences.empty();
bool isSelectedAnimationsAvailable = !animations.empty();
@@ -115,398 +124,170 @@ namespace anm2ed::imgui::wizard
destination = CHANGE_DESTINATION_ITEMS;
if (destination == CHANGE_DESTINATION_ANIMATIONS && !isSelectedAnimationsAvailable && isSelectedFramesAvailable)
destination = CHANGE_DESTINATION_FRAMES;
isFramesDestination = destination == CHANGE_DESTINATION_FRAMES;
isItemsDestination = destination == CHANGE_DESTINATION_ITEMS;
}
bool isFramesDestination = !isFromWizard || destination == CHANGE_DESTINATION_FRAMES;
bool isItemsDestination = isFromWizard && destination == CHANGE_DESTINATION_ITEMS;
auto isLayerPropertyAvailable =
isFramesDestination ? std::ranges::any_of(selectedFrameReferences, [](const Reference& reference)
{ return reference.itemType == LAYER; })
: isItemsDestination ? std::ranges::any_of(selectedItemReferences, [](const Reference& reference)
{ return reference.itemType == LAYER; })
: isLayers;
auto is_layer = [](const Reference& reference) { return reference.itemType == LAYER; };
auto isLayerPropertyAvailable = isFramesDestination ? std::ranges::any_of(selectedFrameReferences, is_layer)
: isItemsDestination ? std::ranges::any_of(selectedItemReferences, is_layer)
: settings.changeIsLayers;
#define PROPERTIES_WIDGET(body, checkboxLabel, isEnabled) \
ImGui::Checkbox(checkboxLabel, &isEnabled); \
ImGui::SameLine(); \
ImGui::BeginDisabled(!isEnabled); \
body; \
ImGui::EndDisabled();
ComponentRow componentRows[] = {
{BASIC_CROP, {&settings.changeIsCropX, &settings.changeIsCropY}, value_ptr(settings.changeCrop), true},
{BASIC_SIZE, {&settings.changeIsSizeX, &settings.changeIsSizeY}, value_ptr(settings.changeSize), true},
{BASIC_POSITION,
{&settings.changeIsPositionX, &settings.changeIsPositionY},
value_ptr(settings.changePosition),
false},
{BASIC_PIVOT, {&settings.changeIsPivotX, &settings.changeIsPivotY}, value_ptr(settings.changePivot), true},
{BASIC_SCALE, {&settings.changeIsScaleX, &settings.changeIsScaleY}, value_ptr(settings.changeScale), false},
{BASIC_SHEAR, {&settings.changeIsShearX, &settings.changeIsShearY}, value_ptr(settings.changeShear), false},
{BASIC_ROTATION, {&settings.changeIsRotation}, &settings.changeRotation, false}};
ComponentRow colorRows[] = {
{BASIC_TINT,
{&settings.changeIsTintR, &settings.changeIsTintG, &settings.changeIsTintB, &settings.changeIsTintA},
value_ptr(settings.changeTint),
false},
{BASIC_COLOR_OFFSET,
{&settings.changeIsColorOffsetR, &settings.changeIsColorOffsetG, &settings.changeIsColorOffsetB},
value_ptr(settings.changeColorOffset),
false}};
auto bool_value = [&](const char* checkboxLabel, const char* valueLabel, bool& isEnabled, bool& value)
{ PROPERTIES_WIDGET(ImGui::Checkbox(valueLabel, &value), checkboxLabel, isEnabled) };
auto enum_value = [&](const char* checkboxLabel, const char* valueLabel, bool& isEnabled, int& value,
const std::vector<int>& ids, std::vector<const char*>& labels)
{ PROPERTIES_WIDGET(combo_id_mapped(valueLabel, &value, ids, labels), checkboxLabel, isEnabled) };
auto color3_value = [&](const char* checkboxRLabel, const char* checkboxGLabel, const char* checkboxBLabel,
const char* valueRLabel, const char* valueGLabel, const char* valueBLabel,
const char* label, bool& isREnabled, bool& isGEnabled, bool& isBEnabled, vec3& value)
auto rows_draw = [&](std::span<ComponentRow> rows, bool isColor)
{
auto style = ImGui::GetStyle();
auto width = (ImGui::CalcItemWidth() - (ImGui::GetFrameHeightWithSpacing() * 2) - (style.ItemSpacing.x * 2) -
ImGui::GetFrameHeight()) /
3;
ivec3 valueAlt = {float_to_uint8(value.r), float_to_uint8(value.g), float_to_uint8(value.b)};
ImGui::PushItemWidth(width);
PROPERTIES_WIDGET(ImGui::DragInt(valueRLabel, &valueAlt.r, DRAG_SPEED, 0, 0, "R:%d"), checkboxRLabel, isREnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragInt(valueGLabel, &valueAlt.g, DRAG_SPEED, 0, 0, "G:%d"), checkboxGLabel, isGEnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragInt(valueBLabel, &valueAlt.b, DRAG_SPEED, 0, 0, "B:%d"), checkboxBLabel, isBEnabled);
ImGui::PopItemWidth();
ImGui::SameLine();
value = vec3(uint8_to_float(valueAlt.r), uint8_to_float(valueAlt.g), uint8_to_float(valueAlt.b));
ImVec4 buttonColor = {isREnabled ? glm::clamp(value.r, 0.0f, 1.0f) : 0,
isGEnabled ? glm::clamp(value.g, 0.0f, 1.0f) : 0,
isBEnabled ? glm::clamp(value.b, 0.0f, 1.0f) : 0, 1};
ImGui::ColorButton(label, buttonColor);
ImGui::SameLine();
ImGui::TextUnformatted(label);
for (auto& row : rows)
{
ImGui::PushID(row.label);
ImGui::BeginDisabled(row.isLayerOnly && !isLayerPropertyAvailable);
components_draw(row, isColor);
ImGui::EndDisabled();
ImGui::PopID();
}
};
auto color4_value = [&](const char* checkboxRLabel, const char* checkboxGLabel, const char* checkboxBLabel,
const char* checkboxALabel, const char* valueRLabel, const char* valueGLabel,
const char* valueBLabel, const char* valueALabel, const char* label, bool& isREnabled,
bool& isGEnabled, bool& isBEnabled, bool& isAEnabled, vec4& value)
auto combo_draw = [&](const char* id, StringType label, bool& isEnabled, int& value, const std::vector<int>& ids,
std::vector<const char*>& labels)
{
auto style = ImGui::GetStyle();
auto width = (ImGui::CalcItemWidth() - (ImGui::GetFrameHeightWithSpacing() * 3) - (style.ItemSpacing.x * 3) -
ImGui::GetFrameHeight()) /
4;
ivec4 valueAlt = {float_to_uint8(value.r), float_to_uint8(value.g), float_to_uint8(value.b),
float_to_uint8(value.a)};
ImGui::PushItemWidth(width);
PROPERTIES_WIDGET(ImGui::DragInt(valueRLabel, &valueAlt.r, DRAG_SPEED, 0, 0, "R:%d"), checkboxRLabel, isREnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragInt(valueGLabel, &valueAlt.g, DRAG_SPEED, 0, 0, "G:%d"), checkboxGLabel, isGEnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragInt(valueBLabel, &valueAlt.b, DRAG_SPEED, 0, 0, "B:%d"), checkboxBLabel, isBEnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragInt(valueALabel, &valueAlt.a, DRAG_SPEED, 0, 0, "A:%d"), checkboxALabel, isAEnabled);
ImGui::PopItemWidth();
ImGui::SameLine();
value = vec4(uint8_to_float(valueAlt.r), uint8_to_float(valueAlt.g), uint8_to_float(valueAlt.b),
uint8_to_float(valueAlt.a));
ImVec4 buttonColor = {
isREnabled ? glm::clamp(value.r, 0.0f, 1.0f) : 0, isGEnabled ? glm::clamp(value.g, 0.0f, 1.0f) : 0,
isBEnabled ? glm::clamp(value.b, 0.0f, 1.0f) : 0, isAEnabled ? glm::clamp(value.a, 0.0f, 1.0f) : 1};
ImGui::ColorButton(label, buttonColor);
ImGui::SameLine();
ImGui::TextUnformatted(label);
ImGui::PushID(id);
if (std::ranges::find(ids, value) == ids.end()) value = ids.front();
property_toggle_begin(isEnabled);
combo_id_mapped(localize.get(label), &value, ids, labels);
ImGui::EndDisabled();
ImGui::PopID();
};
auto float_value = [&](const char* checkboxLabel, const char* valueLabel, bool& isEnabled, float& value)
auto bool_draw = [&](const char* id, StringType label, bool& isEnabled, bool& value)
{
PROPERTIES_WIDGET(ImGui::DragFloat(valueLabel, &value, DRAG_SPEED, 0.0f, 0.0f, float_format_get(value)),
checkboxLabel, isEnabled);
ImGui::PushID(id);
property_toggle_begin(isEnabled);
ImGui::Checkbox(localize.get(label), &value);
ImGui::EndDisabled();
ImGui::PopID();
};
auto float2_value = [&](const char* checkboxXLabel, const char* checkboxYLabel, const char* valueXLabel,
const char* valueYLabel, bool& isXEnabled, bool& isYEnabled, vec2& value)
std::vector<int> noneIds{-1};
std::string noneLabel = localize.get(BASIC_NONE);
std::vector<const char*> noneLabels{noneLabel.c_str()};
std::vector<int> interpolationIds{};
std::vector<const char*> interpolationLabels{};
for (int i = 0; i < (int)std::size(INTERPOLATION_LABELS); ++i)
{
auto style = ImGui::GetStyle();
auto width = (ImGui::CalcItemWidth() - ImGui::GetFrameHeightWithSpacing() - style.ItemSpacing.x) / 2;
ImGui::PushItemWidth(width);
PROPERTIES_WIDGET(ImGui::DragFloat(valueXLabel, &value.x, DRAG_SPEED, 0.0f, 0.0f, float_format_get(value.x)),
checkboxXLabel, isXEnabled);
ImGui::SameLine();
PROPERTIES_WIDGET(ImGui::DragFloat(valueYLabel, &value.y, DRAG_SPEED, 0.0f, 0.0f, float_format_get(value.y)),
checkboxYLabel, isYEnabled);
ImGui::PopItemWidth();
};
auto duration_value = [&](const char* checkboxLabel, const char* valueLabel, bool& isEnabled, int& value)
{
PROPERTIES_WIDGET(input_int_range(valueLabel, value, FRAME_DURATION_MIN, FRAME_DURATION_MAX, STEP, STEP_FAST),
checkboxLabel, isEnabled);
};
interpolationIds.push_back(i);
interpolationLabels.push_back(localize.get(INTERPOLATION_LABELS[i]));
}
auto regions = document.layer_regions_get(document.reference.itemType == LAYER ? document.reference.itemID : -1);
if (!isLayerPropertyAvailable) regionId = shaderId = -1;
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImGui::GetStyle().ItemInnerSpacing);
rows_draw(componentRows, false);
ImGui::PushID("Duration");
property_toggle_begin(settings.changeIsDuration);
input_int_range(localize.get(BASIC_DURATION), settings.changeDuration, FRAME_DURATION_MIN, FRAME_DURATION_MAX, STEP,
STEP_FAST);
ImGui::EndDisabled();
ImGui::PopID();
rows_draw(colorRows, true);
ImGui::BeginDisabled(!isLayerPropertyAvailable);
float2_value("##Is Crop X", "##Is Crop Y", "##Crop X", localize.get(BASIC_CROP), isCropX, isCropY, crop);
float2_value("##Is Size X", "##Is Size Y", "##Size X", localize.get(BASIC_SIZE), isSizeX, isSizeY, size);
combo_draw("Region", BASIC_REGION, settings.changeIsRegion, regionId, regions ? regions->ids : noneIds,
regions ? regions->labels : noneLabels);
ImGui::EndDisabled();
float2_value("##Is Position X", "##Is Position Y", "##Position X", localize.get(BASIC_POSITION), isPositionX,
isPositionY, position);
ImGui::BeginDisabled(!isLayerPropertyAvailable);
float2_value("##Is Pivot X", "##Is Pivot Y", "##Pivot X", localize.get(BASIC_PIVOT), isPivotX, isPivotY, pivot);
ImGui::EndDisabled();
float2_value("##Is Scale X", "##Is Scale Y", "##Scale X", localize.get(BASIC_SCALE), isScaleX, isScaleY, scale);
float2_value("##Is Shear X", "##Is Shear Y", "##Shear X", localize.get(BASIC_SHEAR), isShearX, isShearY, shear);
float_value("##Is Rotation", localize.get(BASIC_ROTATION), isRotation, rotation);
duration_value("##Is Duration", localize.get(BASIC_DURATION), isDuration, duration);
color4_value("##Is Tint R", "##Is Tint G", "##Is Tint B", "##Is Tint A", "##Tint R", "##Tint G", "##Tint B",
"##Tint A", localize.get(BASIC_TINT), isTintR, isTintG, isTintB, isTintA, tint);
color3_value("##Is Color Offset R", "##Is Color Offset G", "##Is Color Offset B", "##Color Offset R",
"##Color Offset G", "##Color Offset B", localize.get(BASIC_COLOR_OFFSET), isColorOffsetR,
isColorOffsetG, isColorOffsetB, colorOffset);
ImGui::BeginDisabled(!isLayerPropertyAvailable);
std::vector<int> fallbackIds{-1};
std::vector<std::string> fallbackLabelsString{localize.get(BASIC_NONE)};
std::vector<const char*> fallbackLabels{fallbackLabelsString[0].c_str()};
std::vector<int> interpolationIds{(int)Interpolation::NONE, (int)Interpolation::LINEAR, (int)Interpolation::EASE_IN,
(int)Interpolation::EASE_OUT, (int)Interpolation::EASE_IN_OUT};
std::vector<std::string> interpolationLabelsString{localize.get(BASIC_NONE), localize.get(BASIC_LINEAR),
localize.get(BASIC_EASE_IN), localize.get(BASIC_EASE_OUT),
localize.get(BASIC_EASE_IN_OUT)};
std::vector<const char*> interpolationLabels{
interpolationLabelsString[0].c_str(), interpolationLabelsString[1].c_str(),
interpolationLabelsString[2].c_str(), interpolationLabelsString[3].c_str(),
interpolationLabelsString[4].c_str()};
const Storage* regionStorage = nullptr;
if (document.reference.itemType == LAYER && document.reference.itemID != -1)
{
if (auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, document.reference.itemID))
{
auto regionIt = document.regionBySpritesheet.find(layer->spritesheetId);
if (regionIt != document.regionBySpritesheet.end()) regionStorage = &regionIt->second;
}
}
auto regionIds = regionStorage && !regionStorage->ids.empty() ? regionStorage->ids : fallbackIds;
auto regionLabels = regionStorage && !regionStorage->labels.empty() ? regionStorage->labels : fallbackLabels;
if (!isLayerPropertyAvailable || std::find(regionIds.begin(), regionIds.end(), regionId) == regionIds.end())
regionId = -1;
PROPERTIES_WIDGET(combo_id_mapped(localize.get(BASIC_REGION), &regionId, regionIds, regionLabels), "##Is Region",
isRegion);
ImGui::EndDisabled();
enum_value("##Is Interpolation", localize.get(BASIC_INTERPOLATED), isInterpolationSet, interpolation,
combo_draw("Interpolation", BASIC_INTERPOLATED, settings.changeIsInterpolationSet, settings.changeInterpolation,
interpolationIds, interpolationLabels);
ImGui::BeginDisabled(!isLayerPropertyAvailable);
auto shaderIds = !document.shader.ids.empty() ? document.shader.ids : fallbackIds;
auto shaderLabels = !document.shader.labels.empty() ? document.shader.labels : fallbackLabels;
if (!isLayerPropertyAvailable || std::find(shaderIds.begin(), shaderIds.end(), shaderId) == shaderIds.end())
shaderId = -1;
PROPERTIES_WIDGET(combo_id_mapped(localize.get(BASIC_SHADER), &shaderId, shaderIds, shaderLabels), "##Is Shader",
isShader);
combo_draw("Shader", BASIC_SHADER, settings.changeIsShader, shaderId,
document.shader.ids.empty() ? noneIds : document.shader.ids,
document.shader.labels.empty() ? noneLabels : document.shader.labels);
ImGui::EndDisabled();
bool_value("##Is Visible", localize.get(BASIC_VISIBLE), isVisibleSet, isVisible);
bool_value("##Is Flip X", localize.get(LABEL_FLIP_X), isFlipXSet, isFlipX);
bool_draw("Visible", BASIC_VISIBLE, settings.changeIsVisibleSet, settings.changeIsVisible);
bool_draw("Flip X", LABEL_FLIP_X, settings.changeIsFlipXSet, settings.changeIsFlipX);
ImGui::SameLine();
bool_value("##Is Flip Y", localize.get(LABEL_FLIP_Y), isFlipYSet, isFlipY);
bool_draw("Flip Y", LABEL_FLIP_Y, settings.changeIsFlipYSet, settings.changeIsFlipY);
ImGui::PopStyleVar();
#undef PROPERTIES_WIDGET
auto frame_change = [&](ChangeType changeType)
{
auto color_value_get = [&](float value)
{
if (changeType == ChangeType::MULTIPLY || changeType == ChangeType::DIVIDE) return (float)float_to_uint8(value);
return value;
};
auto isColorScaled = changeType == ChangeType::MULTIPLY || changeType == ChangeType::DIVIDE;
FrameChange frameChange;
if (isCropX) frameChange.cropX = crop.x;
if (isCropY) frameChange.cropY = crop.y;
if (isSizeX) frameChange.sizeX = size.x;
if (isSizeY) frameChange.sizeY = size.y;
if (isPositionX) frameChange.positionX = position.x;
if (isPositionY) frameChange.positionY = position.y;
if (isPivotX) frameChange.pivotX = pivot.x;
if (isPivotY) frameChange.pivotY = pivot.y;
if (isScaleX) frameChange.scaleX = scale.x;
if (isScaleY) frameChange.scaleY = scale.y;
if (isShearX) frameChange.shearX = shear.x;
if (isShearY) frameChange.shearY = shear.y;
if (isRotation) frameChange.rotation = std::make_optional(rotation);
if (isDuration) frameChange.duration = std::make_optional(duration);
if (isRegion) frameChange.regionId = std::make_optional(regionId);
if (isShader) frameChange.shaderId = std::make_optional(shaderId);
if (isTintR) frameChange.tintR = color_value_get(tint.r);
if (isTintG) frameChange.tintG = color_value_get(tint.g);
if (isTintB) frameChange.tintB = color_value_get(tint.b);
if (isTintA) frameChange.tintA = color_value_get(tint.a);
if (isColorOffsetR) frameChange.colorOffsetR = color_value_get(colorOffset.r);
if (isColorOffsetG) frameChange.colorOffsetG = color_value_get(colorOffset.g);
if (isColorOffsetB) frameChange.colorOffsetB = color_value_get(colorOffset.b);
if (isVisibleSet) frameChange.isVisible = std::make_optional(isVisible);
if (isInterpolationSet) frameChange.interpolation = std::make_optional(static_cast<Interpolation>(interpolation));
if (isFlipXSet) frameChange.isFlipX = std::make_optional(isFlipX);
if (isFlipYSet) frameChange.isFlipY = std::make_optional(isFlipY);
#define X(name, member, isLayerOnly, isColor, isEnabled, value) \
if (settings.isEnabled) \
frameChange.name = isColor && isColorScaled ? (float)float_to_uint8(settings.value) : settings.value;
FRAME_CHANGE_SCALARS
#undef X
if (settings.changeIsDuration) frameChange.duration = settings.changeDuration;
if (settings.changeIsRegion) frameChange.regionId = regionId;
if (settings.changeIsShader) frameChange.shaderId = shaderId;
if (settings.changeIsVisibleSet) frameChange.isVisible = settings.changeIsVisible;
if (settings.changeIsInterpolationSet) frameChange.interpolation = (Interpolation)settings.changeInterpolation;
if (settings.changeIsFlipXSet) frameChange.isFlipX = settings.changeIsFlipX;
if (settings.changeIsFlipYSet) frameChange.isFlipY = settings.changeIsFlipY;
if (isFramesDestination && selectedFrameReferences.empty()) return;
if (isItemsDestination && selectedItemReferences.empty()) return;
manager.command_push(
{manager.selected,
[=, queuedAnimations = std::set<int>(animations.begin(), animations.end()), isRoot = settings.changeIsRoot,
isLayers = settings.changeIsLayers, isNulls = settings.changeIsNulls](Manager&, Document& document)
{
auto& anm2 = document.anm2;
std::vector<std::tuple<Element*, ItemType, std::set<int>>> targets{};
auto all_target_push = [&](Element* item, ItemType type)
{
if (!item) return;
auto indices = std::views::iota(0, track_frames_count_get(*item));
targets.emplace_back(item, type, std::set<int>(indices.begin(), indices.end()));
};
auto queuedFrameReferences = selectedFrameReferences;
auto queuedItemReferences = selectedItemReferences;
auto queuedAnimations = animations;
auto queuedIsFramesDestination = isFramesDestination;
auto queuedIsItemsDestination = isItemsDestination;
auto queuedIsRoot = isRoot;
auto queuedIsLayers = isLayers;
auto queuedIsNulls = isNulls;
if (isFramesDestination)
{
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : selectedFrameReferences)
groupedFrames[{frameReference.animationIndex, frameReference.itemType, frameReference.itemID, -1,
frameReference.groupType, frameReference.groupId}]
.insert(frameReference.frameIndex);
for (auto& [itemReference, selection] : groupedFrames)
if (auto item = anm2.element_get(itemReference))
targets.emplace_back(item, (ItemType)itemReference.itemType, selection);
}
else if (isItemsDestination)
for (auto itemReference : selectedItemReferences)
all_target_push(anm2.element_get(itemReference), (ItemType)itemReference.itemType);
else
for (auto animationIndex : queuedAnimations)
{
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
if (!animation) continue;
if (isRoot) all_target_push(animation_item_get(*animation, ItemType::ROOT), ItemType::ROOT);
for (const auto& row : TRACK_CONTAINERS)
if (auto container = child_first_get(*animation, row.container);
container && (row.itemType == ItemType::LAYER ? isLayers : isNulls))
tracks_each(*container, row.track, [&](Element& track) { all_target_push(&track, row.itemType); });
}
manager.command_push({manager.selected, [=](Manager&, Document& document)
{
auto all_frames_selection = [](const Element& item)
{
std::set<int> selection{};
int index{};
for (const auto& frame : item.children)
if (frame.type == ElementType::FRAME)
{
selection.insert(index);
++index;
}
return selection;
};
auto& anm2 = document.anm2;
if (queuedIsFramesDestination)
{
std::map<Reference, std::set<int>> groupedFrames{};
for (auto frameReference : queuedFrameReferences)
{
auto itemReference = frameReference;
itemReference.frameIndex = -1;
groupedFrames[itemReference].insert(frameReference.frameIndex);
}
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto& [itemReference, selection] : groupedFrames)
{
auto item = anm2.element_get(itemReference);
if (!item) continue;
frames_change(*item, frameChange, static_cast<ItemType>(itemReference.itemType),
changeType, selection);
}
document.change(Document::FRAMES);
return;
}
if (queuedIsItemsDestination)
{
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto itemReference : queuedItemReferences)
{
if (itemReference.itemType == TRIGGER) continue;
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),
changeType, selection);
}
document.change(Document::FRAMES);
return;
}
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto animationIndex : queuedAnimations)
{
auto animation = anm2.element_get(ElementType::ANIMATION, animationIndex);
if (!animation) continue;
if (queuedIsRoot)
{
if (auto item = animation_item_get(*animation, ItemType::ROOT))
{
auto selection = all_frames_selection(*item);
frames_change(*item, frameChange, ItemType::ROOT, changeType, selection);
}
}
if (queuedIsLayers)
{
auto layerAnimations = child_first_get(*animation, ElementType::LAYER_ANIMATIONS);
if (layerAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
{
if (item.type == ElementType::GROUP)
{
for (auto& child : item.children)
self(self, child);
return;
}
if (item.type == ElementType::LAYER_ANIMATION)
{
auto selection = all_frames_selection(item);
frames_change(item, frameChange, ItemType::LAYER, changeType, selection);
}
};
for (auto& item : layerAnimations->children)
item_change(item_change, item);
}
}
if (queuedIsNulls)
{
auto nullAnimations = child_first_get(*animation, ElementType::NULL_ANIMATIONS);
if (nullAnimations)
{
auto item_change = [&](auto&& self, Element& item) -> void
{
if (item.type == ElementType::GROUP)
{
for (auto& child : item.children)
self(self, child);
return;
}
if (item.type == ElementType::NULL_ANIMATION)
{
auto selection = all_frames_selection(item);
frames_change(item, frameChange, ItemType::NULL_, changeType, selection);
}
};
for (auto& item : nullAnimations->children)
item_change(item_change, item);
}
}
}
document.change(Document::FRAMES);
}});
document.snapshots.anm2_push(localize.get(EDIT_CHANGE_FRAME_PROPERTIES));
for (auto& [item, type, selection] : targets)
frames_change(*item, frameChange, type, changeType, selection);
document.change(Document::FRAMES);
}});
isChanged = true;
};
@@ -515,76 +296,69 @@ namespace anm2ed::imgui::wizard
if (isFromWizard)
{
ImGui::SeparatorText(localize.get(LABEL_DESTINATION));
struct DestinationOption
{
StringType label;
StringType tooltip;
ChangeDestination value;
bool isAvailable;
};
DestinationOption destinationOptions[] = {
{BASIC_FRAMES, TOOLTIP_CHANGE_ALL_DESTINATION_FRAMES, CHANGE_DESTINATION_FRAMES, isSelectedFramesAvailable},
{LABEL_ITEMS, TOOLTIP_CHANGE_ALL_DESTINATION_ITEMS, CHANGE_DESTINATION_ITEMS, isSelectedItemsAvailable},
{LABEL_ANIMATIONS_CHILD, TOOLTIP_CHANGE_ALL_DESTINATION_ANIMATIONS, CHANGE_DESTINATION_ANIMATIONS,
isSelectedAnimationsAvailable}};
for (auto& option : destinationOptions)
{
if (option.value != CHANGE_DESTINATION_FRAMES) ImGui::SameLine();
ImGui::BeginDisabled(!option.isAvailable);
ImGui::RadioButton(localize.get(option.label), &destination, option.value);
ImGui::SetItemTooltip("%s", localize.get(option.tooltip));
ImGui::EndDisabled();
}
ImGui::BeginDisabled(!isSelectedFramesAvailable);
ImGui::RadioButton(localize.get(BASIC_FRAMES), &destination, CHANGE_DESTINATION_FRAMES);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_DESTINATION_FRAMES));
ImGui::EndDisabled();
ImGui::SameLine();
ImGui::BeginDisabled(!isSelectedItemsAvailable);
ImGui::RadioButton(localize.get(LABEL_ITEMS), &destination, CHANGE_DESTINATION_ITEMS);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_DESTINATION_ITEMS));
ImGui::EndDisabled();
ImGui::SameLine();
ImGui::BeginDisabled(!isSelectedAnimationsAvailable);
ImGui::RadioButton(localize.get(LABEL_ANIMATIONS_CHILD), &destination, CHANGE_DESTINATION_ANIMATIONS);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_DESTINATION_ANIMATIONS));
ImGui::EndDisabled();
struct TargetOption
{
StringType label;
StringType tooltip;
bool& value;
};
TargetOption targetOptions[] = {{LABEL_ROOT, TOOLTIP_CHANGE_ALL_ROOT, settings.changeIsRoot},
{LABEL_LAYERS, TOOLTIP_CHANGE_ALL_LAYERS, settings.changeIsLayers},
{LABEL_NULLS, TOOLTIP_CHANGE_ALL_NULLS, settings.changeIsNulls}};
ImGui::BeginDisabled(isFramesDestination || isItemsDestination);
ImGui::Checkbox(localize.get(LABEL_ROOT), &isRoot);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_ROOT));
ImGui::SameLine();
ImGui::Checkbox(localize.get(LABEL_LAYERS), &isLayers);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_LAYERS));
ImGui::SameLine();
ImGui::Checkbox(localize.get(LABEL_NULLS), &isNulls);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CHANGE_ALL_NULLS));
for (auto& option : targetOptions)
{
if (&option != targetOptions) ImGui::SameLine();
ImGui::Checkbox(localize.get(option.label), &option.value);
ImGui::SetItemTooltip("%s", localize.get(option.tooltip));
}
ImGui::EndDisabled();
ImGui::Separator();
}
bool isAnyProperty = isCropX || isCropY || isSizeX || isSizeY || isPositionX || isPositionY || isPivotX ||
isPivotY || isScaleX || isScaleY || isShearX || isShearY || isRotation || isDuration ||
isTintR || isTintG || isTintB || isTintA || isColorOffsetR || isColorOffsetG ||
isColorOffsetB || isRegion || isShader || isVisibleSet || isInterpolationSet || isFlipXSet ||
isFlipYSet;
bool isDestinationValid = isFramesDestination ? isSelectedFramesAvailable
: isItemsDestination ? isSelectedItemsAvailable
: isSelectedAnimationsAvailable && (isRoot || isLayers || isNulls);
auto rowWidgetSize = widget_size_with_row_get(5);
bool isAnyProperty = settings.changeIsDuration || settings.changeIsRegion || settings.changeIsShader ||
settings.changeIsVisibleSet || settings.changeIsInterpolationSet ||
settings.changeIsFlipXSet ||
settings.changeIsFlipYSet
#define X(name, member, isLayerOnly, isColor, isEnabled, value) || settings.isEnabled
FRAME_CHANGE_SCALARS
#undef X
;
bool isDestinationValid = isFramesDestination ? isSelectedFramesAvailable
: isItemsDestination
? isSelectedItemsAvailable
: isSelectedAnimationsAvailable &&
(settings.changeIsRoot || settings.changeIsLayers || settings.changeIsNulls);
auto rowWidgetSize = widget_size_with_row_get(CHANGE_TYPE_COUNT);
ImGui::BeginDisabled(!isAnyProperty || !isDestinationValid);
if (ImGui::Button(localize.get(LABEL_ADJUST), rowWidgetSize)) frame_change(ChangeType::ADJUST);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADJUST));
ImGui::SameLine();
if (ImGui::Button(localize.get(BASIC_ADD), rowWidgetSize)) frame_change(ChangeType::ADD);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADD_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_SUBTRACT), rowWidgetSize)) frame_change(ChangeType::SUBTRACT);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SUBTRACT_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_MULTIPLY), rowWidgetSize)) frame_change(ChangeType::MULTIPLY);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_MULTIPLY_VALUES));
ImGui::SameLine();
if (ImGui::Button(localize.get(LABEL_DIVIDE), rowWidgetSize)) frame_change(ChangeType::DIVIDE);
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_DIVIDE_VALUES));
for (auto& button : CHANGE_BUTTONS)
{
if (&button != CHANGE_BUTTONS) ImGui::SameLine();
if (ImGui::Button(localize.get(button.label), rowWidgetSize)) frame_change(button.type);
ImGui::SetItemTooltip("%s", localize.get(button.tooltip));
}
ImGui::EndDisabled();
}
}