mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 10:12:45 +00:00
[MIRROR] porting the notification hiding from TG (#7737)
Co-authored-by: Kashargul <144968721+Kashargul@users.noreply.github.com> Co-authored-by: CHOMPStation2 <chompsation2@gmail.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* ### tgui_input_checkbox
|
||||
* Opens a window with a list of checkboxes and returns a list of selected choices.
|
||||
*
|
||||
* user - The mob to display the window to
|
||||
* message - The message inside the window
|
||||
* title - The title of the window
|
||||
* list/items - The list of items to display
|
||||
* min_checked - The minimum number of checkboxes that must be checked (defaults to 1)
|
||||
* max_checked - The maximum number of checkboxes that can be checked (optional)
|
||||
* timeout - The timeout for the input (optional)
|
||||
*/
|
||||
/proc/tgui_input_checkboxes(mob/user, message, title = "Select", list/items, min_checked = 1, max_checked = 50, timeout = 0, ui_state = GLOB.tgui_always_state)
|
||||
if (!user)
|
||||
user = usr
|
||||
if(!length(items))
|
||||
return
|
||||
if (!istype(user))
|
||||
if (istype(user, /client))
|
||||
var/client/client = user
|
||||
user = client.mob
|
||||
else
|
||||
return
|
||||
if(!user.client.prefs.tgui_input_mode)
|
||||
return input(user, message, title) as null|anything in items
|
||||
var/datum/tgui_checkbox_input/input = new(user, message, title, items, min_checked, max_checked, timeout, ui_state)
|
||||
input.tgui_interact(user)
|
||||
input.wait()
|
||||
if (input)
|
||||
. = input.choices
|
||||
qdel(input)
|
||||
|
||||
/// Window for tgui_input_checkboxes
|
||||
/datum/tgui_checkbox_input
|
||||
/// Title of the window
|
||||
var/title
|
||||
/// Message to display
|
||||
var/message
|
||||
/// List of items to display
|
||||
var/list/items
|
||||
/// List of selected items
|
||||
var/list/choices
|
||||
/// Time when the input was created
|
||||
var/start_time
|
||||
/// Timeout for the input
|
||||
var/timeout
|
||||
/// Whether the input was closed
|
||||
var/closed
|
||||
/// Minimum number of checkboxes that must be checked
|
||||
var/min_checked
|
||||
/// Maximum number of checkboxes that can be checked
|
||||
var/max_checked
|
||||
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
|
||||
var/datum/tgui_state/state
|
||||
|
||||
/datum/tgui_checkbox_input/New(mob/user, message, title, list/items, min_checked, max_checked, timeout, ui_state)
|
||||
src.title = title
|
||||
src.message = message
|
||||
src.items = items.Copy()
|
||||
src.min_checked = min_checked
|
||||
src.max_checked = max_checked
|
||||
src.state = ui_state
|
||||
|
||||
if (timeout)
|
||||
src.timeout = timeout
|
||||
start_time = world.time
|
||||
QDEL_IN(src, timeout)
|
||||
|
||||
/datum/tgui_checkbox_input/Destroy(force, ...)
|
||||
SStgui.close_uis(src)
|
||||
state = null
|
||||
QDEL_NULL(items)
|
||||
|
||||
return ..()
|
||||
|
||||
/datum/tgui_checkbox_input/proc/wait()
|
||||
while (!closed && !QDELETED(src))
|
||||
stoplag(1)
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_interact(mob/user, datum/tgui/ui)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, "CheckboxInput")
|
||||
ui.open()
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_close(mob/user)
|
||||
. = ..()
|
||||
closed = TRUE
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_state(mob/user)
|
||||
return state
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_data(mob/user)
|
||||
var/list/data = list()
|
||||
|
||||
if(timeout)
|
||||
data["timeout"] = CLAMP01((timeout - (world.time - start_time) - 1 SECONDS) / (timeout - 1 SECONDS))
|
||||
|
||||
return data
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_static_data(mob/user)
|
||||
var/list/data = list()
|
||||
|
||||
data["items"] = items
|
||||
data["min_checked"] = min_checked
|
||||
data["max_checked"] = max_checked
|
||||
data["large_buttons"] = user.client.prefs.tgui_large_buttons
|
||||
data["message"] = message
|
||||
data["swapped_buttons"] = !user.client.prefs.tgui_swapped_buttons
|
||||
data["title"] = title
|
||||
|
||||
return data
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_act(action, list/params)
|
||||
. = ..()
|
||||
if (.)
|
||||
return
|
||||
|
||||
switch(action)
|
||||
if("submit")
|
||||
var/list/selections = params["entry"]
|
||||
if(length(selections) >= min_checked && length(selections) <= max_checked)
|
||||
set_choices(selections)
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
|
||||
if("cancel")
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
|
||||
return FALSE
|
||||
|
||||
/datum/tgui_checkbox_input/proc/set_choices(list/selections)
|
||||
src.choices = selections.Copy()
|
||||
/**
|
||||
* ### tgui_input_checkbox
|
||||
* Opens a window with a list of checkboxes and returns a list of selected choices.
|
||||
*
|
||||
* user - The mob to display the window to
|
||||
* message - The message inside the window
|
||||
* title - The title of the window
|
||||
* list/items - The list of items to display
|
||||
* min_checked - The minimum number of checkboxes that must be checked (defaults to 1)
|
||||
* max_checked - The maximum number of checkboxes that can be checked (optional)
|
||||
* timeout - The timeout for the input (optional)
|
||||
*/
|
||||
/proc/tgui_input_checkboxes(mob/user, message, title = "Select", list/items, min_checked = 1, max_checked = 50, timeout = 0, ui_state = GLOB.tgui_always_state)
|
||||
if (!user)
|
||||
user = usr
|
||||
if(!length(items))
|
||||
return
|
||||
if (!istype(user))
|
||||
if (istype(user, /client))
|
||||
var/client/client = user
|
||||
user = client.mob
|
||||
else
|
||||
return
|
||||
if(!user.client.prefs.tgui_input_mode)
|
||||
return input(user, message, title) as null|anything in items
|
||||
var/datum/tgui_checkbox_input/input = new(user, message, title, items, min_checked, max_checked, timeout, ui_state)
|
||||
input.tgui_interact(user)
|
||||
input.wait()
|
||||
if (input)
|
||||
. = input.choices
|
||||
qdel(input)
|
||||
|
||||
/// Window for tgui_input_checkboxes
|
||||
/datum/tgui_checkbox_input
|
||||
/// Title of the window
|
||||
var/title
|
||||
/// Message to display
|
||||
var/message
|
||||
/// List of items to display
|
||||
var/list/items
|
||||
/// List of selected items
|
||||
var/list/choices
|
||||
/// Time when the input was created
|
||||
var/start_time
|
||||
/// Timeout for the input
|
||||
var/timeout
|
||||
/// Whether the input was closed
|
||||
var/closed
|
||||
/// Minimum number of checkboxes that must be checked
|
||||
var/min_checked
|
||||
/// Maximum number of checkboxes that can be checked
|
||||
var/max_checked
|
||||
/// The TGUI UI state that will be returned in ui_state(). Default: always_state
|
||||
var/datum/tgui_state/state
|
||||
|
||||
/datum/tgui_checkbox_input/New(mob/user, message, title, list/items, min_checked, max_checked, timeout, ui_state)
|
||||
src.title = title
|
||||
src.message = message
|
||||
src.items = items.Copy()
|
||||
src.min_checked = min_checked
|
||||
src.max_checked = max_checked
|
||||
src.state = ui_state
|
||||
|
||||
if (timeout)
|
||||
src.timeout = timeout
|
||||
start_time = world.time
|
||||
QDEL_IN(src, timeout)
|
||||
|
||||
/datum/tgui_checkbox_input/Destroy(force, ...)
|
||||
SStgui.close_uis(src)
|
||||
state = null
|
||||
QDEL_NULL(items)
|
||||
|
||||
return ..()
|
||||
|
||||
/datum/tgui_checkbox_input/proc/wait()
|
||||
while (!closed && !QDELETED(src))
|
||||
stoplag(1)
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_interact(mob/user, datum/tgui/ui)
|
||||
ui = SStgui.try_update_ui(user, src, ui)
|
||||
if(!ui)
|
||||
ui = new(user, src, "CheckboxInput")
|
||||
ui.open()
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_close(mob/user)
|
||||
. = ..()
|
||||
closed = TRUE
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_state(mob/user)
|
||||
return state
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_data(mob/user)
|
||||
var/list/data = list()
|
||||
|
||||
if(timeout)
|
||||
data["timeout"] = CLAMP01((timeout - (world.time - start_time) - 1 SECONDS) / (timeout - 1 SECONDS))
|
||||
|
||||
return data
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_static_data(mob/user)
|
||||
var/list/data = list()
|
||||
|
||||
data["items"] = items
|
||||
data["min_checked"] = min_checked
|
||||
data["max_checked"] = max_checked
|
||||
data["large_buttons"] = user.client.prefs.tgui_large_buttons
|
||||
data["message"] = message
|
||||
data["swapped_buttons"] = !user.client.prefs.tgui_swapped_buttons
|
||||
data["title"] = title
|
||||
|
||||
return data
|
||||
|
||||
/datum/tgui_checkbox_input/tgui_act(action, list/params)
|
||||
. = ..()
|
||||
if (.)
|
||||
return
|
||||
|
||||
switch(action)
|
||||
if("submit")
|
||||
var/list/selections = params["entry"]
|
||||
if(length(selections) >= min_checked && length(selections) <= max_checked)
|
||||
set_choices(selections)
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
|
||||
if("cancel")
|
||||
closed = TRUE
|
||||
SStgui.close_uis(src)
|
||||
return TRUE
|
||||
|
||||
return FALSE
|
||||
|
||||
/datum/tgui_checkbox_input/proc/set_choices(list/selections)
|
||||
src.choices = selections.Copy()
|
||||
|
||||
@@ -44,6 +44,22 @@ export const ChatPageSettings = (props) => {
|
||||
}
|
||||
/>
|
||||
</Stack.Item>
|
||||
<Stack.Item>
|
||||
<Button.Checkbox
|
||||
content="Mute"
|
||||
checked={page.hideUnreadCount}
|
||||
icon={page.hideUnreadCount ? 'bell-slash' : 'bell'}
|
||||
tooltip="Disables unread counter"
|
||||
onClick={() =>
|
||||
dispatch(
|
||||
updateChatPage({
|
||||
pageId: page.id,
|
||||
hideUnreadCount: !page.hideUnreadCount,
|
||||
}),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</Stack.Item>
|
||||
{!page.isMain ? (
|
||||
<Stack.Item>
|
||||
<Button
|
||||
|
||||
@@ -39,6 +39,7 @@ export const ChatTabs = (props) => {
|
||||
key={page.id}
|
||||
selected={page === currentPage}
|
||||
rightSlot={
|
||||
!page.hideUnreadCount &&
|
||||
page.unreadCount > 0 && (
|
||||
<UnreadCountWidget value={page.unreadCount} />
|
||||
)
|
||||
|
||||
@@ -26,6 +26,7 @@ export const createPage = (obj) => {
|
||||
name: 'New Tab',
|
||||
acceptedTypes: acceptedTypes,
|
||||
unreadCount: 0,
|
||||
hideUnreadCount: false,
|
||||
createdAt: Date.now(),
|
||||
...obj,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user