Skip to content

Commit

Permalink
Not sure how git is this stupid
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Jul 18, 2019
2 parents 3a2cb17 + 00d0b95 commit 90fe7bc
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 24 deletions.
26 changes: 22 additions & 4 deletions TSOClient/tso.client/UI/Panels/UIAbstractCatalogMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -83,7 +84,19 @@ public UIAbstractCatalogPanel(string mode, UILotControl lotController)
ObjLimitLabel.Alignment = TextAlignment.Center;
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);
Expand Down Expand Up @@ -169,8 +182,8 @@ 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;
Expand All @@ -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)
Expand Down Expand Up @@ -235,9 +251,11 @@ 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);
Expand Down
1 change: 1 addition & 0 deletions TSOClient/tso.client/UI/Panels/UIBuildMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions TSOClient/tso.client/UI/Panels/UIBuyMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions TSOClient/tso.client/UI/Panels/UIObjectHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand Down
11 changes: 6 additions & 5 deletions TSOClient/tso.client/UI/Panels/UIQueryPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -693,18 +694,18 @@ 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();
Thumb3D = null;
Thumbnail.Texture = thumb;
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;
Expand Down
16 changes: 8 additions & 8 deletions TSOClient/tso.client/UI/Panels/Upgrades/UIUpgradeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -142,14 +150,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,21 @@ 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;
obj.UpdateTuning(vm);
}
}

pobj.MultitileGroup.InitialPrice += AddedValue;
if (!isDonated) pobj.MultitileGroup.InitialPrice += AddedValue;

if (vm.IsServer)
vm.GlobalLink.UpdateObjectPersist(vm, pobj.MultitileGroup, (worked, objid) => { });
Expand Down
9 changes: 9 additions & 0 deletions TSOClient/tso.simantics/entities/VMMultitileGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ public int Price
public List<VMEntity> Objects = new List<VMEntity>();
public List<LotTilePos> Offsets = new List<LotTilePos>();

public uint GUID
{
get
{
var obj = BaseObject;
return (obj.MasterDefinition ?? obj.Object.OBJ).GUID;
}
}

public VMEntity BaseObject
{
get
Expand Down

0 comments on commit 90fe7bc

Please sign in to comment.