Skip to content

Commit

Permalink
Fixes for the enabled/disabled button.
Browse files Browse the repository at this point in the history
  • Loading branch information
IceRaptor committed Feb 20, 2019
1 parent 49270a3 commit 64dfc84
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
46 changes: 32 additions & 14 deletions DisorderlyWithdrawal/DisorderlyWithdrawal/Patches/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace DisorderlyWithdrawal.Patches {
[HarmonyPatch(typeof(CombatHUDRetreatEscMenu), "OnRetreatButtonPressed")]
public static class CombatHUDRetreatESCMenu_OnRetreatButtonPressed {
public static bool Prefix(CombatHUDRetreatEscMenu __instance, HBSDOTweenButton ___RetreatButton, CombatGameState ___Combat, CombatHUD ___HUD) {
DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:ORBP - triggered:{ModState.WithdrawalTriggered} tillOverhead:{ModState.RoundsUntilOverhead} tillReady:{ModState.RoundsUntilReady}");
DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:ORBP - triggered:{ModState.WithdrawalTriggered} " +
$"tillOverhead:{ModState.RoundsUntilOverhead} tillReady:{ModState.RoundsUntilReady}");

if (ModState.WithdrawalTriggered && ModState.RoundsUntilOverhead == 0) {
DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:ORBP - Checking for combat damage and active enemies");
Expand All @@ -19,7 +20,7 @@ public static bool Prefix(CombatHUDRetreatEscMenu __instance, HBSDOTweenButton _
int repairCost = (int)Math.Ceiling(ModState.CombatDamage) * DisorderlyWithdrawal.ModConfig.LeopardRepairCostPerDamage;
void withdrawAction() { OnImmediateWithdraw(__instance.IsGoodFaithEffort()); }
GenericPopupBuilder builder = GenericPopupBuilder.Create(GenericPopupType.Warning,
$"Enemies are within weapons range, if you retreat now the Leopard will take {SimGameState.GetCBillString(repairCost)} damage that will have to be repaired.")
$"Enemies are within weapons range! If you withdraw now the Leopard will take {SimGameState.GetCBillString(repairCost)} worth of damage.")
.CancelOnEscape()
.AddButton("Cancel")
.AddButton("Withdraw", withdrawAction, true, null);
Expand Down Expand Up @@ -71,13 +72,13 @@ public static bool Prefix(CombatHUDRetreatEscMenu __instance, CombatGameState __
ModState.RetreatButtonText = textGO.GetComponent<TextMeshProUGUI>();
}

ModState.RetreatButton.SetState(ButtonState.Disabled, true);
//ModState.RetreatButton.SetState(ButtonState.Disabled, true);
ModState.RetreatButtonText.SetText($"In { roundsToWait } Rounds", new object[] { });

GenericPopupBuilder genericPopupBuilder =
GenericPopupBuilder.Create(GenericPopupType.Info,
$"Sumire is inbound and will be overhead in {roundsToWait} rounds. Survive until then!")
.AddButton("Continue");
.AddButton("Continue", new Action(OnContinue), true, null);
genericPopupBuilder.IsNestedPopupWithBuiltInFade = true;
___HUD.SelectionHandler.GenericPopup = genericPopupBuilder.Render();

Expand All @@ -87,27 +88,37 @@ public static bool Prefix(CombatHUDRetreatEscMenu __instance, CombatGameState __
}
}
}

public static void OnContinue() {
DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:ORC OnContinue");
ModState.HUD.SelectionHandler.GenericPopup = null;
}
}


[HarmonyPatch(typeof(CombatHUDRetreatEscMenu), "Update")]
public static class CombatHUDRetreatESCMenu_Update {
public static void Postfix(CombatHUDRetreatEscMenu __instance, CombatGameState ___Combat, CombatHUD ___HUD, bool ___isArena) {
//DisorderlyWithdrawal.Logger.LogIfDebug("CHUDREM:U entered");
//DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:U entered - isArena:{___isArena} untilOverhead:{ModState.RoundsUntilOverhead} untilReady:{ModState.RoundsUntilReady}");

if (!___isArena) {
if (ModState.RoundsUntilOverhead > 0) {
__instance.RetreatButton.SetState(ButtonState.Disabled, true);
//DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:U - wait til overhead - untilOverhead:{ModState.RoundsUntilOverhead} untilReady:{ModState.RoundsUntilReady}");
__instance.RetreatButton.SetState(ButtonState.Disabled, false);
ModState.RetreatButtonText.fontSize = 24;
ModState.RetreatButtonText.color = Color.white;
ModState.RetreatButtonText.SetText($"In { ModState.RoundsUntilOverhead } Rounds", new object[] { });
} else if (ModState.RoundsUntilOverhead == 0) {
__instance.RetreatButton.SetState(ButtonState.Enabled, true);
//DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:U - withdraw turn - untilOverhead:{ModState.RoundsUntilOverhead} untilReady:{ModState.RoundsUntilReady}");
if (__instance.RetreatButton.BaseState != ButtonState.Enabled) {
__instance.RetreatButton.SetState(ButtonState.Enabled, false);
}
ModState.RetreatButtonText.fontSize = 24;
ModState.RetreatButtonText.color = Color.white;
ModState.RetreatButtonText.SetText($"Withdraw", new object[] { });
} else if (ModState.RoundsUntilReady > 0) {
__instance.RetreatButton.SetState(ButtonState.Disabled, true);
//DisorderlyWithdrawal.Logger.LogIfDebug($"CHUDREM:U - wait til ready - untilOverhead:{ModState.RoundsUntilOverhead} untilReady:{ModState.RoundsUntilReady}");
__instance.RetreatButton.SetState(ButtonState.Disabled, false);
ModState.RetreatButtonText.fontSize = 24;
ModState.RetreatButtonText.color = Color.white;
ModState.RetreatButtonText.SetText($"In { ModState.RoundsUntilReady } Rounds", new object[] { });
Expand All @@ -128,20 +139,28 @@ static void Postfix(TurnDirector __instance) {
GenericPopupBuilder genericPopupBuilder =
GenericPopupBuilder.Create(GenericPopupType.Info,
$"Sumire is overhead. If you don't withdraw on this round, she will retreat. She will be unavailable for another {ModState.RoundsUntilReady} rounds!")
.AddButton("Continue");
.AddButton("Continue", new Action(OnContinue), true, null);
genericPopupBuilder.IsNestedPopupWithBuiltInFade = true;
ModState.HUD.SelectionHandler.GenericPopup = genericPopupBuilder.Render();

ModState.RetreatButton.SetState(ButtonState.Enabled, true);
ModState.RetreatButtonText.SetText($"Withdraw Now", new object[] { });

} else if (ModState.RoundsUntilReady == 0) {
ModState.WithdrawalTriggered = false;
ModState.RoundsUntilOverhead = -1;
ModState.RoundsUntilReady = -1;

ModState.RetreatButton.SetState(ButtonState.Enabled, true);
ModState.RetreatButton.SetState(ButtonState.Enabled, false);
ModState.RetreatButtonText.SetText($"Withdraw", new object[] { });
}
}
}

public static void OnContinue() {
DisorderlyWithdrawal.Logger.LogIfDebug($"TD:BNR OnContinue");
ModState.HUD.SelectionHandler.GenericPopup = null;
}
}

[HarmonyPatch(typeof(TurnDirector), "EndCurrentRound")]
Expand Down Expand Up @@ -179,14 +198,14 @@ static void Postfix(TurnDirector __instance) {
}

[HarmonyPatch(typeof(SimGameState), "GetExpenditures")]
[HarmonyAfter(new string[] { "de.morphyum.MechMaintenanceByCost" })]
public static class SimGameState_GetExpenditures {
public static void Postfix(SimGameState __instance, ref int __result, bool proRate) {
DisorderlyWithdrawal.Logger.LogIfDebug($"SGS:GE entered with {__result}");

Statistic aerospaceAssets = __instance.CompanyStats.GetStatistic("AerospaceAssets");
int aerospaceSupport = aerospaceAssets != null ? aerospaceAssets.Value<int>() : 0;
DisorderlyWithdrawal.Logger.LogIfDebug($"Player has aerospace support:{aerospaceSupport}");


switch (aerospaceSupport) {
case 3:
__result = __result + DisorderlyWithdrawal.ModConfig.HeavyWingMonthlyCost;
Expand Down Expand Up @@ -217,10 +236,9 @@ public static void Postfix(AAR_ContractResults_Screen __instance) {
$"The Leopard was damaged in the extraction process, and needs to be repaired." +
$"{SimGameState.GetCBillString(repairCost)} will be deducted for repairs."
)
.AddButton("Continue", new System.Action(OnContinue), false, null)
.AddButton("Continue", new Action(OnContinue), true, null)
.Render();
}

}

public static void OnContinue() {
Expand Down
5 changes: 5 additions & 0 deletions DisorderlyWithdrawal/DisorderlyWithdrawal/Utils/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ public class ModConfig {
public bool Debug = false;

public int LightWingMonthlyCost = 50000;
public float LightWingLeopardDamage = 0.0f;

public int MediumWingMonthlyCost = 75000;
public float MediumWingLeopardDamage = 0.3f;

public int HeavyWingMonthlyCost = 100000;
public float HeavyWingLeopardDamage = 0.6f;

public int LeopardRepairCostPerDamage = 10;

Expand Down
Binary file not shown.

0 comments on commit 64dfc84

Please sign in to comment.