using UnityEngine; public class PlayerChoiceBraveButtonUI : UIBase { private const int CHOICE_BRAVE_BUTTON_HEIGHT = 155; private const int CHOICE_BRAVE_BUTTON_WEIGHT = 155; private const string CHOICE_BRAVE_BUTTON_ON_SPRITE_NAME = "battle_icon_hero_player_on"; private const string CHOICE_BRAVE_BUTTON_OFF_SPRITE_NAME = "battle_icon_hero_player_off"; [SerializeField] private UISprite _choiceBraveButtonSprite; [SerializeField] private UILabel _bpLabel; [SerializeField] private UIWidget _choiceBraveButtonWidget; private bool isFocus; private const float HIDE_OFFSET = 450f; private const float SHOW_OFFSET_DOWN = 400f; private const float SHOW_OFFSET_FORWARD = 50f; public Vector3 BPLabelPosition { get { if (!(_bpLabel != null)) { return Vector3.zero; } return _bpLabel.transform.position; } } public void ShowButton(bool isNewReplay) { if (isNewReplay) { MoveHbpButtonAnchor(isFocus ? Global.PLAYER_CHOICE_BRAVE_BUTTON_POSITION_ZOOM.y : Global.PLAYER_CHOICE_BRAVE_BUTTON_POSITION.y); return; } MoveHbpButtonAnchor(-200f); base.gameObject.SetActive(value: true); iTween.ValueTo(base.gameObject, iTween.Hash("from", -200, "to", Global.PLAYER_CHOICE_BRAVE_BUTTON_POSITION.y, "time", 0.5f, "delay", 0.1f, "onupdate", "MoveHbpButtonAnchor", "easetype", iTween.EaseType.easeInOutExpo)); } public void HideButton() { Vector3 vector = (isFocus ? Global.PLAYER_CHOICE_BRAVE_BUTTON_POSITION_ZOOM : Global.PLAYER_CHOICE_BRAVE_BUTTON_POSITION); iTween.ValueTo(base.gameObject, iTween.Hash("from", vector.y, "to", -200, "time", 0.5f, "onupdate", "MoveHbpButtonAnchor", "easetype", iTween.EaseType.easeInOutExpo)); } public Transform GetButtonTransform() { return base.transform; } public void EnablePulsateEffect() { GameMgr ins = GameMgr.GetIns(); if (!BattleManagerBase.GetIns().BattlePlayer.CanChoiceBrave) { ins.GetEffectMgr().Stop(EffectMgr.EffectType.CMN_UI_HEROSKILL_1); return; } Effect effect = ins.GetEffectMgr().Start(EffectMgr.EffectType.CMN_UI_HEROSKILL_1, GetButtonTransform().position, base.gameObject); if (effect != null) { effect.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true); } } public void DisablePulsateEffect() { GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_UI_HEROSKILL_1); } public void UpdatePulsateEffectAndSprite() { if (BattleManagerBase.GetIns().BattlePlayer.CanChoiceBraveThisTurn) { _choiceBraveButtonSprite.spriteName = "battle_icon_hero_player_on"; EnablePulsateEffect(); } else { _choiceBraveButtonSprite.spriteName = "battle_icon_hero_player_off"; DisablePulsateEffect(); } } public void UpdateActivatingEffect(bool isActivating) { if (isActivating) { Effect effect = GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_UI_HEROSKILL_2, GetButtonTransform().position, base.gameObject); if (effect != null) { effect.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true); } } else { GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_UI_HEROSKILL_2); } } private int SetYtoBottomAnchor(int posY) { int num = Mathf.FloorToInt(77f); return posY - num; } private int SetYtoTopAnchor(int posY) { int num = 77; return posY + num; } private float GetCenterAnchorPosY() { float num = 77f; return (float)_choiceBraveButtonWidget.bottomAnchor.absolute + num; } public void MoveFocus(float beforePosY, float afterPosY) { if (beforePosY < afterPosY) { if (isFocus) { return; } isFocus = true; } else { if (!isFocus) { return; } isFocus = false; } iTween.ValueTo(base.gameObject, iTween.Hash("from", GetCenterAnchorPosY(), "to", afterPosY, "time", 0.2f, "onupdate", "MoveHbpButtonAnchor", "easetype", iTween.EaseType.easeOutQuad)); } public void SetHbpButtonAnchor(float posX, float posY, float posZ, GameObject container) { base.transform.localPosition = new Vector3(posX, posY, posZ); _choiceBraveButtonWidget.bottomAnchor.target = container.transform; _choiceBraveButtonWidget.topAnchor.target = container.transform; _choiceBraveButtonWidget.bottomAnchor.relative = 0f; _choiceBraveButtonWidget.bottomAnchor.absolute = SetYtoBottomAnchor((int)posY); _choiceBraveButtonWidget.topAnchor.relative = 0f; _choiceBraveButtonWidget.topAnchor.absolute = SetYtoTopAnchor((int)posY); _choiceBraveButtonWidget.UpdateAnchors(); } public void MoveHbpButtonAnchor(float posY) { int num = (int)posY; _choiceBraveButtonWidget.bottomAnchor.relative = 0f; _choiceBraveButtonWidget.bottomAnchor.absolute = SetYtoBottomAnchor(num); _choiceBraveButtonWidget.topAnchor.relative = 0f; _choiceBraveButtonWidget.topAnchor.absolute = SetYtoTopAnchor(num); _choiceBraveButtonWidget.UpdateAnchors(); } public void SetBp(int num) { _bpLabel.text = num.ToString(); } }