281 lines
9.4 KiB
C#
281 lines
9.4 KiB
C#
using System;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BrewMonster
|
|
{
|
|
public class HUDMainGamePlay : MonoBehaviour
|
|
{
|
|
#region Fields
|
|
|
|
[SerializeField]private Button _escapeBtn;
|
|
[SerializeField]private Button _btnTask;
|
|
[SerializeField]private Button _btnInvntory;
|
|
[SerializeField]private Toggle _btnTeam;
|
|
[SerializeField]private Toggle _btnTaskTrace;
|
|
[SerializeField]private Transform _taskTraceParent;
|
|
[SerializeField]private Button _btnTeamList;
|
|
[SerializeField]private Button _btnPetBags;
|
|
|
|
public const int AUIPROGRESS_MAX = 100;
|
|
private DlgWinPrgs2 _dlgWinPrgs;
|
|
private CECHostPlayer _pHost;
|
|
|
|
#endregion
|
|
|
|
private void OnEnable()
|
|
{
|
|
_escapeBtn.onClick.AddListener(OnEscapeClicked);
|
|
_btnTask.onClick.AddListener(OnTaskClicked);
|
|
_btnInvntory.onClick.AddListener(OnInventoryClicked);
|
|
_btnTeam.onValueChanged.AddListener(OnTeamClicked);
|
|
_btnTaskTrace.onValueChanged.AddListener(OnTaskTraceClicked);
|
|
_btnTeamList.onClick.AddListener(OnTeamListClicked);
|
|
_btnPetBags.onClick.AddListener(OnCallPetBagsClicked);
|
|
EventBus.Unsubscribe<UIEvent>(OnUIEvent);
|
|
EventBus.Subscribe<UIEvent>(OnUIEvent);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_escapeBtn.onClick.RemoveListener(OnEscapeClicked);
|
|
_btnTask.onClick.RemoveListener(OnTaskClicked);
|
|
_btnInvntory.onClick.RemoveListener(OnInventoryClicked);
|
|
_btnTeam.onValueChanged.RemoveListener(OnTeamClicked);
|
|
_btnTaskTrace.onValueChanged.RemoveListener(OnTaskTraceClicked);
|
|
_btnTeamList.onClick.RemoveListener(OnTeamListClicked);
|
|
_btnPetBags.onClick.RemoveListener(OnCallPetBagsClicked);
|
|
EventBus.Unsubscribe<UIEvent>(OnUIEvent);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
RefreshStatusBar();
|
|
}
|
|
|
|
private void OnUIEvent(UIEvent uiEvent)
|
|
{
|
|
switch(uiEvent.EventType)
|
|
{
|
|
case UIEventType.ShowTrace:
|
|
_btnTaskTrace.isOn = true;
|
|
break;
|
|
case UIEventType.HideTrace:
|
|
_btnTaskTrace.isOn = false;
|
|
break;
|
|
case UIEventType.ShowTeam:
|
|
_btnTeam.isOn = true;
|
|
break;
|
|
case UIEventType.HideTeam:
|
|
_btnTeam.isOn = false;
|
|
break;
|
|
}
|
|
}
|
|
private void OnTaskClicked()
|
|
{
|
|
CECUIManager.Instance.ShowUI("Win_Quest");
|
|
}
|
|
private void OnInventoryClicked()
|
|
{
|
|
CECUIManager.Instance.ShowUI("Win_Inventory");
|
|
}
|
|
private void OnTeamClicked(bool isOn)
|
|
{
|
|
if(isOn)
|
|
{
|
|
CECUIManager.Instance.ShowUI("Win_ArrangeTeam");
|
|
}
|
|
else
|
|
{
|
|
// Hide via stack logic when possible (CECUIManager is stack-driven)
|
|
if (string.Equals(CECUIManager.Instance.GetCurrentUI(), "Win_ArrangeTeam", StringComparison.Ordinal))
|
|
{
|
|
CECUIManager.Instance.HideCurrentUIInStack();
|
|
return;
|
|
}
|
|
|
|
// Fallback: if it isn't the current stacked UI, just hide that dialog instance
|
|
var dlg = CECUIManager.Instance.GetInGameUIMan()?.GetDialog("Win_ArrangeTeam");
|
|
dlg?.Show(false);
|
|
}
|
|
}
|
|
private void OnTaskTraceClicked(bool isOn)
|
|
{
|
|
if(isOn)
|
|
{
|
|
//get dialog from InGameUIManager
|
|
var taskTrace = CECUIManager.Instance.GetInGameUIMan()?.GetDialog("Win_QuestMinion");
|
|
if(taskTrace != null)
|
|
{
|
|
taskTrace.Show(true);
|
|
taskTrace.transform.SetParent(_taskTraceParent);
|
|
taskTrace.transform.localPosition = Vector3.zero;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var UIManager = CECUIManager.Instance.GetInGameUIMan();
|
|
if(UIManager != null)
|
|
{
|
|
var dlg = UIManager.GetDialog("Win_QuestMinion");
|
|
if(dlg != null)
|
|
{
|
|
dlg.Show(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
private void OnTeamListClicked()
|
|
{
|
|
CECUIManager.Instance.ShowUI("Win_TeamMain");
|
|
}
|
|
|
|
private void OnEscapeClicked()
|
|
{
|
|
// Open the exit dialog , not directly exit the game
|
|
|
|
// return;
|
|
if(EC_Game.GetGameRun()?.GetHostPlayer() != null)
|
|
{
|
|
EC_Game.GetGameRun()?.GetHostPlayer().OnClickBtnEscape();
|
|
}
|
|
}
|
|
|
|
private void OnCallPetBagsClicked()
|
|
{
|
|
EC_Game.GetGameRun().GetUIManager().GetInGameUIMan().PopupPetListDialog();
|
|
}
|
|
|
|
#region Progress Bar
|
|
|
|
public void RefreshStatusBar()
|
|
{
|
|
bool bActive = true;
|
|
// if( GetGameUIMan()->GetActiveDialog() &&
|
|
// GetGameUIMan()->GetActiveDialog()->GetFocus() &&
|
|
// GetGameUIMan()->GetActiveDialog()->GetFocus()->GetType() == AUIOBJECT_TYPE_EDITBOX )
|
|
// bActive = false;
|
|
//
|
|
// // Flight bar.
|
|
// RefreshFlightBar(bActive);
|
|
//
|
|
// // Oxigen bar.
|
|
// RefreshOxigenBar(bActive);
|
|
|
|
// Gather bar.
|
|
RefreshGatherBar(bActive);
|
|
|
|
// // group these bars, show only one at one time
|
|
// bool bShow = false;
|
|
// // Power bar.
|
|
// bShow |= RefreshPowerBar(bShow, bActive);
|
|
// // Array bar.
|
|
// bShow |= RefreshArrayBar(bShow, bActive);
|
|
// // Incant bar.
|
|
// bShow |= RefreshIncantBar(bShow, bActive);
|
|
//
|
|
// if (GetHostPlayer()->GetCurSkill() && !bShow)
|
|
// {
|
|
// // ´«Ë͵ȷ½Ê½µ¼ÖÂλÖÃÇл»¡¢¼¼ÄÜ£¨Õó¼¼ÄÜ£©ÈÔÈ»ÔÚÊÍ·Å״̬
|
|
// //
|
|
// GetGameSession()->c2s_CmdCancelAction();
|
|
// }
|
|
//
|
|
// // AutoHP bar.
|
|
// RefreshAutoHPBar(bActive);
|
|
//
|
|
// // AutoMP bar.
|
|
// RefreshAutoMPBar(bActive);
|
|
//
|
|
// // pet status
|
|
// RefreshPetStatus();
|
|
//
|
|
// //ELF status
|
|
// RefreshElfStatus();
|
|
}
|
|
|
|
private bool RefreshGatherBar(bool bActive)
|
|
{
|
|
if (_dlgWinPrgs == null)
|
|
{
|
|
var pDlg = EC_Game.GetGameRun().GetUIManager().GetInGameUIMan().GetDialog("Win_Prgs2");
|
|
if (pDlg == null)
|
|
{
|
|
BMLogger.LogError("Null Win_Prgs2");
|
|
return false;
|
|
}
|
|
|
|
if (pDlg is not DlgWinPrgs2 dlgWinPrgs)
|
|
{
|
|
BMLogger.LogError("Can not cast Win_Prgs2");
|
|
return false;
|
|
}
|
|
_dlgWinPrgs = dlgWinPrgs;
|
|
}
|
|
|
|
if (_pHost == null)
|
|
{
|
|
_pHost = EC_Game.GetGameRun().GetHostPlayer();
|
|
if (_pHost == null) return false;
|
|
}
|
|
|
|
CECCounter counter = _pHost.GetGatherCnt();
|
|
if (_pHost.IsGathering())
|
|
{
|
|
int nCur = (int)counter.GetCounter();
|
|
int nMax = Mathf.Max((int)counter.GetPeriod(), 1);
|
|
|
|
if (!_dlgWinPrgs.IsShow())
|
|
_dlgWinPrgs.Show(bActive);//true, false, bActive
|
|
|
|
// PAUIPROGRESS pProgress = (PAUIPROGRESS)pDlg.GetDlgItem("Prgs");
|
|
// PAUILABEL pLabel = (PAUILABEL)pDlg.GetDlgItem("1");
|
|
|
|
var percent = AUIPROGRESS_MAX * nCur / nMax;
|
|
_dlgWinPrgs.SetProgressAndText(percent*1.0f/100.0f,$"{percent}%");
|
|
// pLabel.SetText(percent);
|
|
// pProgress.SetProgress(AUIPROGRESS_MAX * nCur / nMax);
|
|
if (percent < 100)
|
|
{
|
|
_dlgWinPrgs.SetActiveProgress(true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (_dlgWinPrgs.IsShow())
|
|
{
|
|
_dlgWinPrgs.Show(false);
|
|
_dlgWinPrgs.SetActiveProgress(false);
|
|
}
|
|
}
|
|
|
|
return _dlgWinPrgs.IsShow();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
public enum UIEventType
|
|
{
|
|
ShowTrace,
|
|
HideTrace,
|
|
ShowTeam,
|
|
HideTeam,
|
|
}
|
|
public struct UIEvent
|
|
{
|
|
|
|
public UIEventType EventType;
|
|
public UIEvent(UIEventType eventType)
|
|
{
|
|
EventType = eventType;
|
|
}
|
|
}
|
|
}
|