276 lines
8.8 KiB
C#
276 lines
8.8 KiB
C#
using UnityEngine;
|
|
using Utils;
|
|
|
|
namespace Managers
|
|
{
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
// Add more panels as needed
|
|
|
|
// Singleton instance
|
|
public static UIManager Instance;
|
|
|
|
// Reference to the main UI panel (or the root UI GameObject)
|
|
public GameObject UIPanel;
|
|
|
|
// References to individual views
|
|
public GameObject SettingsPanel;
|
|
public GameObject CharacterPanel;
|
|
public GameObject InventoryPanel;
|
|
public GameObject ToolbarPanel;
|
|
public GameObject RelationshipPanel;
|
|
public GameObject HotkeyPanel;
|
|
public GameObject ManagementPanel;
|
|
public GameObject KnowledgePanel;
|
|
|
|
public GameObject SideBarPanel;
|
|
public SideBarUIController sideBarUIController;
|
|
|
|
private PlayerManager _playerManager;
|
|
private int openPanels;
|
|
|
|
private void Awake()
|
|
{
|
|
// Implement singleton pattern
|
|
if (Instance == null)
|
|
Instance = this;
|
|
else
|
|
Destroy(gameObject);
|
|
|
|
if (sideBarUIController == null) sideBarUIController = GetComponent<SideBarUIController>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
// Register hotkeys with HotkeyManager
|
|
HotkeyManager.Instance.RegisterHotkey("Toggle Inventory", KeyCode.I, ToggleInventory);
|
|
HotkeyManager.Instance.RegisterHotkey("Toggle UI", KeyCode.Home, ToggleUI);
|
|
HotkeyManager.Instance.RegisterHotkey("Toggle Hotkey UI", KeyCode.H, ToggleHotkey);
|
|
HotkeyManager.Instance.RegisterHotkey("Show Character UI", KeyCode.C, () => ShowMainPanel("character"));
|
|
// HotkeyManager.Instance.RegisterHotkey("Show Inventory UI", KeyCode.I, () => ShowPanel("inventory"));
|
|
HotkeyManager.Instance.RegisterHotkey("Show Relationship UI", KeyCode.R,
|
|
() => ShowMainPanel("relationship"));
|
|
HotkeyManager.Instance.RegisterHotkey("Show Settings UI", KeyCode.F1, () => ShowMainPanel("settings"));
|
|
|
|
// close all panels
|
|
HotkeyManager.Instance.RegisterHotkey("Close All Panels", KeyCode.Escape, () => OnClick_CloseAllPanels());
|
|
|
|
_playerManager = GetComponentInParent<PlayerManager>();
|
|
// HotkeyUIManager.Instance.PopulateHotkeyList();
|
|
}
|
|
|
|
private void ToggleHotkey()
|
|
{
|
|
if (HotkeyPanel != null)
|
|
{
|
|
if (HotkeyPanel.activeSelf)
|
|
{
|
|
HotkeyPanel.SetActive(false);
|
|
return;
|
|
}
|
|
|
|
HotkeyPanel.SetActive(true);
|
|
IncrementOpenPanels();
|
|
}
|
|
}
|
|
|
|
private void IncrementOpenPanels()
|
|
{
|
|
openPanels++;
|
|
if (openPanels == 1) _playerManager.SetInMenu();
|
|
}
|
|
|
|
private void DecrementOpenPanels()
|
|
{
|
|
openPanels--;
|
|
if (openPanels == 0) _playerManager.SetNotInMenu();
|
|
}
|
|
|
|
|
|
// Method to toggle the main UI visibility
|
|
public void ToggleUI()
|
|
{
|
|
// todo: will need a way to handle them out of sync.
|
|
if (UIPanel != null) UIPanel.SetActive(!UIPanel.activeSelf);
|
|
if (ToolbarPanel != null) ToolbarPanel.SetActive(!ToolbarPanel.activeSelf);
|
|
}
|
|
|
|
public void OnClick_CloseAllPanels()
|
|
{
|
|
ClosePanels();
|
|
}
|
|
|
|
public void ClosePanels()
|
|
{
|
|
// var sideBarUIController = SideBarPanel.GetComponent<SideBarUIController>();
|
|
SideBarPanel.SetActive(false);
|
|
SettingsPanel.SetActive(false);
|
|
KnowledgePanel.SetActive(false);
|
|
CharacterPanel.SetActive(false);
|
|
InventoryPanel.SetActive(false);
|
|
RelationshipPanel.SetActive(false);
|
|
}
|
|
|
|
public void OnClick_CloseMainPanels()
|
|
{
|
|
// disable sidebar
|
|
SideBarPanel.SetActive(false);
|
|
var sideBarUIController = SideBarPanel.GetComponent<SideBarUIController>();
|
|
sideBarUIController.OnClick_Settings();
|
|
sideBarUIController.OnClick_Character();
|
|
sideBarUIController.OnClick_EnableInventory();
|
|
}
|
|
|
|
public void ToggleInventory()
|
|
{
|
|
if (InventoryPanel)
|
|
{
|
|
if (InventoryPanel.activeSelf)
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
CloseInventory();
|
|
return;
|
|
}
|
|
|
|
sideBarUIController.OnClick_EnableInventory();
|
|
}
|
|
}
|
|
|
|
public void CloseInventory()
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
InventoryPanel.SetActive(false);
|
|
}
|
|
|
|
public void CloseCharacter()
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
CharacterPanel.SetActive(false);
|
|
}
|
|
|
|
public void CloseRelationships()
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
RelationshipPanel.SetActive(false);
|
|
}
|
|
|
|
public void CloseKnowledge()
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
KnowledgePanel.SetActive(false);
|
|
}
|
|
|
|
public void CloseSettings()
|
|
{
|
|
SideBarPanel.SetActive(false);
|
|
SettingsPanel.SetActive(false);
|
|
}
|
|
|
|
|
|
public void OnClick_CloseHotkey()
|
|
{
|
|
GameLogger.Log("OnClick_CloseHotkey");
|
|
if (HotkeyPanel != null) HotkeyPanel.SetActive(false);
|
|
// Add more cases as needed
|
|
// HotkeyUIController.Instance.PopulateHotkeyList();
|
|
}
|
|
|
|
|
|
public void SetZoomLevel(GameObject targetObject, float zoomLevel)
|
|
{
|
|
// Get the RectTransform component of the target object
|
|
var rectTransform = targetObject.GetComponent<RectTransform>();
|
|
|
|
// Calculate the new scale based on the zoom level
|
|
var newScale = 1f + (zoomLevel - 1f);
|
|
|
|
// Set the new scale for the x and y axes
|
|
var newScaleVector = new Vector3(newScale, newScale, 1f);
|
|
rectTransform.localScale = newScaleVector;
|
|
}
|
|
|
|
public void SetUIZoomLevel(float zoomLevel)
|
|
{
|
|
GameLogger.Log("Modifying Zoom level for UI: " + zoomLevel);
|
|
SetZoomLevel(ManagementPanel, zoomLevel);
|
|
SetZoomLevel(ToolbarPanel, zoomLevel);
|
|
}
|
|
|
|
|
|
// Method to show a specific panel and hide others
|
|
public void ShowMainPanel(string panelName)
|
|
{
|
|
// Hide all panels first
|
|
// ManagementPanel.SetActive(true);
|
|
SideBarPanel.SetActive(true);
|
|
|
|
var sideBarUIController = SideBarPanel.GetComponent<SideBarUIController>();
|
|
|
|
|
|
/*if (SettingsPanel != null && panelName != "settings") sideBarUIController.OnClick_Settings();
|
|
if (CharacterPanel != null && panelName != "character") sideBarUIController.OnClick_Character();
|
|
if (InventoryPanel != null && panelName != "inventory") sideBarUIController.OnClick_Inventory();
|
|
if (RelationshipPanel != null && panelName != "relationship") sideBarUIController.OnClick_Relationships();*/
|
|
// if (HotkeyPanel != null && panelName != "hotkey") HotkeyPanel.SetActive(false);
|
|
|
|
// Add more panels as needed
|
|
|
|
// Show the selected panel
|
|
switch (panelName.ToLower())
|
|
{
|
|
case "settings":
|
|
if (SettingsPanel != null) sideBarUIController.OnClick_Settings();
|
|
break;
|
|
case "character":
|
|
if (CharacterPanel != null) sideBarUIController.OnClick_Character();
|
|
break;
|
|
case "inventory":
|
|
if (InventoryPanel != null) sideBarUIController.OnClick_EnableInventory();
|
|
break;
|
|
case "relationship":
|
|
if (RelationshipPanel != null) sideBarUIController.OnClick_Relationships();
|
|
break;
|
|
}
|
|
}
|
|
|
|
public static void ShowMainMenuScreen(bool show)
|
|
{
|
|
// Show the main menu screen
|
|
}
|
|
|
|
public static void ShowGameOverScreen(bool show)
|
|
{
|
|
// Show the game over screen
|
|
}
|
|
|
|
public void EnableInventory()
|
|
{
|
|
SideBarPanel.SetActive(true);
|
|
InventoryPanel.SetActive(true);
|
|
}
|
|
|
|
public void EnableSettings()
|
|
{
|
|
SideBarPanel.SetActive(true);
|
|
SettingsPanel.SetActive(true);
|
|
}
|
|
|
|
public void EnableCharacter()
|
|
{
|
|
SideBarPanel.SetActive(true);
|
|
CharacterPanel.SetActive(true);
|
|
}
|
|
|
|
public void EnableRelationships()
|
|
{
|
|
SideBarPanel.SetActive(true);
|
|
RelationshipPanel.SetActive(true);
|
|
}
|
|
|
|
public void EnableKnowledge()
|
|
{
|
|
SideBarPanel.SetActive(true);
|
|
KnowledgePanel.SetActive(true);
|
|
}
|
|
}
|
|
} |