editor_table

This commit is contained in:
YouWei Zhao 2019-03-21 11:54:50 -04:00
parent b6b6aa33f6
commit ffb8a5e2b3
2 changed files with 81 additions and 19 deletions

View File

@ -9,8 +9,13 @@ editor_table_wrapper = function (editor) {
* HTML模板
*/
editor_table.prototype.select = function (options) {
return `<select>\n${options.join('')}</select>\n`
editor_table.prototype.select = function (value, values) {
return `<select>\n${
editor.table.option(value) +
values.map(function (v) {
return editor.table.option(v)
}).join('')
}</select>\n`
}
editor_table.prototype.option = function (value) {
return `<option value='${JSON.stringify(value)}'>${JSON.stringify(value)}</option>\n`
@ -25,6 +30,51 @@ editor_table_wrapper = function (editor) {
return `<textarea spellcheck='false'>${JSON.stringify(value, null, indent || 0)}</textarea>\n`
}
editor_table.prototype.title = function () {
return `\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n`
}
editor_table.prototype.gap = function (field) {
return `<tr><td>----</td><td>----</td><td>${field}</td></tr>\n`
}
/////////////////////////////////////////////////////////////////////////////
/**
* 表格生成的控制
*/
/**
* 缩进控制, 此函数未实装, 目前全部使用的是0
*/
editor_table.prototype.indent = function (field) {
var num = '\t';
if (field.indexOf("['main']") === 0) return 0;
if (field === "['special']") return 0;
return num;
}
/**
* 注释对象的默认值
*/
editor_table.prototype.defaultcobj = {
// 默认是文本域
_type: 'textarea',
_data: '',
_string: function (args) {//object~[field,cfield,vobj,cobj]
var thiseval = args.vobj;
return (typeof (thiseval) === typeof ('')) && thiseval[0] === '"';
},
// 默认情况下 非对象和数组的视为叶节点
_leaf: function (args) {//object~[field,cfield,vobj,cobj]
var thiseval = args.vobj;
if (thiseval == null || thiseval == undefined) return true;//null,undefined
if (typeof (thiseval) === typeof ('')) return true;//字符串
if (Object.keys(thiseval).length === 0) return true;//数字,true,false,空数组,空对象
return false;
},
}
/////////////////////////////////////////////////////////////////////////////
/**
@ -56,7 +106,7 @@ editor_table_wrapper = function (editor) {
*/
editor_table.prototype.objToTable_ = function (obj, commentObj) {
// 表格抬头
var outstr = ["\n<tr><td>条目</td><td>注释</td><td>值</td></tr>\n"];
var outstr = [editor.table.title()];
var guids = [];
var defaultcobj = {
// 默认是文本域
@ -124,7 +174,7 @@ editor_table_wrapper = function (editor) {
if (cobj._hide) continue;
if (!cobj._leaf) {
// 不是叶节点时, 插入展开的标记并继续遍历, 此处可以改成按钮用来添加新项或折叠等
outstr.push(["<tr><td>----</td><td>----</td><td>", field, "</td></tr>\n"].join(''));
outstr.push(editor.table.gap(field));
recursionParse(field, cfield, vobj, cobj);
} else {
// 是叶节点时, 调objToTr_渲染<tr>
@ -309,28 +359,18 @@ editor_table_wrapper = function (editor) {
var thiseval = vobj;
if (cobj._select) {
var values = cobj._select.values;
var outstr = ['<select>\n', "<option value='", JSON.stringify(thiseval), "'>", JSON.stringify(thiseval), '</option>\n'];
values.forEach(function (v) {
outstr.push(["<option value='", JSON.stringify(v), "'>", JSON.stringify(v), '</option>\n'].join(''))
});
outstr.push('</select>');
return outstr.join('');
return editor.table.select(thiseval,values);
} else if (cobj._input) {
return ["<input type='text' spellcheck='false' value='", JSON.stringify(thiseval), "'/>\n"].join('');
return editor.table.text(thiseval);
} else if (cobj._bool) {
return ["<input type='checkbox' ", (thiseval ? 'checked ' : ''), "/>\n"].join('');
return editor.table.checkbox(thiseval);
} else {
var num = 0;//editor_table.indent(field);
return ["<textarea spellcheck='false' >", JSON.stringify(thiseval, null, num), '</textarea>\n'].join('');
return editor.table.textarea(thiseval,num);
}
}
editor_table.prototype.indent = function (field) {
var num = '\t';
if (field.indexOf("['main']") === 0) return 0;
if (field === "['special']") return 0;
return num;
}
editor.constructor.prototype.table = new editor_table();
}

View File

@ -13,6 +13,7 @@
+ [ ] editor_table 处理表格的生成, 及其响应的事件, 从原editor\_mode中分离
+ [ ] editor_file 调用fs.js编辑文件, 把原editor\_file模块化
+ [ ] editor_game 处理来自core的数据, 导入为editor的数据, 从原editor中分离
+ [ ] editor_util 生成guid等函数, 从editor分离
+ [ ] editor 执行初始化流程加组合各组件
+ [ ] 原editor_mode 移除
@ -29,6 +30,7 @@ editor: {
multi: 组件
file: 组件
table: 组件
util: 组件
}
game: 来自游戏的数据
mode: 当前的模式(左侧的选择)
@ -57,6 +59,26 @@ editor: {
+ [ ] ? 表格折叠
变为四栏, 可以折叠展开
+ [ ] blockly对于无法识别的图块原样返回
+ [ ] ? 简洁的事件方块注册
`editor.registerEvent('log',[['test','Int','测试',0],['floorId','Idstring','楼层','MT0']])`
+ [ ] 一个显示所有快捷键的文本
+ [ ] 更多快捷键
【全塔属性】、【楼层属性】等常用的编辑栏切换
+ [ ] ? 地图编辑优化
常用的地图编辑快捷键/命令复制ctrl+c、粘贴ctrl+v、复制可绑定为现在的“选中xx位置事件” 粘贴为复制xx事件到此处撤回ctrl+z、取消撤回ctrl+y
可以按住拖动图块与事件。
+ [ ] ? 自由建立快捷键到命令的注册表。
## 左侧页面模式
标题? 保存按钮? 添加按钮? 删除按钮?