123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- import { _decorator, Component, Node, profiler, SpriteComponent, LabelComponent, ButtonComponent, loader, SpriteFrame } from 'cc';
- import { NoticeManager } from '../../../engines/notices/NoticeManager';
- import StringUtils from '../../../engines/utils/StringUtils';
- import { PlatformManager } from '../../../Platform/PlatformManager';
- import GameConfigManager from '../../models/GameConfigManager';
- import { GameModel } from '../../models/GameModel';
- const { ccclass, property } = _decorator;
- @ccclass('ShopItemRenderScript')
- export class ShopItemRenderScript extends Component {
-
- @property({
- type:SpriteComponent
- })
- icon:SpriteComponent=null;
- @property({
- type:LabelComponent
- })
- levelLabel:LabelComponent=null;
- @property({
- type:LabelComponent
- })
- nameLabel:LabelComponent=null;
- @property({
- type:ButtonComponent
- })
- freeBuyButton:ButtonComponent=null;
- @property({
- type:LabelComponent
- })
- freeBuyButtonLabel:LabelComponent=null;
- @property({
- type:ButtonComponent
- })
- diamondBuyButton:ButtonComponent=null;
- @property({
- type:LabelComponent
- })
- diamondBuyButtonLabel:LabelComponent=null;
- @property({
- type:ButtonComponent
- })
- GlodBuyButton:ButtonComponent=null;
- @property({
- type:LabelComponent
- })
- GlodBuyButtonLabel:LabelComponent=null;
- @property({
- type:Node
- })
- lockState:Node=null;
-
- private data:any;
- start () {
- // Your initialization goes here.
- }
- UpdateItemRender(data:any):void{
- this.data=data;
- this.RefreshItem();
- }
- private RefreshItem():void{
- let weaponConfig:any=GameConfigManager.GetWeaponConfig(this.data.id);
- //图标
- loader.loadRes(weaponConfig.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
- if(err!=null){
- console.log("加载图标出错:"+weaponConfig.icon);
- return;
- }
- this.icon.spriteFrame=asset;
- })
- //等级
- this.levelLabel.string=weaponConfig.level.toString();
- //名称
- this.nameLabel.string=weaponConfig.name;
- let price:number;
- //state 0 未解锁 1 已解锁
- if(this.data.state==0){
- this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
- this.lockState.active=true;
- }else{
- this.lockState.active=false;
- //buyType 购买方式 0金币购买 1宝石购买 2看广告购买
- if(this.data.buyType==0){//金币购买
- this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
- this.GlodBuyButton.node.active=true;
- price=GameModel.single.GetWeaponBuyPrice(this.data.id);
- this.GlodBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
- }else if(this.data.buyType==1){//宝石购买
- this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
- this.diamondBuyButton.node.active=true;
- price=weaponConfig.consumeDiamond;
- this.diamondBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
- }else{//广告购买
- this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
- this.freeBuyButton.node.active=true;
- }
- }
- }
- /**
- * 金币购买
- */
- GlodBuy():void{
- if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
- NoticeManager.ShowPrompt("购买成功。");
- }
- }
- /**
- * 钻石购买
- */
- DiamondBuy():void{
- if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
- NoticeManager.ShowPrompt("购买成功。");
- }
- }
- /**
- * 视频购买
- */
- VideoBuy():void{
- PlatformManager.showRewardedVideo(()=>{
- if(GameModel.single.BuyWeapon(this.data.buyType,this.data.id)){
- NoticeManager.ShowPrompt("购买成功。");
- }
- }, ()=>{
- NoticeManager.ShowPrompt("购买失败。");
- })
- }
- // update (deltaTime: number) {
- // // Your update function goes here.
- // }
- }
|