View Single Post
  #33  
Old 12-19-2006, 05:33 AM
excaliber7388 excaliber7388 is offline
Banned
excaliber7388's Avatar
Join Date: Jul 2005
Location: US
Posts: 5,229
excaliber7388 can only hope to improve
Send a message via AIM to excaliber7388
You have a great point there!
Maybe I should look into taking this editor, and improving it by adding predefined objects, text editing, etc.
The script is below.
Predefined objects would be saving the array to a client variable.
From there, we would need a gui that would show all the images.
X_X
This would take me a while...someone better want to step in.
PHP Code:
function onActionServerSide(action) {
  switch (
action) {
    case 
"paste": {
        
pasteTiles(params[1],params[2],params[3],params[4],params[5]);
        break;
      }
  }
}

function 
pasteTiles(pastex,pastey,pastew,pasteh,pastearr) {
  for (
tx=0tx<pastewtx++) for (ty=0ty<pastehty++)
    
tiles[pastex+tx,pastey+ty] = pastearr[tx+ty*pastew];
  
updateboard2(pastex,pastey,pastew,pasteh);
}

//#CLIENTSIDE
function onCreated() {
  
this.on false;
  
this.tilex 0;
  
this.tiley 0;
  
this.selecting false;
  
this.selected false;
  
this.selx this.sely this.selx2 this.sely2 0;

  
addGuiControls();
  
setTimer(0.05);
}

function 
onweaponfired() {
    if (
this.on
      
turnoff();
    else
      
turnon();
}

function 
turnon() {
  
this.on true;

  
GUIContainer.addControl(LevelEditor_Window);
  
GUIContainer.addControl(LevelEditor_DragTiles);
  
GraalControl.width GUIContainer.width 200;
  
GraalControl.horizSizing "width";
  
LevelEditor_Window.GUIContainer.width 200;
  
LevelEditor_Window.width 200;
  
LevelEditor_Window.height GUIContainer.height;
  
LevelEditor_Window.horizSizing "left";

  
drawTiles();
  
LevelEditor_Window.show();
}

function 
turnoff() {
  
this.on false;
  
GraalControl.width GUIContainer.width;
  
GraalControl.horizSizing "relative";
  
LevelEditor_Window.hide();
}

function 
onPlayerEnters() {
  if (!
this.on)
    return;
  
drawTiles();
}

function 
addGuiControls() {
  
LevelEditor_Window = new GuiWindowCtrl("LevelEditor_Window");
  
with (LevelEditor_Window) {
    
profile "GuiWindowProfile";
    
0;
    
0;
    
width 200;
    
height 300;
    
canMove true;
    
canResize true;
    
canClose true;
    
canMaximize true;
    
canMinimize true;
    
tile true;
    
text "Select Tiles";
    
visible false;

    new 
GuiScrollCtrl("LevelEditor_Scroll") {
      
profile "GuiScrollProfile";
      
horizSizing "width";
      
vertSizing "height";
      
position "5 23";
      
extent "190 272";
      
willFirstRespond true;
      
hScrollBar "alwaysOn";
      
vScrollBar "alwaysOn";
      
tile true;

      new 
GuiControl("LevelEditor_ScrollFiller") {
        
0;
        
0;
        
width 2048;
        
height 512;
        
scrolllinex 16;
        
scrollliney 16;
      }
    }

    new 
GuiDrawingPanel("LevelEditor_Tiles") {
      
6;
      
24;
      
width 169;
      
height 251;
      
horizSizing "width";
      
vertSizing "height";
    }

    new 
GuiShowImgCtrl("LevelEditor_TilesSelect") {
      
profile "GuiModelessDialogProfile";
      
7;
      
24;
      
width 170;
      
height 252;
      
horizSizing "width";
      
vertSizing "height";
      
dimension 2;
      
polygon NULL;
      
red green blue alpha 0.5;
    }
  }
  
LevelEditor_DragTiles = new GuiDrawingPanel("LevelEditor_DragTiles");
  
LevelEditor_DragTiles.visible false;
  if (
this.on)
    
drawTiles();
}

function 
onTimeout() {
  if (
this.dragging==true) {
    
// Check if the dragging is still ongoing
    
if (!leftmousebutton) {
      
this.dragging false;
      if (
this.dopaste) {
        
// Send the tiles and position to the server
        
wx int(worldx(LevelEditor_DragTiles.x,LevelEditor_DragTiles.x)+0.5);
        
wy int(worldy(LevelEditor_DragTiles.y,LevelEditor_DragTiles.y)+0.5);
        
tarrx int(this.selx/16);
        
tarry int(this.sely/16);
        
tarrw int((this.selx2-this.selx)/16);
        
tarrh int((this.sely2-this.sely)/16);
        
tarr = new[tarrw*tarrh];
        for (
ty=tarryty<tarry+tarrhty++) {
          for (
tx=tarrxtx<tarrx+tarrwtx++)
            
tarr[(tx-tarrx)+(ty-tarry)*tarrw] = int(tx/16)*32*16 ty*16 + (tx%16);
        }
        
triggerServer("gui","LevelEditor","paste",wx,wy,tarrw,tarrh,tarr);
      }
    } else if (!(
mousescreenx in <0,GUIContainer.width-1>) ||
        !(
mousescreeny in <0,GUIContainer.height-1>))
      
this.dragging false;
  }
  if (
this.dragging) {
    
// Move the selected tiles
    
LevelEditor_DragTiles.mousescreenx-this.dragrelx;
    
LevelEditor_DragTiles.mousescreeny-this.dragrely;
    
// Push the tiles behind the window for easier editing
    
if (LevelEditor_DragTiles.x+LevelEditor_DragTiles.width<LevelEditor_Window.x+10 ||
        
LevelEditor_DragTiles.x>=LevelEditor_Window.x+LevelEditor_Window.width-10 ||
        
LevelEditor_DragTiles.y+LevelEditor_DragTiles.height<LevelEditor_Window.y+10 ||
        
LevelEditor_DragTiles.y>=LevelEditor_Window.y+LevelEditor_Window.height-10) {
      
LevelEditor_DragTiles.pushtoback();
      
GraalControl.pushtoback();
      
this.dopaste true;
    }
  } else if (
LevelEditor_DragTiles.visible) {
    
// Hide the tiles if we are not dragging anymore
    
with (LevelEditor_DragTiles) {
      
width height 0;
      
hide();
    }
  }
  
setTimer(0.05);
}

function 
LevelEditor_Tiles.onResize(newwnewh) {
  
drawTiles();
}

function 
LevelEditor_Tiles.onMouseDown(mmodmxmy) {
  if (
checkDragStart(mx,my))
    return;
  
setFirstSelection(mx,my);
}

function 
LevelEditor_Tiles.onMouseDragged(mmodmxmy) {
  if (!
this.selecting)
    return;
  
setSecondSelection(mx,my);
}

function 
LevelEditor_Tiles.onMouseUp(mmodmxmy) {
  if (!
this.selecting)
    return;
  
setSecondSelection(mx,my,true);
}

function 
LevelEditor_Tiles.onMouseWheelUp() {
  
LevelEditor_Scroll.scrollDelta(0,-64);
}

function 
LevelEditor_Tiles.onMouseWheelDown() {
  
LevelEditor_Scroll.scrollDelta(0,64);
}

function 
LevelEditor_Scroll.onScrolled(scrollx,scrolly,deltax,deltay) {
  if (
this.tilex!=scrollx || this.tiley!=scrolly) {
    
this.tilex scrollx;
    
this.tiley scrolly;
    
drawTiles();
    
updateTilesSelection();
  }
}

function 
checkDragStart(mx,my) {
  
localcoord LevelEditor_Tiles.globaltolocalcoord({mx,my});
  
testx this.tilex localcoord[0];
  
testy this.tiley localcoord[1];
  if (
testx in |this.selx,this.selx2> &&
      
testy in |this.sely,this.sely2>) {
    
this.dragging true;
    
this.dopaste false;
    
this.dragrelx localcoord[0]-(this.selx-this.tilex)-1;
    
this.dragrely localcoord[1]-(this.sely-this.tiley)-1;
    
with (LevelEditor_DragTiles) {
      
mx-thiso.dragrelx;
      
my-thiso.dragrely;
      
width thiso.selx2 thiso.selx;
      
height thiso.sely2 thiso.sely;
      
drawimagerectangle(0,0,
        
"TILES",thiso.selx,thiso.sely,
        
width,height);
      
showtop();
    }
    
GraalControl.makefirstresponder(true);
    return 
true;
  } else
    return 
false;
}

function 
drawTiles() {
  
LevelEditor_Tiles.drawimagerectangle(0,0,
    
"TILES",this.tilex,this.tiley,
    
LevelEditor_Tiles.width,LevelEditor_Tiles.height);
}

function 
setFirstSelection(mx,my) {
  
this.selected false;
  
this.selecting true;
  
localcoord LevelEditor_Tiles.globaltolocalcoord({mx,my});
  
this.selorgx = (this.tilex localcoord[0]) & -16;
  
this.selorgy = (this.tiley localcoord[1]) & -16;
  
this.selx = (this.tilex localcoord[0]+8) & -16;
  
this.sely = (this.tiley localcoord[1]+8) & -16;
  
this.selx2 this.selx;
  
this.sely2 this.sely;
}

function 
setSecondSelection(mx,my,finished) {
  
localcoord LevelEditor_Tiles.globaltolocalcoord({mx,my});
  
this.selx2 = (this.tilex localcoord[0]+8) & -16;
  
this.sely2 = (this.tiley localcoord[1]+8) & -16;
  if (
finished) {
    if (
this.selx==this.selx2 && this.sely==this.sely2) {
      
this.selx this.selorgx;
      
this.sely this.selorgy;
      
this.selx2 this.selx 16;
      
this.sely2 this.sely 16;
    }
    
this.selected true;
    
this.selecting false;
  }
  
updateTilesSelection();
}

function 
updateTilesSelection() {
  
selpolx min(int(this.selx),this.selx2);
  
selpolw abs(this.selx2-this.selx);
  
selpoly min(int(this.sely),this.sely2);
  
selpolh abs(this.sely2-this.sely);
  if (
selpolw<=|| selpolh<=0)
    
LevelEditor_TilesSelect.polygon NULL;
  else {
    
selpolx -= this.tilex;
    
selpoly -= this.tiley;
    
LevelEditor_TilesSelect.polygon = {selpolx,selpoly,
      
selpolx+selpolw,selpoly,selpolx+selpolw,selpoly+selpolh,
      
selpolx,selpoly+selpolh};
  }


Last edited by excaliber7388; 12-19-2006 at 05:47 AM..
Reply With Quote