using System; using FGUI.P01_Common; namespace FlowerPower { public class BuyPropUI : BaseUI { private BuyPropUICtrl ctrl; private BuyPropModel model; private FGUI.P09_ChooseProp.com_prop ui; private int state_ = 0; public BuyPropUI(BuyPropUICtrl ctrl) : base(ctrl) { uiName = UIConst.BuyPropUI; this.ctrl = ctrl; } private btn_watchAd btn_watchAd; protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "P09_ChooseProp"; uiInfo.assetName = "com_prop"; uiInfo.layerType = UILayerType.Popup; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = true; } #region 生命周期 protected override void OnInit() { //model = ModuleManager.Instance.GetModel(ModelConst.BuyPropModel) as BuyPropModel; } protected override void OnClose() { GameHelper.showGameUI = true; HallManager.Instance.UpdateSecondEvent -= SetWatchBtnCd; } protected override void OnBind() { ui = baseUI as FGUI.P09_ChooseProp.com_prop; } protected override void OnOpenBefore(object args) { btn_watchAd = ui.btn_watch as btn_watchAd; state_ = (int)args; ui.prop.selectedIndex = state_; ui.btn_buy.GetChild("text_gold").text = GameHelper.Get101Str(ConfigSystem.GetConfig().Purchaseprops); ui.btn_buy.SetClick(buyItem); if (GameHelper.IsGiftSwitch() && ConfigSystem.GetConfig().PiggyBankSwitch == 1) btn_watchAd.img_saveingpot.visible = true; btn_watchAd.SetClick(() => { GameHelper.ShowVideoAd("buy_prop", isSuccess => { if (isSuccess) { GameHelper.SetWatchCd(state_); BuyPropSuccess(); } }); }); InitView(); HallManager.Instance.UpdateSecondEvent += SetWatchBtnCd; SetWatchBtnCd(); } void buyItem() { if (state_ == 0) { } else if (state_ == 1) { } else if (state_ == 2) { } if (GameHelper.CheckGoldNumber(ConfigSystem.GetConfig().Purchaseprops)) { BuyPropSuccess(); } else { GameHelper.ShowTips("Not enough gold"); } } private void BuyPropSuccess() { GameHelper.AddGoldNumber(-ConfigSystem.GetConfig().Purchaseprops); int numbers = GameHelper.GetItemNumber(state_); numbers++; GameHelper.SetItemNumber(state_, numbers); GameDispatcher.Instance.Dispatch(GameMsg.Sheep_item_refresh); GameDispatcher.Instance.Dispatch(GameMsg.Gold_refresh); GameHelper.ShowTips("The purchase was successful", true); CtrlCloseUI(); } private void SetWatchBtnCd() { if (GameHelper.GetWatchCd(state_) > Convert.ToInt32(GameHelper.GetNowTime())) { btn_watchAd.can_buy.selectedIndex = 1; btn_watchAd.btn_text.text = CommonHelper.TimeFormat(GameHelper.GetWatchCd(state_) - Convert.ToInt32(GameHelper.GetNowTime()), CountDownType.Hour); btn_watchAd.enabled = false; } else { btn_watchAd.enabled = true; btn_watchAd.can_buy.selectedIndex = 0; } } protected override void OnOpen(object args) { } protected override void OnHide() { } protected override void OnDisplay(object args) { } #endregion #region 消息 protected override void AddListener() { } protected override void RemoveListener() { } #endregion //初始化页面逻辑 private void InitView() { ui.btn_back.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.SheepwindowUI_Close); }); } } }