Files
18xchat/.svn/pristine/37/3787c099e0c9122357d51e93c831690c1bc80f7f.svn-base
T
2025-07-17 17:18:21 +08:00

297 lines
9.8 KiB
Plaintext

import { _decorator, isValid, Node, Sprite, Toggle, tween, UIOpacity, UITransform, Vec3, view } from 'cc';
import { GButton } from '../../Main/Common/GButton';
import Utils from '../../Main/Common/Utils';
import { InnerMsgCode } from '../../Main/Config/InnerMsgCode';
import li_BaseView from '../../Main/Common/li_BaseView';
import GameManager from '../../Main/Manager/GameManager';
import ResManager from '../../Main/Manager/ResManager';
import { tj_huiyi } from './tj_huiyi';
import GameRootUI from '../../Main/Common/GameRootUI';
import { tj_zhencang } from './tj_zhencang';
import { tj_jilu } from './tj_jilu';
import HttpUnit from '../../Main/Common/HttpUnit';
const { ccclass, property } = _decorator;
/**宠物主界面页签类型 */
export enum TujianPageType {
None, //未知
huiyi, //心动回忆
zhencang, //私房珍藏
jilu, //相遇记录
}
//心动回忆界面
@ccclass('Tujian_UI')
export class Tujian_UI extends li_BaseView {
private _nodeTab: any = {};
private _data;
private _pageType: TujianPageType = TujianPageType.huiyi;
private tgHuiyi: Toggle = null!;//回忆
private tgZhencang: Toggle = null!;//珍藏
private tgJilu: Toggle = null!;//记录
private _btmHuiyi?: tj_huiyi;
private _btmZhencang?: tj_zhencang;
private _btmJilu?: tj_jilu;
/**缩放图片信息 */
private bigPicInfo = {
hyItem: null, //回忆item
npcPic: null, //npc图片
origScale: Vec3.ZERO, //原始缩放
}
//----重写父类接口---------------------------------------
onLoadCT() {
this.registerListenner();
Utils.parseNode(this.node, this._nodeTab)
this.tgHuiyi = this._nodeTab.tjPage1.getComponent(Toggle)
this.tgZhencang = this._nodeTab.tjPage2.getComponent(Toggle)
this.tgJilu = this._nodeTab.tjPage3.getComponent(Toggle)
}
openUIDataCT(data: any): void {
this._data = data
}
registerListenner() {
Utils.addInnerEL(InnerMsgCode.UI_Tj_huiyi_Pic, this, this.resiveHuiyiPic)
Utils.addInnerEL(InnerMsgCode.UI_Tj_huiyi_Lv, this, this.resiveHuiyiLv)
Utils.addInnerEL(InnerMsgCode.Data_ZhencangRedpoint, this, this.resiveZhencangRedpoint)
}
start() {
GButton.BandClick(this._nodeTab.mask, ()=>{
this.onClose();
}, this, 0, null, null, false);
GButton.BandClick(this._nodeTab.btnBack, ()=>{
this.onClose();
}, this);
GButton.RemoveAndBandClick(this._nodeTab.tjPage1,()=>{
this.changePageType(TujianPageType.huiyi);
},this)
GButton.RemoveAndBandClick(this._nodeTab.tjPage2,()=>{
this.changePageType(TujianPageType.zhencang);
},this)
GButton.RemoveAndBandClick(this._nodeTab.tjPage3,()=>{
this.changePageType(TujianPageType.jilu);
},this)
//回忆
GButton.BandClick(this._nodeTab.btnBPBack, ()=>{
this.doHideBigPic();
}, this);
this._nodeTab.BigPicUI.active = false;
this.changePageType(TujianPageType.huiyi, true);
this.refreshRedpointHuiyi();
this.refreshRedpointZhencang();
this.refreshRedpointJilu();
}
update(deltaTime: number) {
}
/**回忆显示大图 */
resiveHuiyiPic(data: any) {
this.doShowBigPic(data);
}
/**前往回忆对应关卡 */
resiveHuiyiLv(data: any) {
this.onClose();
}
resiveZhencangRedpoint(data: any) {
this.refreshRedpointZhencang();
}
//region 切换页面
changePageType(type: TujianPageType, isFroce: boolean = false) {
if (this._pageType == type && !isFroce) {
return
}
//页签改变了,先隐藏所有节点
if (this._pageType != type) {
if(this._btmHuiyi) this._btmHuiyi.node.active = false;
if(this._btmZhencang) this._btmZhencang.node.active = false;
if(this._btmJilu) this._btmJilu.node.active = false;
}
this._pageType = type;
if (type == TujianPageType.huiyi) {//回忆
this.tgHuiyi.isChecked = true;
if (this._btmHuiyi) {
this._btmHuiyi.node.active = true;
} else {
ResManager.I.loadSubpackagePrefab("UI/StartUI/TJ_Huiyi", (res:Node)=>{
if (isValid(this._nodeTab.MidNode)) {
this._nodeTab.MidNode.addChild(res)
this._btmHuiyi = res.getComponent(tj_huiyi)
if (this._pageType == TujianPageType.huiyi) {
this._btmHuiyi.node.active = true;
} else {
this._btmHuiyi.node.active = false;
}
}
})
}
} else if (type == TujianPageType.zhencang) { //珍藏
this.tgZhencang.isChecked = true;
if (this._btmZhencang) {
this._btmZhencang.node.active = true;
} else {
ResManager.I.loadSubpackagePrefab("UI/StartUI/TJ_Zhencang", (res:Node)=>{
if (isValid(this._nodeTab.MidNode)) {
this._nodeTab.MidNode.addChild(res)
this._btmZhencang = res.getComponent(tj_zhencang)
if (this._pageType == TujianPageType.zhencang) {
this._btmZhencang.node.active = true;
} else {
this._btmZhencang.node.active = false;
}
}
})
}
} else if (type == TujianPageType.jilu) { //记录
this.tgJilu.isChecked = true;
if (this._btmJilu) {
this._btmJilu.node.active = true;
} else {
ResManager.I.loadSubpackagePrefab("UI/StartUI/TJ_Jilu", (res:Node)=>{
if (isValid(this._nodeTab.MidNode)) {
this._nodeTab.MidNode.addChild(res)
this._btmJilu = res.getComponent(tj_jilu)
if (this._pageType == TujianPageType.jilu) {
this._btmJilu.node.active = true;
} else {
this._btmJilu.node.active = false;
}
}
})
}
}
}
/**显示大图 */
doShowBigPic(data:any) {
if (!data.hyItem) {
return
}
let npcPic:Node = data.hyItem.npcPic;
this.bigPicInfo.hyItem = data.hyItem;
this.bigPicInfo.npcPic = npcPic;
this.bigPicInfo.origScale = npcPic.scale.clone();
let wpos = new Vec3(0,0,0);
npcPic.getWorldPosition(wpos);
let BigPicRoot:Node = this._nodeTab.BigPicRoot;
let npos = BigPicRoot.getComponent(UITransform).convertToNodeSpaceAR(wpos);
npcPic.setParent(BigPicRoot);
npcPic.setPosition(npos);
let ttime = 0.3;
GameRootUI.DisableOper(ttime+0.1)
//放大图片
let s = 1
let windowSize = view.getVisibleSize(); // 获取窗口大小
let picTf:UITransform = npcPic.getComponent(UITransform);
if (picTf.height < windowSize.height) {
s = windowSize.height / picTf.height;
}
tween((npcPic))
.to(ttime, { scale: new Vec3(s, s, s), position: new Vec3(0, 0, 0) }, { easing: 'quadOut' })
.start();
//显示UI
this._nodeTab.BigPicUI.active = true;
Utils.setString(this._nodeTab.labBPTalk, data.talk);
let bigPicUIOpa:UIOpacity = this._nodeTab.BigPicUI.getComponent(UIOpacity)
bigPicUIOpa.opacity = 0;
tween(bigPicUIOpa)
.delay(ttime*0.7)
.to(ttime*0.3, { opacity: 255 }, { easing: 'quadOut' })
.start();
}
/**隐藏大图 */
doHideBigPic() {
if (!this.bigPicInfo.hyItem) return;
let npcPic = this.bigPicInfo.npcPic
let wpos = new Vec3(0,0,0);
this.bigPicInfo.hyItem.picRoot.getWorldPosition(wpos);
let npos = this._nodeTab.BigPicRoot.getComponent(UITransform).convertToNodeSpaceAR(wpos);
// npcPic.setParent(this.bigPicInfo.hyItem.picRoot);
// npcPic.setPosition(npos);
let ttime = 0.3;
GameRootUI.DisableOper(ttime+0.1)
tween((npcPic))
.to(ttime, { scale: this.bigPicInfo.origScale, position: npos }, { easing: 'quadOut' })
.call(() => {
npcPic.setParent(this.bigPicInfo.hyItem.picRoot);
npcPic.setPosition(new Vec3(0,0,0));
this.bigPicInfo.hyItem = null;
this.bigPicInfo.npcPic = null;
})
.start();
let bigPicUIOpa:UIOpacity = this._nodeTab.BigPicUI.getComponent(UIOpacity)
tween(bigPicUIOpa)
.to(ttime*0.3, { opacity: 0 }, { easing: 'quadOut' })
.call(() => {
this._nodeTab.BigPicUI.active = false;
})
.start();
}
// 刷新红点 回忆
refreshRedpointHuiyi() {
let isshow = HttpUnit.IsHaveHuiyiRedpoint()
this._nodeTab.rp_1.active = isshow;
}
// 刷新红点 珍藏
refreshRedpointZhencang() {
let isshow = HttpUnit.IsHaveZhencangRedpoint()
this._nodeTab.rp_2.active = isshow;
}
// 刷新红点 记录
refreshRedpointJilu() {
let isshow = false
this._nodeTab.rp_3.active = isshow;
}
//已读红点 回忆
readRedpointHuiyi() {
let isshow = HttpUnit.IsHaveHuiyiRedpoint()
if (isshow) {
}
}
//已读红点 珍藏
readRedpointZhencang() {
let isshow = HttpUnit.IsHaveZhencangRedpoint()
if (isshow) {
HttpUnit.ins.readRedpointZhencang({}, (data) => {
if (data) {
}
})
}
}
}