# Copy/Paste 2021-02-20 # --------------------- # With grateful thanks to knucracker for his patient assistance # --------------------- # Also copies special terrain $lmb:0 # left click button $rmb:1 # right click button $themeSlot:1 # theme overlay slot to use $copy:1 # true for copy $markActive:0 # false until area selection start GetPointerTerrainCoords ->mouseZ ->mouseX @BlitImage if (GetMouseButtonDown(<-lmb false)) # start copy area selection true ->markActive --area # delete copy buffer if (@IsMouseValid) <-mouseZ ->areaStartZ <-mouseX ->areaStartX endIf endIf if (NOT(<-markActive) AND (NOT(-?area))) Return endIf # don't run rest if not selecting terrain if (GetMouseButton(<-lmb false)) # track copy area size amd mark terrain if (@IsMouseValid) <-mouseZ ->areaEndZ <-mouseX ->areaEndX MIN(<-areaStartZ <-areaEndZ) ->minZ MAX(<-areaStartZ <-areaEndZ) ->maxZ MIN(<-areaStartX <-areaEndX) ->minX MAX(<-areaStartX <-areaEndX) ->maxX FromCell(<-minX <-minZ) ->minV FroMCell(<-maxX <-MaxZ) ->maxV @MarkArea (V4(0 0 0 0) <-minVOld <-maxVOld) # Clear marker before painting new marker @MarkArea (V4(.4 .4 .4 .4) <-minV <-maxV) # mark terrain <-minV ->minVOld <-maxV ->maxVOld endIf endif if (GetMouseButtonUp(<-lmb false)) # copy terrain, create blit image @MakeCopy endIf if (GetMouseButtonDown(<-rmb true)) # let's paste If (-?area) @Paste else TraceAllSp ("Copy buffer is empty!") endIf endIf ## mainline end - functiosn/routines follow :MakeCopy CreateList ->area CreateList ->pasteImage toCell(<-maxV) ->_maxCellZ ->_maxCellX toCell(<-minV) ->_minCellZ ->_minCellX <-_maxCellX <-_minCellX - ->blitWidth <-_maxCellZ <-_minCellZ - ->blitHeight # Iterate over marked area, copying both cell height and setting texture overlay Do (<-_maxCellZ <-_minCellZ) Do (<-_maxCellX <-_minCellX) GetTerrain (I J ) ->_ter GetTerrainSpecial(I J) ->_terS V2(<-_ter <-_terS) ->_terData <-_ter 20.0 / ->c v4(<-c <-c <-c .6) ->_color AppendToList(<-area <-_terData) AppendToList(<-pasteImage <-_color) loop Loop TraceAllSp ("Copied " GetListCount(<-area) "cells. From min/max" <-minV <-maxV) If (GetListCount(<-area) eq0) --area endif # can't paste 0 zells :BlitImage If(-?PasteImage) ClearThemeOverlay(<-themeSlot Vector0) # remove old mark SetThemeOverlayPixels(<-themeSlot, <-mouseX, <-mouseZ, # set paste overlay <-blitWidth <-blitHeight <-pasteImage) EndIf :MarkArea toCell ->_maxCellZ ->_maxCellX toCell ->_minCellZ ->_minCellX ->_tex <-_maxCellX <-_minCellX - ->_width <-_maxCellZ <-_minCellZ - ->_height SetThemeOverlayRectPixels(<-themeSlot <-_minCellX <-_minCellZ <-_width <-_height <-_tex) :Paste if (@isMouseValid) <-mouseZ ->areaStartZ <-mouseX ->areaStartX else PlaySoundAtPosition("ADAMessage" 8 FromCell(<-mouseX <-mouseZ)) Return endIf if (not(-?area)) Trace ("Copy buffer empty!") PlaySoundAtPosition("ADAMessage" 8 FromCell(<-mouseX <-mouseZ)) Return endif EditAddUndo(0) ->listItem (0) toCell(<-maxV) ->_maxCellZ ->_maxCellX toCell(<-minV) ->_minCellZ ->_minCellX <-_maxCellZ <-_minCellZ - ->sizeZ <-_maxCellX <-_minCellX - ->sizeX Do (<-mouseZ <-sizeZ +, <-mouseZ) Do (<-mouseX <-sizeX +, <-mouseX) <-area[<-listItem] ->_terData EV2(<-_terdata) ->_terS ->_ter SetTerrain(I J <-_ter) SetTerrainSpecial(I J <-_terS) <-listItem 1 add ->listItem loop loop Trace3 ("pasted " <-listitem "cells.") :IsMouseValid if (<-mouseX gte0 and(<-mouseZ gte0) and(<-mouseX lt(<-mapSizeX)) and(<-mouseZ lt(<-mapSizeZ))) true else false endIf :once @Instructions # null mouse positions -1 ->mouseOldZ -1 ->mouseOldX GetMapSize ->mapSizeZ ->mapSizeX CreateThemeOverlay(<-themeSlot <-mapSizeX <-mapSizeZ Vector0) SetThemeOverlayEnabled(<-themeSlot true) # SetThemeOverlayPointFilter(<-themeSlot true) GetCameraTopDown ->initCamera # remember camera position SetCameraTopDown(true) # end Once :Instructions TraceAllSp ("Left Mouse to mark terrain,") TraceAllSp ("right mouse to paste") TraceAllSp ("Drag mouse to select area") :Destroyed SetCameraTopDown(<-initCamera) SetThemeOverlayEnabled(<-themeSlot false) # delete DestroyThemeOverlay(<-themeSlot) # stomp on it