using UnityEngine;

public class EnemyChoiceBraveButtonUI : UIBase
{
	private const int CHOICE_BRAVE_BUTTON_HEIGHT = 135;

	private const int CHOICE_BRAVE_BUTTON_WEIGHT = 135;

	private const string CHOICE_BRAVE_BUTTON_ON_SPRITE_NAME = "battle_icon_hero_enemy_on";

	private const string CHOICE_BRAVE_BUTTON_OFF_SPRITE_NAME = "battle_icon_hero_enemy_off";

	[SerializeField]
	private UISprite _choiceBraveButtonSprite;

	[SerializeField]
	private UILabel _bpLabel;

	private const float HIDE_OFFSET = 450f;

	private const float SHOW_OFFSET = 350f;

	public Vector3 BPLabelPosition
	{
		get
		{
			if (!(_bpLabel != null))
			{
				return Vector3.zero;
			}
			return _bpLabel.transform.position;
		}
	}

	public void ShowButton(bool isNewReplay)
	{
		if (isNewReplay)
		{
			MoveHbpButtonAnchor(Global.ENEMY_CHOICE_BRAVE_BUTTON_POSITION.y);
			return;
		}
		MoveHbpButtonAnchor(200f);
		base.gameObject.SetActive(value: true);
		iTween.ValueTo(base.gameObject, iTween.Hash("from", 200, "to", Global.ENEMY_CHOICE_BRAVE_BUTTON_POSITION.y, "time", 0.5f, "delay", 0.1f, "onupdate", "MoveHbpButtonAnchor", "easetype", iTween.EaseType.easeInOutExpo));
	}

	public void HideButton()
	{
		UpdateSprite();
		iTween.ValueTo(base.gameObject, iTween.Hash("from", Global.ENEMY_CHOICE_BRAVE_BUTTON_POSITION.y, "to", 200, "time", 0.5f, "onupdate", "MoveHbpButtonAnchor", "easetype", iTween.EaseType.easeInOutExpo));
	}

	public void UpdateSprite()
	{
		if (BattleManagerBase.GetIns().BattleEnemy.CanChoiceBraveThisTurn)
		{
			EnablePulsateEffectAndSprite();
			_choiceBraveButtonSprite.spriteName = "battle_icon_hero_enemy_on";
		}
		else
		{
			DisablePulsateEffectAndSprite();
			_choiceBraveButtonSprite.spriteName = "battle_icon_hero_enemy_off";
		}
	}

	public void EnablePulsateEffectAndSprite()
	{
		GameMgr ins = GameMgr.GetIns();
		_choiceBraveButtonSprite.spriteName = "battle_icon_hero_player_on";
		if (!ins.IsAdminWatch || !BattleManagerBase.GetIns().BattleEnemy.CanChoiceBrave)
		{
			ins.GetEffectMgr().Stop(EffectMgr.EffectType.CMN_UI_HEROSKILL_1);
			return;
		}
		Effect effect = ins.GetEffectMgr().Start(EffectMgr.EffectType.CMN_UI_HEROSKILL_1, base.transform.position, base.gameObject);
		if (effect != null)
		{
			effect.gameObject.SetLayer(base.gameObject.layer, isSetChildren: true);
		}
	}

	public void DisablePulsateEffectAndSprite()
	{
		GameMgr.GetIns().GetEffectMgr().Stop(EffectMgr.EffectType.CMN_UI_HEROSKILL_1);
		_choiceBraveButtonSprite.spriteName = "battle_icon_hero_player_off";
	}

	private int SetYtoBottomAnchor(int posY)
	{
		int num = Mathf.FloorToInt(67f);
		return posY - num;
	}

	private int SetYtoTopAnchor(int posY)
	{
		int num = 67;
		return posY + num;
	}

	public void SetHbpButtonAnchor(float posX, float posY, float posZ, GameObject container)
	{
		base.transform.localPosition = new Vector3(posX, posY, posZ);
		UIWidget component = GetComponent<UIWidget>();
		component.bottomAnchor.target = container.transform;
		component.topAnchor.target = container.transform;
		component.bottomAnchor.relative = 1f;
		component.bottomAnchor.absolute = SetYtoBottomAnchor((int)posY);
		component.topAnchor.relative = 1f;
		component.topAnchor.absolute = SetYtoTopAnchor((int)posY);
		component.UpdateAnchors();
	}

	public void MoveHbpButtonAnchor(float posY)
	{
		UIWidget component = GetComponent<UIWidget>();
		int num = (int)posY;
		component.bottomAnchor.relative = 1f;
		component.bottomAnchor.absolute = SetYtoBottomAnchor(num);
		component.topAnchor.relative = 1f;
		component.topAnchor.absolute = SetYtoTopAnchor(num);
		component.UpdateAnchors();
	}

	public void SetBp(int num)
	{
		_bpLabel.text = num.ToString();
	}
}
