rp_11009/assets/Game/Scripts/IconMsg.ts
2026-04-07 15:13:51 +08:00

63 lines
2.1 KiB
TypeScript

import { _decorator, Component, instantiate, Label, Node, UITransform } from 'cc';
import { Icon } from './Icon';
import { I18nManager } from '../../Main/Scripts/managers/I18nManager';
import { ICON_RATE, ICON_RATE_NUM1, ICON_RATE_NUM2 } from './Define';
const { ccclass, property } = _decorator;
@ccclass('IconMsg')
export class IconMsg extends Component {
@property(Node)
grayBg: Node = null;
@property(Node)
mainNode: Node = null;
@property(Node)
leftNode: Node = null;
@property(Node)
rightNode: Node = null;
showIconMsg(iconComp: Icon, isLeft: boolean) {
this.leftNode.active = isLeft;
this.rightNode.active = !isLeft;
let worldPos = iconComp.node.getWorldPosition();
let localPos = this.node.getComponent(UITransform).convertToNodeSpaceAR(worldPos);
this.mainNode.setPosition(localPos);
this.grayBg.once(Node.EventType.TOUCH_END, () => {
this.onHideSelf();
})
let isScatter = iconComp.index === 0;
let node = isLeft ? this.leftNode : this.rightNode;
let iconParent = node.getChildByName('icon');
iconParent.children.forEach(child => child.destroy());
let insIconNode = instantiate(iconComp.node);
// insIconNode.getComponent(Icon).index = iconComp.index;
iconParent.addChild(insIconNode);
insIconNode.setPosition(0, 0, 0);
insIconNode.getComponent(Icon).playIdleSpine(true);
let msg = node.getChildByName('msg');
msg.active = isScatter ? false : true;
msg.children.forEach((child, index) => {
let iconRate = ICON_RATE[iconComp.index];
child.getChildByName('num1').getComponent(Label).string = ICON_RATE_NUM1[index].toString();
child.getChildByName('num2').getComponent(Label).string = ICON_RATE_NUM2[index].toString();
child.getChildByName('multi').getComponent(Label).string = iconRate[2 - index].toString();
})
let scatterMsg = node.getChildByName('scatter');
scatterMsg.active = isScatter ? true : false;
}
onHideSelf() {
this.node.destroy();
}
}