From 00d0b955ecb2ae5f6760a0a005d617a43b24e1fc Mon Sep 17 00:00:00 2001 From: riperiperi Date: Thu, 18 Jul 2019 22:37:11 +0100 Subject: [PATCH] [Upgrades] Fix various issues - Buy mode now properly remembers the chosen upgrade level between purchases of the same object - Upgrades panel is no longer available from inventory - Upgrades no longer give donated objects value again. - Upgrade prices now show a little better with discounts. (in querypanel, not upgrade list) --- .../UI/Panels/UIAbstractCatalogMode.cs | 21 +++++++++++++++++-- TSOClient/tso.client/UI/Panels/UIBuildMode.cs | 1 + TSOClient/tso.client/UI/Panels/UIBuyMode.cs | 1 + .../tso.client/UI/Panels/UIObjectHolder.cs | 11 +++++----- .../tso.client/UI/Panels/UIQueryPanel.cs | 9 ++++---- .../UI/Panels/Upgrades/UIUpgradeList.cs | 17 ++++++++------- .../NetPlay/Model/Commands/VMNetUpgradeCmd.cs | 4 +++- .../entities/VMMultitileGroup.cs | 9 ++++++++ 8 files changed, 52 insertions(+), 21 deletions(-) diff --git a/TSOClient/tso.client/UI/Panels/UIAbstractCatalogMode.cs b/TSOClient/tso.client/UI/Panels/UIAbstractCatalogMode.cs index 3db87cc45..1689ec719 100644 --- a/TSOClient/tso.client/UI/Panels/UIAbstractCatalogMode.cs +++ b/TSOClient/tso.client/UI/Panels/UIAbstractCatalogMode.cs @@ -70,6 +70,7 @@ public UIAbstractCatalogPanel(string mode, UILotControl lotController) Holder.OnPickup += HolderPickup; Holder.OnDelete += HolderDelete; Holder.OnPutDown += HolderPutDown; + Holder.BeforeRelease += HolderBeforeRelease; DynamicOverlay.Add(QueryPanel); ObjLimitLabel = new UILabel(); @@ -84,6 +85,18 @@ public UIAbstractCatalogPanel(string mode, UILotControl lotController) DynamicOverlay.Add(ObjLimitLabel); } + private void HolderBeforeRelease(UIObjectSelection holding, UpdateState state) + { + // remember the upgrade level between entering the catalog + if (!holding.IsBought) + { + var guid = holding.Group.GUID; + var baseObj = holding.Group.BaseObject; + var level = (baseObj.PlatformState as VMTSOObjectState)?.UpgradeLevel ?? 0; + UpgradeLevelMemory[guid] = level; + } + } + public abstract void InitCategoryMap(); public abstract void ChangeCategory(UIElement elem); public abstract void SetPage(int page); @@ -170,7 +183,7 @@ private void HolderDelete(UIObjectSelection holding, UpdateState state) QueryPanel.Active = false; } - private void UpgradeBuyItem(uint guid, byte level) + private float? UpgradeBuyItem(uint guid, byte level) { var upgrades = Content.Content.Get().Upgrades; var filename = BuyItem.BaseObject.Object.Resource.Iff.Filename; @@ -185,7 +198,10 @@ private void UpgradeBuyItem(uint guid, byte level) state.UpgradeLevel = level; } } + BuyItem.InitialPrice = price.Value; + return price.Value; } + return null; } protected virtual void Catalog_OnSelectionChange(int selection) @@ -235,9 +251,10 @@ protected virtual void Catalog_OnSelectionChange(int selection) { BuyItem = LotController.vm.Context.CreateObjectInstance(item.Item.GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH, true); byte upgradeLevel = 0; + float? price = null; if (UpgradeLevelMemory.TryGetValue(item.Item.GUID, out upgradeLevel) && upgradeLevel > 0) { - UpgradeBuyItem(item.Item.GUID, upgradeLevel); + price = UpgradeBuyItem(item.Item.GUID, upgradeLevel); } Holder.SetSelected(BuyItem); QueryPanel.SetInfo(LotController.vm, BuyItem.Objects[0], false); diff --git a/TSOClient/tso.client/UI/Panels/UIBuildMode.cs b/TSOClient/tso.client/UI/Panels/UIBuildMode.cs index 2e3bccb70..18b2939fa 100644 --- a/TSOClient/tso.client/UI/Panels/UIBuildMode.cs +++ b/TSOClient/tso.client/UI/Panels/UIBuildMode.cs @@ -153,6 +153,7 @@ public override void SetPage(int page) public override void ChangeCategory(UIElement elem) { + QueryPanel.InInventory = false; foreach (var btn in CategoryMap.Keys) btn.Selected = false; diff --git a/TSOClient/tso.client/UI/Panels/UIBuyMode.cs b/TSOClient/tso.client/UI/Panels/UIBuyMode.cs index c4f27d730..750c196ce 100644 --- a/TSOClient/tso.client/UI/Panels/UIBuyMode.cs +++ b/TSOClient/tso.client/UI/Panels/UIBuyMode.cs @@ -325,6 +325,7 @@ public override void ChangeCategory(UIElement elem) public void SetMode(int mode) { if (!Roommate) mode = 2; + QueryPanel.InInventory = mode == 2; CatBg.Visible = (mode == 1); ProductCatalogSlider.Visible = (mode == 1); ProductCatalogNextPageButton.Visible = (mode == 1); diff --git a/TSOClient/tso.client/UI/Panels/UIObjectHolder.cs b/TSOClient/tso.client/UI/Panels/UIObjectHolder.cs index d6a4db680..b0e561a5d 100644 --- a/TSOClient/tso.client/UI/Panels/UIObjectHolder.cs +++ b/TSOClient/tso.client/UI/Panels/UIObjectHolder.cs @@ -52,6 +52,7 @@ public class UIObjectHolder //controls the object holder interface public bool DonateMode; private bool Locked; + public event HolderEventHandler BeforeRelease; public event HolderEventHandler OnPickup; public event HolderEventHandler OnDelete; public event HolderEventHandler OnPutDown; @@ -94,7 +95,7 @@ public void SetSelected(VMMultitileGroup Group) var catalogItem = Content.Content.Get().WorldCatalog.GetItemByGUID(guid); if (catalogItem != null) { - var price = (int)catalogItem.Value.Price; + var price = Group.InitialPrice; //(int)catalogItem.Value.Price; var dcPercent = VMBuildableAreaInfo.GetDiscountFor(catalogItem.Value, vm); var finalPrice = (price * (100 - dcPercent)) / 100; if (DonateMode) finalPrice -= (finalPrice * 2) / 3; @@ -164,9 +165,7 @@ public void MoveSelected(Vector2 pos, sbyte level) public void ClearSelected() { - //TODO: selected items are only spooky ghosts of the items themselves. - // ...so that they dont cause serverside desyncs - // and so that clearing selections doesnt delete already placed objects. + if (Holding != null) BeforeRelease?.Invoke(Holding, LastState); if (Holding != null) { RecursiveDelete(vm.Context, Holding.Group.BaseObject); @@ -281,7 +280,7 @@ public void MouseUp(UpdateState state) if (Holding.InventoryPID > 0) InventoryPlaceHolding(); else BuyHolding(); ClearSelected(); - if (OnPutDown != null) OnPutDown(putDown, state); //call this after so that buy mode etc can produce more. + OnPutDown?.Invoke(putDown, state); //call this after so that buy mode etc can produce more. }); return; } else @@ -293,7 +292,7 @@ public void MouseUp(UpdateState state) } ClearSelected(); - if (OnPutDown != null) OnPutDown(putDown, state); //call this after so that buy mode etc can produce more. + OnPutDown?.Invoke(putDown, state); //call this after so that buy mode etc can produce more. } else { diff --git a/TSOClient/tso.client/UI/Panels/UIQueryPanel.cs b/TSOClient/tso.client/UI/Panels/UIQueryPanel.cs index 1efb2ed01..54b557351 100644 --- a/TSOClient/tso.client/UI/Panels/UIQueryPanel.cs +++ b/TSOClient/tso.client/UI/Panels/UIQueryPanel.cs @@ -112,6 +112,7 @@ public class UIQueryPanel : UICachedContainer public UIImage Thumbnail; public UI3DThumb Thumb3D; public bool Roommate = true; + public bool InInventory = false; private VMEntity ActiveEntity; private int LastSalePrice; @@ -554,7 +555,7 @@ public void SetInfo(VM vm, VMEntity entity, bool bought) && (item?.DisableLevel ?? 0) < 2; var upgrades = Content.Content.Get().Upgrades.GetFile(entity.Object.Resource.MainIff.Filename); - if (!sameEntity) SetHasUpgrades(upgrades != null); + if (!sameEntity) SetHasUpgrades(upgrades != null, bought); var upgradeLevel = (entity.PlatformState as VMTSOObjectState)?.UpgradeLevel ?? 0; int price = def.Price; @@ -693,7 +694,7 @@ public void SetInfo(Texture2D thumb, string name, string description, int price) SpecificTabButton.Disabled = true; SellBackButton.Disabled = true; - SetHasUpgrades(null); + SetHasUpgrades(null, false); if (Thumbnail.Texture != null) Thumbnail.Texture.Dispose(); if (Thumb3D != null) Thumb3D.Dispose(); @@ -702,9 +703,9 @@ public void SetInfo(Texture2D thumb, string name, string description, int price) UpdateImagePosition(); } - private void SetHasUpgrades(bool? hasUpgrades) + private void SetHasUpgrades(bool? hasUpgrades, bool bought) { - if (hasUpgrades == null) + if (hasUpgrades == null || (InInventory && !bought)) { UpgradeBack.Visible = false; UpgradeButton.Visible = false; diff --git a/TSOClient/tso.client/UI/Panels/Upgrades/UIUpgradeList.cs b/TSOClient/tso.client/UI/Panels/Upgrades/UIUpgradeList.cs index c67ea07ac..6b344ac92 100644 --- a/TSOClient/tso.client/UI/Panels/Upgrades/UIUpgradeList.cs +++ b/TSOClient/tso.client/UI/Panels/Upgrades/UIUpgradeList.cs @@ -132,6 +132,14 @@ public void Click(int level) } if (ActiveEntity.GhostImage) { + var item = Items[level]; + item.UpdateCanPurchase(); //make sure this is up to date. + if (!item.CanPurchase) + { + HITVM.Get().PlaySoundEvent(UISounds.Error); + return; + } + //object has not been bought yet //instantly switch the upgrade level. Notify the query panel that the level and price has changed. foreach (var obj in ActiveEntity.MultitileGroup.Objects) @@ -142,14 +150,7 @@ public void Click(int level) state.UpgradeLevel = (byte)level; } } - - var item = Items[level]; - item.UpdateCanPurchase(); //make sure this is up to date. - if (!item.CanPurchase) - { - HITVM.Get().PlaySoundEvent(UISounds.Error); - return; - } + var price = item.Price; ActiveEntity.MultitileGroup.InitialPrice = price; // notify the querypanel that it needs to update diff --git a/TSOClient/tso.simantics/NetPlay/Model/Commands/VMNetUpgradeCmd.cs b/TSOClient/tso.simantics/NetPlay/Model/Commands/VMNetUpgradeCmd.cs index e6490cd6f..e98018767 100644 --- a/TSOClient/tso.simantics/NetPlay/Model/Commands/VMNetUpgradeCmd.cs +++ b/TSOClient/tso.simantics/NetPlay/Model/Commands/VMNetUpgradeCmd.cs @@ -22,11 +22,13 @@ public override bool Execute(VM vm, VMAvatar caller) { var pobj = vm.GetObjectByPersist(ObjectPID); if (pobj == null) return false; + var isDonated = false; foreach (var obj in pobj.MultitileGroup.Objects) { var state = obj?.PlatformState as VMTSOObjectState; if (state != null) { + if (state.ObjectFlags.HasFlag(VMTSOObjectFlags.FSODonated)) isDonated = true; state.UpgradeLevel = TargetUpgradeLevel; state.Wear = 20 * 4; state.QtrDaysSinceLastRepair = 0; @@ -34,7 +36,7 @@ public override bool Execute(VM vm, VMAvatar caller) } } - pobj.MultitileGroup.InitialPrice += AddedValue; + if (!isDonated) pobj.MultitileGroup.InitialPrice += AddedValue; if (vm.IsServer) vm.GlobalLink.UpdateObjectPersist(vm, pobj.MultitileGroup, (worked, objid) => { }); diff --git a/TSOClient/tso.simantics/entities/VMMultitileGroup.cs b/TSOClient/tso.simantics/entities/VMMultitileGroup.cs index 7c532db74..2058cf3f2 100644 --- a/TSOClient/tso.simantics/entities/VMMultitileGroup.cs +++ b/TSOClient/tso.simantics/entities/VMMultitileGroup.cs @@ -40,6 +40,15 @@ public int Price public List Objects = new List(); public List Offsets = new List(); + public uint GUID + { + get + { + var obj = BaseObject; + return (obj.MasterDefinition ?? obj.Object.OBJ).GUID; + } + } + public VMEntity BaseObject { get