import MyModel from "../core/MyModel"; import SKUIUtil from "../gear_2.3.4/util/SKUIUtil"; import HorseUtil from "./HorseUtil"; import FGUtil, { TipAlign } from "../gear_2.3.4/fgui/FGUtil"; import SKSocket from "../gear_2.3.4/net/SKSocket"; import GameModel from "../core/GameModel"; import HorseSkillMap from "./HorseSkillMap"; import MsgAlert from "../game/msg/MsgAlert"; import SKDataUtil from "../gear_2.3.4/util/SKDataUtil"; import ItemUtil from "../core/ItemUtil"; import RefiningAlert from "./RefiningAlert"; import GameUtil from "../core/GameUtil"; import SkillUtil from "../game/skill/core/SkillUtil"; import SkillBase, { ESkillQuality } from "../game/skill/core/SkillBase"; import FGAlert from "../gear_2.3.4/fgui/FGAlert"; import Horse from "./Horse"; import SKLogger from "../gear_2.3.4/util/SKLogger"; import { LongPressSpeedProp } from "../core/EEnum"; export default class HorsePanel extends cc.Component { static shared = new HorsePanel(); main: fgui.GComponent; alert: fgui.GComponent; horse_prop: fgui.GComponent; list: fgui.GList; roleNode: cc.Node; previewNode: cc.Node; horseName: fgui.GTextField; horseLevel: fgui.GTextField; ridingTF: fgui.GTextField; tip: fgui.GTextField; controlList: fgui.GList; otherList: fgui.GList; otherTitle: fgui.GComponent; skillList: fgui.GList; skillIcon: fgui.GComponent; skillNameLabel: fgui.GTextField; skillDescRTF: fgui.GRichTextField; currentSkill: SkillBase; mask: fgui.GComponent; parentNode: cc.Node; maxtiemcnt: number = 0; timecnt: number = 0; currentBtn: null; UpgradeSkill: boolean = true; useItemsAlert: fairygui.GComponent = null; useItemsMask: fgui.GComponent; useItemData: null; clickUseItemBlock: (data: any) => void; // constructor() { // } show() { this.loadUI(); } hide() { FGUtil.dispose(this.main); this.unscheduleAllCallbacks() this.main = null; } loadUI() { FGUtil.dispose(this.main); this.unscheduleAllCallbacks() this.main = fgui.UIPackage.createObject("main_ui", "horse_main").asCom; FGUtil.root().addChild(this.main); FGUtil.fitScreen(this.main); this.initUI(); this.initList(); this.refreshList(); this.initPreview(); this.initSelected(); this.initControl(); this.refreshPanel(); this.initEvent(); this.loadHorseSkill(); } loadHorseSkill() { GameModel.send("c2s_horse_skill", { roleid: GameModel.player.roleid }); } // 同步坐騎列表 syncHorseList(data: any) { if (this.main == null) { return; } MyModel.shared.horseList.reset(data.horseList); this.refreshList(); this.refreshPanel(); if (this.useItemsAlert) { let list = FGUtil.getList(this.useItemsAlert, "list"); for (let i = 0; i < list.numItems; i++) { let cell: fgui.GComponent = list.getChildAt(i); let data = cell.node["data"]; let count = ItemUtil.getBagItemCount(data.id); let count_tf = cell.getChild("count").asTextField; count_tf.text = `${count}`; let color = ItemUtil.getUseItemColor(count); count_tf.color = color; } } } syncHorseSkill(data: any) { if (this.main == null) { return; } let dict = {}; if (data && data.list) { for (let info of data.list) { if (info) { let skill = SkillUtil.getHorseSkill(info.skillId); skill.curExp = info.exp; dict[info.position] = skill; } } } GameModel.horseSkill = dict; if (this.main) { this.refreshSkillList(); } RefiningAlert.shared.reset(); this.resetSkillUpItemCount(); } initUI() { this.alert = this.main.getChild("horse_alert").asCom; this.horse_prop = this.alert.getChild("horse_prop").asCom; this.horseName = this.horse_prop.getChild("name_label").asTextField; this.horseLevel = this.horse_prop.getChild("level_label").asTextField; this.ridingTF = FGUtil.getTextField(this.horse_prop, "riding_btn/title"); this.resetSkillUpItemCount(); } resetSkillUpItemCount() { let count = ItemUtil.getBagItemCount(GameUtil.horseSkillUpItemId); let tf = FGUtil.getTextField(this.alert, "horse_skill/item_count"); if (tf) { tf.text = `3/${count}`; } this.UpgradeSkill = true; } initList() { this.list = this.alert.getChild("horse_list").asList; this.list.removeChildrenToPool(); } initPreview() { this.previewNode = this.horse_prop.getChild("preview").asCom.getChild("horse").node; SKUIUtil.addNode("ride_shadow", this.previewNode); SKUIUtil.addNode("ride_behind", this.previewNode); SKUIUtil.addNode("ride_behind1", this.previewNode); SKUIUtil.addNode("ride_behind2", this.previewNode); this.roleNode = SKUIUtil.addNode("role", this.previewNode); SKUIUtil.addNode("ride_front", this.previewNode); SKUIUtil.addNode("ride_front1", this.previewNode); } // 初始化坐騎選擇 initSelected() { let selectedIndex: number = MyModel.shared.horseList.horseIndex - 1; if (selectedIndex != -1) { this.list.selectedIndex = selectedIndex; } else { this.list.selectedIndex = 0; if (this.roleNode) { this.roleNode.active = false; } } } initEvent() { this.list.on(fgui.Event.CLICK_ITEM, this.onClickItem, this); this.alert.getChild("close_btn").onClick(this.hide, this); this.horse_prop.getChild("refining_btn").onClick(this.clickRefining, this); this.horse_prop.getChild("riding_btn").onClick(this.clickRiding, this); this.horse_prop.getChild("add_exp").onClick(this.clickAddExp, this); let mapBtn = FGUtil.getComponent(this.alert, "horse_skill/map_btn"); if (mapBtn) { mapBtn.onClick(this.clickMap, this); } let upBtn = FGUtil.getComponent(this.alert, "horse_skill/up_btn"); if (upBtn) { upBtn.asButton.node.on(cc.Node.EventType.TOUCH_START, this.propertyBtnClick.bind(this)); upBtn.asButton.node.on(cc.Node.EventType.TOUCH_END, this.propertyBtnClick.bind(this)); } } propertyBtnClick(e) { if (e.type == cc.Node.EventType.TOUCH_START) { this.maxtiemcnt = LongPressSpeedProp.MAXTIMECNT; this.timecnt = 0; this.currentBtn = e.target; this.schedule(this.update, 1 / 30) } else if (e.type == cc.Node.EventType.TOUCH_END) { this.timecnt = this.maxtiemcnt; this.update(); this.currentBtn = null; this.unscheduleAllCallbacks(); } } update() { if (this.currentBtn == null) { return; } this.timecnt += LongPressSpeedProp.TIMECNTADD; if (this.timecnt >= this.maxtiemcnt) { if (this.maxtiemcnt > LongPressSpeedProp.MINTIMECNT) { this.maxtiemcnt -= LongPressSpeedProp.TIMECNTSUB; this.maxtiemcnt = Math.max(LongPressSpeedProp.MINTIMECNT, this.maxtiemcnt) } this.timecnt = 0; if (this.UpgradeSkill) { this.UpgradeSkill = false; this.clickUpgradeSkill(); } } } useItemBtnClick(e) { if (e.type == cc.Node.EventType.TOUCH_START) { this.maxtiemcnt = LongPressSpeedProp.MAXTIMECNT; this.timecnt = 0; this.currentBtn = e.target; this.useItemData = e.target.data; this.schedule(this.useItemUpdate, 1 / 30) } else if (e.type == cc.Node.EventType.TOUCH_END) { this.timecnt = this.maxtiemcnt; this.useItemUpdate(); this.currentBtn = null; this.unscheduleAllCallbacks(); } } useItemUpdate() { if (this.currentBtn == null) { return; } this.timecnt += LongPressSpeedProp.TIMECNTADD; if (this.timecnt >= this.maxtiemcnt) { if (this.maxtiemcnt > LongPressSpeedProp.MINTIMECNT) { this.maxtiemcnt -= LongPressSpeedProp.TIMECNTSUB; this.maxtiemcnt = Math.max(LongPressSpeedProp.MINTIMECNT, this.maxtiemcnt) } this.timecnt = 0; if (this.UpgradeSkill) { this.UpgradeSkill = false; this.useHorseUpgradeItem(this.useItemData); } } } useItems(target: fgui.GObject, itemList: number[]) { if (this.useItemsAlert != null) { if (SKUIUtil.isValid(this.useItemsAlert.node)) { this.clickMask(null); } else { this.useItemsAlert = null; } } if (this.useItemsAlert == null) { this.useItemsAlert = fgui.UIPackage.createObject("main_ui", "use_items").asCom; let list = FGUtil.getList(this.useItemsAlert, "list"); list.removeChildrenToPool(); for (let itemId of itemList) { let item = ItemUtil.getItemData(itemId); let cell = list.addItemFromPool().asCom; cell.getChild("title").asTextField.text = item.name; cell.getChild("desc").asTextField.text = item.typedetail; let count = ItemUtil.getBagItemCount(itemId); item.count = count; let count_tf = cell.getChild("count").asTextField; count_tf.text = `${count}`; let color = ItemUtil.getUseItemColor(count); count_tf.color = color; cell.icon = `ui://main_ui/${item.icon}`; cell.node["data"] = item; cell.node.on(cc.Node.EventType.TOUCH_START, this.useItemBtnClick.bind(this)); cell.node.on(cc.Node.EventType.TOUCH_END, this.useItemBtnClick.bind(this)); } list.resizeToFit(); this.useItemsAlert.height = list.height; FGUtil.align(target, this.useItemsAlert, TipAlign.TOP_RIGHT); this.useItemsMask = fgui.UIPackage.createObject("main_ui", "alpha_mask").asCom; this.useItemsMask.onClick(this.clickMask, this); FGUtil.root().addChild(this.useItemsMask); this.useItemsMask.makeFullScreen(); FGUtil.root().addChild(this.useItemsAlert); } } clickMask(even: fgui.Event) { if (this.useItemsAlert) { this.useItemsMask.dispose(); this.useItemsAlert.dispose(); this.useItemsMask = null; this.useItemsAlert = null; this.clickUseItemBlock = null; } } // 點擊升級技能 clickUpgradeSkill() { let current = this.list.selectedIndex * 3 + this.skillList.selectedIndex + 1; let params = { position: current } GameModel.send("c2s_upgrade_skill", params); } // 點擊加坐騎經驗 clickAddExp(event: fgui.Event) { let target = this.horse_prop.getChild("add_exp"); this.useItems(target, GameUtil.horseExpItemList); } // 點擊使用道具 useHorseUpgradeItem(data: any) { let count = ItemUtil.getBagItemCount(data.id); if (count < 1) { MsgAlert.addMsg(`您沒有足夠的[${data.name}]!`) return; } let params = { itemId: data.id, horseIndex: this.list.selectedIndex + 1 }; GameModel.send("c2s_horse_upgrade", params); } onClickItem(item: fgui.GObject) { let index = this.list.getChildIndex(item); this.list.selectedIndex = index; this.refreshPanel(); } // 點擊洗煉 clickRefining(event: cc.Event.EventTouch) { let alert = RefiningAlert.shared; alert.horseIndex = this.list.selectedIndex + 1; alert.show(); } // 點擊騎乘 clickRiding(event: cc.Event.EventTouch) { let dict = MyModel.shared.horseList.dict; let horse = dict[this.list.selectedIndex + 1]; if (horse == null) { return; } let position = MyModel.shared.horseList.getCurrentPosition(); if (horse.position == position) { MyModel.shared.horseList.getDown(); } else { MyModel.shared.horseList.ride(horse.position); } this.refreshPanel(); } // 點擊坐騎技能圖鑑 clickMap(event: fgui.Event) { HorseSkillMap.shared.show(this.list.selectedIndex + 1); } // 刷新坐騎列表 refreshList() { let reset = (this.list.numItems != 4); if (reset) { this.list.removeChildrenToPool(); } let dict = MyModel.shared.horseList.dict; let relive = GameModel.player.relive; let level = GameModel.player.level; // if (level >= 120 && relive == 3){ // for (var i = 0; i < 4; i++) { // let horse: Horse = dict[i + 1]; // let cell = null; // if (reset) { // cell = this.list.addItemFromPool().asButton; // } else { // cell = this.list.getChildAt(i).asButton; // } // cell.title = horse.name; // cell.icon = `ui://main_ui/${horse.resId}`; // cell.getChild("level_label").asTextField.text = `${horse.level}級`; // let type = cell.getController("type"); // type.selectedIndex = i; // } // } if (level >= 100 && relive == 2){ for (var i = 0; i < 3; i++) { let horse: Horse = dict[i + 1]; let cell = null; if (reset) { cell = this.list.addItemFromPool().asButton; } else { cell = this.list.getChildAt(i).asButton; } cell.title = horse.name; cell.icon = `ui://main_ui/${horse.resId}`; cell.getChild("level_label").asTextField.text = `${horse.level}級`; let type = cell.getController("type"); type.selectedIndex = i; } }else if (level >= 80 && relive == 1){ for (var i = 0; i < 2; i++) { let horse: Horse = dict[i + 1]; let cell = null; if (reset) { cell = this.list.addItemFromPool().asButton; } else { cell = this.list.getChildAt(i).asButton; } cell.title = horse.name; cell.icon = `ui://main_ui/${horse.resId}`; cell.getChild("level_label").asTextField.text = `${horse.level}級`; let type = cell.getController("type"); type.selectedIndex = i; } }else if (level >= 60 && relive <= 0){ for (var i = 0; i < 1; i++) { let horse: Horse = dict[i + 1]; let cell = null; if (reset) { cell = this.list.addItemFromPool().asButton; } else { cell = this.list.getChildAt(i).asButton; } cell.title = horse.name; cell.icon = `ui://main_ui/${horse.resId}`; cell.getChild("level_label").asTextField.text = `${horse.level}級`; let type = cell.getController("type"); type.selectedIndex = i; } }else if (level >= 120){ for (var i = 0; i < 4; i++) { let horse: Horse = dict[i + 1]; let cell = null; if (reset) { cell = this.list.addItemFromPool().asButton; } else { cell = this.list.getChildAt(i).asButton; } cell.title = horse.name; cell.icon = `ui://main_ui/${horse.resId}`; cell.getChild("level_label").asTextField.text = `${horse.level}級`; let type = cell.getController("type"); type.selectedIndex = i; } } // for (var i = 0; i < 4; i++) { // let horse: Horse = dict[i + 1]; // let cell = null; // if (reset) { // cell = this.list.addItemFromPool().asButton; // } else { // cell = this.list.getChildAt(i).asButton; // } // cell.title = horse.name; // cell.icon = `ui://main_ui/${horse.resId}`; // cell.getChild("level_label").asTextField.text = `${horse.level}級`; // let type = cell.getController("type"); // type.selectedIndex = i; // } } // 刷新面板 refreshPanel() { let dict = MyModel.shared.horseList.dict; let selectdIndex = this.list.selectedIndex; let horse = dict[selectdIndex + 1]; if (horse == null) { SKLogger.warn(`$警告:找不到坐騎定義${selectdIndex + 1}`); return; } this.horseName.text = horse.name; this.horseLevel.text = `${horse.level}級`; let max_exp = SKDataUtil.maxExp(GameModel.game_conf.horse_exp, horse.exp); let exp_pb = FGUtil.getProgressBar(this.horse_prop, "exp_pb"); exp_pb.value = horse.exp; exp_pb.max = max_exp; HorseUtil.playAni(this.previewNode, MyModel.shared.resId, 1, "stand", horse.resId); let position = MyModel.shared.horseList.getCurrentPosition(); // 重置騎乘標識 let relive = GameModel.player.relive; let level = GameModel.player.level; if (level >= 120 && relive == 3){ for (let i = 0; i < 4; i++) { let temp = this.list.getChildAt(i).asCom; let horse = dict[i + 1]; let flag = temp.getChild("ride_flag"); if (flag) { flag.visible = (horse.position == position); } } } if (level >= 100 && relive == 2){ for (let i = 0; i < 3; i++) { let temp = this.list.getChildAt(i).asCom; let horse = dict[i + 1]; let flag = temp.getChild("ride_flag"); if (flag) { flag.visible = (horse.position == position); } } } if (level >= 80 && relive == 1){ for (let i = 0; i < 2; i++) { let temp = this.list.getChildAt(i).asCom; let horse = dict[i + 1]; let flag = temp.getChild("ride_flag"); if (flag) { flag.visible = (horse.position == position); } } } if (level >= 60 && relive <= 0){ for (let i = 0; i < 1; i++) { let temp = this.list.getChildAt(i).asCom; let horse = dict[i + 1]; let flag = temp.getChild("ride_flag"); if (flag) { flag.visible = (horse.position == position); } } } // for (let i = 0; i < 4; i++) { // let temp = this.list.getChildAt(i).asCom; // let horse = dict[i + 1]; // let flag = temp.getChild("ride_flag"); // if (flag) { // flag.visible = (horse.position == position); // } // } if (position == selectdIndex + 1) { this.ridingTF.text = "下騎"; if (this.roleNode) { this.roleNode.active = true; } } else { this.ridingTF.text = "騎乘"; if (this.roleNode) { this.roleNode.active = false; } } this.refreshControl(); this.refreshSkillList(); } // 初始化管制列表 initControl() { this.tip = FGUtil.getTextField(this.alert, "horse_control/tip"); this.controlList = FGUtil.getList(this.alert, "horse_control/list"); this.otherTitle = FGUtil.getComponent(this.alert, "horse_control/other_title"); this.otherList = FGUtil.getList(this.alert, "horse_control/other_list"); this.controlList.on(fgui.Event.CLICK_ITEM, this.onClickControlItem, this); this.otherList.on(fgui.Event.CLICK_ITEM, this.onClickOtherItem, this); } refreshControl() { let petList = MyModel.shared.petList; if (petList == null) { return; } let list = petList.list; if (list == null) { return; } this.controlList.removeChildrenToPool(); this.otherList.removeChildrenToPool(); for (let i = 0; i < list.length; i++) { let data = list[i]; if (data.control == this.list.selectedIndex + 1) { let cell = this.controlList.addItemFromPool().asCom; cell.getChild("name_label").asTextField.text = data.name; let levelTF = FGUtil.getTextField(cell, "level_label"); levelTF.text = GameUtil.getReliveText(data.relive, data.level); levelTF.color = GameUtil.getReliveColor(data.relive, data.level); FGUtil.getLoader(cell, "item/icon").url = `ui://main_ui/${data.resid}`; FGUtil.getObject(cell, "close").visible = true; cell.data = data; } else { let cell = this.otherList.addItemFromPool().asCom; FGUtil.getTextField(cell, "name_label").text = data.name; FGUtil.getTextField(cell, "level_label").text = GameUtil.getReliveText(data.relive, data.level); FGUtil.getTextField(cell, "level_label").color = GameUtil.getReliveColor(data.relive, data.level); FGUtil.getLoader(cell, "item/icon").url = `ui://main_ui/${data.resid}`; let loader = FGUtil.getLoader(cell, "horse/icon"); let horseResId = MyModel.shared.horseList.getHorseResId(data.control); if (horseResId != 0) { loader.url = `ui://main_ui/${horseResId}`; FGUtil.getObject(cell, `horse`).visible = true; } else { FGUtil.getObject(cell, `horse`).visible = false; } FGUtil.getObject(cell, "close").visible = false; cell.data = data; } } this.controlList.resizeToFit(); this.otherList.resizeToFit(); if (this.controlList.height < 1) { this.tip.visible = true; this.otherTitle.y = this.tip.y + this.tip.height + 5; } else { this.tip.visible = false; this.otherTitle.y = this.controlList.y + this.controlList.height + 5; } this.otherList.y = this.otherTitle.y + this.otherTitle.height + 5; } // 點擊管制召喚獸 onClickControlItem(item: fgui.GObject) { let data = item.data; data.control = 0; this.refreshControl(); let player = GameModel.player; let roleId = player.roleid; SKSocket.send("c2s_pet_control", { roleid: roleId, petid: data.petid, control: 0 }); } // 點擊未管制召喚獸 onClickOtherItem(item: fgui.GObject) { let data = item.data; let player = GameModel.player; if (data.control != 0) { FGAlert.show(`確定[${data.name}]替換管制坐騎?`, () => { FGAlert.hide(); }, () => { FGAlert.hide(); data.control = this.list.selectedIndex + 1; this.refreshControl(); let roleId = player.roleid; let params = { roleid: roleId, petid: data.petid, control: data.control }; SKSocket.send("c2s_pet_control", params); }); return; } data.control = this.list.selectedIndex + 1; this.refreshControl(); let roleId = player.roleid; let params = { roleid: roleId, petid: data.petid, control: data.control }; SKSocket.send("c2s_pet_control", params); } // 刷新技能列表 refreshSkillList() { this.skillList = FGUtil.getList(this.alert, "horse_skill/list"); this.skillList.on(fgui.Event.CLICK_ITEM, this.onClickSkillItem, this); let oldSkillIndex = this.skillList.selectedIndex; this.skillList.removeChildrenToPool(); let horseSkill = GameModel.horseSkill; if (horseSkill == null) { return; } let start = this.list.selectedIndex * 3 + 1; for (let i = 0; i < 3; i++) { let cell = this.skillList.addItemFromPool().asButton; let skill: SkillBase = SKDataUtil.valueForKey(horseSkill, start + i); if (skill == null) { cell.icon = `ui://main_ui/1000`; continue; } let icon = `ui://main_ui/${skill.icon}`; if (skill.quality == ESkillQuality.LOW) { cell.getController("type").selectedIndex = 0; } else { cell.getController("type").selectedIndex = 1; } let exp_pb = FGUtil.getProgressBar(cell, "exp_pb"); if (exp_pb) { exp_pb.value = skill.curExp; } cell.icon = icon; } this.skillList.selectedIndex = (oldSkillIndex == -1 ? 0 : oldSkillIndex); this.skillIcon = FGUtil.getComponent(this.alert, "horse_skill/skill_icon"); this.skillNameLabel = FGUtil.getTextField(this.alert, "horse_skill/skill_name"); this.skillDescRTF = FGUtil.getRichTextField(this.alert, "horse_skill/skill_desc"); this.refreshSkill(); } onClickSkillItem(item: fgui.GObject) { let index = this.skillList.getChildIndex(item); this.skillList.selectedIndex = index; this.refreshSkill(); } refreshSkill() { let current = this.list.selectedIndex * 3 + this.skillList.selectedIndex + 1; let horseSkill = GameModel.horseSkill; this.currentSkill = SKDataUtil.valueForKey(horseSkill, current); if (this.currentSkill) { this.skillIcon.icon = `ui://main_ui/${this.currentSkill.icon}`; if (this.currentSkill.quality == ESkillQuality.LOW) { this.skillIcon.getController("type").selectedIndex = 0; this.skillNameLabel.color = SKUIUtil.colorOfString("#6D0903"); } else { this.skillIcon.getController("type").selectedIndex = 1; this.skillNameLabel.color = SKUIUtil.colorOfString("#CA84F8"); } this.skillNameLabel.text = this.currentSkill.name; let text = ""; text = this.currentSkill.desc; let horse = MyModel.shared.horseList.getHorseBy(this.list.selectedIndex + 1); text += this.currentSkill.getSkillDesc(horse.level, this.currentSkill.curExp); this.skillDescRTF.ubbEnabled = true; this.skillDescRTF.text = text; let exp_pb = FGUtil.getProgressBar(this.alert, "horse_skill/exp_pb"); if (exp_pb) { exp_pb.value = this.currentSkill.curExp; } } else { this.skillIcon.icon = `ui://main_ui/1000`; this.skillIcon.getController("type").selectedIndex = 0; this.skillNameLabel.text = "暫未開放"; let text = "暫未開放,敬請期待!"; this.skillDescRTF.ubbEnabled = true; this.skillDescRTF.text = text; } this.UpgradeSkill = true; } }