341 lines
10 KiB
C#
341 lines
10 KiB
C#
//********************************************************//
|
|
// //
|
|
// Copyright © All rights reserved. MyNameIsVoo. 2020. //
|
|
// //
|
|
// COPYING FORBIDEN //
|
|
// //
|
|
//********************************************************//
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
|
|
using ICWM.HelperSystem;
|
|
using ICWM.RenderSystem;
|
|
|
|
namespace ICWM
|
|
{
|
|
namespace MenuSystem
|
|
{
|
|
public class Menu : MonoBehaviour
|
|
{
|
|
#region Attributes
|
|
|
|
[Header("ATTRIBUTES")]
|
|
public bool lockCursor = true;
|
|
|
|
[Header("REFERENCES")]
|
|
public GameObject m_MainMenu;
|
|
public GameObject m_HelpMenuLevel_0;
|
|
public GameObject m_HelpMenuLevel_1;
|
|
public GameObject m_HUD;
|
|
|
|
[Header("OPTIONS")]
|
|
[SerializeField] private GameObject m_OptionsMenu;
|
|
[SerializeField] private Dropdown m_GameMode;
|
|
[SerializeField] private Dropdown m_NoPlaceMode;
|
|
[SerializeField] private Dropdown m_MiniMenuStyle;
|
|
[SerializeField] private Dropdown m_TypeOfMoney;
|
|
[SerializeField] private Dropdown m_StartMoney;
|
|
[SerializeField] private GameObject m_AddMoneyButton;
|
|
[SerializeField] private Dropdown m_RotateStyle;
|
|
|
|
[Header("HELPERS")]
|
|
public GameObject m_PhysicalMoneyBox;
|
|
|
|
[HideInInspector] public bool isPauseMenu;
|
|
private bool isPauseUnlock = false;
|
|
private bool isOptionsMenu;
|
|
|
|
private bool m_Lock = true;
|
|
|
|
public static Menu instance;
|
|
|
|
#endregion
|
|
|
|
private void OnEnable()
|
|
{
|
|
instance = this;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(InventoryInputSystem.instance.openMenu) && !InventoryBase.instance.isDragHandlerIcon && !ModdingSystem.instance.isActiveModding)
|
|
{
|
|
if (isPauseMenu)
|
|
{
|
|
isPauseMenu = false;
|
|
isOptionsMenu = false;
|
|
m_OptionsMenu.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (!isPauseUnlock)
|
|
isPauseMenu = true;
|
|
}
|
|
|
|
if (isPauseUnlock)
|
|
PauseGame(false);
|
|
}
|
|
|
|
UpdateMenu();
|
|
|
|
if (!isPauseUnlock)
|
|
UpdateCursorLock();
|
|
}
|
|
|
|
#region PUBLIC
|
|
|
|
public void PauseGame(bool state)
|
|
{
|
|
InventoryBase.instance.SetEnableComponentsForInventory(state);
|
|
isPauseUnlock = state;
|
|
Cursor.lockState = state ? CursorLockMode.None : CursorLockMode.Locked;
|
|
Cursor.visible = state;
|
|
}
|
|
|
|
#region Buttons
|
|
|
|
public void StartButton(bool state)
|
|
{
|
|
isPauseMenu = state;
|
|
}
|
|
|
|
public void QuitGame(bool state)
|
|
{
|
|
System.IO.Directory.Delete(Application.dataPath + "/Save", true); // Delete the folder with the files
|
|
|
|
#if UNITY_EDITOR
|
|
Debug.Break();
|
|
#endif
|
|
Application.Quit();
|
|
}
|
|
|
|
public void OptionsButton(bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
isOptionsMenu = true;
|
|
m_MainMenu.SetActive(false);
|
|
m_OptionsMenu.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void BackButton(bool state)
|
|
{
|
|
if (state)
|
|
{
|
|
isOptionsMenu = false;
|
|
m_MainMenu.SetActive(true);
|
|
m_OptionsMenu.SetActive(false);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region OptionsMenu
|
|
|
|
public void GameMode()
|
|
{
|
|
if (m_GameMode.value == 0) // 1st
|
|
{
|
|
InventoryBase.instance.Is1stPerson = true;
|
|
InventoryBase.instance.m_Player.SetActive(true);
|
|
InventoryBase.instance.m_Player3rdCharacter.SetActive(false);
|
|
}
|
|
else if (m_GameMode.value == 1) // 3rd
|
|
{
|
|
InventoryBase.instance.Is1stPerson = false;
|
|
InventoryBase.instance.m_Player3rdCharacter.SetActive(true);
|
|
InventoryBase.instance.m_Player.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void NoPlaceMode()
|
|
{
|
|
if (m_NoPlaceMode.value == 0)
|
|
{
|
|
InventoryBase.instance.NoPlaceMode = InventoryBase.ModeNoPlace.NONE;
|
|
}
|
|
else if (m_NoPlaceMode.value == 1)
|
|
{
|
|
InventoryBase.instance.NoPlaceMode = InventoryBase.ModeNoPlace.NO_PLACE_PLANE;
|
|
}
|
|
else if (m_NoPlaceMode.value == 2)
|
|
{
|
|
InventoryBase.instance.NoPlaceMode = InventoryBase.ModeNoPlace.LOOT_WINDOW;
|
|
}
|
|
}
|
|
|
|
public void MiniMenuStyle()
|
|
{
|
|
if (m_MiniMenuStyle.value == 0)
|
|
{
|
|
InventoryBase.instance.miniMenuStyle = MiniMenuBase.MiniMenuStyle.NONE;
|
|
}
|
|
else if (m_MiniMenuStyle.value == 1)
|
|
{
|
|
InventoryBase.instance.miniMenuStyle = MiniMenuBase.MiniMenuStyle.COLUMN;
|
|
}
|
|
else if (m_MiniMenuStyle.value == 2)
|
|
{
|
|
InventoryBase.instance.miniMenuStyle = MiniMenuBase.MiniMenuStyle.CIRCLE;
|
|
}
|
|
else if (m_MiniMenuStyle.value == 3)
|
|
{
|
|
InventoryBase.instance.miniMenuStyle = MiniMenuBase.MiniMenuStyle.CIRCLE_WITH_LINE;
|
|
}
|
|
}
|
|
|
|
public void TypeOfMoney()
|
|
{
|
|
if (m_TypeOfMoney.value == 0)
|
|
{
|
|
InventoryBase.instance.PlayerStatistics.MoneyWeight = PlayerStatistics.WeightOfMoney.VIRTUAL;
|
|
m_PhysicalMoneyBox.SetActive(false);
|
|
m_StartMoney.gameObject.SetActive(true);
|
|
m_AddMoneyButton.SetActive(true);
|
|
}
|
|
else if (m_TypeOfMoney.value == 1)
|
|
{
|
|
InventoryBase.instance.PlayerStatistics.MoneyWeight = PlayerStatistics.WeightOfMoney.PHYSICAL;
|
|
m_PhysicalMoneyBox.SetActive(true);
|
|
m_StartMoney.gameObject.SetActive(false);
|
|
m_AddMoneyButton.SetActive(false);
|
|
}
|
|
InventoryBase.instance.UpdatePlayerStatistics();
|
|
}
|
|
|
|
public void AddMoney()
|
|
{
|
|
if (m_StartMoney.value == 0)
|
|
{
|
|
InventoryBase.instance.PlayerStatistics.MoneyAmount += 500;
|
|
}
|
|
else if (m_StartMoney.value == 1)
|
|
{
|
|
InventoryBase.instance.PlayerStatistics.MoneyAmount += 1000;
|
|
}
|
|
else if (m_StartMoney.value == 2)
|
|
{
|
|
InventoryBase.instance.PlayerStatistics.MoneyAmount += 10000;
|
|
}
|
|
InventoryBase.instance.UpdatePlayerStatistics();
|
|
}
|
|
|
|
public void RotateStyle()
|
|
{
|
|
if (m_RotateStyle.value == 0)
|
|
{
|
|
IconRender.instance.modeRotate = IconRender.ModeRotate.SPACE;
|
|
}
|
|
else if (m_RotateStyle.value == 1)
|
|
{
|
|
IconRender.instance.modeRotate = IconRender.ModeRotate.ELLIPSE;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Set, Get, etc
|
|
|
|
public void SetTimeScale(float timeScale)
|
|
{
|
|
Time.timeScale = timeScale;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unlock System
|
|
|
|
public void ExitUnlockArea()
|
|
{
|
|
isPauseMenu = false;
|
|
isOptionsMenu = false;
|
|
|
|
if (isPauseUnlock)
|
|
PauseGame(false);
|
|
}
|
|
|
|
public IEnumerator WaitExitUnlockArea(float seconds)
|
|
{
|
|
yield return new WaitForSeconds(seconds);
|
|
|
|
ExitUnlockArea();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region PRIVATE
|
|
|
|
#region Update
|
|
|
|
private void UpdateMenu()
|
|
{
|
|
if (isPauseMenu == true)
|
|
{
|
|
if (InventoryBase.instance.IsPauseWorld)
|
|
SetTimeScale(0.0f);
|
|
if (!isOptionsMenu)
|
|
m_MainMenu.SetActive(true);
|
|
|
|
InventoryBase.instance.SetEnableComponentsForInventory(false);
|
|
}
|
|
else if (!isPauseUnlock)
|
|
{
|
|
SetTimeScale(1.0f);
|
|
m_MainMenu.SetActive(false);
|
|
|
|
if(!InventoryBase.instance.isActive)
|
|
InventoryBase.instance.SetEnableComponentsForInventory(true);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Cursor
|
|
|
|
private void UpdateCursorLock()
|
|
{
|
|
if (lockCursor)
|
|
InternalLockUpdate();
|
|
}
|
|
|
|
private void InternalLockUpdate()
|
|
{
|
|
if (m_Lock == false) // If the cursor is active
|
|
{
|
|
if (!isPauseMenu && !InventoryBase.instance.isActive)
|
|
{
|
|
m_Lock = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (isPauseMenu || InventoryBase.instance.isActive)
|
|
{
|
|
m_Lock = false;
|
|
}
|
|
}
|
|
|
|
if (m_Lock == true)
|
|
{
|
|
Cursor.lockState = CursorLockMode.Locked;
|
|
Cursor.visible = false;
|
|
}
|
|
else
|
|
{
|
|
Cursor.lockState = CursorLockMode.None;
|
|
Cursor.visible = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
}
|