Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/MantleEditor/Private/MantleAnimPack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ TArray<FString> FMantleAnimPack::CheckPack(const TConstArrayView<FString> 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<FEntry> Entries)
{
FString Text;
Expand Down
6 changes: 6 additions & 0 deletions Source/MantleEditor/Private/MantleAnimPack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FString> CheckPack(TConstArrayView<FString> 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<FEntry> Entries);
};
21 changes: 15 additions & 6 deletions Source/MantleEditor/Private/MantleConsumableEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,31 @@ TOptional<double> FMantleConsumableEffect::DocumentSeconds(const UMantleWeaponSo
return Clip ? MomentIn(ConvertedSeconds(*Clip)) : TOptional<double>();
}

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<double> Moment = DocumentSeconds(Source);
if (!Moment.IsSet())
{
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
10 changes: 8 additions & 2 deletions Source/MantleEditor/Private/MantleConsumableEffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double> 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);
};
10 changes: 6 additions & 4 deletions Source/MantleEditor/Private/MantleDevItemBuilderShot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// Maintainer command: Mantle.Dev.ItemBuilderShots <Item model> <Gun model> <UEFN clip> <Directory> [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 <Directory> 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 <Directory> 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.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions Source/MantleEditor/Private/MantlePlacePublishSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions Source/MantleEditor/Private/SMantleWeaponBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2114,9 +2114,19 @@ TSharedRef<SWidget> 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."))
Expand All @@ -2126,7 +2136,10 @@ TSharedRef<SWidget> 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; }))
Expand Down
4 changes: 4 additions & 0 deletions Source/MantleEditor/Private/Tests/MantleCreatorClipsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<FMantleAnimPack::FEntry> Entries = { { TEXT("wave"), TEXT("ast_u1"), TEXT("uefn") }, { TEXT("spin"), TEXT("ast_u2"), Skeleton } };
const FString Text = FMantleAnimPack::WriteDocument(Entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/MantleEditor/Public/MantlePlaceSettingsActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down