| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import { _decorator, Component, Node, Sprite, JsonAsset, Prefab, instantiate, Vec3, Vec4, Quat, RichText, EventHandler, Button } from 'cc';
- import { DataSystem } from '../core/data/DataSystem';
- import { Http } from '../core/net/Http';
- import { ResourceLoader } from '../core/resourceManager/ResourceLoader';
- import { ConfigData } from '../data/ConfigData';
- import { PrizeItem } from './PrizeItem';
- const { ccclass, property, requireComponent } = _decorator;
- @ccclass('TurntableUI')
- @requireComponent(Http)
- export class TurntableUI extends Component {
- @property({ tooltip: "资源加载组件", type: ResourceLoader }) public resourceLoader: ResourceLoader;
- @property({ tooltip: "奖品转盘", type: Node }) public prizeShowBox: Node;
- @property({ tooltip: "剩余次数文本", type: RichText }) public times: RichText;
- @property({ tooltip: "获取次数回调", type: EventHandler }) public getTimesBack: EventHandler;
- @property({ tooltip: "免费抽奖按钮文本", type: Node }) public freeBtnShow: Node;
- @property({ tooltip: "视频抽奖按钮文本", type: Node }) public vidoeBtnShow: Node;
- @property({ tooltip: "抽奖按钮", type: Button }) public drawBtn: Button;
- @property({ tooltip: "帮助按钮", type: Node }) public helpBtn: Node;
- @property({ tooltip: "关闭按钮", type: Node }) public closeBtn: Node;
- @property({ tooltip: "背景", type: Node }) public bg: Node;
- private turntableConfig = [];//转盘配置
- start() {
- this.getConfig();
- }
- private async getConfig() {
- let configData = DataSystem.getData(ConfigData);
- let data;
- if (configData.has("turntable")) {
- data = configData.get("turntable");
- } else {
- data = await (await this.resourceLoader.load<JsonAsset>("configs/turntable", JsonAsset)).json;
- }
- for (let i in data) {
- this.turntableConfig.push(data[i]);
- }
- this.initUI();
- }
- private async initUI() {
- for (var i = 0; i < this.turntableConfig.length; i++) {
- let prefab = await this.resourceLoader.load<Prefab>("prefabs/ui/turntable/turntablePrize", Prefab);
- let prizeItem = instantiate(prefab);
- prizeItem.parent = this.prizeShowBox;
- prizeItem.setPosition(new Vec3(0, 0));
- prizeItem.eulerAngles = new Vec3(0, 0, -60 * i);
- prizeItem.getComponent(PrizeItem).initUI(this.turntableConfig[i].icon, this.turntableConfig[i].num);
- }
- let result = await this.getComponent(Http).send("/api/draw/getDrawTimes");
- if (result && result.code == 0) {
- this.times.string = "<color=#ffffff>剩余次数:</color><color=#ffd522>" + (result.data.freeTimes + result.data.videoTimes) + "</color>";
- if (!result.data.freeTimes) {
- this.freeBtnShow.active = false;
- this.vidoeBtnShow.active = true;
- }
- if (!result.data.videoTimes) {
- this.drawBtn.interactable = false;//按键事件禁用
- this.drawBtn.getComponent(Sprite).grayscale = true;//按键置灰
- }
- this.getTimesBack.emit([result.data.freeTimes, result.data.videoTimes, this.turntableConfig]);
- }
- }
- private initBtn() {
- this.closeBtn.active = true;
- this.helpBtn.active = true;
- }
- private disableBtn() {
- this.closeBtn.active = false;
- this.helpBtn.active = false;
- this.drawBtn.interactable = false;//按键事件禁用
- }
- public onClose() {
- this.bg.active = false;
- }
- }
|