175 lines
5.9 KiB
C#
175 lines
5.9 KiB
C#
/*
|
||
* @Author: 白哉
|
||
* @Description: 输入逻辑
|
||
* @Date: 2025年04月01日 星期二 11:04:30
|
||
* @Modify:
|
||
*/
|
||
|
||
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.EventSystems;
|
||
using RuntimeData;
|
||
using TMPro;
|
||
using Logic.Multilingual;
|
||
using TH1_Core.Managers;
|
||
using TH1_Logic.Main;
|
||
using UI;
|
||
using UnityEngine.UI;
|
||
|
||
namespace Logic
|
||
{
|
||
public class InputLogic
|
||
{
|
||
Main _main;
|
||
MapData _mapData;
|
||
public int highlightCurrentState = 0; //0无1unit2land
|
||
private Vector3 mouseLastDownPosition;
|
||
private Vector2Int lastSelectedTile = new Vector2Int(-1, -1); // 上次点击的land坐标
|
||
private Vector2Int lastSelectedUnit = new Vector2Int(-1, -1); // 上次点击的unit坐标
|
||
|
||
//避免打包的时候吧TooltipTrigger代码剥离删掉的临时变量
|
||
private TooltipTrigger onozukakomachi;
|
||
bool inputLock = false;
|
||
|
||
public InputLogic(Main main, MapData mapData)
|
||
{
|
||
_main = main;
|
||
_mapData = mapData;
|
||
onozukakomachi = null;
|
||
}
|
||
|
||
private bool ShouldIgnoreClick(GameObject clickedUI)
|
||
{
|
||
// 检查当前对象及其所有祖先对象
|
||
Transform currentTransform = clickedUI.transform;
|
||
while (currentTransform != null)
|
||
{
|
||
if (currentTransform.name == "UICanvas" || currentTransform.name == "HintMap" )
|
||
{
|
||
return true;
|
||
}
|
||
|
||
currentTransform = currentTransform.parent;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public void LockInput()
|
||
{
|
||
inputLock = true;
|
||
}
|
||
|
||
public void UnlockInput()
|
||
{
|
||
inputLock = false;
|
||
}
|
||
|
||
public void Update()
|
||
{
|
||
//如果锁了input 但是DebugMode不会锁定input
|
||
if (inputLock &&!DebugCenter.Instance.DebugMode) return;
|
||
|
||
// 检测数字键1-9的按下,执行对应的操作
|
||
if (UIManager.Instance.BottomInfoUI.ROBottomInfoUI.activeSelf)
|
||
{
|
||
for (int i = 1; i <= 9; i++)
|
||
{
|
||
if (Input.GetKeyDown(KeyCode.Alpha1 + i - 1))
|
||
{
|
||
UIManager.Instance.BottomInfoUI.ExecuteActionButtonByIndex(i - 1);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (UIBlockCameraDrag.DownUpEvent) // 检测鼠标点击
|
||
{
|
||
UIBlockCameraDrag.DownUpEvent = false;
|
||
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||
Vector2Int cellPosition = Table.Instance.WorldToGrid(mousePosition);
|
||
if (cellPosition.x >= Main.MapData.MapConfig.Width || cellPosition.x < 0 || cellPosition.y < 0 ||
|
||
cellPosition.y >= Main.MapData.MapConfig.Height)
|
||
return;
|
||
// 获取点击的地块类型
|
||
Main.MapData.GridMap.GetGridDataByPos(cellPosition.x, cellPosition.y, out var clickedTerrain);
|
||
// 根据点击的地形类型执行某些操作(例如,显示消息)
|
||
_main.MapInteractionLogic.OnTileClicked(Main.MapData,clickedTerrain);
|
||
}
|
||
|
||
if (Input.GetKeyDown(KeyCode.E))
|
||
{
|
||
SimulateButtonClick(UIManager.Instance.BottomBarUI.NextTurnButton);
|
||
}
|
||
|
||
if (Input.GetKeyDown(KeyCode.BackQuote))
|
||
{
|
||
#if UNITY_EDITOR
|
||
Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth += 1000;
|
||
#endif
|
||
}
|
||
|
||
if (Input.GetKeyDown(KeyCode.T))
|
||
{
|
||
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
|
||
{
|
||
#if UNITY_EDITOR
|
||
Main.MapData.PlayerMap.SelfPlayerData.PlayerWealth += 1000;
|
||
foreach (TechType techType in System.Enum.GetValues(typeof(TechType)))
|
||
Main.PlayerLogic.ResearchTech(Main.MapData, Main.MapData.PlayerMap.SelfPlayerData,techType,0);
|
||
UIManager.Instance.TechTreeUI.TechTreeUIDataRenderMark = true;
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
if (UIManager.Instance.TechTreeUI.ROTechTreeUI.activeSelf)
|
||
{
|
||
UIManager.Instance.TechTreeUI.SetTechTreeShowHide(false);
|
||
UIManager.Instance.BottomBarUI.SetBottomBarShowHide(true);
|
||
}
|
||
else
|
||
{
|
||
UIManager.Instance.TechTreeUI.SetTechTreeShowHide(true);
|
||
UIManager.Instance.BottomBarUI.SetBottomBarShowHide(false);
|
||
UIManager.Instance.BottomInfoUI.SetBottomInfoHide();
|
||
}
|
||
}
|
||
}
|
||
|
||
if (Input.GetKeyDown(KeyCode.W))
|
||
{
|
||
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
|
||
{
|
||
foreach (WonderTypeEnum wonder in System.Enum.GetValues(typeof(WonderTypeEnum)))
|
||
{
|
||
_mapData.PlayerMap.SelfPlayerData.Wonder.SetWonderState(wonder,WonderState.FINISH_NOT_BUILD);
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
if (Input.GetKeyDown(KeyCode.Escape))
|
||
{
|
||
|
||
|
||
}
|
||
|
||
//HintWindowUIHandleHover();
|
||
}
|
||
|
||
public void SimulateButtonClick(Button button)
|
||
{
|
||
var pointer = new PointerEventData(EventSystem.current);
|
||
var go = button.gameObject;
|
||
|
||
ExecuteEvents.Execute(go, pointer, ExecuteEvents.pointerDownHandler);
|
||
ExecuteEvents.Execute(go, pointer, ExecuteEvents.pointerUpHandler);
|
||
button.onClick.Invoke();
|
||
}
|
||
}
|
||
|
||
|
||
}
|