private void MoveRandomValue(IEnumerable <TradeableItem> source, List <TradeableItem> destination, ITradeEntity trader) { foreach (var amount in source) { if (Library.GetResourceType(amount.ResourceType).HasValue(out var r) && trader.TraderFaction.Race.HasValue(out var race) && race.HatedResources.Any(tag => r.Tags.Contains(tag))) { continue; } if (amount.Count == 0) { continue; } var destAmount = destination.FirstOrDefault(resource => resource.ResourceType == amount.ResourceType); if (destAmount == null) { destAmount = new TradeableItem { Resources = new List <Resource>(), ResourceType = amount.ResourceType }; destination.Add(destAmount); } int numToMove = MathFunctions.RandInt(1, amount.Count + 1); var toMove = amount.Resources.Take(numToMove).ToList(); amount.Resources.RemoveRange(0, numToMove); destAmount.Resources.AddRange(toMove); destAmount.Prototype = destAmount.Resources[0]; break; } }
internal void ReceiveItem(TradeableItem item) { // string destinationYarnNode = this.characterName + ".Receives"; EZYarnVariables.ItemForNpc = item.itemName; PlayerCharacter.instance.TalkToNPC(this, destinationYarnNode); }
private Widget CreateLineItem(TradeableItem Resource) { var r = Root.ConstructWidget(new Gui.Widget { MinimumSize = new Point(1, 32), Background = new TileReference("basic", 0) }); if (Library.GetResourceType(Resource.ResourceType).HasValue(out var res)) { r.AddChild(new Play.ResourceIcon() { MinimumSize = new Point(32 + 16, 32 + 16), MaximumSize = new Point(32 + 16, 32 + 16), Resource = new Resource(res), AutoLayout = AutoLayout.DockLeft, BackgroundColor = Resource.Count > 0 ? new Vector4(1.0f, 1.0f, 1.0f, 1.0f) : new Vector4(0.5f, 0.5f, 0.5f, 0.5f), TextColor = Color.White.ToVector4(), TextHorizontalAlign = HorizontalAlign.Right, TextVerticalAlign = VerticalAlign.Bottom }); } else { r.AddChild(new Widget()); } r.AddChild(new Widget { MinimumSize = new Point(32, 32), TextColor = Color.Black.ToVector4(), AutoLayout = AutoLayout.DockLeft }); r.AddChild(new Gui.Widget { AutoLayout = AutoLayout.DockLeft, MinimumSize = new Point(128 / GameSettings.Current.GuiScale, 0), MaximumSize = new Point(128 / GameSettings.Current.GuiScale, 32), TextColor = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f), TextVerticalAlign = VerticalAlign.Center, TextHorizontalAlign = HorizontalAlign.Left, HoverTextColor = GameSettings.Current.Colors.GetColor("Highlight", Color.DarkRed).ToVector4(), Font = GameSettings.Current.GuiScale == 1 ? "font10" : "font8", ChangeColorOnHover = true, WrapText = true }); r.Layout(); UpdateLineItemText(r, Resource); return(r); }
public void OnItemUsed(TradeableItem item) { if (currentConversationPartner != null && YarnVariables.instance.NpcCanReceive()) //&& currentConversationPartner.state == NPC.State.ReceivingItem) { Debug.Log("Gave " + item.name + " to " + currentConversationPartner.name); currentConversationPartner.ReceiveItem(item); //TalkToNPC(NPC target, string overrideTalkNode = null) } }
public void OnUseButtonClicked() { if (this.CurrentItem != null) { Seeds seedsScriptOnObject = CurrentItem.GetComponent <Seeds>(); if (seedsScriptOnObject != null) { seedsScriptOnObject.UseItem(); } TradeableItem tradeableItem = CurrentItem.GetComponent <TradeableItem>(); if (tradeableItem != null) { tradeableItem.UseItem(); } } }
private void UpdateLineItemText(Widget LineItem, TradeableItem Resource) { if (Resource.Prototype != null) { var font = LineItem.Root.GetTileSheet("font10"); var label = Resource.Prototype.DisplayName; if (font != null) { var measurements = font.MeasureString(label); label = font.WordWrapString(label, 1.0f, 128 / GameSettings.Current.GuiScale, LineItem.WrapWithinWords); if (128 / GameSettings.Current.GuiScale < measurements.X) { LineItem.MinimumSize.Y = font.TileHeight * label.Split('\n').Length; } } LineItem.GetChild(2).Text = label; LineItem.GetChild(2).Invalidate(); var counter = LineItem.GetChild(1);//.Children.LastOrDefault(); if (counter != null) { counter.Text = Resource.Count.ToString(); counter.Invalidate(); } LineItem.GetChild(0).Invalidate(); LineItem.Tooltip = Resource.Prototype.DisplayName + "\n" + Resource.Prototype.Description; for (int i = 0; i < LineItem.Children.Count; i++) { if (i > 0) { LineItem.GetChild(i).TextColor = Resource.Count > 0 ? Color.Black.ToVector4() : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); } LineItem.GetChild(i).BackgroundColor = Resource.Count > 0 ? new Vector4(1.0f, 1.0f, 1.0f, 1.0f) : new Vector4(0.5f, 0.5f, 0.5f, 0.5f); LineItem.GetChild(i).Tooltip = LineItem.Tooltip; LineItem.GetChild(i).Invalidate(); } } }
private void SetupList(WidgetListView listA, WidgetListView listB, List <TradeableItem> resourcesA, List <TradeableItem> resourcesB) { foreach (var resource in resourcesA) { var lineItem = CreateLineItem(resource); var lambdaResource = resource; lineItem.TriggerOnChildClick = true; lineItem.EnableHoverClick(); lineItem.OnClick = (sender, args) => { if (lambdaResource.Count <= 0) { return; } var toMove = 1; if (args.Control) { toMove = lambdaResource.Count; } if (args.Shift) { toMove = Math.Min(5, lambdaResource.Count); } if (lambdaResource.Count - toMove < 0) { return; } var resourcesToMove = lambdaResource.Resources.Take(toMove).ToList(); lambdaResource.Resources.RemoveRange(0, toMove); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f); var existingEntry = resourcesB.FirstOrDefault(r => r.ResourceType == lambdaResource.ResourceType); if (existingEntry == null) { existingEntry = new TradeableItem { ResourceType = lambdaResource.ResourceType, Resources = resourcesToMove, Prototype = resourcesToMove[0] }; resourcesB.Add(existingEntry); var rightLineItem = CreateLineItem(existingEntry); rightLineItem.EnableHoverClick(); listA.AddItem(rightLineItem); rightLineItem.TriggerOnChildClick = true; rightLineItem.OnClick = (_sender, _args) => { var _toMove = 1; if (_args.Control) { _toMove = existingEntry.Count; } if (_args.Shift) { _toMove = Math.Min(5, existingEntry.Count); } if (existingEntry.Count - _toMove < 0) { return; } var _resourcesTomove = existingEntry.Resources.Take(_toMove).ToList(); existingEntry.Resources.RemoveRange(0, _toMove); SoundManager.PlaySound(ContentPaths.Audio.Oscar.sfx_gui_change_selection, 0.1f, MathFunctions.Rand() * 0.25f); if (existingEntry.Count == 0) { var index = resourcesB.IndexOf(existingEntry); if (index >= 0) { resourcesB.RemoveAt(index); listA.RemoveChild(listA.GetChild(index + 1)); } } UpdateColumn(listA, resourcesB); var sourceEntry = resourcesA.FirstOrDefault(r => r.ResourceType == existingEntry.ResourceType); int idx = resourcesA.IndexOf(sourceEntry); sourceEntry.Resources.AddRange(_resourcesTomove); if (idx >= 0) { UpdateLineItemText( listB.GetChild(resourcesA.IndexOf(sourceEntry) + 1), sourceEntry); } Root.SafeCall(OnTotalSelectedChanged, this); }; } else { existingEntry.Resources.AddRange(resourcesToMove); } UpdateColumn(listA, resourcesB); UpdateLineItemText(lineItem, lambdaResource); Root.SafeCall(OnTotalSelectedChanged, this); }; listB.AddItem(lineItem); } }