Commit df546425 authored by ElderLich's avatar ElderLich

Feature: Solo Duel Settings: Add Retry Button

In solo duels vs WindBot, the Settings menu now shows a Retry button above Surrender. Pressing Retry confirms surrender, then automatically starts a new duel with the same solo AI and duel configuration (port/LP/hand/draw/lock/no-check/no-shuffle). This is solo-only behavior and does not affect online/watch/replay.
parent fc945e10
...@@ -131,6 +131,7 @@ namespace MDPro3.Servant ...@@ -131,6 +131,7 @@ namespace MDPro3.Servant
public static float nextNegateAction_AdditionalTime; public static float nextNegateAction_AdditionalTime;
public static ElementObjectManager nextNegateAction_AdditionalManager; public static ElementObjectManager nextNegateAction_AdditionalManager;
public static Action startCard; public static Action startCard;
public Action onSurrenderConfirmed;
public static Material myProtector; public static Material myProtector;
public static Material opProtector; public static Material opProtector;
...@@ -653,11 +654,13 @@ namespace MDPro3.Servant ...@@ -653,11 +654,13 @@ namespace MDPro3.Servant
InterString.Get("是"), InterString.Get("是"),
InterString.Get("否") InterString.Get("否")
}; };
UIManager.ShowPopupYesOrNo(selections, ActionSurrender, null); UIManager.ShowPopupYesOrNo(selections, ActionSurrender, ActionCancelSurrender);
} }
private void ActionSurrender() private void ActionSurrender()
{ {
onSurrenderConfirmed?.Invoke();
onSurrenderConfirmed = null;
surrendered = true; surrendered = true;
if (TcpHelper.tcpClient != null && TcpHelper.tcpClient.Connected) if (TcpHelper.tcpClient != null && TcpHelper.tcpClient.Connected)
{ {
...@@ -670,6 +673,11 @@ namespace MDPro3.Servant ...@@ -670,6 +673,11 @@ namespace MDPro3.Servant
OnExit(); OnExit();
} }
private void ActionCancelSurrender()
{
onSurrenderConfirmed = null;
}
#endregion #endregion
#region Message #region Message
......
...@@ -47,6 +47,17 @@ namespace MDPro3.Servant ...@@ -47,6 +47,17 @@ namespace MDPro3.Servant
[HideInInspector] public SelectionToggle_Solo lastSoloItem; [HideInInspector] public SelectionToggle_Solo lastSoloItem;
private string lastSoloCommand = string.Empty;
private int lastSoloPort = 7911;
private int lastSoloLp = 8000;
private int lastSoloHand = 5;
private int lastSoloDraw = 1;
private bool lastSoloLockHand;
private bool lastSoloNoCheck;
private bool lastSoloNoShuffle;
private bool hasLastSoloLaunchConfig;
private bool retryLastSoloDuelWhenShown;
#region Servant #region Servant
public override int Depth => 3; public override int Depth => 3;
...@@ -59,6 +70,13 @@ namespace MDPro3.Servant ...@@ -59,6 +70,13 @@ namespace MDPro3.Servant
LoadBots(); LoadBots();
} }
protected override void ApplyShowArrangement(int preDepth)
{
base.ApplyShowArrangement(preDepth);
if (retryLastSoloDuelWhenShown)
StartCoroutine(RetryLastSoloDuelWhenReady());
}
protected override void FirstLoadEvent() protected override void FirstLoadEvent()
{ {
base.FirstLoadEvent(); base.FirstLoadEvent();
...@@ -164,7 +182,19 @@ namespace MDPro3.Servant ...@@ -164,7 +182,19 @@ namespace MDPro3.Servant
{ {
string aiCommand = GetWindBotCommand(aiCode, diyDeck); string aiCommand = GetWindBotCommand(aiCode, diyDeck);
if (!string.IsNullOrEmpty(aiCommand)) if (!string.IsNullOrEmpty(aiCommand))
Launch(aiCommand, GetUI<SoloSelectorUI>().IsLockHand(), GetUI<SoloSelectorUI>().IsNoCheck(), GetUI<SoloSelectorUI>().IsNoShuffle()); {
var ui = GetUI<SoloSelectorUI>();
var lockHand = ui.IsLockHand();
var noCheck = ui.IsNoCheck();
var noShuffle = ui.IsNoShuffle();
var duelPort = ui.GetPort();
var duelLp = ui.GetLP();
var duelHand = ui.GetHand();
var duelDraw = ui.GetDraw();
RememberLastSoloLaunch(aiCommand, duelPort, duelLp, duelHand, duelDraw, lockHand, noCheck, noShuffle);
LaunchWithConfig(aiCommand, duelPort, duelLp, duelHand, duelDraw, lockHand, noCheck, noShuffle);
}
} }
public void StartAIForRoom(int aiCode, bool diyDeck) public void StartAIForRoom(int aiCode, bool diyDeck)
...@@ -229,13 +259,60 @@ namespace MDPro3.Servant ...@@ -229,13 +259,60 @@ namespace MDPro3.Servant
} }
public void Launch(string command, bool lockHand, bool noCheck, bool noShuffle) public void Launch(string command, bool lockHand, bool noCheck, bool noShuffle)
{ {
port = GetUI<SoloSelectorUI>().GetPort().ToString(); var ui = GetUI<SoloSelectorUI>();
LaunchWithConfig(command, ui.GetPort(), ui.GetLP(), ui.GetHand(), ui.GetDraw(), lockHand, noCheck, noShuffle);
}
public bool CanRetryLastSoloDuel()
{
return hasLastSoloLaunchConfig;
}
public void QueueRetryLastSoloDuel()
{
if (!CanRetryLastSoloDuel())
return;
retryLastSoloDuelWhenShown = true;
}
private void RememberLastSoloLaunch(string command, int duelPort, int duelLp, int duelHand, int duelDraw
, bool lockHand, bool noCheck, bool noShuffle)
{
lastSoloCommand = command;
lastSoloPort = duelPort;
lastSoloLp = duelLp;
lastSoloHand = duelHand;
lastSoloDraw = duelDraw;
lastSoloLockHand = lockHand;
lastSoloNoCheck = noCheck;
lastSoloNoShuffle = noShuffle;
hasLastSoloLaunchConfig = true;
}
private IEnumerator RetryLastSoloDuelWhenReady()
{
yield return null;
while (showing && inTransition)
yield return null;
if (!showing || !retryLastSoloDuelWhenShown || !hasLastSoloLaunchConfig)
yield break;
retryLastSoloDuelWhenShown = false;
LaunchWithConfig(lastSoloCommand, lastSoloPort, lastSoloLp, lastSoloHand, lastSoloDraw
, lastSoloLockHand, lastSoloNoCheck, lastSoloNoShuffle);
}
private void LaunchWithConfig(string command, int duelPort, int duelLp, int duelHand, int duelDraw
, bool lockHand, bool noCheck, bool noShuffle)
{
port = duelPort.ToString();
string lp = GetUI<SoloSelectorUI>().GetLP().ToString(); string lp = duelLp.ToString();
string hand = GetUI<SoloSelectorUI>().GetHand().ToString(); string hand = duelHand.ToString();
string draw = GetUI<SoloSelectorUI>().GetDraw().ToString(); string draw = duelDraw.ToString();
string args = port + " -1 5 0 F " + (noCheck ? "T " : "F ") + (noShuffle ? "T " : "F ") + lp + " " + hand + " " + draw + " 0 0"; string args = port + " -1 5 0 F " + (noCheck ? "T " : "F ") + (noShuffle ? "T " : "F ") + lp + " " + hand + " " + draw + " 0 0";
if (TcpHelper.IsPortAvailable(int.Parse(port))) if (TcpHelper.IsPortAvailable(duelPort))
{ {
YgoServer.StartServer(args); YgoServer.StartServer(args);
RoomServant.FromSolo = true; RoomServant.FromSolo = true;
......
...@@ -547,6 +547,7 @@ namespace MDPro3.UI.ServantUI ...@@ -547,6 +547,7 @@ namespace MDPro3.UI.ServantUI
public override void Initialize(Servant.Servant servant) public override void Initialize(Servant.Servant servant)
{ {
base.Initialize(servant); base.Initialize(servant);
ButtonRetry.SetClickEvent(OnRetry);
InitializeVolume(); InitializeVolume();
InitializeScreenMode(); InitializeScreenMode();
...@@ -609,7 +610,10 @@ namespace MDPro3.UI.ServantUI ...@@ -609,7 +610,10 @@ namespace MDPro3.UI.ServantUI
ToggleWatch.gameObject.SetActive(false); ToggleWatch.gameObject.SetActive(false);
ToggleReplay.gameObject.SetActive(false); ToggleReplay.gameObject.SetActive(false);
ButtonRetry.gameObject.SetActive(false); var canRetrySolo = RoomServant.FromSolo;
ButtonRetry.gameObject.SetActive(canRetrySolo);
if (canRetrySolo)
ButtonRetry.SetButtonText(InterString.Get("重试"));
ButtonSurrender.gameObject.SetActive(true); ButtonSurrender.gameObject.SetActive(true);
ButtonSurrender.SetButtonText(InterString.Get("投降")); ButtonSurrender.SetButtonText(InterString.Get("投降"));
} }
...@@ -2387,6 +2391,17 @@ namespace MDPro3.UI.ServantUI ...@@ -2387,6 +2391,17 @@ namespace MDPro3.UI.ServantUI
Program.instance.ocgcore.OnDuelResultConfirmed(true); Program.instance.ocgcore.OnDuelResultConfirmed(true);
} }
public void OnRetry()
{
if (OcgCore.condition != OcgCore.Condition.Duel || !RoomServant.FromSolo)
return;
if (!Program.instance.solo.CanRetryLastSoloDuel())
return;
Program.instance.ocgcore.onSurrenderConfirmed = Program.instance.solo.QueueRetryLastSoloDuel;
Program.instance.ocgcore.OnDuelResultConfirmed(true);
}
} }
public partial class SROptions public partial class SROptions
...@@ -2444,4 +2459,4 @@ namespace MDPro3.UI.ServantUI ...@@ -2444,4 +2459,4 @@ namespace MDPro3.UI.ServantUI
} }
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment