Commit 40e3d7f0 authored by Tt's avatar Tt

代码整理

parent b7893774
...@@ -79,18 +79,24 @@ ...@@ -79,18 +79,24 @@
}, },
{ {
"__id__": 14 "__id__": 14
},
{
"__id__": 24
},
{
"__id__": 26
} }
], ],
"_active": true, "_active": true,
"_components": [ "_components": [
{ {
"__id__": 24 "__id__": 33
}, },
{ {
"__id__": 25 "__id__": 34
}, },
{ {
"__id__": 26 "__id__": 35
} }
], ],
"_prefab": null, "_prefab": null,
...@@ -1254,6 +1260,395 @@ ...@@ -1254,6 +1260,395 @@
"preload": false, "preload": false,
"_id": "dey05oKrBIspvsDa6pOIQz" "_id": "dey05oKrBIspvsDa6pOIQz"
}, },
{
"__type__": "cc.Node",
"_name": "item",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 25
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 131.33,
"height": 65.2
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0,
"y": 1
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-102.2,
105.16,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "9bVeK7KRtLiYjbABJie3Gd"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 24
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_srcBlendFactor": 770,
"_dstBlendFactor": 771,
"_string": "ScrollView content\n\n",
"_N$string": "ScrollView content\n\n",
"_fontSize": 16,
"_lineHeight": 20,
"_enableWrapText": true,
"_N$file": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_batchAsBitmap": false,
"_styleFlags": 0,
"_underlineHeight": 0,
"_N$horizontalAlign": 1,
"_N$verticalAlign": 0,
"_N$fontFamily": "Arial",
"_N$overflow": 0,
"_N$cacheMode": 0,
"_id": "bd/vtfl55Jfp7eWEIALhvU"
},
{
"__type__": "cc.Node",
"_name": "scroll",
"_objFlags": 0,
"_parent": {
"__id__": 2
},
"_children": [
{
"__id__": 27
}
],
"_active": true,
"_components": [
{
"__id__": 31
},
{
"__id__": 32
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 240,
"height": 250
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
-390.749,
37.766,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "60RCz+Mn1Pl53s0U1oPyQM"
},
{
"__type__": "cc.Node",
"_name": "view",
"_objFlags": 0,
"_parent": {
"__id__": 26
},
"_children": [
{
"__id__": 28
}
],
"_active": true,
"_components": [
{
"__id__": 30
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 240,
"height": 250
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
0,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "derP1zk0lAd4P8mbkHMXvI"
},
{
"__type__": "cc.Node",
"_name": "content",
"_objFlags": 0,
"_parent": {
"__id__": 27
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 29
}
],
"_prefab": null,
"_opacity": 255,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_contentSize": {
"__type__": "cc.Size",
"width": 220,
"height": 400
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 1
},
"_trs": {
"__type__": "TypedArray",
"ctor": "Float64Array",
"array": [
0,
115.30999755859375,
0,
0,
0,
0,
1,
1,
1,
1
]
},
"_eulerAngles": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_skewX": 0,
"_skewY": 0,
"_is3DNode": false,
"_groupIndex": 0,
"groupIndex": 0,
"_id": "33FgO69m5Dz6H919wtIPIQ"
},
{
"__type__": "cc.Layout",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 28
},
"_enabled": true,
"_layoutSize": {
"__type__": "cc.Size",
"width": 300,
"height": 200
},
"_resize": 1,
"_N$layoutType": 2,
"_N$cellSize": {
"__type__": "cc.Size",
"width": 40,
"height": 40
},
"_N$startAxis": 0,
"_N$paddingLeft": 0,
"_N$paddingRight": 0,
"_N$paddingTop": 0,
"_N$paddingBottom": 0,
"_N$spacingX": 0,
"_N$spacingY": 0,
"_N$verticalDirection": 1,
"_N$horizontalDirection": 0,
"_N$affectedByScale": false,
"_id": "3chvDjaZdOwY3IDRGTebIh"
},
{
"__type__": "cc.Mask",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 27
},
"_enabled": true,
"_materials": [
{
"__uuid__": "eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432"
}
],
"_spriteFrame": null,
"_type": 0,
"_segments": 64,
"_N$alphaThreshold": 0,
"_N$inverted": false,
"_id": "694YKsN2BJQqVjV4pBrSdO"
},
{
"__type__": "cc.ScrollView",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 26
},
"_enabled": true,
"horizontal": false,
"vertical": true,
"inertia": true,
"brake": 0.75,
"elastic": true,
"bounceDuration": 0.23,
"scrollEvents": [],
"cancelInnerEvents": true,
"_N$content": {
"__id__": 28
},
"content": {
"__id__": 28
},
"_N$horizontalScrollBar": null,
"_N$verticalScrollBar": null,
"_id": "92xjV09xlI9aWoOLobZjP8"
},
{
"__type__": "8db05zjxQdJ84wfJbBeDash",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 26
},
"_enabled": true,
"item": {
"__id__": 24
},
"items": [],
"list": [],
"updateItem": null,
"target": {},
"addNum": 1,
"selector": {},
"_id": "7f/tl7SzpGPLUMPbL0tAVw"
},
{ {
"__type__": "cc.Canvas", "__type__": "cc.Canvas",
"_name": "", "_name": "",
......
import { asyncDelay, onHomeworkFinish } from "../script/util"; import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { Shop, Item } from "./shop";
import pg from "./pg";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -29,16 +31,34 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -29,16 +31,34 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
_cantouch = null; _cantouch = null;
private _shop: Shop;
initData() { initData() {
// 所有全局变量 默认都是null // 所有全局变量 默认都是null
this._cantouch = true; this._cantouch = true;
this._shop = new Shop();
// this._shop.list[0]
} }
initView() { initView() {
this.initBg(); this.initBg();
this.initPic(); // this.initPic();
this.initBtn(); // this.initBtn();
this.initIcon(); // this.initIcon();
let scroll = pg.view.find(this, "scroll");
let svt = scroll.getComponent("svt");
// svt.items =
svt.list = [1, 2, 3, 4, 5, 6, 76, 7];
svt.updateItem = this.updateItem;
svt.target = this;
svt.addNum = 1;
svt.flush();
}
updateItem(items, datas) {
console.log(items);
console.log(datas);
} }
initBg() { initBg() {
...@@ -46,138 +66,6 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -46,138 +66,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
bgNode.scale = this._mapScaleMax; bgNode.scale = this._mapScaleMax;
} }
pic1 = null;
pic2 = null;
initPic() {
const canvas = cc.find('Canvas');
const maxW = canvas.width * 0.7;
this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
const picNode1 = sprNode;
picNode1.scale = maxW / picNode1.width;
picNode1.baseX = picNode1.x;
canvas.addChild(picNode1);
this.pic1 = picNode1;
const labelNode = new cc.Node();
labelNode.color = cc.Color.YELLOW;
const label = labelNode.addComponent(cc.Label);
label.string = this.data.text;
label.fontSize = 60;
label.lineHeight = 60;
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
picNode1.addChild(labelNode);
});
this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
const picNode2 = sprNode;
picNode2.scale = maxW / picNode2.width;
canvas.addChild(picNode2);
picNode2.x = canvas.width;
picNode2.baseX = picNode2.x;
this.pic2 = picNode2;
const labelNode = new cc.Node();
const label = labelNode.addComponent(cc.RichText);
const size = 60
label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
label.lineHeight = size;
picNode2.addChild(labelNode);
});
}
initIcon() {
const iconNode = this.getSprNode('icon');
iconNode.zIndex = 5;
iconNode.anchorX = 1;
iconNode.anchorY = 1;
iconNode.parent = cc.find('Canvas');
iconNode.x = iconNode.parent.width / 2 - 10;
iconNode.y = iconNode.parent.height / 2 - 10;
iconNode.on(cc.Node.EventType.TOUCH_START, () => {
this.playAudioByUrl(this.data.audio_url);
})
}
curPage = null;
initBtn() {
this.curPage = 0;
const bottomPart = cc.find('Canvas/bottomPart');
bottomPart.zIndex = 5; // 提高层级
bottomPart.x = bottomPart.parent.width / 2;
bottomPart.y = -bottomPart.parent.height / 2;
const leftBtnNode = bottomPart.getChildByName('btn_left');
//节点中添加了button组件 则可以添加click事件监听
leftBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 0) {
return;
}
this.curPage = 0
this.leftMove();
this.playLocalAudio('btn');
})
const rightBtnNode = bottomPart.getChildByName('btn_right');
//节点中添加了button组件 则可以添加click事件监听
rightBtnNode.on('click', () => {
if (!this._cantouch) {
return;
}
if (this.curPage == 1) {
return;
}
this.curPage = 1
this.rightMove();
// 游戏结束时需要调用这个方法通知系统作业完成
onHomeworkFinish();
this.playLocalAudio('btn');
})
}
leftMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
rightMove() {
this._cantouch = false;
const len = this.pic1.parent.width;
cc.tween(this.pic1)
.to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
.start();
cc.tween(this.pic2)
.to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
.call(() => {
this._cantouch = true;
})
.start();
}
// update (dt) {},
initListener() { initListener() {
...@@ -192,4 +80,139 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -192,4 +80,139 @@ export default class SceneComponent extends MyCocosSceneComponent {
}); });
}) })
} }
// pic1 = null;
// pic2 = null;
// initPic() {
// const canvas = cc.find('Canvas');
// const maxW = canvas.width * 0.7;
// this.getSprNodeByUrl(this.data.pic_url, (sprNode) => {
// const picNode1 = sprNode;
// picNode1.scale = maxW / picNode1.width;
// picNode1.baseX = picNode1.x;
// canvas.addChild(picNode1);
// this.pic1 = picNode1;
// const labelNode = new cc.Node();
// labelNode.color = cc.Color.YELLOW;
// const label = labelNode.addComponent(cc.Label);
// label.string = this.data.text;
// label.fontSize = 60;
// label.lineHeight = 60;
// label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent('cc.Label').font;
// picNode1.addChild(labelNode);
// });
// this.getSprNodeByUrl(this.data.pic_url_2, (sprNode) => {
// const picNode2 = sprNode;
// picNode2.scale = maxW / picNode2.width;
// canvas.addChild(picNode2);
// picNode2.x = canvas.width;
// picNode2.baseX = picNode2.x;
// this.pic2 = picNode2;
// const labelNode = new cc.Node();
// const label = labelNode.addComponent(cc.RichText);
// const size = 60
// label.font = cc.find('Canvas/res/font/BRLNSDB').getComponent(cc.Label).font;
// label.string = `<outline color=#751e00 width=4><size=${size}><color=#ffffff>${this.data.text}</color></size></outline>`
// label.lineHeight = size;
// picNode2.addChild(labelNode);
// });
// }
// initIcon() {
// const iconNode = this.getSprNode('icon');
// iconNode.zIndex = 5;
// iconNode.anchorX = 1;
// iconNode.anchorY = 1;
// iconNode.parent = cc.find('Canvas');
// iconNode.x = iconNode.parent.width / 2 - 10;
// iconNode.y = iconNode.parent.height / 2 - 10;
// iconNode.on(cc.Node.EventType.TOUCH_START, () => {
// this.playAudioByUrl(this.data.audio_url);
// })
// }
// curPage = null;
// initBtn() {
// this.curPage = 0;
// const bottomPart = cc.find('Canvas/bottomPart');
// bottomPart.zIndex = 5; // 提高层级
// bottomPart.x = bottomPart.parent.width / 2;
// bottomPart.y = -bottomPart.parent.height / 2;
// const leftBtnNode = bottomPart.getChildByName('btn_left');
// //节点中添加了button组件 则可以添加click事件监听
// leftBtnNode.on('click', () => {
// if (!this._cantouch) {
// return;
// }
// if (this.curPage == 0) {
// return;
// }
// this.curPage = 0
// this.leftMove();
// this.playLocalAudio('btn');
// })
// const rightBtnNode = bottomPart.getChildByName('btn_right');
// //节点中添加了button组件 则可以添加click事件监听
// rightBtnNode.on('click', () => {
// if (!this._cantouch) {
// return;
// }
// if (this.curPage == 1) {
// return;
// }
// this.curPage = 1
// this.rightMove();
// // 游戏结束时需要调用这个方法通知系统作业完成
// onHomeworkFinish();
// this.playLocalAudio('btn');
// })
// }
// leftMove() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// cc.tween(this.pic1)
// .to(1, { x: this.pic1.baseX }, { easing: 'cubicInOut' })
// .start();
// cc.tween(this.pic2)
// .to(1, { x: this.pic2.baseX }, { easing: 'cubicInOut' })
// .call(() => {
// this._cantouch = true;
// })
// .start();
// }
// rightMove() {
// this._cantouch = false;
// const len = this.pic1.parent.width;
// cc.tween(this.pic1)
// .to(1, { x: this.pic1.baseX - len }, { easing: 'cubicInOut' })
// .start();
// cc.tween(this.pic2)
// .to(1, { x: this.pic2.baseX - len }, { easing: 'cubicInOut' })
// .call(() => {
// this._cantouch = true;
// })
// .start();
// }
// update (dt) {},
} }
class Item {
public type: number;//商品类型
public name: string;//商品名称
public icon: string;//商品图片--可用type生成
public growthValue: number;//生长值
public cost: number;//费用
public discount: number;//折扣
constructor(obj: any) {
this.type = obj.type;
this.name = obj.name;
this.icon = obj.icon;
this.growthValue = obj.growthValue;
this.cost = obj.cost;
this.discount = obj.discount;
}
}
class Shop {
public _list: Array<Item>
constructor() {
this._list = [];
}
parse(list: any) {
if (!list) return;
this._list = list.map(li => {
return new Item(li);
})
}
get list() {
return this._list;
}
}
export { Shop, Item };
{
"ver": "1.0.8",
"uuid": "7696c029-a1e7-49e2-887c-fd3791e8ded1",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
item: cc.Node = null;
@property
items: any = null;
@property
list: Array<any> = [];
@property
updateItem: any = null;
@property
target: any = null;
@property
addNum: number = 1;
@property
selector: any = null;
flush() {
//执行一次更新
this._updateScrollView();
}
onLoad() {
}
_updateScrollView() {
//如果有性能压力改成 顺序加载,并且在关闭的时候能自动检测停止加载
//在界面下方的所有节点自动的显示效果是隐藏效果。
let view = this.node.getChildByName("view");
let content = view.getChildByName("content");
//后面改成动态判断内部节点的方式而不是暴力移除
content.removeAllChildren();
let addNum = this.addNum || 1;
let list = this.list;
let items = this.items;
if (!items || items.length == 0) items = [this.item];
for (let i = 0; i < list.length; i += addNum) {
let datas = [list[i]];
for (let m = 1; m < addNum; m++) {
datas.push(list[i + m]);
}
let item = this._selectorCall(items, datas);
let itemClone = cc.instantiate(item);
itemClone.x = 0;
itemClone.y = 0;
content.addChild(itemClone);
itemClone.active = true;
this._updateItemCall(itemClone, datas);
}
}
_updateItemCall(itemClone, datas) {
this.updateItem && this.updateItem.call(this.target, itemClone, datas);
}
_selectorCall(items, datas) {
return items[0];
if (!this.selector) return items[0];
return this.selector(items, datas);
}
}
{
"ver": "1.0.8",
"uuid": "8db05ce3-c507-49f3-8c1f-25b05e0dab21",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
"experimentalDecorators": true, "experimentalDecorators": true,
"skipLibCheck": true, "skipLibCheck": true,
"outDir": "temp/vscode-dist", "outDir": "temp/vscode-dist",
"allowJs": true,
"forceConsistentCasingInFileNames": true "forceConsistentCasingInFileNames": true
}, },
"exclude": [ "exclude": [
......
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