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:
1 parent
30ea363c39
commit
a4638a422d
9 files changed
+421
-744
No files matched your search
+31
-23
@@ -246,37 +246,45 @@ namespace anm2ed
|
||||
bool isExtendedFormat{};
|
||||
};
|
||||
|
||||
#define FRAME_CHANGE_SCALARS \
|
||||
X(cropX, crop.x, true, false, changeIsCropX, changeCrop.x) \
|
||||
X(cropY, crop.y, true, false, changeIsCropY, changeCrop.y) \
|
||||
X(sizeX, size.x, true, false, changeIsSizeX, changeSize.x) \
|
||||
X(sizeY, size.y, true, false, changeIsSizeY, changeSize.y) \
|
||||
X(pivotX, pivot.x, true, false, changeIsPivotX, changePivot.x) \
|
||||
X(pivotY, pivot.y, true, false, changeIsPivotY, changePivot.y) \
|
||||
X(positionX, position.x, false, false, changeIsPositionX, changePosition.x) \
|
||||
X(positionY, position.y, false, false, changeIsPositionY, changePosition.y) \
|
||||
X(scaleX, scale.x, false, false, changeIsScaleX, changeScale.x) \
|
||||
X(scaleY, scale.y, false, false, changeIsScaleY, changeScale.y) \
|
||||
X(shearX, shear.x, false, false, changeIsShearX, changeShear.x) \
|
||||
X(shearY, shear.y, false, false, changeIsShearY, changeShear.y) \
|
||||
X(rotation, rotation, false, false, changeIsRotation, changeRotation) \
|
||||
X(tintR, tint.r, false, true, changeIsTintR, changeTint.r) \
|
||||
X(tintG, tint.g, false, true, changeIsTintG, changeTint.g) \
|
||||
X(tintB, tint.b, false, true, changeIsTintB, changeTint.b) \
|
||||
X(tintA, tint.a, false, true, changeIsTintA, changeTint.a) \
|
||||
X(colorOffsetR, colorOffset.r, false, true, changeIsColorOffsetR, changeColorOffset.r) \
|
||||
X(colorOffsetG, colorOffset.g, false, true, changeIsColorOffsetG, changeColorOffset.g) \
|
||||
X(colorOffsetB, colorOffset.b, false, true, changeIsColorOffsetB, changeColorOffset.b)
|
||||
|
||||
struct FrameChange
|
||||
{
|
||||
std::optional<int> regionId{};
|
||||
#define X(name, member, isLayerOnly, isColor, isEnabled, value) std::optional<float> name{};
|
||||
FRAME_CHANGE_SCALARS
|
||||
#undef X
|
||||
std::optional<int> duration{};
|
||||
std::optional<int> shaderId{};
|
||||
std::optional<bool> isVisible{};
|
||||
std::optional<Interpolation> interpolation{};
|
||||
std::optional<int> shaderId{};
|
||||
std::optional<float> rotation{};
|
||||
std::optional<int> duration{};
|
||||
std::optional<int> regionId{};
|
||||
std::optional<float> pivotX{};
|
||||
std::optional<float> pivotY{};
|
||||
std::optional<float> cropX{};
|
||||
std::optional<float> cropY{};
|
||||
std::optional<float> positionX{};
|
||||
std::optional<float> positionY{};
|
||||
std::optional<float> sizeX{};
|
||||
std::optional<float> sizeY{};
|
||||
std::optional<float> scaleX{};
|
||||
std::optional<float> scaleY{};
|
||||
std::optional<float> shearX{};
|
||||
std::optional<float> shearY{};
|
||||
std::optional<float> colorOffsetR{};
|
||||
std::optional<float> colorOffsetG{};
|
||||
std::optional<float> colorOffsetB{};
|
||||
std::optional<float> tintR{};
|
||||
std::optional<float> tintG{};
|
||||
std::optional<float> tintB{};
|
||||
std::optional<float> tintA{};
|
||||
std::optional<bool> isFlipX{};
|
||||
std::optional<bool> isFlipY{};
|
||||
};
|
||||
|
||||
inline constexpr StringType INTERPOLATION_LABELS[] = {BASIC_NONE, BASIC_LINEAR, BASIC_EASE_IN, BASIC_EASE_OUT,
|
||||
BASIC_EASE_IN_OUT};
|
||||
|
||||
struct Element
|
||||
{
|
||||
ElementType type{ElementType::UNKNOWN};
|
||||
|
||||
+14
-58
@@ -11,7 +11,6 @@ namespace anm2ed
|
||||
ALL
|
||||
};
|
||||
|
||||
|
||||
void frame_mix(Element& frame, const Element& next, float amount)
|
||||
{
|
||||
frame.rotation = glm::mix(frame.rotation, next.rotation, amount);
|
||||
@@ -254,40 +253,17 @@ namespace anm2ed
|
||||
void frames_change(Element& track, FrameChange change, ItemType itemType, ChangeType changeType,
|
||||
const std::set<int>& selection)
|
||||
{
|
||||
const auto clamp_identity = [](auto value) { return value; };
|
||||
const auto clamp_duration = [](int value) { return std::max(FRAME_DURATION_MIN, value); };
|
||||
|
||||
if (selection.empty()) return;
|
||||
|
||||
auto apply_scalar_with_clamp = [&](auto& target, const auto& optionalValue, auto clampFunc)
|
||||
auto apply = [&](auto& target, const auto& optionalValue)
|
||||
{
|
||||
if (!optionalValue) return;
|
||||
auto value = *optionalValue;
|
||||
|
||||
switch (changeType)
|
||||
{
|
||||
case ChangeType::ADJUST:
|
||||
target = clampFunc(value);
|
||||
break;
|
||||
case ChangeType::ADD:
|
||||
target = clampFunc(target + value);
|
||||
break;
|
||||
case ChangeType::SUBTRACT:
|
||||
target = clampFunc(target - value);
|
||||
break;
|
||||
case ChangeType::MULTIPLY:
|
||||
target = clampFunc(target * value);
|
||||
break;
|
||||
case ChangeType::DIVIDE:
|
||||
if (value == decltype(value){}) return;
|
||||
target = clampFunc(target / value);
|
||||
break;
|
||||
}
|
||||
if (changeType == ChangeType::ADJUST) target = value;
|
||||
if (changeType == ChangeType::ADD) target += value;
|
||||
if (changeType == ChangeType::SUBTRACT) target -= value;
|
||||
if (changeType == ChangeType::MULTIPLY) target *= value;
|
||||
if (changeType == ChangeType::DIVIDE && value != decltype(value){}) target /= value;
|
||||
};
|
||||
|
||||
auto apply_scalar = [&](auto& target, const auto& optionalValue)
|
||||
{ apply_scalar_with_clamp(target, optionalValue, clamp_identity); };
|
||||
|
||||
for (auto index : selection)
|
||||
{
|
||||
auto frame = track_frame_get(track, index);
|
||||
@@ -298,34 +274,14 @@ namespace anm2ed
|
||||
if (change.isFlipX) frame->scale.x = -frame->scale.x;
|
||||
if (change.isFlipY) frame->scale.y = -frame->scale.y;
|
||||
|
||||
apply_scalar(frame->rotation, change.rotation);
|
||||
apply_scalar_with_clamp(frame->duration, change.duration, clamp_duration);
|
||||
|
||||
if (itemType == ItemType::LAYER)
|
||||
{
|
||||
apply_scalar(frame->crop.x, change.cropX);
|
||||
apply_scalar(frame->crop.y, change.cropY);
|
||||
apply_scalar(frame->pivot.x, change.pivotX);
|
||||
apply_scalar(frame->pivot.y, change.pivotY);
|
||||
apply_scalar(frame->size.x, change.sizeX);
|
||||
apply_scalar(frame->size.y, change.sizeY);
|
||||
if (change.regionId) frame->regionId = *change.regionId;
|
||||
if (change.shaderId) frame->shaderId = *change.shaderId;
|
||||
}
|
||||
|
||||
apply_scalar(frame->position.x, change.positionX);
|
||||
apply_scalar(frame->position.y, change.positionY);
|
||||
apply_scalar(frame->scale.x, change.scaleX);
|
||||
apply_scalar(frame->scale.y, change.scaleY);
|
||||
apply_scalar(frame->shear.x, change.shearX);
|
||||
apply_scalar(frame->shear.y, change.shearY);
|
||||
apply_scalar(frame->colorOffset.x, change.colorOffsetR);
|
||||
apply_scalar(frame->colorOffset.y, change.colorOffsetG);
|
||||
apply_scalar(frame->colorOffset.z, change.colorOffsetB);
|
||||
apply_scalar(frame->tint.x, change.tintR);
|
||||
apply_scalar(frame->tint.y, change.tintG);
|
||||
apply_scalar(frame->tint.z, change.tintB);
|
||||
apply_scalar(frame->tint.w, change.tintA);
|
||||
apply(frame->duration, change.duration);
|
||||
if (change.duration) frame->duration = std::max(FRAME_DURATION_MIN, frame->duration);
|
||||
if (itemType == ItemType::LAYER && change.regionId) frame->regionId = *change.regionId;
|
||||
if (itemType == ItemType::LAYER && change.shaderId) frame->shaderId = *change.shaderId;
|
||||
#define X(name, member, isLayerOnly, isColor, isEnabled, value) \
|
||||
if (!isLayerOnly || itemType == ItemType::LAYER) apply(frame->member, change.name);
|
||||
FRAME_CHANGE_SCALARS
|
||||
#undef X
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -955,6 +955,13 @@ namespace anm2ed
|
||||
return result;
|
||||
}
|
||||
|
||||
Storage* Document::layer_regions_get(int layerId)
|
||||
{
|
||||
auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, layerId);
|
||||
auto regions = layer ? regionBySpritesheet.find(layer->spritesheetId) : regionBySpritesheet.end();
|
||||
return regions == regionBySpritesheet.end() ? nullptr : ®ions->second;
|
||||
}
|
||||
|
||||
Element* Document::frame_get() { return anm2.element_get(reference); }
|
||||
Element* Document::item_get() { return anm2.element_get(document::item_reference_get(reference)); }
|
||||
Element* Document::animation_get() { return anm2.element_get(ElementType::ANIMATION, reference.animationIndex); }
|
||||
|
||||
@@ -137,6 +137,7 @@ namespace anm2ed
|
||||
void frame_references_clear();
|
||||
std::vector<Reference> layer_references_get();
|
||||
|
||||
Storage* layer_regions_get(int);
|
||||
Element* frame_get();
|
||||
Element* item_get();
|
||||
Element* spritesheet_get();
|
||||
|
||||
@@ -17,6 +17,33 @@ using namespace glm;
|
||||
|
||||
namespace anm2ed::imgui
|
||||
{
|
||||
struct Vec2Field
|
||||
{
|
||||
StringType label;
|
||||
StringType tooltip;
|
||||
StringType edit;
|
||||
vec2 Element::* member;
|
||||
bool isRegionField;
|
||||
};
|
||||
|
||||
constexpr Vec2Field VEC2_FIELDS[] = {
|
||||
{BASIC_CROP, TOOLTIP_CROP, EDIT_FRAME_CROP, &Element::crop, true},
|
||||
{BASIC_SIZE, TOOLTIP_SIZE, EDIT_FRAME_SIZE, &Element::size, true},
|
||||
{BASIC_POSITION, TOOLTIP_POSITION, EDIT_FRAME_POSITION, &Element::position, false},
|
||||
{BASIC_PIVOT, TOOLTIP_PIVOT, EDIT_FRAME_PIVOT, &Element::pivot, true},
|
||||
{BASIC_SCALE, TOOLTIP_SCALE, EDIT_FRAME_SCALE, &Element::scale, false},
|
||||
{BASIC_SHEAR, TOOLTIP_SHEAR, EDIT_FRAME_SHEAR, &Element::shear, false}};
|
||||
|
||||
struct FlipButton
|
||||
{
|
||||
StringType label;
|
||||
StringType edit;
|
||||
StringType tooltip;
|
||||
};
|
||||
|
||||
constexpr FlipButton FLIP_BUTTONS[] = {{LABEL_FLIP_X, EDIT_FRAME_FLIP_X, TOOLTIP_FLIP_X},
|
||||
{LABEL_FLIP_Y, EDIT_FRAME_FLIP_Y, TOOLTIP_FLIP_Y}};
|
||||
|
||||
void FrameProperties::update(Manager& manager, Settings& settings)
|
||||
{
|
||||
auto& document = *manager.get();
|
||||
@@ -37,72 +64,31 @@ namespace anm2ed::imgui
|
||||
auto& type = reference.itemType;
|
||||
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, [=](Manager&, Document& document) mutable
|
||||
{
|
||||
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.snapshots.frames_push(localize.get(message), {queuedReference});
|
||||
behavior(document, *frame, item, queuedReference);
|
||||
document.change(Document::FRAMES);
|
||||
}});
|
||||
};
|
||||
|
||||
auto persistent_edit = [&](auto state, auto message, auto behavior)
|
||||
auto frame_edit = [&](edit::Type state, StringType message, auto behavior)
|
||||
{
|
||||
if (state == edit::NONE) return;
|
||||
|
||||
auto queuedReference = reference;
|
||||
manager.command_push({manager.selected, [=](Manager&, Document& document) mutable
|
||||
{
|
||||
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.snapshots.frames_push(localize.get(message), {queuedReference});
|
||||
behavior(document, *frame, item, queuedReference);
|
||||
if (state == edit::END) document.change(Document::FRAMES);
|
||||
}});
|
||||
manager.command_push(
|
||||
{manager.selected, [=, queuedReference = reference](Manager&, Document& document) mutable
|
||||
{
|
||||
auto frame = queuedReference.frameIndex < 0 ? nullptr : document.anm2.element_get(queuedReference);
|
||||
if (!frame) return;
|
||||
auto item = document.anm2.element_get(Reference{queuedReference.animationIndex, queuedReference.itemType,
|
||||
queuedReference.itemID, -1, queuedReference.groupType,
|
||||
queuedReference.groupId});
|
||||
if (state == edit::START || state == edit::COMPLETE)
|
||||
document.snapshots.frames_push(localize.get(message), {queuedReference});
|
||||
behavior(document, *frame, item, queuedReference);
|
||||
if (state == edit::END || state == edit::COMPLETE) document.change(Document::FRAMES);
|
||||
}});
|
||||
};
|
||||
|
||||
auto regionLabelsString = std::vector<std::string>{localize.get(BASIC_NONE)};
|
||||
auto regionLabels = std::vector<const char*>{regionLabelsString[0].c_str()};
|
||||
auto regionIds = std::vector<int>{-1};
|
||||
auto interpolationLabelsString =
|
||||
std::vector<std::string>{localize.get(BASIC_NONE), localize.get(BASIC_LINEAR), localize.get(BASIC_EASE_IN),
|
||||
localize.get(BASIC_EASE_OUT), localize.get(BASIC_EASE_IN_OUT)};
|
||||
auto interpolationLabels =
|
||||
std::vector<const char*>{interpolationLabelsString[0].c_str(), interpolationLabelsString[1].c_str(),
|
||||
interpolationLabelsString[2].c_str(), interpolationLabelsString[3].c_str(),
|
||||
interpolationLabelsString[4].c_str()};
|
||||
auto interpolationValues =
|
||||
std::vector<int>{(int)Interpolation::NONE, (int)Interpolation::LINEAR, (int)Interpolation::EASE_IN,
|
||||
(int)Interpolation::EASE_OUT, (int)Interpolation::EASE_IN_OUT};
|
||||
|
||||
if (type == LAYER && reference.itemID != -1)
|
||||
{
|
||||
if (auto layer = anm2.element_get(ElementType::LAYER_ELEMENT, reference.itemID))
|
||||
{
|
||||
auto regionIt = document.regionBySpritesheet.find(layer->spritesheetId);
|
||||
if (regionIt != document.regionBySpritesheet.end() && !regionIt->second.ids.empty() &&
|
||||
!regionIt->second.labels.empty())
|
||||
{
|
||||
regionLabels = regionIt->second.labels;
|
||||
regionIds = regionIt->second.ids;
|
||||
}
|
||||
}
|
||||
}
|
||||
auto regions = document.layer_regions_get(type == LAYER ? reference.itemID : -1);
|
||||
auto noneLabel = std::string(localize.get(BASIC_NONE));
|
||||
auto regionLabels = regions ? regions->labels : std::vector<const char*>{noneLabel.c_str()};
|
||||
auto regionIds = regions ? regions->ids : std::vector<int>{-1};
|
||||
std::vector<const char*> interpolationLabels{};
|
||||
for (auto label : INTERPOLATION_LABELS)
|
||||
interpolationLabels.push_back(localize.get(label));
|
||||
|
||||
auto mode_selector_draw = [&]()
|
||||
{
|
||||
@@ -136,7 +122,7 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto eventId = useFrame.eventId;
|
||||
frame_edit(EDIT_TRIGGER_EVENT,
|
||||
frame_edit(edit::COMPLETE, EDIT_TRIGGER_EVENT,
|
||||
[eventId](Document&, Element& frame, Element*, const Reference&) { frame.eventId = eventId; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TRIGGER_EVENT));
|
||||
@@ -147,7 +133,7 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto atFrame = useFrame.atFrame;
|
||||
frame_edit(EDIT_TRIGGER_AT_FRAME,
|
||||
frame_edit(edit::COMPLETE, EDIT_TRIGGER_AT_FRAME,
|
||||
[atFrame](Document& document, Element& frame, Element* item, const Reference&)
|
||||
{
|
||||
frame.atFrame = atFrame;
|
||||
@@ -163,7 +149,8 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto isVisible = useFrame.isVisible;
|
||||
frame_edit(EDIT_TRIGGER_VISIBILITY, [isVisible](Document&, Element& frame, Element*, const Reference&)
|
||||
frame_edit(edit::COMPLETE, EDIT_TRIGGER_VISIBILITY,
|
||||
[isVisible](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.isVisible = isVisible; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TRIGGER_VISIBILITY));
|
||||
@@ -185,7 +172,7 @@ namespace anm2ed::imgui
|
||||
{
|
||||
auto soundIndex = (std::size_t)i;
|
||||
auto soundId = id;
|
||||
frame_edit(EDIT_TRIGGER_SOUND,
|
||||
frame_edit(edit::COMPLETE, EDIT_TRIGGER_SOUND,
|
||||
[soundIndex, soundId](Document&, Element& frame, Element*, const Reference&)
|
||||
{
|
||||
if (soundIndex < frame.soundIds.size()) frame.soundIds[soundIndex] = soundId;
|
||||
@@ -201,7 +188,7 @@ namespace anm2ed::imgui
|
||||
auto widgetSize = imgui::widget_size_with_row_get(2);
|
||||
|
||||
if (ImGui::Button(localize.get(BASIC_ADD), widgetSize) && frame)
|
||||
frame_edit(EDIT_ADD_TRIGGER_SOUND,
|
||||
frame_edit(edit::COMPLETE, EDIT_ADD_TRIGGER_SOUND,
|
||||
[](Document&, Element& frame, Element*, const Reference&) { frame.soundIds.push_back(-1); });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ADD_TRIGGER_SOUND));
|
||||
|
||||
@@ -209,7 +196,7 @@ namespace anm2ed::imgui
|
||||
|
||||
ImGui::BeginDisabled(useFrame.soundIds.empty());
|
||||
if (ImGui::Button(localize.get(BASIC_REMOVE), widgetSize) && frame)
|
||||
frame_edit(EDIT_REMOVE_TRIGGER_SOUND,
|
||||
frame_edit(edit::COMPLETE, EDIT_REMOVE_TRIGGER_SOUND,
|
||||
[](Document&, Element& frame, Element*, const Reference&)
|
||||
{
|
||||
if (!frame.soundIds.empty()) frame.soundIds.pop_back();
|
||||
@@ -221,71 +208,27 @@ namespace anm2ed::imgui
|
||||
{
|
||||
bool isRegionSet = frame && displayFrame.regionId != -1 && displayFrame.crop == frame->crop &&
|
||||
displayFrame.size == frame->size && displayFrame.pivot == frame->pivot;
|
||||
ImGui::BeginDisabled(type == ROOT || type == NULL_ || isRegionSet);
|
||||
for (auto& field : VEC2_FIELDS)
|
||||
{
|
||||
auto cropDisplay = frame ? displayFrame.crop : vec2();
|
||||
auto cropEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_CROP), frame ? &cropDisplay : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(displayFrame.crop) : "");
|
||||
persistent_edit(cropEdit, EDIT_FRAME_CROP,
|
||||
[cropDisplay](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.crop = cropDisplay; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_CROP));
|
||||
|
||||
auto sizeDisplay = frame ? displayFrame.size : vec2();
|
||||
auto sizeEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_SIZE), frame ? &sizeDisplay : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(displayFrame.size) : "");
|
||||
persistent_edit(sizeEdit, EDIT_FRAME_SIZE,
|
||||
[sizeDisplay](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.size = sizeDisplay; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SIZE));
|
||||
const auto& source = field.isRegionField ? displayFrame : useFrame;
|
||||
auto value = frame ? source.*field.member : vec2();
|
||||
ImGui::BeginDisabled(field.isRegionField && (type == ROOT || type == NULL_ || isRegionSet));
|
||||
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) : "");
|
||||
frame_edit(state, field.edit,
|
||||
[value, member = field.member](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.*member = value; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(field.tooltip));
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
auto positionEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_POSITION), frame ? &useFrame.position : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(frame->position) : "");
|
||||
persistent_edit(positionEdit, EDIT_FRAME_POSITION,
|
||||
[position = useFrame.position](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.position = position; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_POSITION));
|
||||
|
||||
ImGui::BeginDisabled(type == ROOT || type == NULL_ || isRegionSet);
|
||||
{
|
||||
auto pivotDisplay = frame ? displayFrame.pivot : vec2();
|
||||
auto pivotEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_PIVOT), frame ? &pivotDisplay : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(displayFrame.pivot) : "");
|
||||
persistent_edit(pivotEdit, EDIT_FRAME_PIVOT,
|
||||
[pivotDisplay](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.pivot = pivotDisplay; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_PIVOT));
|
||||
}
|
||||
ImGui::EndDisabled();
|
||||
|
||||
auto scaleEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_SCALE), frame ? &useFrame.scale : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(frame->scale) : "");
|
||||
persistent_edit(scaleEdit, EDIT_FRAME_SCALE,
|
||||
[scale = useFrame.scale](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.scale = scale; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SCALE));
|
||||
|
||||
auto shearEdit =
|
||||
drag_float2_persistent(localize.get(BASIC_SHEAR), frame ? &useFrame.shear : &dummy_value<vec2>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? vec2_format_get(frame->shear) : "");
|
||||
persistent_edit(shearEdit, EDIT_FRAME_SHEAR,
|
||||
[shear = useFrame.shear](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.shear = shear; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_SHEAR));
|
||||
|
||||
auto rotationEdit =
|
||||
drag_float_persistent(localize.get(BASIC_ROTATION), frame ? &useFrame.rotation : &dummy_value<float>(),
|
||||
DRAG_SPEED, 0.0f, 0.0f, frame ? float_format_get(frame->rotation) : "");
|
||||
persistent_edit(rotationEdit, EDIT_FRAME_ROTATION,
|
||||
[rotation = useFrame.rotation](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.rotation = rotation; });
|
||||
frame_edit(rotationEdit, EDIT_FRAME_ROTATION,
|
||||
[rotation = useFrame.rotation](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.rotation = rotation; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_ROTATION));
|
||||
|
||||
if (input_int_range(localize.get(BASIC_DURATION), frame ? useFrame.duration : dummy_value<int>(),
|
||||
@@ -294,23 +237,24 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto duration = useFrame.duration;
|
||||
frame_edit(EDIT_FRAME_DURATION, [duration](Document&, Element& frame, Element*, const Reference&)
|
||||
frame_edit(edit::COMPLETE, EDIT_FRAME_DURATION,
|
||||
[duration](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.duration = duration; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_DURATION));
|
||||
|
||||
auto tintEdit =
|
||||
color_edit4_persistent(localize.get(BASIC_TINT), frame ? &useFrame.tint : &dummy_value<vec4>());
|
||||
persistent_edit(tintEdit, EDIT_FRAME_TINT,
|
||||
[tint = useFrame.tint](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.tint = tint; });
|
||||
frame_edit(tintEdit, EDIT_FRAME_TINT,
|
||||
[tint = useFrame.tint](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.tint = tint; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_TINT));
|
||||
|
||||
auto colorOffsetEdit = color_edit3_persistent(localize.get(BASIC_COLOR_OFFSET),
|
||||
frame ? &useFrame.colorOffset : &dummy_value<vec3>());
|
||||
persistent_edit(colorOffsetEdit, EDIT_FRAME_COLOR_OFFSET,
|
||||
[colorOffset = useFrame.colorOffset](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.colorOffset = colorOffset; });
|
||||
frame_edit(colorOffsetEdit, EDIT_FRAME_COLOR_OFFSET,
|
||||
[colorOffset = useFrame.colorOffset](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.colorOffset = colorOffset; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_COLOR_OFFSET));
|
||||
|
||||
ImGui::BeginDisabled(type != LAYER);
|
||||
@@ -319,7 +263,7 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto regionId = useFrame.regionId;
|
||||
frame_edit(EDIT_SET_REGION_PROPERTIES,
|
||||
frame_edit(edit::COMPLETE, EDIT_SET_REGION_PROPERTIES,
|
||||
[regionId](Document& document, Element& frame, Element*, const Reference& reference)
|
||||
{
|
||||
frame.regionId = regionId;
|
||||
@@ -333,10 +277,10 @@ namespace anm2ed::imgui
|
||||
ImGui::EndDisabled();
|
||||
|
||||
auto interpolationValue = frame ? static_cast<int>(useFrame.interpolation) : dummy_value<int>();
|
||||
if (combo_id_mapped(localize.get(BASIC_INTERPOLATED), &interpolationValue, interpolationValues,
|
||||
interpolationLabels) &&
|
||||
if (ImGui::Combo(localize.get(BASIC_INTERPOLATED), &interpolationValue, interpolationLabels.data(),
|
||||
(int)interpolationLabels.size()) &&
|
||||
frame)
|
||||
frame_edit(EDIT_FRAME_INTERPOLATION,
|
||||
frame_edit(edit::COMPLETE, EDIT_FRAME_INTERPOLATION,
|
||||
[interpolationValue](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.interpolation = static_cast<Interpolation>(interpolationValue); });
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FRAME_INTERPOLATION));
|
||||
@@ -347,7 +291,8 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto shaderId = useFrame.shaderId;
|
||||
frame_edit(EDIT_FRAME_SHADER, [shaderId](Document&, Element& frame, Element*, const Reference&)
|
||||
frame_edit(edit::COMPLETE, EDIT_FRAME_SHADER,
|
||||
[shaderId](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.shaderId = shaderId; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FRAME_SHADER));
|
||||
@@ -357,42 +302,27 @@ namespace anm2ed::imgui
|
||||
frame)
|
||||
{
|
||||
auto isVisible = useFrame.isVisible;
|
||||
frame_edit(EDIT_FRAME_VISIBILITY, [isVisible](Document&, Element& frame, Element*, const Reference&)
|
||||
frame_edit(edit::COMPLETE, EDIT_FRAME_VISIBILITY,
|
||||
[isVisible](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.isVisible = isVisible; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FRAME_VISIBILITY));
|
||||
|
||||
auto widgetSize = widget_size_with_row_get(2);
|
||||
|
||||
if (ImGui::Button(localize.get(LABEL_FLIP_X), widgetSize) && frame)
|
||||
for (int axis = 0; axis < (int)std::size(FLIP_BUTTONS); ++axis)
|
||||
{
|
||||
if (ImGui::IsKeyDown(ImGuiMod_Ctrl))
|
||||
frame_edit(EDIT_FRAME_FLIP_X,
|
||||
[](Document&, Element& frame, Element*, const Reference&)
|
||||
if (axis > 0) ImGui::SameLine();
|
||||
if (ImGui::Button(localize.get(FLIP_BUTTONS[axis].label), widgetSize) && frame)
|
||||
frame_edit(edit::COMPLETE, FLIP_BUTTONS[axis].edit,
|
||||
[axis, isPositionFlipped = ImGui::IsKeyDown(ImGuiMod_Ctrl)](Document&, Element& frame,
|
||||
Element*, const Reference&)
|
||||
{
|
||||
frame.scale.x = -frame.scale.x;
|
||||
frame.position.x = -frame.position.x;
|
||||
frame.scale[axis] = -frame.scale[axis];
|
||||
if (isPositionFlipped) frame.position[axis] = -frame.position[axis];
|
||||
});
|
||||
else
|
||||
frame_edit(EDIT_FRAME_FLIP_X, [](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.scale.x = -frame.scale.x; });
|
||||
ImGui::SetItemTooltip("%s", localize.get(FLIP_BUTTONS[axis].tooltip));
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FLIP_X));
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(localize.get(LABEL_FLIP_Y), widgetSize) && frame)
|
||||
{
|
||||
if (ImGui::IsKeyDown(ImGuiMod_Ctrl))
|
||||
frame_edit(EDIT_FRAME_FLIP_Y,
|
||||
[](Document&, Element& frame, Element*, const Reference&)
|
||||
{
|
||||
frame.scale.y = -frame.scale.y;
|
||||
frame.position.y = -frame.position.y;
|
||||
});
|
||||
else
|
||||
frame_edit(EDIT_FRAME_FLIP_Y, [](Document&, Element& frame, Element*, const Reference&)
|
||||
{ frame.scale.y = -frame.scale.y; });
|
||||
}
|
||||
ImGui::SetItemTooltip("%s", localize.get(TOOLTIP_FLIP_Y));
|
||||
|
||||
ImGui::Separator();
|
||||
ImGui::Dummy(ImVec2(0.0f, ImGui::GetFrameHeight()));
|
||||
|
||||
@@ -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 = ®ionIt->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), ®ionId, 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();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -86,7 +86,8 @@ namespace anm2ed::types::edit
|
||||
NONE,
|
||||
START,
|
||||
DURING,
|
||||
END
|
||||
END,
|
||||
COMPLETE
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ namespace anm2ed::util::math
|
||||
return formatString.c_str();
|
||||
}
|
||||
|
||||
const char* vec2_format_get(vec2& value)
|
||||
const char* vec2_format_get(const vec2& value)
|
||||
{
|
||||
static std::string formatString{};
|
||||
int decimalCountX = float_decimals_needed(value.x);
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ namespace anm2ed::util::math
|
||||
|
||||
const char* float_format_get(float);
|
||||
|
||||
const char* vec2_format_get(glm::vec2&);
|
||||
const char* vec2_format_get(const glm::vec2&);
|
||||
|
||||
glm::mat4 quad_model_get(glm::vec2 = {}, glm::vec2 = {}, glm::vec2 = {}, glm::vec2 = glm::vec2(1.0f), float = {},
|
||||
glm::vec2 = {});
|
||||
|
||||
Reference in new issue
Block a user