From 3b617f29a8268ce8b57b7c30bb84da862db3c55c Mon Sep 17 00:00:00 2001 From: Kakarot Date: Thu, 3 Dec 2026 02:00:44 -0600 Subject: [PATCH] Consumable use time with a Use clip, and where an animation pack is stored - Build an item, consumable: with a Use clip the game ignores useSeconds (the use lasts the clip's length), so the "Choose how long one use takes" box is replaced by "Use time: set by your Use animation.", the effect line is the clip's own time and the summary says so. - A finished animation pack publish pointed at Place Settings > Storage, which refuses packs. It now names the Avatar Storage entry to add (Name, Kind animPack, Item, Version). Co-Authored-By: Claude Sonnet 5.5 --- .../MantleEditor/Private/MantleAnimPack.cpp | 6 ++++++ Source/MantleEditor/Private/MantleAnimPack.h | 6 ++++++ .../Private/MantleConsumableEffect.cpp | 21 +++++++++++++------ .../Private/MantleConsumableEffect.h | 10 +++++++-- .../Private/MantleDevItemBuilderShot.cpp | 10 +++++---- .../Private/MantlePlacePublishSession.cpp | 6 ++++++ .../Private/SMantleWeaponBuilder.cpp | 17 +++++++++++++-- .../Private/Tests/MantleCreatorClipsTest.cpp | 4 ++++ .../MantleWeaponBuilderConsumableTest.cpp | 10 +++++++-- .../Public/MantlePlaceSettingsActor.h | 2 +- 10 files changed, 75 insertions(+), 17 deletions(-) diff --git a/Source/MantleEditor/Private/MantleAnimPack.cpp b/Source/MantleEditor/Private/MantleAnimPack.cpp index cf20a5af..3c537dd9 100644 --- a/Source/MantleEditor/Private/MantleAnimPack.cpp +++ b/Source/MantleEditor/Private/MantleAnimPack.cpp @@ -97,6 +97,12 @@ TArray FMantleAnimPack::CheckPack(const TConstArrayView Names) return Problems; } +FString FMantleAnimPack::PublishedMessage(const FString& Name, const bool bPublic, const int32 Version, const FString& ItemId) +{ + return FString::Printf(TEXT("'%s' is in your library (%s, version %d). To use it in a place, choose Tools > Mantle > Place settings and add an Avatar Storage entry: a Name, Kind %s, Item %s, Version %d."), + *Name, bPublic ? TEXT("public") : TEXT("private"), Version, LibraryKind(), *ItemId, Version); +} + FString FMantleAnimPack::WriteDocument(const TConstArrayView Entries) { FString Text; diff --git a/Source/MantleEditor/Private/MantleAnimPack.h b/Source/MantleEditor/Private/MantleAnimPack.h index 3316d54d..c636a105 100644 --- a/Source/MantleEditor/Private/MantleAnimPack.h +++ b/Source/MantleEditor/Private/MantleAnimPack.h @@ -48,6 +48,12 @@ struct FMantleAnimPack /** Why a pack cannot be published, in plain words, one line each; empty when it can: no clips, over MaxClips, a missing, unusable or repeated name. */ static TArray CheckPack(TConstArrayView Names); + /** + * What a finished publish tells the creator. A place stores a pack in Avatar Storage on Mantle Place Settings (plain Storage + * refuses it), by hand: the Library window does not add packs. + */ + static FString PublishedMessage(const FString& Name, bool bPublic, int32 Version, const FString& ItemId); + /** The document's JSON text (compact), the entries in the order given. */ static FString WriteDocument(TConstArrayView Entries); }; diff --git a/Source/MantleEditor/Private/MantleConsumableEffect.cpp b/Source/MantleEditor/Private/MantleConsumableEffect.cpp index edef06b5..f84d0a7e 100644 --- a/Source/MantleEditor/Private/MantleConsumableEffect.cpp +++ b/Source/MantleEditor/Private/MantleConsumableEffect.cpp @@ -45,6 +45,20 @@ TOptional FMantleConsumableEffect::DocumentSeconds(const UMantleWeaponSo return Clip ? MomentIn(ConvertedSeconds(*Clip)) : TOptional(); } +bool FMantleConsumableEffect::OffersUseTime(const UMantleWeaponSource& Source) +{ + return Source.ClipUse.IsNull(); +} + +FString FMantleConsumableEffect::UseTimeSummary(const UMantleWeaponSource& Source) +{ + if (!OffersUseTime(Source)) + { + return TEXT("your Use animation's length"); + } + return Source.Consumable.bOverrideUseSeconds ? FString::Printf(TEXT("%.1f seconds"), Source.Consumable.UseSeconds) : FString(TEXT("the animation's own length")); +} + FText FMantleConsumableEffect::Line(const UMantleWeaponSource& Source) { const TOptional Moment = DocumentSeconds(Source); @@ -52,15 +66,10 @@ FText FMantleConsumableEffect::Line(const UMantleWeaponSource& Source) { return FText::GetEmpty(); } - double Played = Moment.GetValue(); - if (Source.Consumable.bOverrideUseSeconds) - { - Played *= Source.Consumable.UseSeconds / ConvertedSeconds(*Source.ClipUse.Get()); - } FNumberFormattingOptions Format; Format.SetMinimumFractionalDigits(1); Format.SetMaximumFractionalDigits(1); - return FText::Format(LOCTEXT("EffectAt", "The effect happens at {0} s."), FText::AsNumber(Played, &Format)); + return FText::Format(LOCTEXT("EffectAt", "The effect happens at {0} s."), FText::AsNumber(Moment.GetValue(), &Format)); } #undef LOCTEXT_NAMESPACE diff --git a/Source/MantleEditor/Private/MantleConsumableEffect.h b/Source/MantleEditor/Private/MantleConsumableEffect.h index 4468fdb6..37a7e31d 100644 --- a/Source/MantleEditor/Private/MantleConsumableEffect.h +++ b/Source/MantleEditor/Private/MantleConsumableEffect.h @@ -27,9 +27,15 @@ struct FMantleConsumableEffect /** The document's useEffectSeconds for a source: set only for a consumable with a Use clip. Loads the clip. Game thread. */ static TOptional DocumentSeconds(const UMantleWeaponSource& Source); + /** Whether the creator may choose how long one use takes: not with their own Use clip, whose length is the use's in the game. */ + static bool OffersUseTime(const UMantleWeaponSource& Source); + + /** The "Use time" words of the builder's summary. */ + static FString UseTimeSummary(const UMantleWeaponSource& Source); + /** - * The line the builder shows beside the Use slot, with the time as it plays: a chosen use time speeds the clip up or slows it - * down, and the moment moves with it. Empty when DocumentSeconds is unset. Loads the clip. Game thread. + * The line the builder shows beside the Use slot: the game plays the creator's clip at its own speed (a chosen use time does + * not apply), so the time is the document's. Empty when DocumentSeconds is unset. Loads the clip. Game thread. */ static FText Line(const UMantleWeaponSource& Source); }; diff --git a/Source/MantleEditor/Private/MantleDevItemBuilderShot.cpp b/Source/MantleEditor/Private/MantleDevItemBuilderShot.cpp index 6f6deb3e..cd21df67 100644 --- a/Source/MantleEditor/Private/MantleDevItemBuilderShot.cpp +++ b/Source/MantleEditor/Private/MantleDevItemBuilderShot.cpp @@ -2,7 +2,7 @@ // // Maintainer command: Mantle.Dev.ItemBuilderShots [Exit] // Opens Build an item in a window and goes through it three times: a consumable (hunger) with the clip as Use, a usable item with the clip as Hold, -// and a pistol (mantle #333 P2). The type picker, each Animations screen and the usable item's size screen (tipped forward) are photographed into after 30 frames, and the usable item's Animations +// and a pistol (mantle #333 P2). The type picker, each Animations screen, the consumable's "Use and effect" screen (with the Use clip set and a use time chosen before it) and the usable item's size screen (tipped forward) are photographed into after 30 frames, and the usable item's Animations // screen once more with its Hold clip playing and the item in the hand; each item is created (so its document is written under // /Game/MantleWeapons/P2Shot*/), and its clip is played on the Animations screen. Nothing uploads. The editor needs to draw // (no -nullrhi). Logs MANTLE_ITEM_SHOT lines. @@ -115,6 +115,8 @@ struct FMantleItemBuilderShotAccess // A hunger consumable, so the written document is one with an effect and its amount (mantle #333 G4). Held->Panel->Working->Consumable.Effect = EMantleWeaponSourceConsumableEffect::Hunger; Held->Panel->Working->Consumable.Amount = 40.f; + // A use time chosen before the Use clip: the "Use and effect" picture shows it is no longer offered. + Held->Panel->Working->Consumable.bOverrideUseSeconds = true; } } }); // The screens' count depends on the type, which the first step picks, so each later step is queued by its place and skipped past the end. @@ -130,9 +132,9 @@ struct FMantleItemBuilderShotAccess return; } const FString Title = Panel.Flow->GetSteps()[Step].Title.ToString(); - // Pictures are of the builder's new screens only: the type picker and the Animations screen (the size screen has its own shots - // after the item is created). The other screens are gone through unphotographed. - Held->bSkip = Title != TEXT("Animations"); + // Pictures are of the builder's new screens only: the type picker, the Animations screen and the consumable's "Use and effect" + // (the size screen has its own shots after the item is created). The other screens are gone through unphotographed. + Held->bSkip = Title != TEXT("Animations") && !(Hold == EMantleWeaponHold::Consumable && Title == TEXT("Use and effect")); if (Panel.Working->Model.IsNull()) { Panel.SetModel(Model); diff --git a/Source/MantleEditor/Private/MantlePlacePublishSession.cpp b/Source/MantleEditor/Private/MantlePlacePublishSession.cpp index b6a1003b..714582d3 100644 --- a/Source/MantleEditor/Private/MantlePlacePublishSession.cpp +++ b/Source/MantleEditor/Private/MantlePlacePublishSession.cpp @@ -2933,6 +2933,12 @@ void FMantlePlacePublishSession::FinishLibrary() Fail(FString::Printf(TEXT("'%s' was uploaded, but nothing was added to your library. Publish again; nothing is uploaded twice."), *GetLevelName())); return; } + // #333: an animation pack (published on its own) goes in a place's Avatar Storage, not in Storage. + if (LibraryRefs.Num() == 1 && LibraryJobs.ContainsByPredicate([](const FLibraryJob& Candidate) { return Candidate.bAnimPack; })) + { + Finish(FMantleAnimPack::PublishedMessage(LibraryRefs[0].Name, bLibraryPublic, LibraryRefs[0].Version, LibraryRefs[0].ItemId)); + return; + } Finish(LibraryRefs.Num() == 1 ? FString::Printf(TEXT("'%s' is in your library (%s, version %d). Add it to a place from Place Settings > Storage."), *LibraryRefs[0].Name, bLibraryPublic ? TEXT("public") : TEXT("private"), LibraryRefs[0].Version) diff --git a/Source/MantleEditor/Private/SMantleWeaponBuilder.cpp b/Source/MantleEditor/Private/SMantleWeaponBuilder.cpp index 63cb62f0..e807e1e8 100644 --- a/Source/MantleEditor/Private/SMantleWeaponBuilder.cpp +++ b/Source/MantleEditor/Private/SMantleWeaponBuilder.cpp @@ -1333,7 +1333,7 @@ FText SMantleWeaponBuilder::SummaryText() const Lines.Add(FString::Printf(TEXT("Gives %s: %.0f; uses: %d"), What, C.Amount, C.Uses)); } Lines.Add(FString::Printf(TEXT("Use time: %s; wait between uses: %.1f seconds; %s"), - C.bOverrideUseSeconds ? *FString::Printf(TEXT("%.1f seconds"), C.UseSeconds) : TEXT("the animation's own length"), C.CooldownSeconds, + *FMantleConsumableEffect::UseTimeSummary(*Working), C.CooldownSeconds, C.bMoveWhileUsing ? TEXT("can walk while using") : TEXT("stands still while using"))); } else @@ -2114,9 +2114,19 @@ TSharedRef SMantleWeaponBuilder::MakeTuningStep() + SVerticalBox::Slot().AutoHeight()[MakeRow(LOCTEXT("Uses", "Uses"), LOCTEXT("UsesTip", "How many times it can be used before it is gone."), MakeIntSpin(1, 100, [this] { return Working->Consumable.Uses; }, [this](int32 V) { Working->Consumable.Uses = V; }))] + + SVerticalBox::Slot().AutoHeight() + [ + // With the creator's Use clip the game ignores a chosen use time: the use lasts as long as the clip. + SNew(STextBlock) + .AutoWrapText(true) + .ColorAndOpacity(FSlateColor::UseSubduedForeground()) + .Visibility_Lambda([this] { return FMantleConsumableEffect::OffersUseTime(*Working) ? EVisibility::Collapsed : EVisibility::Visible; }) + .Text(LOCTEXT("UseTimeOwnClip", "Use time: set by your Use animation.")) + ] + SVerticalBox::Slot().AutoHeight().Padding(0.f, 3.f) [ SNew(SCheckBox) + .Visibility_Lambda([this] { return FMantleConsumableEffect::OffersUseTime(*Working) ? EVisibility::Visible : EVisibility::Collapsed; }) .IsChecked_Lambda([this] { return Working->Consumable.bOverrideUseSeconds ? ECheckBoxState::Checked : ECheckBoxState::Unchecked; }) .OnCheckStateChanged_Lambda([this](ECheckBoxState State) { Working->Consumable.bOverrideUseSeconds = State == ECheckBoxState::Checked; }) .ToolTipText(LOCTEXT("OverrideUseTimeTip", "Off: one use takes as long as the animation (2.5 seconds). On: the animation plays faster or slower to fit the time below.")) @@ -2126,7 +2136,10 @@ TSharedRef SMantleWeaponBuilder::MakeTuningStep() ] + SVerticalBox::Slot().AutoHeight() [ - SNew(SBox).Visibility_Lambda([this] { return Working->Consumable.bOverrideUseSeconds ? EVisibility::Visible : EVisibility::Collapsed; }) + SNew(SBox).Visibility_Lambda([this] + { + return Working->Consumable.bOverrideUseSeconds && FMantleConsumableEffect::OffersUseTime(*Working) ? EVisibility::Visible : EVisibility::Collapsed; + }) [ MakeRow(LOCTEXT("UseSeconds", "Use time (seconds)"), LOCTEXT("UseSecondsTip", "From 0.5 to 10 seconds. The effect happens at the same point of the animation, scaled to this time."), MakeFloatSpin(0.5f, 10.f, 0.1f, [this] { return Working->Consumable.UseSeconds; }, [this](float V) { Working->Consumable.UseSeconds = V; })) diff --git a/Source/MantleEditor/Private/Tests/MantleCreatorClipsTest.cpp b/Source/MantleEditor/Private/Tests/MantleCreatorClipsTest.cpp index c20031a3..489250b1 100644 --- a/Source/MantleEditor/Private/Tests/MantleCreatorClipsTest.cpp +++ b/Source/MantleEditor/Private/Tests/MantleCreatorClipsTest.cpp @@ -353,6 +353,10 @@ bool FMantleAnimPackTest::RunTest(const FString& Parameters) } TestTrue(TEXT("the largest pack's document fits"), FTCHARToUTF8(*FMantleAnimPack::WriteDocument(Largest)).Length() <= 64 * 1024); + // The finished publish points at Avatar Storage (the backend refuses a pack in plain Storage) and gives what the entry needs. + const FString Done = FMantleAnimPack::PublishedMessage(TEXT("Tricks"), false, 2, TEXT("itm_utricks")); + TestEqual(TEXT("the finished message"), Done, FString(TEXT("'Tricks' is in your library (private, version 2). To use it in a place, choose Tools > Mantle > Place settings and add an Avatar Storage entry: a Name, Kind animPack, Item itm_utricks, Version 2."))); + // The document: format, then {name, asset, skeleton} in the order given. const TArray Entries = { { TEXT("wave"), TEXT("ast_u1"), TEXT("uefn") }, { TEXT("spin"), TEXT("ast_u2"), Skeleton } }; const FString Text = FMantleAnimPack::WriteDocument(Entries); diff --git a/Source/MantleEditor/Private/Tests/MantleWeaponBuilderConsumableTest.cpp b/Source/MantleEditor/Private/Tests/MantleWeaponBuilderConsumableTest.cpp index 914c8f64..657a3ab1 100644 --- a/Source/MantleEditor/Private/Tests/MantleWeaponBuilderConsumableTest.cpp +++ b/Source/MantleEditor/Private/Tests/MantleWeaponBuilderConsumableTest.cpp @@ -280,14 +280,20 @@ bool FMantleWeaponBuilderConsumableEffectMomentTest::RunTest(const FString& Para AddError(Error); } - // A chosen use time speeds the clip up: the document keeps the clip's own seconds, the line says when it happens as played. + // The game plays the creator's clip at its own speed, so a use time chosen earlier changes nothing and is no longer offered. Input->Consumable.bOverrideUseSeconds = true; Input->Consumable.UseSeconds = 4.0f; TestEqual(TEXT("the document keeps clip seconds"), Build(*Input).UseEffectSeconds.Value, 1.2); - TestEqual(TEXT("the line scales"), FMantleConsumableEffect::Line(*Input).ToString(), FString(TEXT("The effect happens at 2.4 s."))); + TestEqual(TEXT("the line is the clip's own"), FMantleConsumableEffect::Line(*Input).ToString(), FString(TEXT("The effect happens at 1.2 s."))); + TestFalse(TEXT("no use time to choose with a Use clip"), FMantleConsumableEffect::OffersUseTime(*Input)); + TestEqual(TEXT("the summary says so"), FMantleConsumableEffect::UseTimeSummary(*Input), FString(TEXT("your Use animation's length"))); Input->ClipHold.Reset(); Input->ClipUse.Reset(); + TestTrue(TEXT("without a Use clip the use time is offered"), FMantleConsumableEffect::OffersUseTime(*Input)); + TestEqual(TEXT("and the chosen time shows"), FMantleConsumableEffect::UseTimeSummary(*Input), FString(TEXT("4.0 seconds"))); + Input->Consumable.bOverrideUseSeconds = false; + TestEqual(TEXT("unchosen: the animation's"), FMantleConsumableEffect::UseTimeSummary(*Input), FString(TEXT("the animation's own length"))); // A made clip compresses in the background; thrown away before that lands, the engine warns. FAssetCompilingManager::Get().FinishAllCompilation(); Clip->ClearFlags(RF_Public | RF_Standalone); diff --git a/Source/MantleEditor/Public/MantlePlaceSettingsActor.h b/Source/MantleEditor/Public/MantlePlaceSettingsActor.h index 9cdc3f52..fc8aca16 100644 --- a/Source/MantleEditor/Public/MantlePlaceSettingsActor.h +++ b/Source/MantleEditor/Public/MantlePlaceSettingsActor.h @@ -394,7 +394,7 @@ struct MANTLEEDITOR_API FMantleAvatarStorageSetting UPROPERTY(EditAnywhere, Category = "Mantle") FString Name; - /** "avatarItem" (a body, hair, clothing or emote) or "customAvatar". */ + /** "avatarItem" (a body, hair, clothing or emote), "customAvatar" or "animPack" (an animation pack). */ UPROPERTY(EditAnywhere, Category = "Mantle") FString Kind = TEXT("avatarItem");