123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504 |
- import { ui } from "../ui/layaMaxUI";
- import { ViewManager, ViewType } from "./ViewManager";
- import ShopItem from "../Tools/ShopItem";
- import GuangGao from "../Net/GuangGao";
- import { ArcherWorrior, ServerManager } from "../Net/ServerManager";
- import { AccountManager } from "../Net/AccountManager";
- import { WXSDK } from "../Net/WXSDK";
- import { AccountUser } from "../Net/PlayerData";
- import GamePool from "../Tools/GamePool";
- import { AssetManager } from "../Tools/AssetManager";
- import ResDic from "../Tools/ResDic";
- import { GameManager } from "../Game/GameManager";
- export enum SkinGetForType {
- Geted = 1,//已经拥有
- Bycoin = 2,//通过金币
- GetByVideo = 3,//通过视频
- GetByActivity = 4,//通过活动
- Using = -1,//使用中
- }
- export default class ShopView extends ui.SkinViewUI{
- private static ins:ShopView;
- constructor(){
- super();
- ShopView.ins = this;
- }
- public static get Instance():ShopView{
- if(ShopView.ins == null){
- console.log("new shopview");
- return new ShopView();
- }
- return ShopView.ins
- }
- //首次打开皮肤界面
- firstopen:boolean = true;
- equip_Cap:number;
- equip_Horse:number;
- showroleId:number = 0;
- private uiArr = [];
- private CharacterLightImage:Laya.Image;
- private HorseLightImage:Laya.Image;
- private GetByCoin:Laya.Box;
- private RequireCoinNum:Laya.Text;
- private GetByVideo:Laya.Box;
- private RequireVideoNum:Laya.Text;
- private GetByActive:Laya.Box;
- private Geted:Laya.Box;
- private Using:Laya.Text;
- private skinGetForType:SkinGetForType;
- public _data:any;
- //帽子数据源
- private CapArray = [];
- //马数据源
- private HorseArray = [];
- Show(){
- WXSDK.AldEvent("打开皮肤商店界面")
- let data = AccountManager.Instance.curplayerData.GainCollocation("theme");
- for (let i = 0; i < data.length; i++) {
- if(i<5){
- this.CapArray.push(data[i]);
- }
- else{
- this.HorseArray.push(data[i]);
- }
- }
- this.BackBtn.clickHandler =new Laya.Handler(this,this.ClickClose);
- this.CharacterBtn.clickHandler =new Laya.Handler(this,this.ClickCap);
- this.HorseBtn.clickHandler =new Laya.Handler(this,this.ClickHorse);
- this.GetBtn.clickHandler =new Laya.Handler(this,this.ClickGet);
- this.VideoGetCoinBtn.clickHandler = new Laya.Handler(this,this.VideoGet);
- this.CharacterLightImage = this.CharacterBtn.getChildByName("light") as Laya.Image;
- this.HorseLightImage = this.HorseBtn.getChildByName("light") as Laya.Image;
- this.GetByCoin = this.GetBtn.getChildByName("GetByCoin") as Laya.Box;
- this.RequireCoinNum = this.GetByCoin.getChildByName("CoinNum") as Laya.Text;
- this.GetByVideo = this.GetBtn.getChildByName("GetByVideo") as Laya.Box;
- this.RequireVideoNum = this.GetByVideo.getChildByName("VideoNum") as Laya.Text;
- this.GetByActive = this.GetBtn.getChildByName("GetByActive") as Laya.Box;
- this.Geted = this.GetBtn.getChildByName("Geted") as Laya.Box;
- this.Using = this.GetBtn.getChildByName("Using") as Laya.Text;
- this.uiArr.push(this.Using);
- this.uiArr.push(this.Geted);
- this.uiArr.push(this.GetByCoin);
- this.uiArr.push(this.GetByVideo);
- this.uiArr.push(this.GetByActive);
- this.equip_Horse = AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["2"];
- this.equip_Cap = AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["1"];
- this.showroleId = 1;
- this.ItemList.selectEnable = false;
- this.ItemList.vScrollBarSkin = "";
- this.ItemList.renderHandler = Laya.Handler.create(this, this.UpdateItem, null, false);
- this.ItemList.array = this.CapArray;
- this.ItemList.refresh();
- this.ShowButton(1);
- this.height = Laya.stage.height;
- Laya.stage.on(Laya.Event.RESIZE,this,()=>
- {
- this.height = Laya.stage.height;
- })
- }
- Close(){
- WXSDK.AldEvent("关闭皮肤商城界面");
- }
- ClickClose(){
- var equiphorseid = Number(AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["2"]);
- var equipcap = Number(AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["1"]);
- if(equipcap){
- if(equipcap != this.equip_Cap){
- GameManager.Instance.SetCap(equipcap);
- }
- }
- if(equiphorseid != this.equip_Horse){
- GameManager.Instance.SetHorse(equiphorseid);
- }
- ViewManager.Instance.ShowView(ViewType.MainView);
- }
- UpdateItem(cell: Laya.Box, index: number) {
- let item = cell.getComponent(ShopItem) as ShopItem;
- item.RefreshItem();
- }
- RefreshItem(){
- this.ItemList.refresh();
- }
- //点击帽子选项
- ClickCap(){
- this.firstopen = true;
- if(this.equip_Cap){
- this.showroleId = this.equip_Cap;
- }
- else{
- this.showroleId = 1;
- }
- this.ShowButton(1);
- this.CharacterLightImage.visible = true;
- this.HorseLightImage.visible = false;
- this.ItemList.vScrollBarSkin = "";
- this.ItemList.array = this.CapArray;
- this.ItemList.renderHandler = Laya.Handler.create(this,this.UpdateItem,null,false);
- }
- //点击马选项
- ClickHorse(){
- this.firstopen = true;
- this.showroleId = this.equip_Horse;
- this.ShowButton(2);
- this.CharacterLightImage.visible = false;
- this.HorseLightImage.visible = true;
- this.ItemList.vScrollBarSkin = "";
- this.ItemList.array = this.HorseArray;
- this.ItemList.renderHandler = Laya.Handler.create(this,this.UpdateItem,null,false);
- }
- RefreshButton(_skinGetForType: SkinGetForType) {
- this.skinGetForType = _skinGetForType;
- this.ShowUI(this.skinGetForType);
- }
- ShowButton(type:number){//1帽子 2.马
- if(type == 1){
- var equipcap = Number(AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["1"]);
- var usingId = equipcap;
-
- let item = this.CapArray[0].require_type;
- this._data = this.CapArray[0];
- var _id = this._data.id;
- var hasequip = AccountManager.Instance.curplayerData.HasEquip(_id);
- var require_type = item;
- if (usingId == _id ) {
- this.skinGetForType = SkinGetForType.Using;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (hasequip) {
- this.skinGetForType = SkinGetForType.Geted;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 2) {
- this.skinGetForType = SkinGetForType.Bycoin;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 4 ) {
- this.skinGetForType = SkinGetForType.GetByActivity;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 3) {
- this.skinGetForType = SkinGetForType.GetByVideo;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- // if(equipcap){
- // this.GetByCoin.visible = false;
- // this.GetByVideo.visible = false;
- // this.GetByActive.visible = false;
- // this.Geted.visible = false;
- // this.Using.visible = true;
- // }
- // else{
- // switch (item) {
- // case 2:
- // this.skinGetForType = SkinGetForType.Bycoin;
- // this.RefreshButton(this.skinGetForType);
- // break;
- // case 3:
- // this.skinGetForType = SkinGetForType.GetByVideo;
- // this.RefreshButton(this.skinGetForType);
- // break;
- // }
- // this.GetByCoin.visible = false;
- // this.GetByVideo.visible = false;
- // this.GetByActive.visible = false;
- // this.Geted.visible = false;
- // this.Using.visible = false;
- // }
- }
- else{
- var equiphorse = Number(AccountManager.Instance.curplayerData.GetUser(AccountUser.equip_themes)["2"]);
- var usingId = equiphorse;
-
- let item = this.HorseArray[0].require_type;
- this._data = this.HorseArray[0];
- var _id = this._data.id;
- var hasequip = AccountManager.Instance.curplayerData.HasEquip(_id);
- var require_type = item;
- if (usingId == _id ) {
- this.skinGetForType = SkinGetForType.Using;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (hasequip) {
- this.skinGetForType = SkinGetForType.Geted;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 2) {
- this.skinGetForType = SkinGetForType.Bycoin;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 4 ) {
- this.skinGetForType = SkinGetForType.GetByActivity;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- if (require_type == 3) {
- this.skinGetForType = SkinGetForType.GetByVideo;
- this.RefreshButton(this.skinGetForType);
- return;
- }
- }
- }
- //点击获得按钮
- ClickGet() {
- switch (this.skinGetForType) {
- case SkinGetForType.Bycoin:
- var money = Number(AccountManager.Instance.curplayerData.GainAccount("money"));
- if (money < Number(this._data.require_num)) {
- WXSDK.ShowTxt("金币不足--")
- }
- else {
- this.Buy();
- }
- console.log("金币--")
- break;
- case SkinGetForType.GetByActivity:
- WXSDK.ShowTxt("暂未开放!")
- console.log("活动获取--")
- break;
- case SkinGetForType.GetByVideo:
- console.log("视频获取--")
- this.VideoGet();
- break;
- case SkinGetForType.Geted:
- // console.log("已经拥有--")
- this.Use();
- break;
- }
- }
- ShowUI(_type: SkinGetForType) {
- console.log("所需类型--", _type);
- if(_type == SkinGetForType.Using){
- for (let index = 0; index < this.uiArr.length; index++) {
- if(index == 0){
- this.uiArr[index].visible = true;
- }
- else{
- this.uiArr[index].visible = false;
- }
- }
- return
- }
- this.Using.visible = false;
- for (let index = 1; index < this.uiArr.length; index++) {
- if (index == _type) {
- this.uiArr[index].visible = true;
- } else {
- this.uiArr[index].visible = false;
- }
- }
- // if(_type == SkinGetForType.Geted)return
- switch (_type) {
- case SkinGetForType.Bycoin:
- this.RequireCoinNum.text = this._data.require_num.toString();
- break;
- case SkinGetForType.GetByVideo:
- this.RequireVideoNum.text = AccountManager.Instance.curplayerData.GetProgress(this._data.id) + "/" + this._data.require_num.toString();
- break;
- }
- }
- //视频获取
- VideoGet() {
- GuangGao.Instance.loadVideo(isLoaded => {
- if (isLoaded) {
- GuangGao.Instance.showVideo(isOk => {
- if (isOk) {
- WXSDK.AldEvent("皮肤界面看视频得金币成功");
- var getkey = ArcherWorrior.vd;
- let param = [{ "reward_item": "1000" }, { "reward_num": "200" }, { "t": AccountManager.Instance.ServerTime.toString() }];
- ServerManager.Instance.SendHttp(getkey, param, Laya.Handler.create(this, this.VideoGetSuccess), Laya.Handler.create(this, this.VideoGetFail));
- }
- });
- }
- else {
- WXSDK.fengxiangtupian(isOk => {
- if (isOk) {
- WXSDK.AldEvent("皮肤界面看视频得金币成功");
- var getkey = ArcherWorrior.vd;
- let param = [{ "reward_item": "1000" }, { "reward_num": "200" }, { "t": AccountManager.Instance.ServerTime.toString() }];
- ServerManager.Instance.SendHttp(getkey, param, Laya.Handler.create(this, this.VideoGetSuccess), Laya.Handler.create(this, this.VideoGetFail));
- }
- });
- }
- })
- }
- //视频获取成功
- VideoGetSuccess(_data) {
- this.RefreshItem();
- console.log("LookVideo->suc:" + JSON.stringify(_data));
- }
- //视频获取失败
- VideoGetFail(_data) {
- console.log("LookVideo->fail:" + JSON.stringify(_data));
- }
- //使用装备
- Use() {
- var agrs = [{ "id": this._data.id }];
- ServerManager.Instance.SendHttp(ArcherWorrior.WearEquip, agrs, Laya.Handler.create(this, this.UseSuccess), Laya.Handler.create(this, this.UseFail));
- }
- //使用成功
- UseSuccess(data) {
- this.RefreshItem();
- // this.ShowButton();
- this.RefreshButton(SkinGetForType.Using);
- WXSDK.ShowTxt("装备成功!");
- console.log("装备suc:" + JSON.stringify(data));
- }
- //使用失败
- UseFail(data) {
- console.log(data);
- // console.log("装备err:" + JSON.stringify(data));
- }
- //购买
- Buy() {
- var agrs = [{ "id": this._data.id.toString() }];
- // var agrs = [{ "id": this._data.id }];
- ServerManager.Instance.SendHttp(ArcherWorrior.BuyEquip, agrs, Laya.Handler.create(this, this.BuySuccess), Laya.Handler.create(this, this.BuyFail));
- }
- //购买成功
- BuySuccess(data) {
- WXSDK.AldEvent("购买"+this._data.name+"成功");
- this.RefreshItem();
- this.RefreshButton(SkinGetForType.Using);
- // this.ShowUI(SkinGetForType.Geted);
- console.log("购买suc:" + JSON.stringify(data));
- }
- //购买失败
- BuyFail(data) {
- console.log("购买fail:" + JSON.stringify(data));
- // this.instance.RefreshItem();
- }
- }
- // 展示人物皮肤界面scene类
- export class ShopScene {
- private static ins: ShopScene;
- constructor() { ShopScene.ins = this; }
- public static get Instance(): ShopScene {
- if (ShopScene.ins) {
- return ShopScene.ins;
- }
- else {
- return new ShopScene();
- }
- }
- public first: boolean = true;
- public _shopscene: Laya.Scene3D;
- public _player: Laya.Sprite3D;
- public _motor: Laya.Sprite3D;
- public _camera: Laya.Camera;
- public _position: Laya.Vector3;
- public _sprite: Laya.Sprite3D;
- public _motorsprite: Laya.Sprite3D;
- public motordic: ResDic = new ResDic();
- public playernode: Laya.Sprite3D;
- public motornode: Laya.Sprite3D;
- public CreateMoto(_motorindex: number, _image?: Laya.Image,trial = null) {//type1:moto
- if (!this._shopscene || this._shopscene.destroyed || this._shopscene == null) {
- this.first = true;
- this._shopscene = new Laya.Scene3D();
- this._camera = new Laya.Camera();
- if(trial){
- this._camera.transform.position = new Laya.Vector3(0, 0.7, 3);
- this._camera.clearFlag = 2;
- this._camera.fieldOfView = 40;
- }
- else{
- this._camera.transform.position = new Laya.Vector3(0, 0.6, 3.5);
- this._camera.clearFlag = 2;
- this._camera.fieldOfView = 30;
- }
- this._shopscene.addChild(this._camera);
- let _light = new Laya.DirectionLight();
- _light.intensity = 0.5;
- this._shopscene.addChild(_light);
- //拿到玩家空节点
- var player = GamePool.Instance.GetModel(AssetManager.Instance.Horse.get(_motorindex), "");
- // this._sprite =Laya.Sprite3D.instantiate(player);
- this._shopscene.addChild(player);
- _image.addChild(this._shopscene);
- player.transform.position = new Laya.Vector3(0, 0, -2);
- this._position = new Laya.Vector3(0, 0.01, 0);
- }
- if (_image) {
- this._camera.viewport = new Laya.Viewport(_image.x, _image.y, _image.width, _image.height);
- }
- if (this._motor) {
- this._motor.active = false;
- this._motor.removeSelf();
- this._motor = null;
- }
- // var go;
- // if (this.motordic.has(_motorindex)) {
- // go = this.motordic.get(_motorindex);
- // go.active = true;
- // } else {
- // //////需更改
- // var motormodel = GamePools.Instance.GetModel(AssetManager.Instance.Motor.get(_motorindex), "");
- // motormodel.transform.position = new Laya.Vector3(0, 0, 0);
- // var jiasu = motormodel.getChildAt(0). getChildByName("putongjiasu") as Laya.Sprite3D;
- // var chaojijiasu = motormodel.getChildAt(0).getChildByName("chaojijiasu") as Laya.Sprite3D;
- // var suduxian = motormodel.getChildAt(0).getChildByName("speedline") as Laya.Sprite3D;
- // jiasu.active = false;
- // chaojijiasu.active = false;
- // suduxian.active = false;
- // go = Sprite3D.instantiate(motormodel);
- // this.motordic.set(_motorindex, go);
- // }
- // this._motor = go
- // if (this._motor) {
- // this.motornode.addChild(this._motor);
- // }
- if (!this.first) return;
- this.first = false;
- Laya.timer.frameLoop(1, this, this.Rotation,[player]);
- }
- Rotation(model:Laya.Sprite3D) {
- // if (!this._sprite) return;
- // if(this._sprite.destroyed)return;
- model.transform.rotate(this._position);
- }
- CloseShop() {
- Laya.timer.clear(this, this.Rotation);
- if (this._motor) {
- this._motor.active = false;
- this._motor.removeSelf();
- }
- if (this._player) {
- this._player.active = false;
- this._player.removeSelf();
- }
- if (this._shopscene) {
- this._shopscene.destroy(true);
- }
- this._shopscene = null;
- this._motor = null;
- this._sprite = null;
- this._player = null;
- this.first = true;
- }
- }
|