Skip to content

Commit

Permalink
Add: show incremental message
Browse files Browse the repository at this point in the history
  • Loading branch information
fullkawa committed Jul 20, 2011
1 parent 0e43424 commit 540cb44
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/m3.enchant.js
Expand Up @@ -537,21 +537,23 @@ enchant.m3.Player.prototype = {
* @param cut 一カット分のシナリオデータ
*/
getMessage: function(cut, layers) {
var msg = "";
var msg = {};
var layers = this.LAYERS.concat(['msg']);

for (var i=0; i<layers.length; i++) {
var key = layers[i];
var layer = cut[key];
if (layer != undefined) {
if (typeof(layer) == 'string' && layer.length > 0) {
msg += layer + '<br/>';
msg = { msg: layer };
}
else if (layer instanceof Character) {
var chara = layer.getWords();
if (chara.msg != undefined && chara.msg.length > 0) {
msg += chara.name + '<br/>';
msg += chara.msg + '<br/>';
msg = {
name: chara.name,
msg: chara.msg
};
}
}
}
Expand Down Expand Up @@ -614,6 +616,7 @@ enchant.m3.Player.prototype = {
*/
playNext: function() {
this.layers.setSequence(this.seqs[this.seqNo], this.seqs[++this.seqNo]);
this.msg.setSequence(this.msgqs[this.seqNo]);
},

playBack: function() {
Expand Down Expand Up @@ -921,12 +924,25 @@ enchant.m3.Message = enchant.Class.create(enchant.m3.RoundLabel, {
*/
this.textBuf = '';

/**
* 文字送りされない、固定文字列
* 台詞の主の名前など
*/
this.prefix = '';

/**
* 文字送りのためのカウンタ
*/
this.cnt = 0;

/**
* 文字送りの表示スピード
* 小さいほど遅い
*/
this.weight = 1;

this.addEventListener(enchant.Event.ENTER_FRAME, function() {
// TODO: 文字送り
this.text = this.prefix + this.textBuf.substring(0, this.cnt * this.weight);
this.cnt++;
});

Expand All @@ -935,6 +951,18 @@ enchant.m3.Message = enchant.Class.create(enchant.m3.RoundLabel, {
}
});

/**
* シーケンスをセットする
*/
enchant.m3.Message.prototype.setSequence = function(seq) {
if (seq != undefined) {
this.setMessage(seq.msg, seq.name);
}
else {
console.warn('seq is undefined.');
}
};

/**
* テキストをメッセージウィンドウに表示する
* @param text {String} 表示するテキスト
Expand All @@ -943,10 +971,11 @@ enchant.m3.Message = enchant.Class.create(enchant.m3.RoundLabel, {
enchant.m3.Message.prototype.setMessage = function(text, name) {
this.text = '';
this.textBuf = '';
this.prefix = '';
this.cnt = 0;

if (name != undefined) {
this.text = '<span class="m3_msg_name">' + name + '</span><br/>';
this.prefix = '<span class="m3_msg_name">' + name + '</span><br/>';
}
if (text != undefined) {
this.textBuf = text + '<br/>';
Expand Down

0 comments on commit 540cb44

Please sign in to comment.