Bläddra i källkod

Editor: Fix remove function of UIPoints.

Mugen87 4 år sedan
förälder
incheckning
d7826b1f0a
2 ändrade filer med 14 tillägg och 3 borttagningar
  1. 6 0
      editor/js/libs/ui.js
  2. 8 3
      editor/js/libs/ui.three.js

+ 6 - 0
editor/js/libs/ui.js

@@ -124,6 +124,12 @@ UIElement.prototype = {
 
 		return this;
 
+	},
+
+	getIndexOfChild: function ( element ) {
+
+		return Array.prototype.indexOf.call( this.dom.children, element.dom );
+
 	}
 
 };

+ 8 - 3
editor/js/libs/ui.three.js

@@ -699,7 +699,8 @@ UIPoints.prototype.deletePointRow = function ( idx, dontUpdate ) {
 	if ( ! this.pointsUI[ idx ] ) return;
 
 	this.pointsList.remove( this.pointsUI[ idx ].row );
-	this.pointsUI[ idx ] = null;
+
+	this.pointsUI.splice( idx, 1 );
 
 	if ( dontUpdate !== true ) {
 
@@ -707,6 +708,8 @@ UIPoints.prototype.deletePointRow = function ( idx, dontUpdate ) {
 
 	}
 
+	this.lastPointIdx --;
+
 };
 
 function UIPoints2() {
@@ -782,11 +785,12 @@ UIPoints2.prototype.createPointRow = function ( x, y ) {
 	var txtX = new UINumber( x ).setWidth( '30px' ).onChange( this.update );
 	var txtY = new UINumber( y ).setWidth( '30px' ).onChange( this.update );
 
-	var idx = this.lastPointIdx;
 	var scope = this;
 	var btn = new UIButton( '-' ).onClick( function () {
 
 		if ( scope.isEditing ) return;
+
+		var idx = scope.pointsList.getIndexOfChild( pointRow );
 		scope.deletePointRow( idx );
 
 	} );
@@ -873,11 +877,12 @@ UIPoints3.prototype.createPointRow = function ( x, y, z ) {
 	var txtY = new UINumber( y ).setWidth( '30px' ).onChange( this.update );
 	var txtZ = new UINumber( z ).setWidth( '30px' ).onChange( this.update );
 
-	var idx = this.lastPointIdx;
 	var scope = this;
 	var btn = new UIButton( '-' ).onClick( function () {
 
 		if ( scope.isEditing ) return;
+
+		var idx = scope.pointsList.getIndexOfChild( pointRow );
 		scope.deletePointRow( idx );
 
 	} );