//join("emerafuncdebug"); function onActionServerSide() { switch (params[0]) { case "placetiles": PlaceTiles(params[1], params[2], params[3]); break; } } function PlaceTiles(mx, my, ti) { temp.tilesel = ti; for (temp.i = 0; temp.i < temp.tilesel.size(); temp.i++) { for (temp.o = 0; temp.o < temp.tilesel[temp.i].size(); temp.o++) { tiles[mx + temp.o, my + temp.i] = temp.tilesel[temp.i][temp.o]; } } updateboard2(mx, my, temp.tilesel[0].size(), temp.tilesel.size()); } //#CLIENTSIDE function onCreated() { DrawEditor(); } function onKeyPressed(code, Key) { if (code == 220 || Key == "z") { Editor(); } } function DrawEditor() { new GuiControl("EditorWindow") { useownprofile = true; clientrelative = true; width = 750; height = 150; clientextent = { width, height }; x = screenwidth / 2 - width / 2; y = 10; visible = false; profile.border = 2; new GuiScrollCtrl("EditorScroll") { profile = GuiBlueScrollProfile; width = 750; height = 150; x = y = 0; thiso.catchevent(this, "onMouseDragged", "onTilesetSelection"); thiso.catchevent(this, "onMouseUp", "onTilesetSelect"); new GuiDrawingPanel("EditorTiles") { width = 2048; height = 512; x = y = 0; clearall(); drawimage(0, 0, gettileset()); thiso.catchevent(this, "onMouseDragged", "onTilesetSelection"); thiso.catchevent(this, "onMouseUp", "onTilesetSelect"); new GuiControl("EditorSelection") { useownprofile = true; width = 32; height = 32; x = thiso.endsel[0]; y = thiso.startsel[1]; profile.opaque = true; profile.fillcolor = { 255, 255, 255, 100 }; } } } } } function ChatBar.onAction() { args = ChatBar.text.tokenize(" "); switch (args[0]) { case "/ul": ChatBar.text = "update level"; break; } } function Editor() { if (EditorWindow.visible == false) { EditorWindow.visible = true; } else { EditorWindow.visible = false; } } function PlaceTiles(mx, my) { triggerserver("weapon", this.name, "PlaceTiles", mx, my, this.tilesel); } function onTilesetSelection(obj, keymod, mx, my) { DrawSelection(mx, my); } function EditorTiles.onMouseDown(keymod, mx, my) { EditorSelection.visible = true; EditorSelection.width = EditorSelection.height = 16; temp.osel = EditorTiles.globaltolocalcoord({ mx, my }); this.startsel = { shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16) }; this.endsel = { NULL, NULL }; player.chat = this.startsel; MoveSelection(this.startsel[0], this.startsel[1]); } function MoveSelection(locx, locy) { EditorSelection.x = locx; EditorSelection.y = locy; } function DrawSelection(mx, my) { temp.osel = EditorTiles.globaltolocalcoord({ mx, my }); this.endsel = { shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16) }; EditorSelection.x = thiso.startsel[0]; EditorSelection.y = thiso.startsel[1]; EditorSelection.width = thiso.endsel[0] - thiso.startsel[0]; EditorSelection.height = thiso.endsel[1] - thiso.startsel[1]; } function onTilesetSelect(obj, keymod, mx, my) { SelectMouseTiles(mx, my); } function SelectMouseTiles(mx, my) { temp.osel = EditorTiles.globaltolocalcoord({ mx, my }); this.endsel = { shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16) }; EditorSelection.visible = false; GrabTileSelection(); } function GraalControl.onMouseUp() { temp.osel = EditorTiles.globaltolocalcoord({ mx, my }); this.endsel = { shared.roundto(temp.osel[0], 16), shared.roundto(temp.osel[1], 16) }; EditorSelection.visible = false; GrabTileSelection(); } function GrabTileSelection() { temp.tilew = (this.endsel[0] - this.startsel[0]) / 16; temp.tileh = (this.endsel[1] - this.startsel[1]) / 16; this.tilesel = {}; temp.tilear = {}; for (temp.i = 0; temp.i < temp.tileh; temp.i++) { for (temp.o = 0; temp.o < temp.tilew; temp.o++) { temp.tilear.add(ImageToTile(this.startsel[0] + (temp.o * 16), this.startsel[1] + (temp.i * 16))); } this.tilesel.add(temp.tilear); player.chat = temp.tilear; temp.tilear = {}; } this.tileedit = true; } function onMouseDown(mode) { if (EditorWindow.visible != true) { return; } if (mode == "right" && this.tileedit == true) { if (this.tilesel.size() > 0) { PlaceTiles(int(mousex), int(mousey)); player.chat = this.tilesel; } } } function GraalControl.onMouseDown() { if (EditorWindow.visible != true) { return; } if (!this.start_drag) { this.place_tiles = false; this.start_drag = true; this.drag_type = "level"; this.start_loc = { shared.roundto(mousex, 1), shared.roundto(mousey, 1) }; this.end_loc = {}; } } //Thanks dusty <3 function ImageToTile(tx, ty) { return this.tile = ((int(tx / 16) % 16) + (int(tx / 256) * 512)) + ((int(ty / 16) * 16) % 512); }