OSDN Git Service

core.jsのバグ修正および手直し。。
authorttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 14:42:55 +0000 (23:42 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Tue, 3 Sep 2013 14:42:55 +0000 (23:42 +0900)
resumeStage()の引数に安全のためfuncをとれるようにした。

www/corelib/classes/SelectWidgetClass.js
www/corelib/core.js

index 8ef34d3..e7f7643 100644 (file)
@@ -42,88 +42,13 @@ var SelectWidgetClass = function(manager, args){
        this.selectKeyPressed = true;
        this.isHidden = false;
        
+       this.modalFunc = null;
+       
 }.extend(WidgetClass, {
        attach : function(){
-               var wBox, wItem, wMessage, bOk, bCancel;
-               wBox = document.createElement('div');
-               with(wBox)
-               {
-                       style.position = "absolute";
-                       style.top = this.origin.y + "px";
-                       style.left = this.origin.x + "px";
-                       style.width = this.size.x + "px";
-                       style.height = this.size.y + "px";
-                       style.backgroundColor = this.backColor;
-                       style.border = this.border;
-                       style.zIndex = "999";
-               }
-               wItem = document.createElement('div');
-               with(wItem)
-               {
-                       style.position = "absolute";
-                       style.top = this.padding + "px";
-                       style.left = this.padding + "px";
-                       style.width = (this.size.x - (this.padding * 2)) + "px";
-                       style.height = (this.size.y - (this.padding * 2) - this.buttonHeight - this.messageHeight) + "px";
-                       style.overflow = "hidden";
-               }
-               wBox.appendChild(wItem);
-               
-               var xloc = this.itemPadding, yloc = this.itemPadding;
-               var maxHeight = 0;
-               for(var i = 0; i < this.items.length; i++)
-               {
-                       var w = this.items[i];
-                       if(xloc + w.size.x > (this.size.x - (this.padding * 2)) - this.itemPadding)
-                       {
-                               xloc = this.itemPadding;
-                               yloc += maxHeight + this.itemPadding;
-                               maxHeight = 0;
-                       }
-                       
-                       wItem.appendChild(w.createHtmlElement(xloc, yloc));
-                       w.updateHtmlElement()
-                       
-                       xloc += w.size.x + this.itemPadding;
-                       
-                       if(maxHeight < w.size.y) maxHeight = w.size.y;
-                       
-               }
-               
-               wMessage = createMessageBox(
-                       "",                                                                                                                     //id
-                       this.size.x - (this.padding * 2) - (this.messageMergin * 2),    //width
-                       this.messageHeight - (this.messageMergin * 2),                                  //height
-                       this.messageMergin + this.padding,                                                              //x
-                       this.size.y - this.padding - this.buttonHeight - this.messageHeight + this.messageMergin,       //y
-                       wBox,
-                       "",                                                                                                                             //color
-                       "white",                                                                                                                //foreColor
-                       16                                                                                                                              //mergin
-               );
-               wMessage.style.border = this.messageBorder;
-               changeMessageBox(wMessage, "", false);  //初めは空の文字列にしておく
-               this.wMessage = wMessage;
-               this.okButton = new SelectWidgetItemClass(true, "決定", new Point2D(this.buttonWidth, this.buttonHeight), false, "決定します。");
-               bOk = this.okButton.createHtmlElement(this.size.x - this.padding - this.buttonWidth, this.size.y - this.padding - this.buttonHeight)
-               wBox.appendChild(bOk);
-               
-               if(this.enableCancel)
-               {
-                       this.cancelButton = new SelectWidgetItemClass(true, "キャンセル", new Point2D(this.buttonWidth, this.buttonHeight), false, "キャンセルします。");
-                       bCancel = this.cancelButton.createHtmlElement(this.size.x - this.padding - (this.buttonWidth * 2) - this.itemPadding * 2, this.size.y - this.padding - this.buttonHeight);
-                       wBox.appendChild(bCancel);
-                       this.items.push(this.cancelButton);
-               }
-               this.items.push(this.okButton);
-               
-               this.manager.mainArea.appendChild(wBox);
-               this.wBox = wBox;
-               
-               // 初期選択状態をつくる
-               this.moveCursor(this.defaultCursor);
                var w = this;
-               this.manager.pauseStage(function()
+               var that = this;
+               this.modalFunc = function()
                {
                        // pauseStageに直接tickを設置するとtick内のthisでmanagerが取得されてしまう
                        if(!w.tick())
@@ -131,11 +56,98 @@ var SelectWidgetClass = function(manager, args){
                                w.manager.resumeStage();
                                //w.manager.removeWidget(w);
                        }
+               };
+               this.manager.pauseStage(this.modalFunc,
+               function(){
+                       var wBox, wItem, wMessage, bOk, bCancel;
+                       wBox = document.createElement('div');
+                       with(wBox)
+                       {
+                               style.position = "absolute";
+                               style.top = that.origin.y + "px";
+                               style.left = that.origin.x + "px";
+                               style.width = that.size.x + "px";
+                               style.height = that.size.y + "px";
+                               style.backgroundColor = that.backColor;
+                               style.border = that.border;
+                               style.zIndex = "999";
+                       }
+                       wItem = document.createElement('div');
+                       with(wItem)
+                       {
+                               style.position = "absolute";
+                               style.top = that.padding + "px";
+                               style.left = that.padding + "px";
+                               style.width = (that.size.x - (that.padding * 2)) + "px";
+                               style.height = (that.size.y - (that.padding * 2) - that.buttonHeight - that.messageHeight) + "px";
+                               style.overflow = "hidden";
+                       }
+                       wBox.appendChild(wItem);
+                       
+                       var xloc = that.itemPadding, yloc = that.itemPadding;
+                       var maxHeight = 0;
+                       for(var i = 0; i < that.items.length; i++)
+                       {
+                               var w = that.items[i];
+                               if(xloc + w.size.x > (that.size.x - (that.padding * 2)) - that.itemPadding)
+                               {
+                                       xloc = that.itemPadding;
+                                       yloc += maxHeight + that.itemPadding;
+                                       maxHeight = 0;
+                               }
+                               
+                               wItem.appendChild(w.createHtmlElement(xloc, yloc));
+                               w.updateHtmlElement()
+                               
+                               xloc += w.size.x + that.itemPadding;
+                               
+                               if(maxHeight < w.size.y) maxHeight = w.size.y;
+                               
+                       }
+                       
+                       wMessage = createMessageBox(
+                               "",                                                                                                                     //id
+                               that.size.x - (that.padding * 2) - (that.messageMergin * 2),    //width
+                               that.messageHeight - (that.messageMergin * 2),                                  //height
+                               that.messageMergin + that.padding,                                                              //x
+                               that.size.y - that.padding - that.buttonHeight - that.messageHeight + that.messageMergin,       //y
+                               wBox,
+                               "",                                                                                                                             //color
+                               "white",                                                                                                                //foreColor
+                               16                                                                                                                              //mergin
+                       );
+                       wMessage.style.border = that.messageBorder;
+                       changeMessageBox(wMessage, "", false);  //初めは空の文字列にしておく
+                       that.wMessage = wMessage;
+                       that.okButton = new SelectWidgetItemClass(true, "決定", new Point2D(that.buttonWidth, that.buttonHeight), false, "決定します。");
+                       bOk = that.okButton.createHtmlElement(that.size.x - that.padding - that.buttonWidth, that.size.y - that.padding - that.buttonHeight)
+                       wBox.appendChild(bOk);
+                       
+                       if(that.enableCancel)
+                       {
+                               that.cancelButton = new SelectWidgetItemClass(true, "キャンセル", new Point2D(that.buttonWidth, that.buttonHeight), false, "キャンセルします。");
+                               bCancel = that.cancelButton.createHtmlElement(that.size.x - that.padding - (that.buttonWidth * 2) - that.itemPadding * 2, that.size.y - that.padding - that.buttonHeight);
+                               wBox.appendChild(bCancel);
+                               that.items.push(that.cancelButton);
+                       }
+                       that.items.push(that.okButton);
+                       
+                       that.manager.mainArea.appendChild(wBox);
+                       that.wBox = wBox;
+                       
+                       // 初期選択状態をつくる
+                       that.moveCursor(that.defaultCursor);
                });
        },
        detach : function(){
-               this.manager.mainArea.removeChild(this.wBox);
-               this.manager.resumeStage();
+               if(this.wBox){
+                       this.manager.mainArea.removeChild(this.wBox);
+                       
+               }
+               if(this.modalFunc)
+               {
+                       this.manager.resumeStage(this.modalFunc);
+               }
                if(this.callback)
                {
                        this.callback(this.callbackArg);
@@ -148,6 +160,8 @@ var SelectWidgetClass = function(manager, args){
                        return false;
                }
                
+               if(!this.wBox) return true;
+               
                //カーソルの移動
                if(this.manager.UIManager.keyState.cursorLeft)
                {
index 23bd7ed..3216dfc 100644 (file)
@@ -220,7 +220,13 @@ GameManager.prototype = {
        pauseStage: function(func, initFunc){
                //ステージの実行を一時停止する。一時停止中、funcに指定された関数が毎tick毎に呼ばれる
                if(!this.stagePaused){
-                       if(!initFunc) initFunc = null;
+                       if(!initFunc)
+                       {
+                               initFunc = null;
+                       }else
+                       {
+                               initFunc();
+                       }
                        this.stagePausedFunctions.push(func);
                        this.stagePausedInitFunctions.push(initFunc);
                        this.stagePaused = true;
@@ -237,18 +243,41 @@ GameManager.prototype = {
                        }
                }
        },
-       resumeStage: function(){
+       //func は、pauseStageのinitFuncが実行されてそのpauseStage()による待機状態に入る前にresumeStage()が実行された時の安全策
+       resumeStage: function(func){
                //ステージの実行を再開する
                if(this.stagePaused) {
                        //必ずpauseStage()の引数に指定したfunc()の中から呼ばれる・・・はず。
-                       this.stagePausedFunctions.splice(0, 1);
-                       this.stagePausedInitFunctions.splice(0, 1);
+                       var beforeFunc = this.stagePausedFunctions[0];
+                       if(func)
+                       {
+                               var ind = -1;
+                               for(var i in this.stagePausedFunctions)
+                               {
+                                       if(this.stagePausedFunctions[i] == func)
+                                       {
+                                               ind = i; break;
+                                       }
+                               }
+                               if(ind == -1)
+                               {
+                                       return false;
+                               }else
+                               {
+                                       this.stagePausedFunctions.splice(ind, 1);
+                                       this.stagePausedInitFunctions.splice(ind, 1);
+                               }
+                       }else
+                       {
+                               this.stagePausedFunctions.splice(0, 1);
+                               this.stagePausedInitFunctions.splice(0, 1);
+                       }
                        if(this.stagePausedFunctions.length == 0)
                        {
                                this.stagePaused = false;
                        }else
                        {
-                               this.stagePausedInitFunctions[0]();
+                               if(this.stagePausedFunctions[0] != beforeFunc) this.stagePausedInitFunctions[0]();
                        }
                        return true;
                } else{