Skip to content

Commit

Permalink
Added better handling of partitioning in derived screens
Browse files Browse the repository at this point in the history
fixes #1298
  • Loading branch information
vchelaru committed Dec 10, 2023
1 parent 22fb0e0 commit 2818d8b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ private static void GenerateStackingCollision(ICodeBlock codeBlock,

if (isSecondTileShapeCollection == false)
{
// return stackable vs stackable
// return stackable vs stackable
block.Line($"return FlatRedBall.Math.Geometry.IStackableExtensionMethods.CollideAgainstBounceStackable(first, second, 1, 1);");
}
else
Expand All @@ -624,16 +624,38 @@ private static void GenerateStackingCollision(ICodeBlock codeBlock,

public static bool CanBePartitioned(NamedObjectSave nos)
{
if (nos.IsList)
var canBePartitioned = true;
if(nos.IsList == false)
{
canBePartitioned = false;
}

if(canBePartitioned)
{
var genericType = nos.SourceClassGenericType;

var entity = ObjectFinder.Self.GetEntitySave(genericType);

return entity?.IsICollidableRecursive() == true;
var isCollidable = entity?.IsICollidableRecursive() == true;
// If not collidable, then we don't need to partition...at least not now. Maybe in the future
// we could support this if people want manual partitioning?
canBePartitioned = isCollidable;
}

if(canBePartitioned)
{
if (nos.DefinedByBase)
{
var baseNos = ObjectFinder.Self.GetRootDefiningObject(nos);
if (baseNos != null)
{
canBePartitioned = false;
}
}
}


return false;
return canBePartitioned;
}

public override ICodeBlock GenerateAddToManagers(ICodeBlock codeBlock, IElement element)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public static void RefreshViewModelTo(IElement container,
// Set this before updating from Glue object so that we don't persist values which
// don't apply
viewModel.CanBePartitioned = CollisionCodeGenerator.CanBePartitioned(thisNamedObject);
viewModel.DefinedByBase = thisNamedObject.DefinedByBase;
viewModel.UpdateFromGlueObject();
if(viewModel.CanBePartitioned)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FlatRedBall.Glue.MVVM;
using FlatRedBall.Math;
using Localization;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -30,9 +31,20 @@ public bool CanBePartitioned
[DependsOn(nameof(CanBePartitioned))]
public Visibility PartitioningControlUiVisibility => CanBePartitioned.ToVisibility();

public bool DefinedByBase
{
get => Get<bool>();
set => Set(value);
}

[DependsOn(nameof(CanBePartitioned))]
public Visibility AlreadyOrCantBePartitionedVisibility => (!CanBePartitioned).ToVisibility();

[DependsOn(nameof(NoPartitioningText))]
public string NoPartitioningText =>
DefinedByBase ? "Partitioning properties are not available on derived objects"
: "Partitioning not available for this object";

[SyncedProperty(SyncingConditionProperty = nameof(CanBePartitioned))]
public bool PerformCollisionPartitioning
{
Expand Down Expand Up @@ -203,6 +215,6 @@ public ObservableCollection<NamedObjectPairRelationshipViewModel> NamedObjectPai
public CollidableNamedObjectRelationshipViewModel()
{
NamedObjectPairs = new ObservableCollection<NamedObjectPairRelationshipViewModel>();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
<CheckBox IsChecked="{Binding IsSortListEveryFrameChecked}" VerticalContentAlignment="Center" Content="{x:Static localization:Texts.ListSortEveryFrame}" />
</StackPanel>
</StackPanel>
<Label Visibility="{Binding AlreadyOrCantBePartitionedVisibility}" Content="{x:Static localization:Texts.ObjectNoPartitioning}" />
<TextBlock Visibility="{Binding AlreadyOrCantBePartitionedVisibility}"
TextWrapping="Wrap"
Width="{Binding ElementName=ScrollViewerInstance, Path=ViewportWidth}"

Text="{Binding NoPartitioningText}" />

<!--Source https://stackoverflow.com/questions/1981137/c-sharp-wpf-scrollviewer-textblock-troubles-->
<TextBlock
Expand Down
9 changes: 0 additions & 9 deletions FRBDK/Localization/Texts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions FRBDK/Localization/Texts.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1459,9 +1459,6 @@ for {1}?</value>
<data name="ListSortEveryFrame" xml:space="preserve">
<value>Sort List every frame</value>
</data>
<data name="ObjectNoPartitioning" xml:space="preserve">
<value>This object has no partitioning options available.</value>
</data>
<data name="HintObjectAutoPartition" xml:space="preserve">
<value>This object is automatically partitioned, or it does not need partitioning</value>
</data>
Expand Down

0 comments on commit 2818d8b

Please sign in to comment.