Commit 28e608e7 authored by wildfirecode's avatar wildfirecode

Merge branch 'gifts' of gitlab2.dui88.com:clq/db-game-template into gifts

parents bca13172 d404a8fc
import { DataManager } from "../../tw/manager/DataManager";
import { NetManager } from "../../tw/manager/NetManager";
import { ModuleTypes } from "../../../libs/new_wx/types/sceneTypes";
import wait from "../../../libs/new_tc/wait";
import submitAfterDostart from "../../../libs/new_tw/ctrls/submitAfterDostart";
import PanelCtrl from "../../../libs/new_wx/ctrls/panelCtrl";
import Panel from "./Panel";
import centerAnchorOffset from "../views/centerAnchorOffset"
import showAlertPanel from "../../../libs/new_wx/ctrls/showAlertPanel";
import getCountTxt from "../../../libs/new_tw/datas/getCountTxt";
export default class SlotPanel extends Panel {
optionList: any;
......@@ -11,6 +17,7 @@ export default class SlotPanel extends Panel {
itemWidth: number;
speed: number;
prizeIndex: number;
countTxt: eui.Label;
start() {
this.optionList = []
this.itemList = []
......@@ -26,43 +33,50 @@ export default class SlotPanel extends Panel {
this.initSlot()
}
private async initSlot() {
this['slotStartBtn'] && this['slotStartBtn'].once(egret.TouchEvent.TOUCH_TAP, this.onTap_slotStart, this);
this.optionList = DataManager.ins.getOptionsData.optionList.filter(item => (item as any).scoreArea === '1,10')
this.drawMask()
this.renderSlotWrap()
this.updateCountTxt()
}
play() {
egret.startTick(this.onTick, this)
egret.startTick(this.onTick, this)
}
onTick() {
this.itemList.forEach(item => {
item.x -= this.speed
if (item.x < -300){
item.x = this.itemList[this.itemList.length-1].x + this.itemWidth
if (item.x < -300) {
item.x = this.itemList[this.itemList.length - 1].x + this.itemWidth
this.itemList.push(item)
this.itemList.shift()
}
})
this.conveyorList.forEach(item => {
item.x -= this.speed
if (item.x < -300){
item.x = this.conveyorList[this.conveyorList.length-1].x + item.width
if (item.x < -300) {
item.x = this.conveyorList[this.conveyorList.length - 1].x + item.width
this.conveyorList.push(item)
this.conveyorList.shift()
}
})
if((this.prizeIndex > -1) && this.itemList[this.prizeIndex].x < 385){
if ((this.prizeIndex > -1) && this.itemList[this.prizeIndex].x < 385) {
this.speed = 0
}
return false
}
onTap_slotStart() {
if (!this.check()) return;
// this.gameReset()
this.closeBtns.forEach(btn => btn.touchEnabled = false);
this['slotStartBtn'].touchEnabled = false;
this.calcSpeed(1, 20)
.then(() =>{
this.stop()
})
.then(() => {
this.stop()
})
}
calcSpeed(count, val) {
......@@ -74,7 +88,7 @@ export default class SlotPanel extends Panel {
setTimeout(() => {
calc()
}, 100)
}else {
} else {
resolve()
}
}
......@@ -84,12 +98,21 @@ export default class SlotPanel extends Panel {
}
stop() {
setTimeout(() => {
this.speed = 4
this.prizeIndex = this.optionList.findIndex(item => item.name === '场景1奖品B')
console.log(this.prizeIndex)
},2000)
submitAfterDostart((status, data) => {
let prizeName = data.lottery.name
wait(2000).then(() => {
this.speed = 4
this.prizeIndex = this.optionList.findIndex(item => item.name === prizeName)
console.log(this.prizeIndex)
wait(300).then(() => PanelCtrl.instance.show(ModuleTypes.PRIZE_PANEL));
wait(300).then(() => {
NetManager.ins.getInfo()
this.gameReset()
});
})
}, 10);
}
gameReset() {
this.speed = 1
this.prizeIndex = -1
......@@ -98,29 +121,30 @@ export default class SlotPanel extends Panel {
this.renderOptions(slotWrap)
this.renderConveyor(slotWrap)
}
private renderConveyor = async(container: any) => {
private renderConveyor = async (container: any) => {
let conveyor
await loadImageByUrl('conveyor_png').then((img: any) => {
conveyor = img
})
this.conveyorList = []
for(let i = 0; i < this.optionList.length; i++){
for (let i = 0; i < this.optionList.length; i++) {
let conveyorHash
conveyorHash = cloneImage(conveyor)
conveyorHash.y = 244
conveyorHash.x = 150 + conveyor.width * (i - 1)
this.conveyorList.push(conveyorHash)
}
this.conveyorList.forEach(element => { container.addChild(element)})
this.conveyorList.forEach(element => { container.addChild(element) })
}
private drawMask = () => {
var circle:egret.Shape = new egret.Shape();
var circle: egret.Shape = new egret.Shape();
circle.graphics.beginFill(0x0000ff);
circle.graphics.drawCircle(0,0,432/2);
circle.graphics.drawCircle(0, 0, 432 / 2);
circle.graphics.endFill();
circle.x = 159+432/2
circle.y = 367 +432/2
circle.x = 159 + 432 / 2
circle.y = 367 + 432 / 2
this.addChild(circle)
this.mask = circle
}
......@@ -134,7 +158,6 @@ export default class SlotPanel extends Panel {
this.addChild(slotWrap)
this.play()
slotWrap.mask = this.mask
this.addChild(this['slotWrapTop'])
}
......@@ -147,7 +170,7 @@ export default class SlotPanel extends Panel {
return loadImageByUrl(item.logo).then(image => {
gift = image
gift.x = x += this.itemWidth
gift.y = gift.height/2
gift.y = gift.height / 2
centerAnchorOffset(gift)
this.itemList.push(gift)
container.addChild(gift)
......@@ -156,10 +179,27 @@ export default class SlotPanel extends Panel {
}, Promise.resolve())
}
updateCountTxt() {
if (this.countTxt) {
this.countTxt.text = getCountTxt();
}
}
check() {
if (DataManager.ins.getInfoData.status.code == 2) {
showAlertPanel('对不起,您的积分不足。', null, 'lackOfMoney')
return false;
}
if (DataManager.ins.getInfoData.status.code == 3) {
showAlertPanel('对不起,参与次数已用完。', null, 'lackOfChance')
return false;
}
return true;
}
get skinKey() { return 'Slot' }
protected get closeBtns(): eui.Button[] {
this['slotStartBtn'] && this['slotStartBtn'].addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_slotStart, this);
return [this['slotClose']]
}
}
......
......@@ -18,7 +18,7 @@
},
{
"name": "preload",
"keys": "conveyor_png,slot_close_png,slot_start_btn_png,slot_wrap-bottom_png,slot_wrap-top_png"
"keys": "conveyor_png,slot_close_png,slot_start_btn_png,slot_wrap-bottom_png,slot_wrap-top_png,closeBtn2_png,hand2_png,treasurebg3_png,treasurebg22_png,conveyor2_png,slot_close2_png,slot_start_btn2_png,slot_wrap-bottom2_png,slot_wrap-top2_png"
}
],
"resources": [
......@@ -313,6 +313,51 @@
"name": "slot_wrap-top_png",
"type": "image",
"url": "assets/slot/slot_wrap-top.png"
},
{
"name": "closeBtn2_png",
"type": "image",
"url": "assets/startScene/closeBtn.png"
},
{
"name": "hand2_png",
"type": "image",
"url": "assets/treasure/hand.png"
},
{
"name": "treasurebg3_png",
"type": "image",
"url": "assets/treasure/treasurebg.png"
},
{
"name": "treasurebg22_png",
"type": "image",
"url": "assets/treasure/treasurebg2.png"
},
{
"name": "conveyor2_png",
"type": "image",
"url": "assets/slot/conveyor.png"
},
{
"name": "slot_close2_png",
"type": "image",
"url": "assets/slot/slot_close.png"
},
{
"name": "slot_start_btn2_png",
"type": "image",
"url": "assets/slot/slot_start_btn.png"
},
{
"name": "slot_wrap-bottom2_png",
"type": "image",
"url": "assets/slot/slot_wrap-bottom.png"
},
{
"name": "slot_wrap-top2_png",
"type": "image",
"url": "assets/slot/slot_wrap-top.png"
}
]
}
\ No newline at end of file
......@@ -17,4 +17,5 @@
</e:skinName>
</e:Button>
<e:Image id="slotWrapTop" x="159" y="367.06" source="slot_wrap-top_png" anchorOffsetX="0" anchorOffsetY="0"/>
<e:Label id="countTxt" text="1/1" width="100%" verticalAlign="middle" textAlign="center" left="0" y="1011"/>
</e:Skin>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment