using IgnoreOPS; using FairyGUI; using FGUI.ZM_Setting_07; using IgnoreOPS; using UnityEngine; using btn_head = FGUI.ZM_Common_01.btn_head; // using FGUI.G006_menu; namespace RedHotRoast { public class ArrowSettingUI : BaseUI { private ArrowSettingUICtrl ctrl; private ArrowSettingModel model; private int _selectIndex = -1; private const int TotalItem = 8; private com_arrow_setting ui; public ArrowSettingUI(ArrowSettingUICtrl ctrl) : base(ctrl) { uiName = UIConst.ArrowSettingUI; this.ctrl = ctrl; } protected override void SetUIInfo(UIInfo uiInfo) { uiInfo.packageName = "ZM_Setting_07"; uiInfo.assetName = "com_arrow_setting"; uiInfo.layerType = UILayerType.Popup; uiInfo.isNeedOpenAnim = false; uiInfo.isNeedCloseAnim = false; uiInfo.isNeedUIMask = true; } #region 生命周期 protected override void OnInit() { model = moduleManager.GetModel(ModelConst.ArrowSettingModel) as ArrowSettingModel; } protected override void OnClose() { // WebviewManager.ShezhiACT(true); GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, true); } protected override void OnBind() { ui = baseUI as com_arrow_setting; } protected override void OnOpenBefore(object args) { GameDispatcher.Instance.Dispatch(GameMsg.StopArrowTouch, false); // if (Screen.safeArea.y != 0) // { // ui.title.y += Screen.safeArea.y; // } // WebviewManager.ShezhiACT(false); _selectIndex = DataMgr.PlayerAvatarId.Value; GetSliderValueByScale((float)args); InitView(); } private void GetSliderValueByScale(float speed) { float validScale = Mathf.Clamp(speed, 1200f, 1700f); float ratio = (validScale - 1200f) / (1700f - 1200f); float sliderVal = ratio * 100f; ui.speed_slide.value = Mathf.Clamp(sliderVal, 0f, 100f); } protected override void OnOpen(object args) { // CommonHelper.FadeIn(ui); ui.show.Play(); } protected override void OnHide() { } protected override void OnDisplay(object args) { } #endregion #region 消息 protected override void AddListener() { HallManager.Instance.AddChangeGiftSwitch(InitView); } protected override void RemoveListener() { HallManager.Instance.RemoveChangeGiftSwitch(InitView); } #endregion private void InitView() { SetVersion(); SetUID(); var namStr = GameHelper.GetUserName(); ui.edit_name.input.text = namStr; ui.btn_privacy.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 0); }); ui.btn_terms.SetClick(() => { UICtrlDispatcher.Instance.Dispatch(UICtrlMsg.PrivacyUI_Open, 1); }); ui.btn_official.SetClick(() => { OpenBrowser.OpenURL("http://captainsroll.com/"); }); ui.btn_us.SetClick(() => { GameHelper.OpenEmail(); }); ui.btn_revive.SetClick(() => { GameDispatcher.Instance.Dispatch(GameMsg.reset_game, false); CtrlCloseUI(); }); ui.level_text.SetVar("lv",GameHelper.GetLevel().ToString()).FlushVars(); ui.speed_slide.onChanged.Add(SetSlideValue); ui.btn_music.on_off.selectedIndex = model.IsOpenMusic ? 0 : 1; ui.btn_sound.on_off.selectedIndex = GRoot.inst.soundVolume > 0 ? 0 : 1; ui.btn_music.SetClick(SetMusic); ui.btn_sound.SetClick(SetSound); ui.btn_close.SetClick(() => { ui.hide.Play(UpdateUserInfo); }); if (GameHelper.IsGiftSwitch()) { // ui.btn_restore.visible = false; } else { ui.btn_us.visible = true; } ui.btn_restore.SetClick(() => { // ApplePayManager.Instance.AppleRestore((success, message) => // { // if (success) // { // GameHelper.ShowTips("Restore Purchases Success!"); // // SaveData.GetSaveObject().is_get_packreward = success; // SaveData.GetSaveObject().have_slot = success; // GameDispatcher.Instance.Dispatch(GameMsg.noads_refresh); // } // else // { // // Debug.Log("[barry] restore failed: " + success); // GameHelper.ShowTips("There are no recoverable transactions"); // } // }); }); } private void SetSlideValue() { var sliderValue = (float)ui.speed_slide.value; // 先把滑块值钳位在 0~100 内 float val = Mathf.Clamp(sliderValue, 0f, 100f); // 线性映射:0→0.6,100→1.5 float ratio = val / 100f; float speed = 1200f + ratio * (1700f - 1200f); speed = Mathf.Clamp(speed, 1200f, 1700f); GameDispatcher.Instance.Dispatch(GameMsg.UpdateSpeed, speed); } private void SetMusic() { model.IsOpenMusic = !model.IsOpenMusic; ui.btn_music.on_off.selectedIndex = model.IsOpenMusic ? 0 : 1; } private void SetSound() { var sound = GRoot.inst.soundVolume; sound = sound > 0 ? 0 : 1; GRoot.inst.soundVolume = sound; PlayerPrefs.SetFloat("soundVolume", sound); ui.btn_sound.on_off.selectedIndex = sound > 0 ? 0 : 1; } private void SetVersion() { // Debug.Log($"SetVersion====== {Application.version}"); ui.text_version.SetVar("count", Application.version).FlushVars(); } private void SetUID() { ui.text_uid.SetVar("UID", GameHelper.GetLoginModel().Uid.ToString()).FlushVars(); } private void SetAvatar() { if (_selectIndex != -1 && _selectIndex != DataMgr.PlayerAvatarId.Value) { DataMgr.PlayerAvatarId.Value = _selectIndex; } } private void UpdateUserInfo() { SaveName(); CtrlCloseUI(); } private void SaveName() { var name = ui.edit_name.input.text; if (string.IsNullOrEmpty(name) || name.IsNullOrWhiteSpace()) { GameHelper.ShowTips("The input cannot be null", true); return; } if (name.Equals(DataMgr.PlayerName)) return; // GameHelper.ShowTips("Name changed successfully"); DataMgr.PlayerName.Value = name; } } }