Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distillation properties to handbook #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
62 changes: 60 additions & 2 deletions Systems/Handbook/CollectibleBehaviorHandbookTextAndExtraInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,24 @@ protected bool addProcessesIntoInfo(ItemSlot inSlot, ICoreClientAPI capi, Action
components.Add(cmp);
components.Add(new ClearFloatTextComponent(capi, marginBottom)); //nice margin below the item graphic
}

// Distills into
DistillationProps dprops = getDistillationprops(inSlot.Itemstack);
if (dprops != null)
{
AddHeading(components, capi, "One liter distills into", ref haveText);

var dstack = dprops.DistilledStack?.ResolvedItemstack.Clone();
if (dprops.Ratio != 0)
{
dstack.StackSize = (int)(100 * inSlot.Itemstack.StackSize * dprops.Ratio);
}
var cmp = new ItemstackTextComponent(capi, dstack, 40, 10, EnumFloat.Inline, (cs) => openDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(cs)));
cmp.ShowStacksize = dprops.Ratio != 0;
cmp.PaddingLeft = TinyIndent;
components.Add(cmp);
components.Add(new ClearFloatTextComponent(capi, marginBottom)); //nice margin below the item graphic
}


TransitionableProperties[] props = collObj.GetTransitionableProperties(capi.World, stack, null);
Expand Down Expand Up @@ -737,6 +755,7 @@ protected bool addCreatedByInfo(ICoreClientAPI capi, ItemStack[] allStacks, Acti
List<ItemStack> dryables = new List<ItemStack>();
List<ItemStack> meltables = new List<ItemStack>();
List<ItemStack> juiceables = new List<ItemStack>();
List<ItemStack> distillables = new List<ItemStack>();


foreach (var val in allStacks)
Expand Down Expand Up @@ -769,6 +788,16 @@ protected bool addCreatedByInfo(ICoreClientAPI capi, ItemStack[] allStacks, Acti
}
}

if (val.ItemAttributes?["distillationProps"].Exists == true)
{
var dsprops = getDistillationProps(val);
var distilledStack = dsprops.DistilledStack?.ResolvedItemstack;
if (distilledStack != null && distilledStack.Equals(capi.World, stack, GlobalConstants.IgnoredStackAttributes) && !distillables.Any(s => s.Equals(capi.World, val, GlobalConstants.IgnoredStackAttributes)))
{
distillables.Add(val);
}
}

TransitionableProperties[] oprops = val.Collectible.GetTransitionableProperties(capi.World, val, null);
if (oprops != null)
{
Expand Down Expand Up @@ -826,7 +855,7 @@ protected bool addCreatedByInfo(ICoreClientAPI capi, ItemStack[] allStacks, Acti
string customCreatedBy = stack.Collectible.Attributes?["handbook"]?["createdBy"]?.AsString(null);
string bakingInitialIngredient = collObj.Attributes?["bakingProperties"]?.AsObject<BakingProperties>()?.InitialCode;

if (grecipes.Count > 0 || smithable || knappable || clayformable || customCreatedBy != null || bakables.Count > 0 || barrelRecipestext.Count > 0 || grindables.Count > 0 || curables.Count > 0 || ripenables.Count > 0 || dryables.Count > 0 || meltables.Count > 0 || crushables.Count > 0 || bakingInitialIngredient != null || juiceables.Count > 0)
if (grecipes.Count > 0 || smithable || knappable || clayformable || customCreatedBy != null || bakables.Count > 0 || barrelRecipestext.Count > 0 || grindables.Count > 0 || curables.Count > 0 || ripenables.Count > 0 || dryables.Count > 0 || meltables.Count > 0 || crushables.Count > 0 || bakingInitialIngredient != null || juiceables.Count > 0 || distillables.Count > 0)
{
AddHeading(components, capi, "Created by", ref haveText);

Expand Down Expand Up @@ -1032,7 +1061,29 @@ protected bool addCreatedByInfo(ICoreClientAPI capi, ItemStack[] allStacks, Acti
juiceables.RemoveAt(0);
if (dstack == null) continue;

SlideshowItemstackTextComponent comp = new SlideshowItemstackTextComponent(capi, dstack, bakables, 40, EnumFloat.Inline, (cs) => openDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(cs)));
SlideshowItemstackTextComponent comp = new SlideshowItemstackTextComponent(capi, dstack, juiceables, 40, EnumFloat.Inline, (cs) => openDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(cs)));
comp.PaddingLeft = firstPadding;
firstPadding = 0;
components.Add(comp);
}

components.Add(new RichTextComponent(capi, "\n", CairoFont.WhiteSmallText()));
}

if (distillables.Count > 0)
{
components.Add(verticalSpace);
verticalSpace = verticalSpaceSmall;
AddSubHeading(components, capi, openDetailPageFor, "Distillation", null);

int firstPadding = TinyPadding;
while (juiceables.Count > 0)
jacopouggeri marked this conversation as resolved.
Show resolved Hide resolved
{
ItemStack dstack = distillables[0];
distillables.RemoveAt(0);
if (dstack == null) continue;

SlideshowItemstackTextComponent comp = new SlideshowItemstackTextComponent(capi, dstack, distillables, 40, EnumFloat.Inline, (cs) => openDetailPageFor(GuiHandbookItemStackPage.PageCodeForStack(cs)));
comp.PaddingLeft = firstPadding;
firstPadding = 0;
components.Add(comp);
Expand Down Expand Up @@ -1388,5 +1439,12 @@ public JuiceableProperties getjuiceableProps(ItemStack stack)

return props;
}

public static DistillationProps getDistillationProps(ItemStack stack)
{
var distillationProps = stack?.ItemAttributes?["distillationProps"]?.AsObject<DistillationProps>(null, stack.Collectible.Code.Domain);
return distillationProps != null && !distillationProps.DistilledStack.Resolve(Api.World, "distillation props distilled stack") ? null : distillationProps;
}

}
}