import { _decorator, Node, Tween, tween, v3 } from 'cc';
import { NodeEx } from '../../framework/pool/NodeEx';
import { TipsPool } from '../common/Pool';
import { GameConf } from '../data/GameConf';
const { ccclass, property } = _decorator;

@ccclass('TempTipsNode')
export class TempTipsNode extends NodeEx {

	protected onLoad() {
		this.Node.fuck_01.active = false;
		this.Node.fuck_02.active = false;
		this.Node.fuck_03.active = false;
		this.Node.fuck_04.active = false;
	}

	protected onDestroy() {
		//如果该组件有事件自行取消注释
		//Framework.event.removeEvent(this);
		super.onDestroy();
	}

	//节点被放入池中时调用
	unuse() {
		Tween.stopAllByTarget(this.node);
		this.node.setPosition(0, 0);
		this.Node.fuck_01.active = false;
		this.Node.fuck_02.active = false;
		this.Node.fuck_03.active = false;
		this.Node.fuck_04.active = false;
	}

	//节点从池中取出时调用
	reuse(type: GameConf.TipsType, value: number) {
		value = Math.floor(value);
		this.Node.fuck_01.active = false;
		this.Node.fuck_02.active = false;
		this.Node.fuck_03.active = false;
		this.Node.fuck_04.active = false;
		if (type == GameConf.TipsType.cost) {
			this.Node.fuck_03.active = true;
			this.Label.fuck_03.string = value + "%";
		} else if (type == GameConf.TipsType.select) {
			this.Node.fuck_04.active = true;
			this.Label.fuck_04.string = "+" + value + "%";
		} else if (type == GameConf.TipsType.settle) {
			this.Node.fuck_02.active = true;
			this.Label.fuck_02.string = "+" + value + "%";
		} else if (type == GameConf.TipsType.visit) {
			this.Node.fuck_01.active = true;
			this.Label.fuck_01.string = "+" + value + "%";
		}
		this._runAction();
	}

	private _runAction() {
		Tween.stopAllByTarget(this.node);
		tween(this.node).by(1.5, { position: v3(0, 150) }).call(() => {
			TipsPool.putNode(this);
		}).start();
	}
}