Commit c31b11a3 authored by Tt's avatar Tt

处理数据

parent 93babd5f
import { asyncDelay, onHomeworkFinish } from "../script/util"; import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent"; import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import pg from "./tool/pg"; import pg from "./tool/pg";
import { GameNGT14 } from "./tool/Game"; import { Block, BLOCK_TYPE, GameNGT14, Question, Option } from "./tool/Game";
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
...@@ -69,6 +69,101 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -69,6 +69,101 @@ export default class SceneComponent extends MyCocosSceneComponent {
} }
} }
gameStart() { gameStart() {
this.updateQuestion();
this.updateWords();
}
private layout_question: cc.Node;
updateQuestion() {
let data = GameNGT14.getIns().getCurrent();
this.layout_question = pg.view.find(this, 'layout_question');
let img_big = pg.view.find(this.layout_question, 'base/img_big');
let img_small = pg.view.find(this.layout_question, 'base/img_small');
let label_big = pg.view.find(this.layout_question, 'base/label_big');
let label_small = pg.view.find(this.layout_question, 'base/label_small');
// 需要处理数据
this.updateItem(this.layout_question,data);
}
getLayByOption(option: Option, base) {
return option.isDoubleLine() ? cc.instantiate(pg.view.find(base, 'layout_double')) : cc.instantiate(pg.view.find(base, 'layout_single'));
}
getNodeByBlock(block: Block, base) {
switch (block.type) {
case BLOCK_TYPE.IMG:
return cc.instantiate(pg.view.find(base, 'img'))
case BLOCK_TYPE.TXT:
return cc.instantiate(pg.view.find(base, 'label'))
case BLOCK_TYPE.LINE:
return cc.instantiate(pg.view.find(base, 'line'))
case BLOCK_TYPE.TAG:
return cc.instantiate(pg.view.find(base, 'tag'))
}
}
updateItem(item, data: Question) {
pg.view.visible(item, true);
item.data = data;
let board = pg.view.find(item, 'board');
let base = pg.view.find(item, 'base');
// 确定基础layout
let layout = pg.view.find(item, 'layout');
let list: Array<Option> = data.getList();
list.forEach(option => {
//确定使用的单双行
let lay = this.getLayByOption(option, base);
pg.view.addChild(layout, lay);
let blocks = option.getList();
blocks.forEach(block => {
//确定使用哪种节点
let node = this.getNodeByBlock(block, base);
pg.view.addChild(lay, node);
this.updateNode(node, block)
})
})
setTimeout(() => {
let height = layout.height;
item.height = height + 15;
}, 0);
// pg.view.touchOn(item, this.onTouchItem, this)
// let btn_ok = pg.view.find(item, 'btn_ok');
// pg.view.touchOn(btn_ok, this.onTouchOk, this)
}
updateNode(item, block: Block) {
item.data = block;
switch (block.type) {
case BLOCK_TYPE.IMG:
this.updateImg(item, block)
break
case BLOCK_TYPE.TXT:
this.updateLabel(item, block)
break
case BLOCK_TYPE.LINE:
this.updateLine(item, block)
break
case BLOCK_TYPE.TAG:
this.updateTag(item, block)
break
}
}
updateImg(item, block: Block) {
pg.view.setNetImg(item, block.img, { w: 253, h: 174 })
}
updateLine(item, block: Block) {
item.width = block.line * 30;
pg.view.visible(pg.view.find(item, 'label/input_cursor'), false)
// pg.view.touchOn(item, this.onTouchLine, this);
}
updateLabel(item, block: Block) {
pg.view.setString(item, block.text)
}
updateTag(item, block: Block) {
let tag_default = pg.view.find(item, 'tag_default')
let tag_input = pg.view.find(item, 'tag_input')
pg.view.setString(pg.view.find(tag_default, 'label'), block.tag)
pg.view.setString(pg.view.find(tag_input, 'label'), block.tag)
}
updateWords() {
let word = pg.view.find(this, 'word'); let word = pg.view.find(this, 'word');
this.layout_words = pg.view.find(this, 'layout_words'); this.layout_words = pg.view.find(this, 'layout_words');
this.layout_words.removeAllChildren() this.layout_words.removeAllChildren()
......
...@@ -131,7 +131,7 @@ let pg = { ...@@ -131,7 +131,7 @@ let pg = {
return node; return node;
}, },
//添加节点 //添加节点
addChild(item, child, zIndex) { addChild(item, child, zIndex = 0) {
if (!child) return console.log("addChild error ->请传入子节点"); if (!child) return console.log("addChild error ->请传入子节点");
if (!item) return console.log("addChild error ->请传入父节点"); if (!item) return console.log("addChild error ->请传入父节点");
let node = item.node ? item.node : item; let node = item.node ? item.node : item;
......
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