Remember nearby spawn setting
This commit is contained in:
parent
5a5d868230
commit
6d6140d45d
@ -110,6 +110,7 @@ namespace TH1_UI.View.Outside
|
||||
|
||||
// 联机 CREATIVE 模式下独立保存上次 MapSize,与单机面板隔离
|
||||
private const string LAST_MAP_SIZE_INDEX_KEY_MULTI = "LastCreativeMapSizeIndex_Multi";
|
||||
private const string DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY = "DisableNearbySpawnPoints";
|
||||
private static readonly uint[] CreativeWinMatchConfigIds = { 7, 9, 10 };
|
||||
private static readonly int[] TurnTimeLimitSeconds = { 0, 30, 45, 60, 90, 120, 180, 240, 300 };
|
||||
|
||||
@ -1221,6 +1222,8 @@ namespace TH1_UI.View.Outside
|
||||
timeLimitSeconds = Main.Instance.MapConfig.IsLimitTime ? Main.Instance.MapConfig.TimeLimitSeconds : 0;
|
||||
disableNearbySpawnPoints = Main.Instance.MapConfig.DisableNearbySpawnPoints;
|
||||
}
|
||||
if (_lobby.IsLobbyOwner() && gameMode == RuntimeData.GameMode.CREATIVE && !disableNearbySpawnPoints)
|
||||
disableNearbySpawnPoints = PlayerPrefs.GetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, 0) == 1;
|
||||
// 对齐单机:直接 -2 反向映射(不 clamp)
|
||||
uint playerCountIdx = playerCount >= 2 ? playerCount - 2 : 0;
|
||||
uint mapSizeIdx = mapSize switch
|
||||
@ -1593,6 +1596,7 @@ namespace TH1_UI.View.Outside
|
||||
}
|
||||
|
||||
Main.Instance.MapConfig?.ResetTransientMatchOptions();
|
||||
ApplySavedDisableNearbySpawnPreferenceToMapConfig();
|
||||
|
||||
if (CreateRoomPanelMono != null)
|
||||
{
|
||||
@ -1631,6 +1635,7 @@ namespace TH1_UI.View.Outside
|
||||
{
|
||||
if (!CanCreateRoomNow()) return;
|
||||
Main.Instance.MapConfig?.ResetTransientMatchOptions();
|
||||
ApplySavedDisableNearbySpawnPreferenceToMapConfig();
|
||||
|
||||
//隐藏创建房间面板
|
||||
CreateRoomPanel?.SetActive(false);
|
||||
@ -1652,6 +1657,7 @@ namespace TH1_UI.View.Outside
|
||||
{
|
||||
if (!CanCreateRoomNow()) return;
|
||||
Main.Instance.MapConfig?.ResetTransientMatchOptions();
|
||||
ApplySavedDisableNearbySpawnPreferenceToMapConfig();
|
||||
|
||||
_lobby.OnLobbyEnteredEvent += OnLobbyJoinSuccess;
|
||||
_lobby.OnLobbyErrorEvent += OnLobbyJoinFailed;
|
||||
@ -1674,6 +1680,14 @@ namespace TH1_UI.View.Outside
|
||||
_lobby.OnLobbyCreatedEvent += OnLobbyCreatedForPrefs;
|
||||
}
|
||||
|
||||
private static void ApplySavedDisableNearbySpawnPreferenceToMapConfig()
|
||||
{
|
||||
var mapConfig = Main.Instance?.MapConfig;
|
||||
if (mapConfig == null || mapConfig.GameMode != RuntimeData.GameMode.CREATIVE) return;
|
||||
|
||||
mapConfig.DisableNearbySpawnPoints = PlayerPrefs.GetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, 0) == 1;
|
||||
}
|
||||
|
||||
private void ClearPendingCreatedRoomNameIfCreateDidNotStart()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_pendingCreateRoomNameForPrefs) || _lobby == null)
|
||||
@ -1839,6 +1853,7 @@ namespace TH1_UI.View.Outside
|
||||
gameMode == RuntimeData.GameMode.CREATIVE
|
||||
&& NearToggle != null
|
||||
&& NearToggle.isOn;
|
||||
SaveDisableNearbySpawnPointsPreference(gameMode, Main.Instance.MapConfig.DisableNearbySpawnPoints);
|
||||
Main.Instance.MapConfig.IsLimitTime = timeLimitSeconds > 0;
|
||||
Main.Instance.MapConfig.TimeLimitSeconds = timeLimitSeconds;
|
||||
if (resetGuestReady) Main.Instance.MapConfig.ResetGuestReadyStates();
|
||||
@ -1970,7 +1985,10 @@ namespace TH1_UI.View.Outside
|
||||
TimeGroup.Init(TimeGroup.SelectedIndex);
|
||||
}
|
||||
if (WaterRow != null) WaterRow.SetActive(isCreative);
|
||||
RefreshNearToggle(isCreative, isOwner, Main.Instance?.MapConfig?.DisableNearbySpawnPoints == true);
|
||||
bool nearToggleSelected = Main.Instance?.MapConfig?.DisableNearbySpawnPoints == true;
|
||||
if (isCreative && isOwner && !nearToggleSelected)
|
||||
nearToggleSelected = PlayerPrefs.GetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, 0) == 1;
|
||||
RefreshNearToggle(isCreative, isOwner, nearToggleSelected);
|
||||
|
||||
if (isCreative) // CREATIVE:MapSize/Water 对房主放开
|
||||
{
|
||||
@ -2036,10 +2054,18 @@ namespace TH1_UI.View.Outside
|
||||
if (mapConfig == null || mapConfig.DisableNearbySpawnPoints == selected) return;
|
||||
|
||||
mapConfig.DisableNearbySpawnPoints = selected;
|
||||
SaveDisableNearbySpawnPointsPreference(mapConfig.GameMode, selected);
|
||||
mapConfig.ResetGuestReadyStates();
|
||||
mapConfig.CheckMapConfigChanged();
|
||||
}
|
||||
|
||||
private static void SaveDisableNearbySpawnPointsPreference(RuntimeData.GameMode gameMode, bool selected)
|
||||
{
|
||||
if (gameMode != RuntimeData.GameMode.CREATIVE) return;
|
||||
PlayerPrefs.SetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, selected ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
private void RefreshNearToggle(bool isCreative, bool isOwner, bool selected)
|
||||
{
|
||||
if (NearToggle == null) return;
|
||||
|
||||
@ -33,6 +33,7 @@ public class UIOutsideSelectCheckPanelMono : MonoBehaviour
|
||||
public AnimancerComponent Animancer;
|
||||
|
||||
private const string LAST_MAP_SIZE_INDEX_KEY = "LastCreativeMapSizeIndex";
|
||||
private const string DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY = "DisableNearbySpawnPoints";
|
||||
private static readonly uint[] CreativeWinMatchConfigIds = { 7, 9, 10 };
|
||||
private static readonly List<(CivEnum Civ, ForceEnum Force)> FallbackForceOptions = new List<(CivEnum Civ, ForceEnum Force)>
|
||||
{
|
||||
@ -154,7 +155,12 @@ public class UIOutsideSelectCheckPanelMono : MonoBehaviour
|
||||
ResumeToggle.onValueChanged.RemoveAllListeners();
|
||||
ResumeToggle.onValueChanged.AddListener(OnTestModeChanged);
|
||||
}
|
||||
ResetNearToggle();
|
||||
if (NearToggle != null)
|
||||
{
|
||||
NearToggle.onValueChanged.RemoveAllListeners();
|
||||
NearToggle.onValueChanged.AddListener(OnNearToggleChanged);
|
||||
}
|
||||
SetNearToggleSavedValue(gameMode == RuntimeData.GameMode.CREATIVE);
|
||||
|
||||
GameMode.Init(gameModeIdx);
|
||||
PlayerCount.Init(playerCountIdx);
|
||||
@ -228,10 +234,10 @@ public class UIOutsideSelectCheckPanelMono : MonoBehaviour
|
||||
return GetCreativeMatchConfigIdByWinIndex(WinSelectedIndex);
|
||||
}
|
||||
|
||||
private void ResetNearToggle()
|
||||
private void SetNearToggleSavedValue(bool isCreative)
|
||||
{
|
||||
if (NearToggle == null) return;
|
||||
NearToggle.SetIsOnWithoutNotify(false);
|
||||
NearToggle.SetIsOnWithoutNotify(isCreative && PlayerPrefs.GetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, 0) == 1);
|
||||
}
|
||||
|
||||
private void RefreshNearToggleVisibility(bool isCreative)
|
||||
@ -240,7 +246,25 @@ public class UIOutsideSelectCheckPanelMono : MonoBehaviour
|
||||
|
||||
NearToggle.gameObject.SetActive(isCreative);
|
||||
NearToggle.interactable = isCreative;
|
||||
if (!isCreative) NearToggle.SetIsOnWithoutNotify(false);
|
||||
NearToggle.SetIsOnWithoutNotify(isCreative && PlayerPrefs.GetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, 0) == 1);
|
||||
}
|
||||
|
||||
private void OnNearToggleChanged(bool selected)
|
||||
{
|
||||
if (GameMode == null || GameMode.SelectedIndex != 2) return;
|
||||
SaveDisableNearbySpawnPointsPreference(selected);
|
||||
}
|
||||
|
||||
public void SaveDisableNearbySpawnPointsPreference()
|
||||
{
|
||||
if (GameMode == null || GameMode.SelectedIndex != 2) return;
|
||||
SaveDisableNearbySpawnPointsPreference(NearToggle != null && NearToggle.isOn);
|
||||
}
|
||||
|
||||
private static void SaveDisableNearbySpawnPointsPreference(bool selected)
|
||||
{
|
||||
PlayerPrefs.SetInt(DISABLE_NEARBY_SPAWN_POINTS_PREFS_KEY, selected ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
public void Show()
|
||||
|
||||
@ -332,6 +332,7 @@ namespace TH1_UI.View.Outside
|
||||
Main.Instance.MapConfig.WaterType = waterType;
|
||||
Main.Instance.MapConfig.DisableNearbySpawnPoints =
|
||||
gameMode == GameMode.CREATIVE && SelectCheckPanelMono.DisableNearbySpawnPoints;
|
||||
SelectCheckPanelMono.SaveDisableNearbySpawnPointsPreference();
|
||||
Main.Instance.MapConfig.SetSinglePlayerCiv(
|
||||
Table.Instance.TransCivEnumToCivId(_selectEmpire.Civ),
|
||||
Table.Instance.TransForceEnumToForceId(_selectEmpire.Force));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user