|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using Game;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Assertions;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
public class GameUI : MonoBehaviour {
|
|
|
|
|
|
|
|
private UIDocument document;
|
|
|
|
public static GameUI Singleton;
|
|
|
|
private void Awake() {
|
|
|
|
Singleton = this;
|
|
|
|
document = GetComponent<UIDocument>();
|
|
|
|
PreparePlayerPanels();
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<VisualElement> PlayerPanels => document.rootVisualElement.Children().Where(e => e.ClassListContains("player_panel")).ToList();
|
|
|
|
|
|
|
|
public VisualElement PlayerPanel(Side side) {
|
|
|
|
return side switch {
|
|
|
|
Side.Top => PlayerPanels[0],
|
|
|
|
Side.Bottom => PlayerPanels[1],
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(side), side, null)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO create correct visual element, attach it to panel with background-image and return it
|
|
|
|
public static VisualElement AddModification(VisualElement playerPanel, ActiveModification modification) {
|
|
|
|
VisualElement listElement = ModsList(playerPanel, modification.Properties.Type);
|
|
|
|
|
|
|
|
return listElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static VisualElement ModsList(VisualElement player, ModType type) {
|
|
|
|
return type switch {
|
|
|
|
ModType.Buff => player.Children().First(e => e.ClassListContains("mods_list")),
|
|
|
|
ModType.Nerf => player.Children().Last(e => e.ClassListContains("mods_list")),
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
void PreparePlayerPanels() {
|
|
|
|
var players = PlayerPanels;
|
|
|
|
Assert.AreEqual(players.Count, 2);
|
|
|
|
|
|
|
|
float heightPercentage = Dimensions.Singleton.panelHeightPercentage;
|
|
|
|
foreach (var playerPanel in players)
|
|
|
|
playerPanel.style.height = Length.Percent(heightPercentage);
|
|
|
|
}
|
|
|
|
}
|