using cfg.CampCfg;
using Cysharp.Threading.Tasks;
using Framework;
using Gameplay.Common;
using PhxhSDK;
using System.Collections;
using System.Collections.Generic;
using TGS;
using UnityEngine;
using static UnityEngine.InputSystem.Controls.AxisControl;
namespace Gameplay.Camp
{
public sealed partial class Camp
{
///
/// 所有Cell,key:Cell索引,value:Cell
///
private Dictionary dicCellByIndex;
///
/// 所有Cell,key:Cell行列,Value:Cell
///
private Dictionary dicCellByRowCol;
///
/// 格子状态,key:格子索引,value:格子状态
///
private Dictionary dicCellState;
///
/// 网格系统
///
public TerrainGridSystem GridSystem { get; private set; }
///
/// 是否显示所有网格
///
public bool IsShowAllGrid
{
set
{
GridSystem.showCells = value;
GridSystem.showTerritories = value;
GridSystem.showTerritoriesInteriorBorders = value;
if (value)
GridSystem.ShowAll();
else
GridSystem.HideAll();
}
}
private void InitCell()
{
dicCellByIndex = new Dictionary();
dicCellByRowCol = new Dictionary();
dicCellState = new Dictionary();
}
private void SetInfoByCell(TerrainGridSystem terrainGridSystem)
{
GridSystem = terrainGridSystem;
dicCellByIndex.Clear();
dicCellByRowCol.Clear();
dicCellState.Clear();
foreach (Cell cell in GridSystem.cells)
{
dicCellByIndex[cell.index] = cell;
dicCellByRowCol[new Vector2Int(cell.row, cell.column)] = cell;
dicCellState[cell.index] = E_CampCellState.Empty;
}
}
private void ExitCell()
{
GridSystem = null;
dicCellByIndex.Clear();
dicCellByRowCol.Clear();
dicCellState.Clear();
}
///
/// 尝试通过索引获取cell
///
///
///
///
private bool TryGetCellByIndex(int index, out Cell cell)
{
if (!dicCellByIndex.TryGetValue(index, out cell))
return false;
return null != cell;
}
///
/// 尝试通过行列索引获取cell
///
///
///
///
private bool TryGetCellByRowCol(Vector2Int rowAndCol, out Cell cell)
{
if (!dicCellByRowCol.TryGetValue(rowAndCol, out cell))
return false;
return null != cell;
}
///
/// 尝试通过索引获取cell状态
///
///
///
///
private bool TryGetCellStateByIndex(int index, out E_CampCellState cellState)
{
if (!dicCellState.TryGetValue(index, out cellState))
return false;
return true;
}
///
/// 设置格子颜色
///
private void SetCellColorByCellState(int cellIndex, E_CampCellState cellState)
{
Color color = cellState switch
{
E_CampCellState.Empty => new Color(0f, 0f, 0f, 0f),
E_CampCellState.Occupancy => Color.black,
_ => throw new System.Exception("未处理的格子类型")
};
GridSystem.CellSetColor(cellIndex, color);
}
///
/// 设置格子颜色
///
private void SetCellColorByCellState(Cell cell, E_CampCellState cellState)
{
Color color = cellState switch
{
E_CampCellState.Empty => new Color(0f, 0f, 0f, 0f),
E_CampCellState.Occupancy => Color.black,
E_CampCellState.Valid => Color.green,
E_CampCellState.Invalid => Color.red,
_ => throw new System.Exception("未处理的格子类型")
};
GridSystem.CellSetColor(cell.index, color);
}
///
/// 获取地块位置通过偏移
///
///
///
///
private Vector2Int GetCellPosByOffset(Vector2Int centerPos, Vector2 offset)
{
Vector2Int offsetInt = new((int)offset.x, (int)offset.y);
if (1 == (centerPos.x & 1) && // 中心在奇数行
1 == (offsetInt.x & 1)) // 偏移格子相距中心奇数行
++offsetInt.y;
return centerPos + offsetInt;
}
}
}