forked from ss220-space/Paradise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code_imp: pref holder & improve pref viewer (ss220-space#6422)
* 1 * dme * rework to element * 2 * fastfix * inconsistent * 3 * fix x10 * fix x11 * fix x12 * parenthesis.... * fix x14
- Loading branch information
Showing
14 changed files
with
118 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
#define HASBIT(CONTAINER, FLAG) ((CONTAINER) & (FLAG)) | ||
|
||
#define SETBIT(CONTAINER, FLAG) (CONTAINER |= (FLAG)) | ||
#define SETBIT(CONTAINER, FLAG) ((CONTAINER) |= (FLAG)) | ||
|
||
#define CLEARBIT(CONTAINER, FLAG) (CONTAINER &= ~(FLAG)) | ||
#define CLEARBIT(CONTAINER, FLAG) ((CONTAINER) &= ~(FLAG)) | ||
|
||
#define TOGGLEBIT(CONTAINER, FLAG) (CONTAINER ^= (FLAG)) | ||
#define TOGGLEBIT(CONTAINER, FLAG) ((CONTAINER) ^= (FLAG)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/datum/component/pref_holder | ||
var/list/preferences | ||
|
||
/datum/component/pref_holder/Destroy(force) | ||
LAZYNULL(preferences) | ||
|
||
return ..() | ||
|
||
/datum/component/pref_holder/Initialize(list/preferences) | ||
var/mob/target = parent | ||
|
||
if(!istype(target)) | ||
return COMPONENT_INCOMPATIBLE | ||
|
||
src.preferences = preferences || forge_preferences() | ||
|
||
/datum/component/pref_holder/RegisterWithParent() | ||
RegisterSignal(parent, COMSIG_BODY_TRANSFER_TO, PROC_REF(on_mind_transfer)) | ||
|
||
/datum/component/pref_holder/UnregisterFromParent() | ||
UnregisterSignal(parent, COMSIG_BODY_TRANSFER_TO) | ||
|
||
/datum/component/pref_holder/proc/on_mind_transfer(mob/source) | ||
SIGNAL_HANDLER | ||
|
||
preferences = forge_preferences() | ||
|
||
/datum/component/pref_holder/proc/forge_preferences() | ||
var/mob/mob = parent | ||
|
||
if(!mob.client) | ||
return | ||
|
||
var/list/prefs | ||
|
||
for(var/datum/preference_info/pref as anything in GLOB.preferences_info) | ||
var/datum/preference_toggle/toggle = pref.get_preference_toggle() | ||
|
||
if(!toggle) | ||
continue | ||
|
||
if(!HASBIT(mob.client.prefs.toggles, toggle.preftoggle_bitflag) \ | ||
&& !HASBIT(mob.client.prefs.toggles2, toggle.preftoggle_bitflag) | ||
) | ||
continue | ||
|
||
LAZYADD(prefs, new pref.type) | ||
|
||
return prefs |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/datum/element/pref_viewer | ||
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY | ||
var/list/preferences_to_show | ||
|
||
/datum/element/pref_viewer/Destroy(force) | ||
LAZYNULL(preferences_to_show) | ||
|
||
return ..() | ||
|
||
/datum/element/pref_viewer/Attach( | ||
mob/target, | ||
list/preferences_to_show | ||
) | ||
. = ..() | ||
|
||
if(!istype(target)) | ||
return ELEMENT_INCOMPATIBLE | ||
|
||
src.preferences_to_show = preferences_to_show | ||
RegisterSignal(target, COMSIG_MOB_RUN_EXAMINATE, PROC_REF(on_examine)) | ||
|
||
/datum/element/pref_viewer/Detach(mob/target) | ||
. = ..() | ||
|
||
UnregisterSignal(target, COMSIG_MOB_RUN_EXAMINATE) | ||
|
||
/datum/element/pref_viewer/proc/on_examine(mob/source, mob/target, list/result) | ||
SIGNAL_HANDLER | ||
|
||
if(!istype(target) || !target.client || !target.GetComponent(/datum/component/pref_holder)) | ||
return | ||
|
||
INVOKE_ASYNC(src, PROC_REF(modify_examine), target, result) | ||
|
||
/datum/element/pref_viewer/proc/modify_examine(mob/target, list/result) | ||
var/datum/component/pref_holder/holder = target.GetComponent(/datum/component/pref_holder) | ||
|
||
for(var/datum/preference_info/info as anything in holder.preferences) | ||
if(!is_type_in_list(info, preferences_to_show)) | ||
continue | ||
|
||
LAZYADD(result, info.get_examine_text()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
GLOBAL_LIST_INIT(preferences_info, list()) | ||
|
||
/datum/preference_info | ||
var/name | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters