evershade/Assets/Scripts/Managers/UIManager.cs

131 lines
4.0 KiB
C#

using UnityEngine;
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 InventoryUIController InventoryUIController;
private void Awake()
{
// Implement singleton pattern
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
// Register hotkeys with HotkeyManager
HotkeyManager.Instance.RegisterHotkey("Toggle Inventory", KeyCode.I, ToggleInventory);
HotkeyManager.Instance.RegisterHotkey("Toggle UI", KeyCode.Home, ToggleUI);
// HotkeyUIManager.Instance.PopulateHotkeyList();
}
// 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 ToggleInventory()
{
if (InventoryPanel != null) ShowPanel("inventory");
}
public void ToggleHotkey()
{
if (HotkeyPanel != null) ShowPanel("hotkey");
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)
{
Debug.Log("Modifying Zoom level for UI: " + zoomLevel);
SetZoomLevel(ManagementPanel, zoomLevel);
SetZoomLevel(ToolbarPanel, zoomLevel);
}
// Method to show a specific panel and hide others
public void ShowPanel(string panelName)
{
// Hide all panels first
if (SettingsPanel != null && panelName != "settings") SettingsPanel.SetActive(false);
if (CharacterPanel != null && panelName != "character") CharacterPanel.SetActive(false);
if (InventoryPanel != null && panelName != "inventory") InventoryPanel.SetActive(false);
if (RelationshipPanel != null && panelName != "relationship") RelationshipPanel.SetActive(false);
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) SettingsPanel.SetActive(true);
break;
case "character":
if (CharacterPanel != null) CharacterPanel.SetActive(true);
break;
case "inventory":
if (InventoryPanel != null) InventoryPanel.SetActive(true);
break;
case "relationship":
if (RelationshipPanel != null) RelationshipPanel.SetActive(true);
break;
case "hotkey":
if (HotkeyPanel != null) HotkeyPanel.SetActive(true);
break;
// Add more cases as needed
}
}
public void ShowMainMenuScreen(bool show)
{
// Show the main menu screen
}
public void ShowGameOverScreen(bool show)
{
// Show the game over screen
}
}