* A bit of work on VerticalMenuView
* Inheritance updates for Views * Fixes and better handling of MCI factory
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
/* jslint node: true */
|
||||
'use strict';
|
||||
|
||||
var TextView = require('./text_view.js').TextView;
|
||||
var EditTextView = require('./edit_text_view.js').EditTextView;
|
||||
var ButtonView = require('./button_view.js').ButtonView;
|
||||
var Config = require('./config.js').config;
|
||||
var packageJson = require('../package.json');
|
||||
var assert = require('assert');
|
||||
var TextView = require('./text_view.js').TextView;
|
||||
var EditTextView = require('./edit_text_view.js').EditTextView;
|
||||
var ButtonView = require('./button_view.js').ButtonView;
|
||||
var VerticalMenuView = require('./vertical_menu_view.js').VerticalMenuView;
|
||||
var Config = require('./config.js').config;
|
||||
var packageJson = require('../package.json');
|
||||
var assert = require('assert');
|
||||
|
||||
exports.MCIViewFactory = MCIViewFactory;
|
||||
|
||||
@@ -19,11 +20,19 @@ MCIViewFactory.prototype.getPredefinedViewLabel = function(name) {
|
||||
switch(name) {
|
||||
case 'BN' : label = Config.bbsName; break;
|
||||
case 'VL' : label = 'ENiGMA½ v' + packageJson.version; break;
|
||||
case 'VN' : label = packageJson.version; break;
|
||||
}
|
||||
|
||||
return label;
|
||||
};
|
||||
|
||||
// :TODO: probably do something like this and generalize all of this:
|
||||
/*
|
||||
var MCI_ARG_MAP = {
|
||||
'ET' : { 0 : 'maxLength', 1 : 'textStyle' }
|
||||
};
|
||||
*/
|
||||
|
||||
MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
assert(mci.code);
|
||||
assert(mci.id > 0);
|
||||
@@ -37,8 +46,18 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
position : { x : mci.position[0], y : mci.position[1] },
|
||||
};
|
||||
|
||||
// :TODO: move this stuff out of the switch to their own methods/objects
|
||||
function setOption(pos, name) {
|
||||
if(mci.args.length > pos && mci.args[pos].length > 0) {
|
||||
options[name] = mci.args[pos];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(mci.code) {
|
||||
case 'TL' :
|
||||
// :TODO: convert to setOption()
|
||||
if(mci.args.length > 0) {
|
||||
options.textStyle = mci.args[0];
|
||||
}
|
||||
@@ -56,19 +75,17 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
break;
|
||||
|
||||
case 'ET' :
|
||||
if(mci.args.length > 0) {
|
||||
options.maxLength = mci.args[0];
|
||||
options.dimens = { width : options.maxLength };
|
||||
if(setOption(0, 'maxLength')) {
|
||||
options.dimens = { width : options.maxLength };
|
||||
}
|
||||
|
||||
if(mci.args.length > 1) {
|
||||
options.textStyle = mci.args[1];
|
||||
}
|
||||
setOption(1, 'textStyle');
|
||||
|
||||
view = new EditTextView(this.client, options);
|
||||
break;
|
||||
|
||||
case 'PL' :
|
||||
// :TODO: convert to setOption()
|
||||
if(mci.args.length > 0) {
|
||||
options.text = this.getPredefinedViewLabel(mci.args[0]);
|
||||
if(options.text) {
|
||||
@@ -91,6 +108,7 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
break;
|
||||
|
||||
case 'BV' :
|
||||
// :TODO: convert to setOption()
|
||||
if(mci.args.length > 0) {
|
||||
options.text = mci.args[0];
|
||||
options.dimens = { width : options.text.length };
|
||||
@@ -98,6 +116,12 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
|
||||
|
||||
view = new ButtonView(this.client, options);
|
||||
break;
|
||||
|
||||
case 'VM' :
|
||||
setOption(0, 'itemSpacing');
|
||||
|
||||
view = new VerticalMenuView(this.client, options);
|
||||
break;
|
||||
}
|
||||
|
||||
return view;
|
||||
|
||||
Reference in New Issue
Block a user