Implemented dungeon selector
This commit is contained in:
parent
514d985ddb
commit
aeeb15cb12
46 changed files with 26355 additions and 32 deletions
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using DungeonSelection;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
public class DungeonSelectMenuController : MonoBehaviour
|
||||
{
|
||||
private Button _next;
|
||||
private Button _previous;
|
||||
private Button _start;
|
||||
private Image _thumbnailImage;
|
||||
private Label _dungeonName;
|
||||
private VisualElement _dungeonThumbnail;
|
||||
|
||||
private DungeonData _currentlyShowingDungeon;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
VisualElement root = GetComponent<UIDocument>().rootVisualElement;
|
||||
|
||||
_dungeonThumbnail = root.Q<VisualElement>("DungeonThumbnail");
|
||||
_next = root.Q<Button>("Next");
|
||||
_next.clicked += NextClicked;
|
||||
_previous = root.Q<Button>("Previous");
|
||||
_previous.clicked += PreviousClicked;
|
||||
_start = root.Q<Button>("Start");
|
||||
_start.clicked += StartClicked;
|
||||
_dungeonName = root.Q<Label>("DungeonName");
|
||||
|
||||
|
||||
GameEvents.ShowingDungeon += ShowDungeon;
|
||||
GameEvents.ShowingFirstDugeon += () => SetPreviousButtonEnabled(false);
|
||||
GameEvents.ShowingLastDungeon += () => SetNextButtonEnabled(false);
|
||||
}
|
||||
|
||||
private void ShowDungeon(DungeonData dungeon)
|
||||
{
|
||||
_currentlyShowingDungeon = dungeon;
|
||||
_dungeonName.text = _currentlyShowingDungeon.DungeonName;
|
||||
|
||||
if (_thumbnailImage == null)
|
||||
{
|
||||
_thumbnailImage = new Image();
|
||||
_thumbnailImage.scaleMode = ScaleMode.ScaleAndCrop;
|
||||
_dungeonThumbnail.Add(_thumbnailImage);
|
||||
}
|
||||
|
||||
_thumbnailImage.image = _currentlyShowingDungeon.Thumbnail.texture;
|
||||
}
|
||||
|
||||
private void SetPreviousButtonEnabled(bool enabled)
|
||||
{
|
||||
_previous.SetEnabled(enabled);
|
||||
}
|
||||
|
||||
private void SetNextButtonEnabled(bool enabled)
|
||||
{
|
||||
_next.SetEnabled(enabled);
|
||||
}
|
||||
|
||||
private void NextClicked()
|
||||
{
|
||||
SetPreviousButtonEnabled(true);
|
||||
SetNextButtonEnabled(true);
|
||||
UIEvents.NextDungeonClicked?.Invoke();
|
||||
}
|
||||
|
||||
private void PreviousClicked()
|
||||
{
|
||||
SetPreviousButtonEnabled(true);
|
||||
SetNextButtonEnabled(true);
|
||||
UIEvents.PreviousDungeonClicked?.Invoke();
|
||||
}
|
||||
|
||||
private void StartClicked()
|
||||
{
|
||||
UIEvents.EnterDungeonClicked?.Invoke(_currentlyShowingDungeon);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue