From d33e6637adfde3a05cbf346b89b418d242613ba0 Mon Sep 17 00:00:00 2001 From: unid15 Date: Sat, 18 Nov 2017 00:30:00 +0100 Subject: [PATCH] Buildmode update 2 (#16526) * Buildmode update * Allow spawn to spawn areas * Fixes click-dragging functionality * Fully fixes click-drag --- code/WorkInProgress/buildmode.dm | 92 +++++++++++++++++++-- code/game/objects/structures/ladders.dm | 6 +- code/modules/admin/admin.dm | 5 ++ code/modules/admin/verbs/modifyvariables.dm | 11 +-- 4 files changed, 101 insertions(+), 13 deletions(-) diff --git a/code/WorkInProgress/buildmode.dm b/code/WorkInProgress/buildmode.dm index cc10d794c7a..52546730f3f 100644 --- a/code/WorkInProgress/buildmode.dm +++ b/code/WorkInProgress/buildmode.dm @@ -97,6 +97,7 @@ to_chat(usr, "Left Mouse Button on turf/obj = Place objects") to_chat(usr, "Right Mouse Button = Delete objects") to_chat(usr, "Middle Mouse Button = Copy atom") + to_chat(usr, "Middle Mouse Button twice on a turf = Area editing mode") to_chat(usr, "") to_chat(usr, "Ctrl+Shift+Left Mouse Button = Sets bottom left corner for fill mode") to_chat(usr, "Ctrl+Shift+Right Mouse Button = Sets top right corner for fill mode") @@ -153,6 +154,7 @@ obj/effect/bmode/buildholder/New() ..() cl.screen -= list(builddir,buildhelp,buildmode,buildquit) cl.buildmode_objs &= ~list(builddir,buildhelp,buildmode,buildquit,src) + cl.images -= buildmode.area_overlay buildmodeholders -= src /obj/effect/bmode/buildmode @@ -162,6 +164,12 @@ obj/effect/bmode/buildholder/New() var/valueholder = "derp" var/objholder = /obj/structure/closet var/atom/copycat + var/image/area_overlay + +/obj/effect/bmode/buildmode/New() + ..() + + area_overlay = image('icons/turf/areas.dmi', "yellow") /obj/effect/bmode/buildmode/Click(location, control, params) var/list/pa = params2list(params) @@ -271,7 +279,6 @@ obj/effect/bmode/buildholder/New() message_admins(msglog) log_admin(msglog) to_chat(usr, "If the server is lagging the operation will periodically sleep so the fill may take longer than typical.") - var/turf_op = ispath(whatfill, /turf) var/deletions = 0 for(var/turf/T in fillturfs) if(areaAction == MASS_DELETE || areaAction == SELECTIVE_DELETE) @@ -289,7 +296,8 @@ obj/effect/bmode/buildholder/New() if(areaAction == MASS_DELETE) T.ChangeTurf(get_base_turf(T.z)) else - if(turf_op) + if(ispath(whatfill, /area) || istype(holder.buildmode.copycat, /area)) + //In case of a selective fill, make sure the turf fits into the criteria before changing it if(areaAction == SELECTIVE_FILL) if(strict) if(T.type != chosen) @@ -297,6 +305,23 @@ obj/effect/bmode/buildholder/New() else if(!istype(T, chosen)) continue + + var/area/A + if(istype(holder.buildmode.copycat, /area)) + A = holder.buildmode.copycat + else + A = locate(whatfill) + + T.set_area(A) + else if(ispath(whatfill, /turf)) + if(areaAction == SELECTIVE_FILL) + if(strict) + if(T.type != chosen) + continue + else + if(!istype(T, chosen)) + continue + T.ChangeTurf(whatfill) else if(areaAction == SELECTIVE_FILL) @@ -495,7 +520,7 @@ obj/effect/bmode/buildholder/New() message_admins(msglog) log_admin(msglog) to_chat(usr, "If the server is lagging the operation will periodically sleep so the fill may take longer than typical.") - var/turf_op = ispath(holder.buildmode.objholder,/turf) + var/deletions = 0 for(var/turf/T in fillturfs) if(areaAction == MASS_DELETE || areaAction == SELECTIVE_DELETE) @@ -513,7 +538,8 @@ obj/effect/bmode/buildholder/New() if(areaAction == MASS_DELETE) T.ChangeTurf(get_base_turf(T.z)) else - if(turf_op) + if(ispath(holder.buildmode.objholder, /area) || istype(holder.buildmode.copycat, /area)) + //In case of a selective fill, make sure the turf fits into the criteria before changing it if(areaAction == SELECTIVE_FILL) if(strict) if(T.type != chosen) @@ -521,6 +547,23 @@ obj/effect/bmode/buildholder/New() else if(!istype(T, chosen)) continue + + var/area/A + if(istype(holder.buildmode.copycat, /area)) + A = holder.buildmode.copycat + else + A = locate(holder.buildmode.objholder) + + T.set_area(A) + else if(ispath(holder.buildmode.objholder, /turf)) + if(areaAction == SELECTIVE_FILL) + if(strict) + if(T.type != chosen) + continue + else + if(!istype(T, chosen)) + continue + T.ChangeTurf(holder.buildmode.objholder) else if(areaAction == SELECTIVE_FILL) @@ -552,6 +595,10 @@ obj/effect/bmode/buildholder/New() T.ChangeTurf(holder.buildmode.copycat.type) spawn(1) T.appearance = holder.buildmode.copycat.appearance + else if(isarea(holder.buildmode.copycat)) + var/turf/T = get_turf(object) + T.set_area(holder.buildmode.copycat) + return else var/atom/movable/A = new holder.buildmode.copycat.type(get_turf(object)) if(istype(A)) @@ -559,10 +606,14 @@ obj/effect/bmode/buildholder/New() A.dir = holder.builddir.dir log_admin("[key_name(usr)] made a [holder.buildmode.copycat.type] at [formatJumpTo(RT)]") else - if(ispath(holder.buildmode.objholder,/turf)) + if(ispath(holder.buildmode.objholder,/turf)) //Handle turf changing var/turf/T = get_turf(object) T.ChangeTurf(holder.buildmode.objholder) - else + else if(ispath(holder.buildmode.objholder,/area)) //Handle area changing + var/area/A = locate(holder.buildmode.objholder) + var/turf/T = get_turf(object) + T.set_area(A) + else //Handle object spawning var/obj/A = new holder.buildmode.objholder (get_turf(object)) if(istype(A)) A.dir = holder.builddir.dir @@ -579,6 +630,35 @@ obj/effect/bmode/buildholder/New() holder.buildmode.copycat = object to_chat(usr, "You will now build a lookalike of [object] when clicking.") else + //Handle leaving area editing mode + if(istype(holder.buildmode.copycat, /area)) + var/area/A = holder.buildmode.copycat + if(get_area(object) == A) //Leave area editing mode by copying an object from a different area + //Note: it would be much better to do this on any middle mouse button click + //I tried it, and it made this too sensitive, since after a double click, a THIRD mouse click was registered, + //so it would immediately leave area editing mode if you clicked on a turf too quickly + + //Blame the old coders + return + + holder.buildmode.copycat = null + user.client.images.Remove(holder.buildmode.area_overlay) + to_chat(usr, "No longer editing area.") + return + + //Handle entering area editing mode + if(isturf(object)) + //Middle mouse buttoning a turf twice will enter area editing mode for its area. Use the build-adv function to modify the area + if(holder.buildmode.copycat == object) + to_chat(usr, "Modifying area of [object] ([formatJumpTo(object)]). Use the build-adv function to add tiles. Middle-click anywhere outside of the area to stop.") + var/area/A = get_area(object) + holder.buildmode.copycat = A + holder.buildmode.area_overlay.loc = A + user.client.images.Add(holder.buildmode.area_overlay) //Enable area visualisation + return + else + holder.buildmode.copycat = object + holder.buildmode.objholder = object.type to_chat(usr, "You will now build [object.type] when clicking.") diff --git a/code/game/objects/structures/ladders.dm b/code/game/objects/structures/ladders.dm index 1aad48b34a2..029ac53730a 100644 --- a/code/game/objects/structures/ladders.dm +++ b/code/game/objects/structures/ladders.dm @@ -49,9 +49,11 @@ var/list/ladders = list() if(L.id == id) if(L.height == (height - 1)) - down = L + src.down = L + L.up = src else if(L.height == (height + 1)) - up = L + src.up = L + L.down = src if(up && down) //if both our connections are filled break diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index 6a89bed5c85..d10742e0b34 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -1309,6 +1309,11 @@ var/global/floorIsLava = 0 if(ispath(chosen,/turf)) var/turf/T = get_turf(usr.loc) T.ChangeTurf(chosen) + else if(ispath(chosen, /area)) + var/area/A = locate(chosen) + var/turf/T = get_turf(usr.loc) + + T.set_area(A) else new chosen(usr.loc) diff --git a/code/modules/admin/verbs/modifyvariables.dm b/code/modules/admin/verbs/modifyvariables.dm index d9263c07887..c2233f7d3b8 100644 --- a/code/modules/admin/verbs/modifyvariables.dm +++ b/code/modules/admin/verbs/modifyvariables.dm @@ -194,14 +194,15 @@ var/list/forbidden_varedit_object_types = list( to_chat(user, "Unknown type: [selected_type]") if(edited_datum && edited_variable) + if(edited_datum.variable_edited(edited_variable, old_value, new_value)) + //variable_edited() can block the edit in case there's special behavior for a variable (for example, updating lights after they're changed) + new_value = edited_datum.vars[edited_variable] + else + edited_datum.vars[edited_variable] = new_value + if(logging) log_admin("[key_name(usr)] modified [edited_datum]'s [edited_variable] to [new_value]") - if(edited_datum.variable_edited(edited_variable, old_value, new_value)) - new_value = old_value //Return the old value if the variable_edited proc blocked the edit - - edited_datum.vars[edited_variable] = new_value - return new_value #undef V_MARKED_DATUM