This commit is contained in:
@@ -35,101 +35,368 @@
|
||||
else
|
||||
painting = null
|
||||
|
||||
|
||||
//////////////
|
||||
// CANVASES //
|
||||
//////////////
|
||||
|
||||
#define AMT_OF_CANVASES 4 //Keep this up to date or shit will break.
|
||||
|
||||
//To safe memory on making /icons we cache the blanks..
|
||||
GLOBAL_LIST_INIT(globalBlankCanvases, new(AMT_OF_CANVASES))
|
||||
|
||||
/obj/item/canvas
|
||||
name = "canvas"
|
||||
desc = "Draw out your soul on this canvas!"
|
||||
icon = 'icons/obj/artstuff.dmi'
|
||||
icon_state = "11x11"
|
||||
resistance_flags = FLAMMABLE
|
||||
var/whichGlobalBackup = 1 //List index
|
||||
var/width = 11
|
||||
var/height = 11
|
||||
var/list/grid
|
||||
var/canvas_color = "#ffffff" //empty canvas color
|
||||
var/ui_x = 400
|
||||
var/ui_y = 400
|
||||
var/used = FALSE
|
||||
var/painting_name //Painting name, this is set after framing.
|
||||
var/finalized = FALSE //Blocks edits
|
||||
var/author_ckey
|
||||
var/icon_generated = FALSE
|
||||
var/icon/generated_icon
|
||||
|
||||
/obj/item/canvas/nineteenXnineteen
|
||||
icon_state = "19x19"
|
||||
whichGlobalBackup = 2
|
||||
// Painting overlay offset when framed
|
||||
var/framed_offset_x = 11
|
||||
var/framed_offset_y = 10
|
||||
|
||||
/obj/item/canvas/twentythreeXnineteen
|
||||
icon_state = "23x19"
|
||||
whichGlobalBackup = 3
|
||||
pixel_x = 10
|
||||
pixel_y = 9
|
||||
|
||||
/obj/item/canvas/twentythreeXtwentythree
|
||||
icon_state = "23x23"
|
||||
whichGlobalBackup = 4
|
||||
|
||||
//HEY YOU
|
||||
//ARE YOU READING THE CODE FOR CANVASES?
|
||||
//ARE YOU AWARE THEY CRASH HALF THE SERVER WHEN SOMEONE DRAWS ON THEM...
|
||||
//...AND NOBODY CAN FIGURE OUT WHY?
|
||||
//THEN GO ON BRAVE TRAVELER
|
||||
//TRY TO FIX THEM AND REMOVE THIS CODE
|
||||
/obj/item/canvas/Initialize()
|
||||
..()
|
||||
return INITIALIZE_HINT_QDEL //Delete on creation
|
||||
. = ..()
|
||||
reset_grid()
|
||||
|
||||
//Find the right size blank canvas
|
||||
/obj/item/canvas/proc/getGlobalBackup()
|
||||
. = null
|
||||
if(GLOB.globalBlankCanvases[whichGlobalBackup])
|
||||
. = GLOB.globalBlankCanvases[whichGlobalBackup]
|
||||
else
|
||||
var/icon/I = icon(initial(icon),initial(icon_state))
|
||||
GLOB.globalBlankCanvases[whichGlobalBackup] = I
|
||||
. = I
|
||||
/obj/item/canvas/proc/reset_grid()
|
||||
grid = new/list(width,height)
|
||||
for(var/x in 1 to width)
|
||||
for(var/y in 1 to height)
|
||||
grid[x][y] = canvas_color
|
||||
|
||||
/obj/item/canvas/attack_self(mob/user)
|
||||
. = ..()
|
||||
ui_interact(user)
|
||||
|
||||
/obj/item/canvas/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = FALSE, \
|
||||
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.default_state)
|
||||
|
||||
//One pixel increments
|
||||
/obj/item/canvas/attackby(obj/item/I, mob/user, params)
|
||||
//Click info
|
||||
var/list/click_params = params2list(params)
|
||||
var/pixX = text2num(click_params["icon-x"])
|
||||
var/pixY = text2num(click_params["icon-y"])
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "Canvas", name, ui_x, ui_y, master_ui, state)
|
||||
ui.set_autoupdate(FALSE)
|
||||
ui.open()
|
||||
|
||||
//Should always be true, otherwise you didn't click the object, but let's check because SS13~
|
||||
if(!click_params || !click_params["icon-x"] || !click_params["icon-y"])
|
||||
return
|
||||
|
||||
//Cleaning one pixel with a soap or rag
|
||||
if(istype(I, /obj/item/soap) || istype(I, /obj/item/reagent_containers/rag))
|
||||
//Pixel info created only when needed
|
||||
var/icon/masterpiece = icon(icon,icon_state)
|
||||
var/thePix = masterpiece.GetPixel(pixX,pixY)
|
||||
var/icon/Ico = getGlobalBackup()
|
||||
if(!Ico)
|
||||
qdel(masterpiece)
|
||||
return
|
||||
|
||||
var/theOriginalPix = Ico.GetPixel(pixX,pixY)
|
||||
if(thePix != theOriginalPix) //colour changed
|
||||
DrawPixelOn(theOriginalPix,pixX,pixY)
|
||||
qdel(masterpiece)
|
||||
|
||||
//Drawing one pixel with a crayon
|
||||
else if(istype(I, /obj/item/toy/crayon))
|
||||
var/obj/item/toy/crayon/C = I
|
||||
DrawPixelOn(C.paint_color, pixX, pixY)
|
||||
/obj/item/canvas/attackby(obj/item/I, mob/living/user, params)
|
||||
if(user.a_intent == INTENT_HELP)
|
||||
ui_interact(user)
|
||||
else
|
||||
return ..()
|
||||
|
||||
/obj/item/canvas/ui_data(mob/user)
|
||||
. = ..()
|
||||
.["grid"] = grid
|
||||
.["name"] = painting_name
|
||||
.["finalized"] = finalized
|
||||
|
||||
//Clean the whole canvas
|
||||
/obj/item/canvas/attack_self(mob/user)
|
||||
if(!user)
|
||||
/obj/item/canvas/examine(mob/user)
|
||||
. = ..()
|
||||
ui_interact(user)
|
||||
|
||||
/obj/item/canvas/ui_act(action, params)
|
||||
. = ..()
|
||||
if(. || finalized)
|
||||
return
|
||||
var/icon/blank = getGlobalBackup()
|
||||
if(blank)
|
||||
//it's basically a giant etch-a-sketch
|
||||
icon = blank
|
||||
user.visible_message("<span class='notice'>[user] cleans the canvas.</span>","<span class='notice'>You clean the canvas.</span>")
|
||||
var/mob/user = usr
|
||||
switch(action)
|
||||
if("paint")
|
||||
var/obj/item/I = user.get_active_held_item()
|
||||
var/color = get_paint_tool_color(I)
|
||||
if(!color)
|
||||
return FALSE
|
||||
var/x = text2num(params["x"])
|
||||
var/y = text2num(params["y"])
|
||||
grid[x][y] = color
|
||||
used = TRUE
|
||||
update_icon()
|
||||
. = TRUE
|
||||
if("finalize")
|
||||
. = TRUE
|
||||
if(!finalized)
|
||||
finalize(user)
|
||||
|
||||
/obj/item/canvas/proc/finalize(mob/user)
|
||||
finalized = TRUE
|
||||
author_ckey = user.ckey
|
||||
generate_proper_overlay()
|
||||
try_rename(user)
|
||||
|
||||
/obj/item/canvas/update_overlays()
|
||||
. = ..()
|
||||
if(!icon_generated)
|
||||
if(used)
|
||||
var/mutable_appearance/detail = mutable_appearance(icon,"[icon_state]wip")
|
||||
detail.pixel_x = 1
|
||||
detail.pixel_y = 1
|
||||
. += detail
|
||||
else
|
||||
var/mutable_appearance/detail = mutable_appearance(generated_icon)
|
||||
detail.pixel_x = 1
|
||||
detail.pixel_y = 1
|
||||
. += detail
|
||||
|
||||
/obj/item/canvas/proc/generate_proper_overlay()
|
||||
if(icon_generated)
|
||||
return
|
||||
var/png_filename = "data/paintings/temp_painting.png"
|
||||
var/result = rustg_dmi_create_png(png_filename,"[width]","[height]",get_data_string())
|
||||
if(result)
|
||||
CRASH("Error generating painting png : [result]")
|
||||
generated_icon = new(png_filename)
|
||||
icon_generated = TRUE
|
||||
update_icon()
|
||||
|
||||
/obj/item/canvas/proc/get_data_string()
|
||||
var/list/data = list()
|
||||
for(var/y in 1 to height)
|
||||
for(var/x in 1 to width)
|
||||
data += grid[x][y]
|
||||
return data.Join("")
|
||||
|
||||
//Todo make this element ?
|
||||
/obj/item/canvas/proc/get_paint_tool_color(obj/item/I)
|
||||
if(!I)
|
||||
return
|
||||
if(istype(I, /obj/item/toy/crayon))
|
||||
var/obj/item/toy/crayon/C = I
|
||||
return C.paint_color
|
||||
else if(istype(I, /obj/item/pen))
|
||||
var/obj/item/pen/P = I
|
||||
switch(P.colour)
|
||||
if("black")
|
||||
return "#000000"
|
||||
if("blue")
|
||||
return "#0000ff"
|
||||
if("red")
|
||||
return "#ff0000"
|
||||
return P.colour
|
||||
else if(istype(I, /obj/item/soap) || istype(I, /obj/item/reagent_containers/glass/rag))
|
||||
return canvas_color
|
||||
|
||||
/obj/item/canvas/proc/try_rename(mob/user)
|
||||
var/new_name = stripped_input(user,"What do you want to name the painting?")
|
||||
if(!painting_name && new_name && user.canUseTopic(src,BE_CLOSE))
|
||||
painting_name = new_name
|
||||
SStgui.update_uis(src)
|
||||
|
||||
/obj/item/canvas/nineteenXnineteen
|
||||
icon_state = "19x19"
|
||||
width = 19
|
||||
height = 19
|
||||
ui_x = 600
|
||||
ui_y = 600
|
||||
pixel_x = 6
|
||||
pixel_y = 9
|
||||
framed_offset_x = 8
|
||||
framed_offset_y = 9
|
||||
|
||||
/obj/item/canvas/twentythreeXnineteen
|
||||
icon_state = "23x19"
|
||||
width = 23
|
||||
height = 19
|
||||
ui_x = 800
|
||||
ui_y = 600
|
||||
pixel_x = 4
|
||||
pixel_y = 10
|
||||
framed_offset_x = 6
|
||||
framed_offset_y = 8
|
||||
|
||||
/obj/item/canvas/twentythreeXtwentythree
|
||||
icon_state = "23x23"
|
||||
width = 23
|
||||
height = 23
|
||||
ui_x = 800
|
||||
ui_y = 800
|
||||
pixel_x = 5
|
||||
pixel_y = 9
|
||||
framed_offset_x = 5
|
||||
framed_offset_y = 6
|
||||
|
||||
/obj/item/wallframe/painting
|
||||
name = "painting frame"
|
||||
desc = "The perfect showcase for your favorite deathtrap memories."
|
||||
icon = 'icons/obj/decals.dmi'
|
||||
custom_materials = null
|
||||
flags_1 = 0
|
||||
icon_state = "frame-empty"
|
||||
result_path = /obj/structure/sign/painting
|
||||
|
||||
/obj/structure/sign/painting
|
||||
name = "Painting"
|
||||
desc = "Art or \"Art\"? You decide."
|
||||
icon = 'icons/obj/decals.dmi'
|
||||
icon_state = "frame-empty"
|
||||
buildable_sign = FALSE
|
||||
var/obj/item/canvas/C
|
||||
var/persistence_id
|
||||
|
||||
/obj/structure/sign/painting/Initialize(mapload, dir, building)
|
||||
. = ..()
|
||||
SSpersistence.painting_frames += src
|
||||
AddComponent(/datum/component/art, 20)
|
||||
if(dir)
|
||||
setDir(dir)
|
||||
if(building)
|
||||
pixel_x = (dir & 3)? 0 : (dir == 4 ? -30 : 30)
|
||||
pixel_y = (dir & 3)? (dir ==1 ? -30 : 30) : 0
|
||||
|
||||
/obj/structure/sign/painting/Destroy()
|
||||
. = ..()
|
||||
SSpersistence.painting_frames -= src
|
||||
|
||||
/obj/structure/sign/painting/attackby(obj/item/I, mob/user, params)
|
||||
if(!C && istype(I, /obj/item/canvas))
|
||||
frame_canvas(user,I)
|
||||
else if(C && !C.painting_name && istype(I,/obj/item/pen))
|
||||
try_rename(user)
|
||||
else
|
||||
return ..()
|
||||
|
||||
/obj/structure/sign/painting/examine(mob/user)
|
||||
. = ..()
|
||||
if(C)
|
||||
C.ui_interact(user,state = GLOB.physical_obscured_state)
|
||||
|
||||
/obj/structure/sign/painting/wirecutter_act(mob/living/user, obj/item/I)
|
||||
. = ..()
|
||||
if(C)
|
||||
C.forceMove(drop_location())
|
||||
C = null
|
||||
to_chat(user, "<span class='notice'>You remove the painting from the frame.</span>")
|
||||
update_icon()
|
||||
return TRUE
|
||||
|
||||
/obj/structure/sign/painting/proc/frame_canvas(mob/user,obj/item/canvas/new_canvas)
|
||||
if(user.transferItemToLoc(new_canvas,src))
|
||||
C = new_canvas
|
||||
if(!C.finalized)
|
||||
C.finalize(user)
|
||||
to_chat(user,"<span class='notice'>You frame [C].</span>")
|
||||
update_icon()
|
||||
|
||||
/obj/structure/sign/painting/proc/try_rename(mob/user)
|
||||
if(!C.painting_name)
|
||||
C.try_rename(user)
|
||||
|
||||
/obj/structure/sign/painting/update_icon_state()
|
||||
. = ..()
|
||||
if(C && C.generated_icon)
|
||||
icon_state = null
|
||||
else
|
||||
icon_state = "frame-empty"
|
||||
|
||||
|
||||
#undef AMT_OF_CANVASES
|
||||
/obj/structure/sign/painting/update_overlays()
|
||||
. = ..()
|
||||
if(C && C.generated_icon)
|
||||
var/mutable_appearance/MA = mutable_appearance(C.generated_icon)
|
||||
MA.pixel_x = C.framed_offset_x
|
||||
MA.pixel_y = C.framed_offset_y
|
||||
. += MA
|
||||
var/mutable_appearance/frame = mutable_appearance(C.icon,"[C.icon_state]frame")
|
||||
frame.pixel_x = C.framed_offset_x - 1
|
||||
frame.pixel_y = C.framed_offset_y - 1
|
||||
. += frame
|
||||
|
||||
/obj/structure/sign/painting/proc/load_persistent()
|
||||
if(!persistence_id)
|
||||
return
|
||||
if(!SSpersistence.paintings || !SSpersistence.paintings[persistence_id] || !length(SSpersistence.paintings[persistence_id]))
|
||||
return
|
||||
var/list/chosen = pick(SSpersistence.paintings[persistence_id])
|
||||
var/title = chosen["title"]
|
||||
var/author = chosen["ckey"]
|
||||
var/png = "data/paintings/[persistence_id]/[chosen["md5"]].png"
|
||||
if(!fexists(png))
|
||||
stack_trace("Persistent painting [chosen["md5"]].png was not found in [persistence_id] directory.")
|
||||
return
|
||||
var/icon/I = new(png)
|
||||
var/obj/item/canvas/new_canvas
|
||||
var/w = I.Width()
|
||||
var/h = I.Height()
|
||||
for(var/T in typesof(/obj/item/canvas))
|
||||
new_canvas = T
|
||||
if(initial(new_canvas.width) == w && initial(new_canvas.height) == h)
|
||||
new_canvas = new T(src)
|
||||
break
|
||||
new_canvas.fill_grid_from_icon(I)
|
||||
new_canvas.generated_icon = I
|
||||
new_canvas.icon_generated = TRUE
|
||||
new_canvas.finalized = TRUE
|
||||
new_canvas.painting_name = title
|
||||
new_canvas.author_ckey = author
|
||||
C = new_canvas
|
||||
update_icon()
|
||||
|
||||
/obj/structure/sign/painting/proc/save_persistent()
|
||||
if(!persistence_id || !C)
|
||||
return
|
||||
if(sanitize_filename(persistence_id) != persistence_id)
|
||||
stack_trace("Invalid persistence_id - [persistence_id]")
|
||||
return
|
||||
var/data = C.get_data_string()
|
||||
var/md5 = md5(data)
|
||||
var/list/current = SSpersistence.paintings[persistence_id]
|
||||
if(!current)
|
||||
current = list()
|
||||
for(var/list/entry in current)
|
||||
if(entry["md5"] == md5)
|
||||
return
|
||||
var/png_directory = "data/paintings/[persistence_id]/"
|
||||
var/png_path = png_directory + "[md5].png"
|
||||
var/result = rustg_dmi_create_png(png_path,"[C.width]","[C.height]",data)
|
||||
if(result)
|
||||
CRASH("Error saving persistent painting: [result]")
|
||||
current += list(list("title" = C.painting_name , "md5" = md5, "ckey" = C.author_ckey))
|
||||
SSpersistence.paintings[persistence_id] = current
|
||||
|
||||
/obj/item/canvas/proc/fill_grid_from_icon(icon/I)
|
||||
var/h = I.Height() + 1
|
||||
for(var/x in 1 to width)
|
||||
for(var/y in 1 to height)
|
||||
grid[x][y] = I.GetPixel(x,h-y)
|
||||
|
||||
//Presets for art gallery mapping, for paintings to be shared across stations
|
||||
/obj/structure/sign/painting/library
|
||||
persistence_id = "library"
|
||||
|
||||
/obj/structure/sign/painting/library_secure
|
||||
persistence_id = "library_secure"
|
||||
|
||||
/obj/structure/sign/painting/library_private // keep your smut away from prying eyes, or non-librarians at least
|
||||
persistence_id = "library_private"
|
||||
|
||||
/obj/structure/sign/painting/vv_get_dropdown()
|
||||
. = ..()
|
||||
VV_DROPDOWN_OPTION(VV_HK_REMOVE_PAINTING, "Remove Persistent Painting")
|
||||
|
||||
/obj/structure/sign/painting/vv_do_topic(list/href_list)
|
||||
. = ..()
|
||||
if(href_list[VV_HK_REMOVE_PAINTING])
|
||||
if(!check_rights(NONE))
|
||||
return
|
||||
var/mob/user = usr
|
||||
if(!persistence_id || !C)
|
||||
to_chat(user,"<span class='warning'>This is not a persistent painting.</span>")
|
||||
return
|
||||
var/md5 = md5(C.get_data_string())
|
||||
var/author = C.author_ckey
|
||||
var/list/current = SSpersistence.paintings[persistence_id]
|
||||
if(current)
|
||||
for(var/list/entry in current)
|
||||
if(entry["md5"] == md5)
|
||||
current -= entry
|
||||
var/png = "data/paintings/[persistence_id]/[md5].png"
|
||||
fdel(png)
|
||||
for(var/obj/structure/sign/painting/P in SSpersistence.painting_frames)
|
||||
if(P.C && md5(P.C.get_data_string()) == md5)
|
||||
QDEL_NULL(P.C)
|
||||
log_admin("[key_name(user)] has deleted a persistent painting made by [author].")
|
||||
message_admins("<span class='notice'>[key_name_admin(user)] has deleted persistent painting made by [author].</span>")
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
datum/tgui/master_ui = null, datum/ui_state/state = GLOB.physical_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "tank_dispenser", name, 275, 103, master_ui, state)
|
||||
ui = new(user, src, ui_key, "TankDispenser", name, 275, 103, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
/obj/structure/tank_dispenser/ui_data(mob/user)
|
||||
|
||||
Reference in New Issue
Block a user