|
@@ -1,4 +1,9 @@
|
|
|
-import { _decorator, Component, Node, SpriteComponent, LabelComponent, ButtonComponent } from 'cc';
|
|
|
+import { _decorator, Component, Node, 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('FenceItemRenderScript')
|
|
@@ -11,7 +16,7 @@ export class FenceItemRenderScript extends Component {
|
|
|
@property({
|
|
|
type:LabelComponent
|
|
|
})
|
|
|
- levelLabel:LabelComponent=null;
|
|
|
+ hpLabel:LabelComponent=null;
|
|
|
|
|
|
@property({
|
|
|
type:LabelComponent
|
|
@@ -49,6 +54,7 @@ export class FenceItemRenderScript extends Component {
|
|
|
})
|
|
|
GlodBuyButtonLabel:LabelComponent=null;
|
|
|
|
|
|
+ private data:any;
|
|
|
|
|
|
start () {
|
|
|
// Your initialization goes here.
|
|
@@ -56,7 +62,93 @@ export class FenceItemRenderScript extends Component {
|
|
|
|
|
|
|
|
|
UpdateItemRender(data:any):void{
|
|
|
+ this.data=data;
|
|
|
+ let config:any=GameConfigManager.GetFenceConfig(data.id);
|
|
|
+ //图标
|
|
|
+ loader.loadRes(config.icon+"/spriteFrame",SpriteFrame,(err:Error,asset:SpriteFrame)=>{
|
|
|
+ if(err!=null){
|
|
|
+ console.log("加载图标出错:"+config.icon);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.icon.spriteFrame=asset;
|
|
|
+ })
|
|
|
+ //等级
|
|
|
+ this.hpLabel.string="HP:"+config.hp.toString();
|
|
|
+ //名称
|
|
|
+ this.nameLabel.string=config.name;
|
|
|
+ let price:number;
|
|
|
+
|
|
|
+ if(data.id<=GameModel.single.currentFenceId){
|
|
|
+ this.freeBuyButton.node.active=this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
|
|
|
+ }else{
|
|
|
+ //buyType 购买方式 0金币购买 1宝石购买 2看广告购买
|
|
|
+ if(data.buyType==0){//金币购买
|
|
|
+ this.freeBuyButton.node.active=this.diamondBuyButton.node.active=false;
|
|
|
+ this.GlodBuyButton.node.active=true;
|
|
|
+ price=config.buyConsume;
|
|
|
+ this.GlodBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
|
|
|
+ }else if(data.buyType==1){//宝石购买
|
|
|
+ this.freeBuyButton.node.active=this.GlodBuyButton.node.active=false;
|
|
|
+ this.diamondBuyButton.node.active=true;
|
|
|
+ price=config.buyConsume;
|
|
|
+ this.diamondBuyButtonLabel.string=StringUtils.numberUtilsEn(price);
|
|
|
+ }else{//广告购买
|
|
|
+ this.diamondBuyButton.node.active=this.GlodBuyButton.node.active=false;
|
|
|
+ this.freeBuyButton.node.active=true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 金币购买
|
|
|
+ */
|
|
|
+ GlodBuy():void{
|
|
|
+ if(this.BuyFence()){
|
|
|
+ NoticeManager.ShowPrompt("购买成功。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 钻石购买
|
|
|
+ */
|
|
|
+ DiamondBuy():void{
|
|
|
+ if(this.BuyFence()){
|
|
|
+ NoticeManager.ShowPrompt("购买成功。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 视频购买
|
|
|
+ */
|
|
|
+ VideoBuy():void{
|
|
|
+ PlatformManager.showRewardedVideo(()=>{
|
|
|
+ if(this.BuyFence()){
|
|
|
+ NoticeManager.ShowPrompt("购买成功。");
|
|
|
+ }
|
|
|
+ }, ()=>{
|
|
|
+ NoticeManager.ShowPrompt("购买失败。");
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ private BuyFence():boolean{
|
|
|
+ //金钱购买
|
|
|
+ if(this.data.buyType==0){
|
|
|
+ if(GameModel.single.gold<this.data.buyConsume){
|
|
|
+ NoticeManager.ShowPrompt("金币不足!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ GameModel.single.gold-=this.data.buyConsume;
|
|
|
+ }else if(this.data.buyType==1){//钻石购买
|
|
|
+ if(GameModel.single.diamond<this.data.buyConsume){
|
|
|
+ NoticeManager.ShowPrompt("钻石不足!");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ GameModel.single.diamond-=this.data.buyConsume;
|
|
|
+ }
|
|
|
+ GameModel.single.currentFenceId=this.data.id;
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
// update (deltaTime: number) {
|