From f2a3b06c13a2e02fa5027bb2f6958c5c3bb4feb1 Mon Sep 17 00:00:00 2001
From: kevinz000 <2003111+kevinz000@users.noreply.github.com>
Date: Sat, 29 Dec 2018 03:11:26 -0800
Subject: [PATCH] Refactors the Preferences window to use appearances (#41978)
Instead of using expensive getFlatIcon() calls, character previews are now shown using appearance clones in a second map window.
Its creating a secondary map and adding mut_appearances as screen objs on that map.
There are 1 set of dummy objects per client, it also only creates them while the preview window is open and garbage collects them when it's closed.
Because it creates the MA from the main preview dummy mob, the dummy mob's appearance remains a seperate object and they don't affect each other
---
code/datums/browser.dm | 1 -
code/modules/client/client_defines.dm | 4 +++
code/modules/client/client_procs.dm | 21 ++++++++++++++
code/modules/client/preferences.dm | 26 +++++++----------
.../mob/dead/new_player/preferences_setup.dm | 29 ++-----------------
interface/skin.dmf | 29 +++++++++++++++++++
6 files changed, 68 insertions(+), 42 deletions(-)
diff --git a/code/datums/browser.dm b/code/datums/browser.dm
index f13123d99223..b6536b6b4115 100644
--- a/code/datums/browser.dm
+++ b/code/datums/browser.dm
@@ -461,4 +461,3 @@
// so just reset the user mob's machine var
if(src && src.mob)
src.mob.unset_machine()
- return
diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm
index f1e405d61418..11b55b6ea7bc 100644
--- a/code/modules/client/client_defines.dm
+++ b/code/modules/client/client_defines.dm
@@ -74,4 +74,8 @@
var/datum/player_details/player_details //these persist between logins/logouts during the same round.
+<<<<<<< HEAD
var/encoding = "1252" // yogs - LibVG
+=======
+ var/list/char_render_holders //Should only be a key-value list of north/south/east/west = obj/screen.
+>>>>>>> 620db42963... Refactors the Preferences window to use appearances (#41978)
diff --git a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm
index f6a2baab1eb5..81a09b8275b4 100644
--- a/code/modules/client/client_procs.dm
+++ b/code/modules/client/client_procs.dm
@@ -453,6 +453,7 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
GLOB.ahelp_tickets.ClientLogout(src)
GLOB.directory -= ckey
GLOB.clients -= src
+ QDEL_LIST_ASSOC_VAL(char_render_holders)
if(movingmob != null)
movingmob.client_mobs_in_contents -= mob
UNSETEMPTY(movingmob.client_mobs_in_contents)
@@ -881,3 +882,23 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
/client/proc/AnnouncePR(announcement)
if(prefs && prefs.chat_toggles & CHAT_PULLR)
to_chat(src, announcement)
+
+/client/proc/show_character_previews(mutable_appearance/MA)
+ var/pos = 0
+ for(var/D in GLOB.cardinals)
+ pos++
+ var/obj/screen/O = LAZYACCESS(char_render_holders, "[D]")
+ if(!O)
+ O = new
+ LAZYSET(char_render_holders, "[D]", O)
+ screen |= O
+ O.appearance = MA
+ O.dir = D
+ O.screen_loc = "character_preview_map:0,[pos]"
+
+/client/proc/clear_character_previews()
+ for(var/index in char_render_holders)
+ var/obj/screen/S = char_render_holders[index]
+ screen -= S
+ qdel(S)
+ char_render_holders = null
diff --git a/code/modules/client/preferences.dm b/code/modules/client/preferences.dm
index 20a3ca736798..78417ad7b84e 100644
--- a/code/modules/client/preferences.dm
+++ b/code/modules/client/preferences.dm
@@ -25,7 +25,6 @@ GLOBAL_LIST_EMPTY(preferences_datums)
//If it's 0, that's good, if it's anything but 0, the owner of this prefs file's antag choices were,
//autocorrected this round, not that you'd need to check that.
-
var/UI_style = null
var/buttons_locked = FALSE
var/hotkeys = TRUE // yogs - Rebindable Keybindings
@@ -71,9 +70,6 @@ GLOBAL_LIST_EMPTY(preferences_datums)
var/preferred_ai_core_display = "Blue"
var/prefered_security_department = SEC_DEPT_RANDOM
- //Mob preview
- var/icon/preview_icon = null
-
//Quirk list
var/list/positive_quirks = list()
var/list/negative_quirks = list()
@@ -155,7 +151,6 @@ GLOBAL_LIST_EMPTY(preferences_datums)
if(!user || !user.client)
return
update_preview_icon()
- user << browse_rsc(preview_icon, "previewicon.png")
var/list/dat = list("
")
dat += "Character Settings"
@@ -227,11 +222,7 @@ GLOBAL_LIST_EMPTY(preferences_datums)
dat += "Preferred AI Core Display: [preferred_ai_core_display]
"
dat += "Preferred Security Department: [prefered_security_department]
"
- dat += ""
-
- dat += ""
-
- dat += " | "
+ dat += ""
dat += "Body
"
dat += "Random Body "
@@ -724,9 +715,11 @@ GLOBAL_LIST_EMPTY(preferences_datums)
dat += "Reset Setup"
dat += ""
- var/datum/browser/popup = new(user, "preferences", "Character Setup
", 640, 770)
+ winshow(user, "preferences_window", TRUE)
+ var/datum/browser/popup = new(user, "preferences_browser", "Character Setup
", 640, 770)
popup.set_content(dat.Join())
popup.open(FALSE)
+ onclose(user, "preferences_window", src)
#undef APPEARANCE_CATEGORY_COLUMN
#undef MAX_MUTANT_ROWS
@@ -857,12 +850,10 @@ GLOBAL_LIST_EMPTY(preferences_datums)
HTML += "
[message]"
HTML += "Reset Preferences"
- user << browse(null, "window=preferences")
var/datum/browser/popup = new(user, "mob_occupation", "Occupation Preferences
", width, height)
popup.set_window_options("can_close=0")
popup.set_content(HTML)
popup.open(FALSE)
- return
/datum/preferences/proc/SetJobPreferenceLevel(datum/job/job, level)
if (!job)
@@ -1051,12 +1042,10 @@ GLOBAL_LIST_EMPTY(preferences_datums)
[quirk_name] - [initial(T.desc)]
"
dat += "
Reset Quirks"
- user << browse(null, "window=preferences")
var/datum/browser/popup = new(user, "mob_occupation", "Quirk Preferences
", 900, 600) //no reason not to reuse the occupation window, as it's cleaner that way
popup.set_window_options("can_close=0")
popup.set_content(dat.Join())
popup.open(FALSE)
- return
/datum/preferences/proc/GetQuirkBalance()
var/bal = 0
@@ -1065,6 +1054,13 @@ GLOBAL_LIST_EMPTY(preferences_datums)
bal -= initial(T.value)
return bal
+/datum/preferences/Topic(href, href_list, hsrc) //yeah, gotta do this I guess..
+ . = ..()
+ if(href_list["close"])
+ var/client/C = usr.client
+ if(C)
+ C.clear_character_previews()
+
/datum/preferences/proc/process_link(mob/user, list/href_list)
// yogs start - Donor features
if(href_list["preference"] == "donor")
diff --git a/code/modules/mob/dead/new_player/preferences_setup.dm b/code/modules/mob/dead/new_player/preferences_setup.dm
index 6588c08ebbce..b74dd1b28be5 100644
--- a/code/modules/mob/dead/new_player/preferences_setup.dm
+++ b/code/modules/mob/dead/new_player/preferences_setup.dm
@@ -25,12 +25,10 @@
if(job_engsec_high)
switch(job_engsec_high)
if(AI_JF)
- preview_icon = icon('icons/mob/ai.dmi', resolve_ai_icon(preferred_ai_core_display), SOUTH)
- preview_icon.Scale(64, 64)
+ parent.show_character_previews(image('icons/mob/ai.dmi', icon_state = resolve_ai_icon(preferred_ai_core_display), dir = SOUTH))
return
if(CYBORG)
- preview_icon = icon('icons/mob/robots.dmi', "robot", SOUTH)
- preview_icon.Scale(64, 64)
+ parent.show_character_previews(image('icons/mob/robots.dmi', icon_state = "robot", dir = SOUTH))
return
// Set up the dummy for its photoshoot
@@ -61,26 +59,5 @@
mannequin.job = previewJob.title
previewJob.equip(mannequin, TRUE)
COMPILE_OVERLAYS(mannequin)
- CHECK_TICK
- preview_icon = icon('icons/effects/effects.dmi', "nothing")
- preview_icon.Scale(48+32, 16+32)
- CHECK_TICK
- mannequin.setDir(NORTH)
-
- var/icon/stamp = getFlatIcon(mannequin)
- CHECK_TICK
- preview_icon.Blend(stamp, ICON_OVERLAY, 25, 17)
- CHECK_TICK
- mannequin.setDir(WEST)
- stamp = getFlatIcon(mannequin)
- CHECK_TICK
- preview_icon.Blend(stamp, ICON_OVERLAY, 1, 9)
- CHECK_TICK
- mannequin.setDir(SOUTH)
- stamp = getFlatIcon(mannequin)
- CHECK_TICK
- preview_icon.Blend(stamp, ICON_OVERLAY, 49, 1)
- CHECK_TICK
- preview_icon.Scale(preview_icon.Width() * 2, preview_icon.Height() * 2) // Scaling here to prevent blurring in the browser.
- CHECK_TICK
+ parent.show_character_previews(new /mutable_appearance(mannequin))
unset_busy_human_dummy(DUMMY_HUMAN_SLOT_PREFERENCES)
diff --git a/interface/skin.dmf b/interface/skin.dmf
index 75f58db1bba1..f180581cf92b 100644
--- a/interface/skin.dmf
+++ b/interface/skin.dmf
@@ -1,5 +1,6 @@
macro "default"
+
menu "menu"
elem
name = "&File"
@@ -277,6 +278,34 @@ window "outputwindow"
is-default = true
saved-params = ""
+window "preferences_window"
+ elem "preferences_window"
+ type = MAIN
+ pos = 372,0
+ size = 1120x1000
+ anchor1 = none
+ anchor2 = none
+ background-color = none
+ is-visible = false
+ saved-params = "pos;size;is-minimized;is-maximized"
+ statusbar = false
+ elem "preferences_browser"
+ type = BROWSER
+ pos = -8,-8
+ size = 896x1008
+ anchor1 = 0,0
+ anchor2 = 90,100
+ background-color = none
+ saved-params = ""
+ elem "character_preview_map"
+ type = MAP
+ pos = 887,0
+ size = 313x1000
+ anchor1 = 90,0
+ anchor2 = 100,100
+ right-click = true
+ saved-params = "zoom;letterbox;zoom-mode"
+
window "statwindow"
elem "statwindow"
type = MAIN