123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510 |
- var ShopLayer = cc.Layer.extend({
- sprite: null,
- ctor: function () {
- var self = this;
- self._super();
- self.y = winSize.height;
- var STOP_PRICE = 30;
- var SINGLE_PRICE = 10;
- var SAME_PRICE = 50;
-
- var scoreArea = ccui.Layout.create();
- scoreArea.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- scoreArea.setBackGroundColor(cc.color(111, 168, 233));
- scoreArea.setSize(cc.size(494, 150));
- scoreArea.x = 72;
- scoreArea.y = -194;
- self.addChild(scoreArea);
- var yourScoreLabel = ccui.Text.create();
- yourScoreLabel.attr({
- anchorX: 0,
- color: cc.color(255, 255, 255),
- fontSize: 38,
- x: 20,
- y: 114,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: Localize[lang]['yourScore'] + ':'
- });
- scoreArea.addChild(yourScoreLabel);
- var yourScore = ccui.Text.create();
- yourScore.attr({
- color: cc.color(255, 210, 0),
- fontSize: 58,
- x: 250,
- y: 50,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: totalScore
- });
- scoreArea.addChild(yourScore);
- var line = ccui.Layout.create();
- line.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- line.setBackGroundColor(cc.color(208, 208, 208));
- line.setContentSize(cc.size(496, 2));
- line.attr({
- x: 72,
- y: -221
- });
- self.addChild(line);
- var showPopup = function (tool) {
- curTool = tool;
- alpha.enabled = alpha.visible = buyPopup.enabled = buyPopup.visible = true;
- amountText.string = 1;
- };
- var closePopup = function () {
- alpha.enabled = alpha.visible = buyPopup.enabled = buyPopup.visible = false;
- };
- var curTool;
- // stop
- var stopArea = ccui.Layout.create();
- stopArea.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- stopArea.setBackGroundColor(cc.color(255, 255, 255));
- stopArea.setSize(cc.size(494, 150));
- stopArea.x = 72;
- stopArea.y = -384;
- self.addChild(stopArea);
- var stopIcon = ccui.ImageView.create();
- stopIcon.loadTexture(res.stop, texType);
- stopIcon.attr({
- x: 35,
- y: 110
- });
- stopArea.addChild(stopIcon);
- var stopCount = ccui.Text.create();
- stopCount.attr({
- color: cc.color(0, 0, 0),
- fontSize: 32,
- x: 35,
- y: 30,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: stopLeft
- });
- stopArea.addChild(stopCount);
- var stopText = ccui.Text.create();
- stopText.attr({
- anchorX: 0,
- anchorY: 1,
- color: cc.color(150, 150, 150),
- fontSize: 22,
- x: 80,
- y: 138,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
- string: Localize[lang]['stop']
- });
- stopText.setTextAreaSize(cc.size(400, 70));
- stopArea.addChild(stopText);
- var stopBuyBtn = ccui.Button.create();
- stopBuyBtn.setScale9Enabled(true);
- stopBuyBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- stopBuyBtn.loadTextures(res.btn4, res.btn4, null, texType);
- stopBuyBtn.setContentSize(cc.size(150, 50));
- stopBuyBtn.setPressedActionEnabled(true);
- stopBuyBtn.attr({
- x: 412,
- y: 31
- });
- stopBuyBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- showPopup('stop');
- }
- }, stopArea);
- stopArea.addChild(stopBuyBtn);
- var stopBuyText = ccui.Text.create();
- stopBuyText.attr({
- color: cc.color(255, 255, 255),
- fontSize: 22,
- x: 76,
- y: 36,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: Localize[lang]['buy']
- });
- stopBuyBtn.addChild(stopBuyText);
- var stopPrice = ccui.Text.create();
- stopPrice.attr({
- color: cc.color(255, 210, 0),
- fontSize: 18,
- x: 76,
- y: 12,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: STOP_PRICE
- });
- stopBuyBtn.addChild(stopPrice);
- // single
- var singleArea = ccui.Layout.create();
- singleArea.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- singleArea.setBackGroundColor(cc.color(255, 255, 255));
- singleArea.setSize(cc.size(494, 150));
- singleArea.x = 72;
- singleArea.y = -556;
- self.addChild(singleArea);
- var singleIcon = ccui.ImageView.create();
- singleIcon.loadTexture(res.single, texType);
- singleIcon.attr({
- x: 35,
- y: 110
- });
- singleArea.addChild(singleIcon);
- var singleCount = ccui.Text.create();
- singleCount.attr({
- color: cc.color(0, 0, 0),
- fontSize: 32,
- x: 35,
- y: 30,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: singleLeft
- });
- singleArea.addChild(singleCount);
- var singleText = ccui.Text.create();
- singleText.attr({
- anchorX: 0,
- anchorY: 1,
- color: cc.color(150, 150, 150),
- fontSize: 22,
- x: 80,
- y: 138,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
- string: Localize[lang]['single1']
- });
- singleText.setTextAreaSize(cc.size(400, 70));
- singleArea.addChild(singleText);
- var singleBuyBtn = ccui.Button.create();
- singleBuyBtn.setScale9Enabled(true);
- singleBuyBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- singleBuyBtn.loadTextures(res.btn4, res.btn4, null, texType);
- singleBuyBtn.setContentSize(cc.size(150, 50));
- singleBuyBtn.setPressedActionEnabled(true);
- singleBuyBtn.attr({
- x: 412,
- y: 31
- });
- singleBuyBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- showPopup('single');
- }
- }, singleArea);
- singleArea.addChild(singleBuyBtn);
- var singleBuyText = ccui.Text.create();
- singleBuyText.attr({
- color: cc.color(255, 255, 255),
- fontSize: 22,
- x: 76,
- y: 36,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: Localize[lang]['buy']
- });
- singleBuyBtn.addChild(singleBuyText);
- var singlePrice = ccui.Text.create();
- singlePrice.attr({
- color: cc.color(255, 210, 0),
- fontSize: 18,
- x: 76,
- y: 12,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: SINGLE_PRICE
- });
- singleBuyBtn.addChild(singlePrice);
- // same
- var sameArea = ccui.Layout.create();
- sameArea.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- sameArea.setBackGroundColor(cc.color(255, 255, 255));
- sameArea.setSize(cc.size(494, 150));
- sameArea.x = 72;
- sameArea.y = -726;
- self.addChild(sameArea);
- var sameIcon = ccui.ImageView.create();
- sameIcon.loadTexture(res.same, texType);
- sameIcon.attr({
- x: 35,
- y: 110
- });
- sameArea.addChild(sameIcon);
- var sameCount = ccui.Text.create();
- sameCount.attr({
- color: cc.color(0, 0, 0),
- fontSize: 32,
- x: 35,
- y: 30,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: sameLeft
- });
- sameArea.addChild(sameCount);
- var sameText = ccui.Text.create();
- sameText.attr({
- anchorX: 0,
- anchorY: 1,
- color: cc.color(150, 150, 150),
- fontSize: 22,
- x: 80,
- y: 138,
- textAlign: cc.TEXT_ALIGNMENT_LEFT,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_TOP,
- string: Localize[lang]['same']
- });
- sameText.setTextAreaSize(cc.size(400, 70));
- sameArea.addChild(sameText);
- var sameBuyBtn = ccui.Button.create();
- sameBuyBtn.setScale9Enabled(true);
- sameBuyBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- sameBuyBtn.loadTextures(res.btn4, res.btn4, null, texType);
- sameBuyBtn.setContentSize(cc.size(150, 50));
- sameBuyBtn.setPressedActionEnabled(true);
- sameBuyBtn.attr({
- x: 412,
- y: 31
- });
- sameBuyBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- showPopup('same');
- }
- }, sameArea);
- sameArea.addChild(sameBuyBtn);
- var sameBuyText = ccui.Text.create();
- sameBuyText.attr({
- color: cc.color(255, 255, 255),
- fontSize: 22,
- x: 76,
- y: 36,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: Localize[lang]['buy']
- });
- sameBuyBtn.addChild(sameBuyText);
- var samePrice = ccui.Text.create();
- samePrice.attr({
- color: cc.color(255, 210, 0),
- fontSize: 18,
- x: 76,
- y: 12,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: SAME_PRICE
- });
- sameBuyBtn.addChild(samePrice);
- var checkScore = function () {
- stopBuyBtn.setTouchEnabled(totalScore >= STOP_PRICE);
- singleBuyBtn.setTouchEnabled(totalScore >= SINGLE_PRICE);
- sameBuyBtn.setTouchEnabled(totalScore >= SAME_PRICE);
- };
- checkScore();
- var alpha = ccui.Layout.create();
- alpha.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- alpha.setBackGroundColor(cc.color(0, 0, 0));
- alpha.setBackGroundColorOpacity(128);
- alpha.setSize(winSize);
- alpha.attr({
- y: -winSize.height,
- zIndex: 100,
- touchEnabled: true,
- enabled: false,
- visible: false
- });
- self.addChild(alpha);
- var buyPopup = ccui.Layout.create();
- buyPopup.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- buyPopup.setBackGroundColor(cc.color(246, 246, 246));
- buyPopup.setSize(cc.size(462, 270));
- buyPopup.attr({
- x: winSize.width / 2 - 231,
- y: -winSize.height / 2 - 135,
- zIndex: 101
- });
- self.addChild(buyPopup);
- var minusBtn = ccui.Button.create();
- minusBtn.loadTextures(res.minus, res.minus, null, texType);
- minusBtn.setPressedActionEnabled(true);
- minusBtn.attr({
- x: 102,
- y: 180
- });
- minusBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- if (amountText.string > 1) {
- amountText.string = (amountText.string >> 0) - 1;
- }
- }
- }, buyPopup);
- buyPopup.addChild(minusBtn);
- var amountBg = ccui.Layout.create();
- amountBg.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID);
- amountBg.setBackGroundColor(cc.color(255, 255, 255));
- amountBg.setSize(cc.size(150, 70));
- amountBg.attr({
- x: 151,
- y: 145
- });
- buyPopup.addChild(amountBg);
- var amountText = ccui.Text.create();
- amountText.attr({
- color: cc.color(144, 144, 144),
- fontSize: 38,
- x: 224,
- y: 178,
- textAlign: cc.TEXT_ALIGNMENT_CENTER,
- verticalAlign: cc.VERTICAL_TEXT_ALIGNMENT_CENTER,
- string: 1
- });
- buyPopup.addChild(amountText);
- var addBtn = ccui.Button.create();
- addBtn.loadTextures(res.add, res.add, null, texType);
- addBtn.setPressedActionEnabled(true);
- addBtn.attr({
- x: 353,
- y: 180
- });
- addBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- var price;
- switch (curTool) {
- case 'stop':
- price = STOP_PRICE;
- break;
- case 'single':
- price = SINGLE_PRICE;
- break;
- case 'same':
- price = SAME_PRICE;
- break;
- }
- var amount = (amountText.string >> 0) + 1;
- if (totalScore >= price * amount) {
- amountText.string = amount;
- }
- }
- }, buyPopup);
- buyPopup.addChild(addBtn);
- var buyBtn = ccui.Button.create();
- buyBtn.setScale9Enabled(true);
- buyBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- buyBtn.loadTextures(res.btn4, res.btn4, null, texType);
- buyBtn.setContentSize(cc.size(260, 80));
- buyBtn.setTitleText(Localize[lang]['buy']);
- buyBtn.setTitleFontSize(38);
- buyBtn.setPressedActionEnabled(true);
- buyBtn.attr({
- x: 230,
- y: 68
- });
- buyBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- var price, amount = amountText.string >> 0;
- switch (curTool) {
- case 'stop':
- price = STOP_PRICE;
- stopLeft += amount;
- stopCount.string = stopLeft;
- break;
- case 'single':
- price = SINGLE_PRICE;
- singleLeft += amount;
- singleCount.string = singleLeft;
- break;
- case 'same':
- price = SAME_PRICE;
- sameLeft += amount;
- sameCount.string = sameLeft;
- break;
- }
- totalScore -= price * amount;
- yourScore.string = totalScore;
- checkScore();
- closePopup();
- }
- }, buyPopup);
- buyPopup.addChild(buyBtn);
- var closeBtn = ccui.Button.create();
- closeBtn.setScale9Enabled(true);
- closeBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- closeBtn.loadTextures(res.btn4, res.btn4, null, texType);
- closeBtn.setContentSize(cc.size(40, 40));
- closeBtn.setTitleText('X');
- closeBtn.setTitleFontSize(20);
- closeBtn.setPressedActionEnabled(true);
- closeBtn.attr({
- x: 440,
- y: 248
- });
- closeBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- closePopup();
- }
- }, buyPopup);
- buyPopup.addChild(closeBtn);
- buyPopup.enabled = buyPopup.visible = false;
- var startBtn = ccui.Button.create();
- startBtn.setScale9Enabled(true);
- startBtn.setCapInsets(cc.rect(1, 1, 1, 1));
- startBtn.loadTextures(res.btn4, res.btn4, null, texType);
- startBtn.setContentSize(cc.size(288, 70));
- startBtn.setTitleText(Localize[lang]['start']);
- startBtn.setTitleFontSize(40);
- startBtn.setPressedActionEnabled(true);
- startBtn.attr({
- x: winSize.width / 2,
- y: -773
- });
- startBtn.addTouchEventListener(function (sender, type) {
- if (type == ccui.Widget.TOUCH_ENDED) {
- director.runScene(new LevelScene());
- }
- }, self);
- self.addChild(startBtn);
- return true;
- }
- });
- var ShopScene = cc.Scene.extend({
- onEnter: function () {
- this._super();
- var layer = new ShopLayer();
- this.addChild(layer);
- }
- });
|