176 lines
5.3 KiB
C#
176 lines
5.3 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Animancer;
|
||
using Logic.AI;
|
||
using Logic.Multilingual;
|
||
using MongoDB.Driver;
|
||
using NodeCanvas.Tasks.Actions;
|
||
using RuntimeData;
|
||
using TH1_Logic.Core;
|
||
using TH1_Logic.Net;
|
||
using TH1_Logic.Steam;
|
||
using TH1_UI.HintUI;
|
||
using TH1_UI.View.Outside;
|
||
using TH1Resource;
|
||
using TMPro;
|
||
using UI.HintUI;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class UIOutsideSelectCheckPanelMono : MonoBehaviour
|
||
{
|
||
|
||
public UIOutsideSelectOptionGroupMono GameMode;
|
||
public UIOutsideSelectOptionGroupMono PlayerCount;
|
||
public UIOutsideSelectOptionGroupMono MapSize;
|
||
public UIOutsideSelectOptionGroupMono Diff;
|
||
public UIOutsideSelectOptionGroupMono Water;
|
||
public Button StartButton;
|
||
public Button CloseButton;
|
||
public Button BlockerButton;
|
||
public AnimancerComponent Animancer;
|
||
|
||
// PlayerPrefs key for saving last selected map size in CREATIVE mode
|
||
private const string LAST_MAP_SIZE_INDEX_KEY = "LastCreativeMapSizeIndex";
|
||
|
||
private Action _onStartClick;
|
||
public void Init(Action onStartClick)
|
||
{
|
||
InitSetting();
|
||
_onStartClick = onStartClick;
|
||
StartButton.onClick.RemoveAllListeners();
|
||
StartButton.onClick.AddListener(() =>
|
||
{
|
||
//Animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||
_onStartClick.Invoke();
|
||
});
|
||
|
||
CloseButton.onClick.RemoveAllListeners();
|
||
CloseButton.onClick.AddListener(Hide);
|
||
|
||
BlockerButton.onClick.RemoveAllListeners();
|
||
BlockerButton.onClick.AddListener(Hide);
|
||
}
|
||
public void InitSetting()
|
||
{
|
||
|
||
uint playerCount = 2;
|
||
AIDifficult diff = AIDifficult.HARD;
|
||
GameMode gameMode = RuntimeData.GameMode.PERFECT;
|
||
//读取玩家缺省存储值
|
||
if (Main.Instance.MapConfig != null)
|
||
{
|
||
playerCount = Main.Instance.MapConfig.PlayerCount;
|
||
diff = Main.Instance.MapConfig.AIDiff;
|
||
gameMode = Main.Instance.MapConfig.GameMode;
|
||
}
|
||
|
||
|
||
uint playerCountIdx = playerCount >= 2 ? playerCount - 2 : 0;
|
||
// CREATIVE模式下从PlayerPrefs读取上次的MapSize选择,其他模式根据玩家数量计算
|
||
uint mapSizeIdx = gameMode == RuntimeData.GameMode.CREATIVE
|
||
? (uint)PlayerPrefs.GetInt(LAST_MAP_SIZE_INDEX_KEY, 3) // 默认18x18 (index 3)
|
||
: playerCount switch
|
||
{
|
||
2 => 0,
|
||
3 => 1,
|
||
4 => 2,
|
||
_ => 3
|
||
};
|
||
uint diffIdx = diff switch
|
||
{
|
||
AIDifficult.EASY => 0,
|
||
AIDifficult.NORMAL => 1,
|
||
AIDifficult.HARD => 2,
|
||
_ => 3
|
||
};
|
||
uint gameModeIdx = gameMode switch
|
||
{
|
||
RuntimeData.GameMode.DOMINATION => 0,
|
||
RuntimeData.GameMode.PERFECT => 1,
|
||
RuntimeData.GameMode.CREATIVE => 2,
|
||
_ => 2
|
||
};
|
||
|
||
// Water设置:CREATIVE模式从存档读取,其他模式强制为Pangea(2)
|
||
uint waterIdx = gameMode == RuntimeData.GameMode.CREATIVE && Main.Instance.MapConfig != null
|
||
? (uint)Main.Instance.MapConfig.WaterType
|
||
: 2; // default Pangea
|
||
|
||
GameMode.Init(gameModeIdx);
|
||
GameMode.OnOptionClicked = OnGameModeOptionClicked;
|
||
PlayerCount.Init(playerCountIdx);
|
||
PlayerCount.OnOptionClicked = OnPlayerOptionClicked;
|
||
MapSize.Init(mapSizeIdx);
|
||
Diff.Init(diffIdx);
|
||
if (Water != null) Water.Init(waterIdx);
|
||
OnGameModeOptionClicked(gameModeIdx);
|
||
}
|
||
|
||
public void OnPlayerOptionClicked(uint idx)
|
||
{
|
||
// Only auto-sync MapSize in non-CREATIVE modes
|
||
if (GameMode.SelectedIndex == 2) return;
|
||
uint mapSizeIdx = idx switch
|
||
{
|
||
0 => 0,
|
||
1 => 1,
|
||
2 => 2,
|
||
_ => 3
|
||
};
|
||
MapSize.Select(mapSizeIdx);
|
||
}
|
||
|
||
public void OnGameModeOptionClicked(uint idx)
|
||
{
|
||
if (idx == 2) // CREATIVE
|
||
{
|
||
MapSize.Passive = false;
|
||
MapSize.Init(MapSize.SelectedIndex);
|
||
if (Water != null) { Water.Passive = false; Water.Init(Water.SelectedIndex); }
|
||
}
|
||
else // DOMINATION / PERFECT
|
||
{
|
||
MapSize.Passive = true;
|
||
MapSize.Init(MapSize.SelectedIndex);
|
||
// Sync MapSize with PlayerCount
|
||
OnPlayerOptionClicked(PlayerCount.SelectedIndex);
|
||
if (Water != null) { Water.Passive = true; Water.Init(2); } // 重置为盘古大陆(Pangea)
|
||
}
|
||
}
|
||
|
||
public void Show()
|
||
{
|
||
InitSetting();
|
||
gameObject.SetActive(true);
|
||
Animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeIn);
|
||
|
||
Timer.Instance.TimerRegister(this, () =>
|
||
{
|
||
|
||
GameMode.OnShow();
|
||
PlayerCount.OnShow();
|
||
MapSize.OnShow();
|
||
Diff.OnShow();
|
||
if (Water != null) Water.OnShow();
|
||
},0.01f,"");
|
||
|
||
}
|
||
|
||
public void Hide()
|
||
{
|
||
var state = Animancer.Play(ResourceCache.Instance.AnimCache.UICommonPanelFadeOut);
|
||
state.Events.OnEnd = () => { gameObject.SetActive(false); };
|
||
}
|
||
void Start()
|
||
{
|
||
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
} |