2025-05-18 01:04:31 +08:00

510 lines
9.9 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-09-02
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "UI_Ingame" company="Kimch"></copyright>
// <summary></summary>
// ***********************************************************************
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace G
{
public class UI_Ingame : MonoBehaviour
{
public int chamaxhp
{
get;
private set;
}
public int chahp
{
get;
private set;
}
public float chasp
{
get;
private set;
}
public float chamaxsp
{
get;
private set;
}
private bool chargeon;
private bool infinitymode;
public Transform[] cut_extreme = new Transform[2];
private int damagecount;
private float playtime;
private bool general;
private bool generaldead;
private int cur_general = -1;
public bool angelOn;
private float _charge;
private Transform _cha1;
private EntityMainPlayer _scriptCha;
public Joystick joystick
{
get;
set;
}
public Vector2 joystickDirection => joystick.direction;
#region Method
public void GainEquipment(EntityItemEquipment equipment)
{
if (equipment.quality >= 3)
UI.ToastBox.ShowEquipment(equipment.propName, equipment.quality, equipment.propIcon);
UI.QuickBox.ShowEquipment(equipment);
}
public void GainMoney(int id, int amount)
{
var propItem = ItemProxy.Instance.GetStaticItem<ItemProp>(id);
if (propItem != null)
{
if (propItem.id ==1)
{
UI.ToastBox.ShowText(F.Utils.Text.Format("获得{0}: {1}", propItem.name, amount.ToString()), 9);
}
else
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, F.Utils.Text.Format("获得{0}: {1}", propItem.name, amount.ToString()));
}
}
}
#endregion
#region Unity
public static UI_Ingame Instance;
private void Awake()
{
Instance = this;
}
private void Start()
{
var canvas = GetComponent<Canvas>();
canvas.worldCamera = KUIRoot.RootCamera;
var canvasScaler = GetComponent<UnityEngine.UI.CanvasScaler>();
canvasScaler.matchWidthOrHeight = KUIRoot.RootCanvas.GetComponent<UnityEngine.UI.CanvasScaler>().matchWidthOrHeight;
_effectRoot = transform.Find("_effectRoot");
_cha1 = GameObject.FindWithTag("Player").transform;
_scriptCha = _cha1.GetComponent<EntityMainPlayer>();
InvokeRepeating(nameof(CountDown), 0.1f, 1f);
//cur_general = script_spawn.cur_general;
chamaxsp = _scriptCha.maxSp;
}
private void Update()
{
if (_comboTimer <= 5f)
{
_comboTimer += Time.deltaTime;
if (_comboTimer > 5f)
{
_comboNumber = 0;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_BATTLE_STAGE_HINT, null, "combo");
}
}
if (chargeon)
{
if (_charge < 1f)
{
_charge += Time.deltaTime;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_HOLD_STATE, _charge / 1F);
}
else
{
_charge = 0f;
_scriptCha.Eximpact();
chargeon = false;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_HOLD_STATE, 0f);
}
}
}
private void OnApplicationPause(bool pocus)
{
if (pocus)
{
//PauseOn();
}
}
#endregion
#region Field
Transform _effectRoot;
#endregion
#region Method
public void ShowEffect(string name)
{
StartCoroutine(ShowEffectCO(name, 1));
}
IEnumerator ShowEffectCO(string name, float delay)
{
var fx = _effectRoot.Find(name);
if (!fx)
yield break;
fx.gameObject.SetActive(true);
yield return new WaitForSeconds(2f);
fx.gameObject.SetActive(false);
}
void HideAllEffects()
{
for (int i = _effectRoot.childCount - 1; i >= 0; i--)
{
_effectRoot.GetChild(i).gameObject.SetActive(false);
}
}
#endregion
public void ResetTime()
{
playtime = 0f;
damagecount = 0;
InvokeRepeating(nameof(CountDown), 0.1f, 1f);
}
public string stage_num_text;
private void CountDown()
{
int num = (int)(playtime / 60f);
int num2 = (int)playtime % 60;
string arg = " : ";
if (num2 < 10)
{
arg = " : 0";
}
//stage_num.text = num + arg + num2;
stage_num_text = num + arg + num2;
//timeText.text = stage_num_text;
}
public bool CallGeneral(short _dead)
{
if (cur_general < 0)
{
return false;
}
if (!_scriptCha.isLife || generaldead)
{
return false;
}
if (chasp >= 10f)
{
if (!general)
{
general = true;
}
else
{
general = false;
}
//script_spawn.CallGeneral(general, chahp, chamaxhp);
_scriptCha.GeneralOnOff(general, _dead);
return true;
}
return false;
}
public void GeneralDead()
{
general = false;
generaldead = true;
}
public void GetAngel()
{
}
private int _comboNumber;
private float _comboTimer;
public void ComboPlus(float amount)
{
_comboTimer = 0f;
GlobalNotifier.PostNotification(GlobalDefine.EVENT_BATTLE_STAGE_HINT, (++_comboNumber) + ":", "combo");
}
public void SuperModeOn()
{
cut_extreme[0].gameObject.SetActive(true);
cut_extreme[1].gameObject.SetActive(true);
}
public void ShowBubble(string text, float duration = 0f, float delay = 0f)
{
StartCoroutine(ShowBubbleCO(text, duration, delay));
}
private IEnumerator ShowBubbleCO(string text, float duration, float delay)
{
yield return new WaitForSeconds(delay);
var bubble = BoardManager.Instance.CreateBubbleBoard("BubbleBoard");
bubble.gameObject.SetActive(true);
bubble.SetContent(text);
//bubble.SetTarget(script_cha.transform);
bubble.SetDuration(duration);
}
public void ResetPower()
{
chargeon = false;
_charge = 0f;
}
public void PowerCharge()
{
chargeon = true;
}
public void GrabCharge()
{
_charge += 0.02f;
}
/// <summary>
///
/// </summary>
/// <param name="a"></param>
public void GainExp(int a)
{
_scriptCha.GainExp(a);
}
public void PauseOn()
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, null, "menu");
Time.timeScale = 0f;
}
public void Settle(string source = "")
{
_scriptCha.StopControl();
GameLevel.Instance.UnloadLevel();
UI.QuickBox.Clear();
if (GameLevel.Instance.normalMode)
{
KUIWindow.OpenWindow<UI.SettleWindow>(GameLevel.Instance.battleResult);
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, source, "settle");
}
else
{
KUIWindow.OpenWindow<UI.EndlessSettleWindow>(GameLevel.Instance.battleResult);
//GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, "endless_" + source, "settle");
}
}
/// <summary>
/// 拒绝复活
/// </summary>
public void OnRefuseRevive()
{
GameLevel.Instance.FinishLevel(false, "refuse_revive");
Settle("refuse_revive");
KStatistics.Instance.ReportRevive(GameLevel.Instance.curStageId.ToString(), "fail");
}
/// <summary>
///
/// </summary>
public void OnClickRestart()
{
Time.timeScale = 1f;
GameLevel.Instance.FinishLevel(false, "restart");
Settle("restart");
//pauseGO.SetActive(false);
}
/// <summary>
///
/// </summary>
public void OnClickSetting()
{
//option = true;
}
public void OnClickContinue()
{
Time.timeScale = 1f;
//pause = false;
_scriptCha.StartControl();
//this.gameObject.SetActive(false);
//GC.Collect();
}
public void Resurrection()
{
_scriptCha.Reborn();
KStatistics.Instance.ReportRevive(GameLevel.Instance.curStageId.ToString(), "success");
}
public void Damaged_Extreme()
{
damagecount++;
}
void SetHpProgress(float hp)
{
if (hp < 0.2f)
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_BATTLE_STAGE_HINT, type: "dying");
}
else if (hp < 0.5f)
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_BATTLE_STAGE_HINT, type: "danger");
}
else
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_BATTLE_STAGE_HINT, type: "heal");
}
}
public void Damaged(int damage)
{
var board = BoardManager.Instance.CreateDamageBoard("DamageBoard");
board.SetValue(damage, DamageBoardType.PLAYER_HP_SUB);
board.SetPosition(_cha1.position + new Vector3(0f, 0.2f, 0f));
}
public void GameOver()
{
if (EntityMainPlayer.Instance.deathCount < 2)
{
GlobalNotifier.PostNotification(GlobalDefine.EVENT_GAME_WINDOW, null, "rivive");
KStatistics.Instance.ReportEventDied(GameLevel.Instance.curStageId.ToString(), 1);
}
else
{
GameLevel.Instance.FinishLevel(false, "game_over");
Settle("game_over");
KStatistics.Instance.ReportEventDied(GameLevel.Instance.curStageId.ToString(), 2);
}
}
public void StatUpdate_sp(float _sp)
{
chasp = _sp;
if (chasp >= 50f)
{
}
else
{
}
if (cur_general != -1 && !generaldead)
{
}
}
public void StatUpdate_hp(int _hp, int _maxhp)
{
float num = 0f;
//if (cur_difficulty != 2)
{
chahp = _hp;
chamaxhp = _maxhp;
num = chahp / (float)chamaxhp;
SetHpProgress(num);
}
}
public void OnSkillBtnClick(Cha_Moves.MovesInfo buffInfo)
{
_scriptCha.OnSkillBtnClick(buffInfo);
}
/// <summary>
///
/// </summary>
public void OnSkillBtnClick(int index)
{
if (index == 0)
{
_scriptCha.OnSPBtnClick();
}
}
public bool autoAttack
{
get { return _scriptCha.autoAttack; }
}
/// <summary>
///
/// </summary>
public bool OnAutoBtnClick()
{
_scriptCha.autoAttack = !_scriptCha.autoAttack;
return _scriptCha.autoAttack;
}
public bool OnAutoSkillBtnClick()
{
_scriptCha.autoCastSkill = !_scriptCha.autoCastSkill;
return _scriptCha.autoCastSkill;
}
public void OnAttack()
{
_scriptCha.OnAttackBtnClick();
}
public void OnDodge()
{
_scriptCha.OnDodgeBtnClick();
}
public void OnEquipmentChanged()
{
_scriptCha.SyncValue(false);
}
}
}