Przeglądaj źródła

Added remove Folder from Gui

Nikatlas 6 lat temu
rodzic
commit
ab834ef280
3 zmienionych plików z 22 dodań i 8 usunięć
  1. 10 0
      src/Game/app.js
  2. 7 5
      src/Game/misc/Button.js
  3. 5 3
      src/Game/misc/Text.js

+ 10 - 0
src/Game/app.js

@@ -5,6 +5,16 @@ import Router from './Router.js'
 import Menu from './views/Menu';
 
 let DATGUI = require('dat.gui');
+DATGUI.default.GUI.prototype.removeFolder = function(name) {
+  var folder = this.__folders[name];
+  if (!folder) {
+    return;
+  }
+  folder.close();
+  this.__ul.removeChild(folder.domElement.parentNode);
+  delete this.__folders[name];
+  this.onResize();
+}
 
 class App {
 	constructor(){

+ 7 - 5
src/Game/misc/Button.js

@@ -17,22 +17,23 @@ class Button extends PIXI.Sprite{
 
         this.imageURL = image || getParam('imageURL') || DefaultImageUrl;
         if(Gui) {
-            this.Gui = Gui.addFolder("Button");
+            this.Gui = Gui;
+            this.folder = Gui.addFolder('Button');
             let position = {
                 x:0,
                 y:0
             };
             this.controllers = [];
-            this.controllers.push(this.Gui.add(this, 'imageURL').onFinishChange((v) => this.loadImage(v)));
-            this.controllers.push(this.Gui.add(position, 'x').onFinishChange((v) => this.position.x = v));
-            this.controllers.push(this.Gui.add(position, 'y').onFinishChange((v) => this.position.y = v));
+            this.controllers.push(this.folder.add(this, 'imageURL').onFinishChange((v) => this.loadImage(v)));
+            this.controllers.push(this.folder.add(position, 'x').onFinishChange((v) => this.position.x = v));
+            this.controllers.push(this.folder.add(position, 'y').onFinishChange((v) => this.position.y = v));
         }
 
         this.anchor.set(0.5,0.5);
         this.interactive = true;
         this.buttonMode = true;
 
-        this.textNode = new Text({...props, Gui:this.Gui});
+        this.textNode = new Text({...props, Gui:this.folder});
         this.addChild(this.textNode);
 
         this.loadImage(this.imageURL);
@@ -48,6 +49,7 @@ class Button extends PIXI.Sprite{
     }
 
     _kill() {
+        this.Gui.removeFolder('Button');
         this.controllers.forEach((e) => e.remove());
         this.textNode._kill();
         this.destroy();

+ 5 - 3
src/Game/misc/Text.js

@@ -10,8 +10,9 @@ class Text extends PIXI.Container{
 
 		this.text = text || '';
 		if(Gui) {
-			this.Gui = Gui.addFolder("Text");
-			this.controller = this.Gui.add(this, 'text').onFinishChange((v) => this.setText(v));
+			this.Gui = Gui;
+			this.folder = Gui.addFolder("Text");
+			this.controller = this.folder.add(this, 'text').onFinishChange((v) => this.setText(v));
 		}
 
 		this.textNode = new PIXI.Text(text,{fontFamily : 'Arial', fontSize: 28, fill : 0x000000, align : 'center'});
@@ -20,7 +21,8 @@ class Text extends PIXI.Container{
 	}
 
 	_kill() {
-		this.Gui.remove(this.controller);
+		this.controller.remove();
+		this.Gui.removeFolder('Text');
 		this.destroy();
 	}