OSDN Git Service

メッセージを出せるようになった
authorttwilb <ttwilb@users.sourceforge.jp>
Thu, 22 Aug 2013 13:40:52 +0000 (22:40 +0900)
committerttwilb <ttwilb@users.sourceforge.jp>
Thu, 22 Aug 2013 13:40:52 +0000 (22:40 +0900)
出し方
mainManager.addWidget(new MessageWidgetClass(mainManager, ["Hello, world\n"]));

www/corelib/classes/MessageWidgetClass.js
www/corelib/coresubf.js
www/index_local_debug.html

index 0fe1e74..aea0b36 100644 (file)
@@ -10,11 +10,18 @@ var MessageWidgetClass = function(manager, args)
        //\89ü\8ds\82ª\93ü\82Á\82Ä\82¢\82é\82Æ\82±\82ë\82Å\88ê\8e\9e\92â\8e~\82µ\81«\83L\81[\82Ì\89\9f\89º\82ð\91Ò\82Â
        
        this.messageIndex = 0;
-       this.interval = 15;
+       this.interval = 5;
        this.intervalCount = 0;
        
+       this.wBox = null;
+       this.isPaused = false;
+       
 }.extend(WidgetClass, {
-       attached : function(){
+       attach : function(){
+               
+               this.wBox = createMessageBox("MessageBoxWidghetMessageBox-" + this.manager.tickCount,
+                                               this.size.x, this.size.y, this.origin.x, this.origin.y,
+                                               this.manager.mainArea, undefined, undefined, 5);
                var w = this;
                this.manager.pauseStage(function()
                {
@@ -22,24 +29,33 @@ var MessageWidgetClass = function(manager, args)
                        return w.tick();
                });
        },
+       detach : function(){
+               this.manager.mainArea.removeChild(this.wBox);
+       },
        tick : function(){
-               if(!this.manager.keyState.downArrow) this.downKeyPushed = false;
+               if(!this.manager.UIManager.keyState.cursorDown) this.downKeyPushed = false;
                if(this.intervalCount >= this.interval)
                {
                        if(this.message[this.messageIndex] == '\n')
                        {
                                if(!this.downKeyPushed)
                                {
-                                       if(this.manager.keyState.downArrow)
+                                       if(this.manager.UIManager.keyState.cursorDown)
                                        {
                                                this.downKeyPushed = true;
                                                this.messageIndex++;
+                                               this.isPaused = false;
+                                       }else
+                                       {
+                                               this.isPaused = true;
                                        }
                                }
                        }else
                        {
                                this.messageIndex++;
+                               this.isPaused = false;
                        }
+                       
                        if(this.messageIndex >= this.message.length)
                        {
                                //\83\81\83b\83Z\81[\83W\82ð\95Â\82\82é
@@ -51,40 +67,13 @@ var MessageWidgetClass = function(manager, args)
                {
                        this.intervalCount++;
                }
-               return true;
-       },
-       draw : function(){
-               this.manager.mainContext.globalAlpha = 0.5;
-               this.manager.mainContext.fillRect(this.origin.x, this.origin.y, this.size.x, this.size.y);
-               this.manager.mainContext.globalAlpha = 1.0;
                
-               var lineHead = 0;
-               var lines = [];
-               var height = 0;
-               var ysiz = 16;
-               for(var index = 0; index <= this.messageIndex; index++)
+               if(this.wBox != null)
                {
-                       var siz = this.manager.mainContext.measureText(this.message.slice(lineHead, index + 1 - lineHead));
-                       if(siz.x > this.size.x || this.message[index] == "\n"){
-                               lines.push(this.message.slice(lineHead, index - lineHead));
-                               lineHead = index;
-                               height += ysiz;
-                       }
+                       changeMessageBox(this.wBox, this.message.slice(0, this.messageIndex), this.isPaused);
                }
-               
-               var yloc = this.origin.y + this.size.y - height;
-               for(var i = 0; i < lines.length; i++)
-               {
-                       var line = lines[i];
-                       if(yloc >= this.origin.y)
-                       {
-                               drawText(this.manager.mainContext, line, this.origin.x, yloc);
-                       }
-                       
-                       yloc += ysiz;
-               }
-               
-               
-               
+               return true;
+       },
+       draw : function(){
        }
 });
index 0e0bdbd..d5ad413 100644 (file)
@@ -34,41 +34,36 @@ function createMessageBox(id, width, height, x, y, parent, color, foreColor, z)
        if(foreColor == undefined) foreColor = "#fff";
        
        var base = document.createElement("div");
-       with(base.style)
-       {
-               opacity = "0.7";
-               top = y + "px";
-               left = x + "px";
-               width = width + "px";
-               height = height + "px";
-               backgroundColor = color;
-               color = foreColor;
-               position = "absolute";
-               border = "1px " + foreColor + " solid";
-               overflow = "hidden";
-               fontSize = "32px";
-       }
+       base.style.opacity = "0.7";
+       base.style.top = y + "px";
+       base.style.left = x + "px";
+       base.style.backgroundColor = color;
+       base.style.color = foreColor;
+       base.style.position = "absolute";
+       base.style.border = "1px " + foreColor + " solid";
+       base.style.overflow = "hidden";
+       base.style.fontSize = "32px";
+       base.style.width = width + "px";
+       base.style.height = height + "px";
+       base.style.zIndex = "100";
        base.id = id;
        
        var p = document.createElement("div");
-       with(p.style)
-       {
-               position = "relative";
-               padding = "16px";
-               margin = "0 auto";
-       }
+       p.style.position = "absolute";
+       p.style.padding = "16px";
+       p.style.width = (width - 32) + "px";
+       p.style.bottom = "0";
+       p.style.wordBreak = "break-all";
        p.className = "messageBoxInside";
        base.appendChild(p);
        
        var ar = document.createElement("div");
-       with(ar.style)
-       {
-               position = "absolute"l
-               bottom = "0";
-               right = "0";
-               width = "16px";
-               height = "16px";
-       }
+       ar.style.position = "absolute";
+       ar.style.bottom = "0";
+       ar.style.right = "0";
+       ar.style.padding = "4px";
+       //ar.style.width = "24px";
+       //ar.style.height = "16px";
        ar.innerText = "▼";
        ar.className = "messageBoxArrow";
        base.appendChild(ar);
@@ -80,17 +75,18 @@ function createMessageBox(id, width, height, x, y, parent, color, foreColor, z)
 function changeMessageBox(box, message, showArrow)
 {
        if(showArrow == undefined) showArrow = false;
-       for(var i = 0; i < box.length; i++)
+       for(var i = 0; i < box.childNodes.length; i++)
        {
-               var element = box.item(i);      // [ ] ではない
+               var element = box.childNodes[i];
                if(element.className == "messageBoxInside")
                {
-                       element.innerHTML = message;
-                       element.style.top = parseInt(box.style.height) - parseInt(element.style.height);        //"px"は削除される
+                       element.innerText = message;
+                       //element.style.top = (parseInt(box.style.height.slice(0, box.style.height.length - 2)) - parseInt(element.style.height.slice(0, element.style.height.length - 2))) + "px";     //"px"は削除される
+                       //console.log(box.style.height.slice(0, box.style.height.length - 2) + "  " + element.style.height.slice(0, element.style.height.length - 2));
                        
                }else if(element.className == "messageBoxArrow")
                {
-                       element.display = showArrow ? "block" : "none";
+                       element.style.display = (showArrow && mainManager.tickCount % 30 < 15) ? "block" : "none";
                }
        }
 }
index e5f38db..1a44985 100644 (file)
@@ -71,6 +71,12 @@ function switchDebug()
        }
 }
 
+function reload()
+{
+       localStorage.setItem("previewStage", document.getElementById('stageCode').value);
+       location.reload();
+}
+
 </script>
 </head>
 <body>
@@ -78,7 +84,7 @@ function switchDebug()
        <div id="Resources"></div>
        <div style="z-index: 1;">
                <form><textarea id="DebugText" rows="8" cols="64"></textarea></form>
-               <input type="button" onclick="run(); return false;" value="ステージの実行/再実行"><input type="button" onclick="stop(); return false;" value="ステージの停止"><input type="button" onclick="switchDebug(); return false;" value="デバッグの有効/無効">
+               <input type="button" onclick="run(); return false;" value="ステージの実行/再実行"><input type="button" onclick="stop(); return false;" value="ステージの停止"><input type="button" onclick="switchDebug(); return false;" value="デバッグの有効/無効"><input type="button" onclick="reload(); return false;" value="ページの再読み込み">
        </div>
        <div style="display: none;"><form><textarea id="stageCode"></textarea></form></div>
 </body>