Add support for right-click block purchasing on swap button
This commit is contained in:
@@ -22,6 +22,9 @@ namespace TerraTech {
|
|||||||
panelTraverse = Traverse.Create(__instance);
|
panelTraverse = Traverse.Create(__instance);
|
||||||
var placeButton = panelTraverse.Field("m_PlaceButton").GetValue<Button>();
|
var placeButton = panelTraverse.Field("m_PlaceButton").GetValue<Button>();
|
||||||
placeButton.gameObject.AddComponent<RightClickHandler>();
|
placeButton.gameObject.AddComponent<RightClickHandler>();
|
||||||
|
|
||||||
|
var swapButton = panelTraverse.Field("m_SwapButton").GetValue<Button>();
|
||||||
|
swapButton.gameObject.AddComponent<RightClickHandlerSwap>();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
@@ -33,17 +36,17 @@ namespace TerraTech {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RightClickHandler : MonoBehaviour, IPointerClickHandler {
|
public abstract class BaseRightClickHandler : MonoBehaviour, IPointerClickHandler {
|
||||||
public static Traverse m_TechAvailLookupTraverse;
|
protected static Traverse m_TechAvailLookupTraverse;
|
||||||
public static Dictionary<Snapshot, TechDataAvailValidation> m_TechAvailLookup;
|
protected static Dictionary<Snapshot, TechDataAvailValidation> m_TechAvailLookup;
|
||||||
|
|
||||||
private void Awake() {
|
protected virtual void Awake() {
|
||||||
var trav = Traverse.Create(Singleton.Manager<ManSnapshots>.inst);
|
var trav = Traverse.Create(Singleton.Manager<ManSnapshots>.inst);
|
||||||
m_TechAvailLookupTraverse = trav.Field("m_TechAvailLookup");
|
m_TechAvailLookupTraverse = trav.Field("m_TechAvailLookup");
|
||||||
m_TechAvailLookup = m_TechAvailLookupTraverse.GetValue<Dictionary<Snapshot, TechDataAvailValidation>>();
|
m_TechAvailLookup = m_TechAvailLookupTraverse.GetValue<Dictionary<Snapshot, TechDataAvailValidation>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<BlockTypes, int> CalculateMissingBlocks(
|
protected Dictionary<BlockTypes, int> CalculateMissingBlocks(
|
||||||
Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> blockAvailability, bool isSpawning) {
|
Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> blockAvailability, bool isSpawning) {
|
||||||
Dictionary<BlockTypes, int> missing = new Dictionary<BlockTypes, int>();
|
Dictionary<BlockTypes, int> missing = new Dictionary<BlockTypes, int>();
|
||||||
|
|
||||||
@@ -60,7 +63,7 @@ namespace TerraTech {
|
|||||||
return missing;
|
return missing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int CalculateTotalCost(Dictionary<BlockTypes, int> missingBlocks) {
|
protected int CalculateTotalCost(Dictionary<BlockTypes, int> missingBlocks) {
|
||||||
int totalCost = 0;
|
int totalCost = 0;
|
||||||
RecipeManager recipeManager = Singleton.Manager<RecipeManager>.inst;
|
RecipeManager recipeManager = Singleton.Manager<RecipeManager>.inst;
|
||||||
|
|
||||||
@@ -74,7 +77,7 @@ namespace TerraTech {
|
|||||||
return totalCost;
|
return totalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryPurchaseBlocks(Dictionary<BlockTypes, int> missingBlocks, int totalCost) {
|
protected bool TryPurchaseBlocks(Dictionary<BlockTypes, int> missingBlocks, int totalCost) {
|
||||||
ManPlayer player = Singleton.Manager<ManPlayer>.inst;
|
ManPlayer player = Singleton.Manager<ManPlayer>.inst;
|
||||||
if (player.GetCurrentMoney() < totalCost) {
|
if (player.GetCurrentMoney() < totalCost) {
|
||||||
if (Main.debugBuyAll.Value)
|
if (Main.debugBuyAll.Value)
|
||||||
@@ -92,7 +95,7 @@ namespace TerraTech {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ProcessPurchase(
|
protected bool ProcessPurchase(
|
||||||
Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> blockAvailability, bool isSpawning) {
|
Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> blockAvailability, bool isSpawning) {
|
||||||
try {
|
try {
|
||||||
if (blockAvailability == null) {
|
if (blockAvailability == null) {
|
||||||
@@ -120,7 +123,7 @@ namespace TerraTech {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> GetCurrentBlockAvailability() {
|
protected Dictionary<BlockTypes, TechDataAvailValidation.BlockTypeAvailability> GetCurrentBlockAvailability() {
|
||||||
SnapshotLiveData selectedSnapshotData = UISnapshotPanelBuyAll.selectedData;
|
SnapshotLiveData selectedSnapshotData = UISnapshotPanelBuyAll.selectedData;
|
||||||
Snapshot selectedSnapshot = selectedSnapshotData.m_Snapshot;
|
Snapshot selectedSnapshot = selectedSnapshotData.m_Snapshot;
|
||||||
if (selectedSnapshot == null) {
|
if (selectedSnapshot == null) {
|
||||||
@@ -145,15 +148,30 @@ namespace TerraTech {
|
|||||||
return mBlockAvailability;
|
return mBlockAvailability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnPointerClick(PointerEventData eventData) {
|
public abstract void OnPointerClick(PointerEventData eventData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RightClickHandler : BaseRightClickHandler {
|
||||||
|
public override void OnPointerClick(PointerEventData eventData) {
|
||||||
if (Main.debugBuyAll.Value)
|
if (Main.debugBuyAll.Value)
|
||||||
Console.WriteLine("UISnapshotPanel.OnPointerClick: {0} {1}", gameObject.name, eventData.button);
|
Console.WriteLine("UISnapshotPanel.OnPointerClick: {0} {1}", gameObject.name, eventData.button);
|
||||||
try {
|
try {
|
||||||
if (eventData.button == PointerEventData.InputButton.Right) {
|
if (eventData.button == PointerEventData.InputButton.Right)
|
||||||
// For now, we're using the spawn new tech logic (isSpawning = true)
|
|
||||||
// You can add another button/input handler that calls this with isSpawning = false for morphing
|
|
||||||
ProcessPurchase(GetCurrentBlockAvailability(), true);
|
ProcessPurchase(GetCurrentBlockAvailability(), true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (Main.debugBuyAll.Value)
|
||||||
|
Console.WriteLine("Shit exploded fml: {0}", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RightClickHandlerSwap : BaseRightClickHandler {
|
||||||
|
public override void OnPointerClick(PointerEventData eventData) {
|
||||||
|
if (Main.debugBuyAll.Value)
|
||||||
|
Console.WriteLine("UISnapshotPanel.OnPointerClick: {0} {1}", gameObject.name, eventData.button);
|
||||||
|
try {
|
||||||
|
if (eventData.button == PointerEventData.InputButton.Right)
|
||||||
|
ProcessPurchase(GetCurrentBlockAvailability(), false);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (Main.debugBuyAll.Value)
|
if (Main.debugBuyAll.Value)
|
||||||
Console.WriteLine("Shit exploded fml: {0}", e);
|
Console.WriteLine("Shit exploded fml: {0}", e);
|
||||||
|
Reference in New Issue
Block a user