Skip to content

Commit

Permalink
[TM] Make credits toggleable (#1431)
Browse files Browse the repository at this point in the history
## Что этот PR делает
Добавляет возможность отключить автоматическое воспроизведение титров в
настройках игры. Администратор все равно может зафорсить титры в текущем
раунде, если считает нужным.
Добавляет ***новую таблицу с префами***, надо будет так и другие фичи
сделать.

## Почему это хорошо для игры
Можно не прожимать "Прекратить  смотреть синематик" каждый раунд.

## Изображения изменений


![image](https://github.com/user-attachments/assets/e50fbe28-ee32-4304-a16c-c8c6b73b77b5)


## Тестирование
- [x] Свойство в настройках реально влияет на воспроизведение титров.
- [x] Админ реально может зафорсить титры, никакие настройки от этого не
спасут.
- [x] Настройки сохранились в тестовой БД и подсосались после
перезапуска сервера.

## Changelog

:cl: Maxiemar
add: Автоматическое воспроизведение титров в конце раунда теперь можно
отключить в настройках игры.
add: Администрация может зафорсить титры на конец раунда, если захочет
всем напомнить, как они выглядят. Server -> Toggle Credits.
/:cl:
  • Loading branch information
m-dzianishchyts authored Aug 23, 2024
1 parent 449920f commit 4d7d93a
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 2 deletions.
28 changes: 28 additions & 0 deletions SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -711,3 +711,31 @@ CREATE TABLE `budget` (
# Adds species whitelist ~legendaxe

ALTER TABLE `player` ADD `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ('["human"]');

# Updating DB from 59.220.6 to 59.220.7
# Adds SS220 toggle prefs ~Maxiemar

DROP TABLE IF EXISTS `player_220`;
CREATE TABLE `player_220` (
`ckey` VARCHAR(32) NOT NULL COLLATE utf8mb4_unicode_ci,
`toggles` int(11) DEFAULT NULL,
PRIMARY KEY (`ckey`) USING BTREE
) COLLATE = utf8mb4_unicode_ci ENGINE = InnoDB;

ALTER TABLE `player_220`
ADD CONSTRAINT `fk_player_220_ckey`
FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`)
ON DELETE CASCADE
ON UPDATE CASCADE;

DROP TRIGGER IF EXISTS `player_insert`;
DELIMITER //
CREATE TRIGGER `player_insert`
AFTER INSERT ON `player`
FOR EACH ROW
BEGIN
INSERT INTO `player_220` (`ckey`)
VALUES (NEW.ckey);
END;
//
DELIMITER ;
31 changes: 31 additions & 0 deletions SQL/updates220/59.220.6-59.220.7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Updating DB from 59.220.6 to 59.220.7
# Adds SS220 toggle prefs ~Maxiemar

DROP TABLE IF EXISTS `player_220`;
CREATE TABLE `player_220` (
`ckey` VARCHAR(32) NOT NULL COLLATE utf8mb4_unicode_ci,
`toggles` int(11) DEFAULT NULL,
PRIMARY KEY (`ckey`) USING BTREE
) COLLATE = utf8mb4_unicode_ci ENGINE = InnoDB;

ALTER TABLE `player_220`
ADD CONSTRAINT `fk_player_220_ckey`
FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`)
ON DELETE CASCADE
ON UPDATE CASCADE;

DROP TRIGGER IF EXISTS `player_insert`;
DELIMITER //
CREATE TRIGGER `player_insert`
AFTER INSERT ON `player`
FOR EACH ROW
BEGIN
INSERT INTO `player_220` (`ckey`)
VALUES (NEW.ckey);
END;
//
DELIMITER ;

INSERT INTO `player_220` (`ckey`)
SELECT `ckey`
FROM `player`;
4 changes: 4 additions & 0 deletions code/__DEFINES/_ss220.dm
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#define MODPACK_CHAT_BADGES

// TODO: someday preferences will use TGUI and you will probably be able to move it to modular_ss220\_defines220\code\preferences_defines.dm
/// Interacts with the toggles220 bitflag
#define PREFTOGGLE_TOGGLE220 220
2 changes: 1 addition & 1 deletion code/__DEFINES/misc_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
#define INVESTIGATE_HOTMIC "hotmic"

// The SQL version required by this version of the code
#define SQL_VERSION 592206
#define SQL_VERSION 592207

// Vending machine stuff
#define CAT_NORMAL (1<<0)
Expand Down
4 changes: 4 additions & 0 deletions code/modules/client/preference/preferences.dm
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,10 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts
dat += "<td style='width: 20%'><a href='byond://?_src_=prefs;preference=preference_toggles;toggle=[toggle.UID()];'>[(toggles & toggle.preftoggle_bitflag) ? "<span class='good'>Enabled</span>" : "<span class='bad'>Disabled</span>"]</a></td>"
if(PREFTOGGLE_TOGGLE2)
dat += "<td style='width: 20%'><a href='byond://?_src_=prefs;preference=preference_toggles;toggle=[toggle.UID()];'>[(toggles2 & toggle.preftoggle_bitflag) ? "<span class='good'>Enabled</span>" : "<span class='bad'>Disabled</span>"]</a></td>"
// SS220 ADDITION - START
if(PREFTOGGLE_TOGGLE220)
dat += "<td style='width: 20%'><a href='byond://?_src_=prefs;preference=preference_toggles;toggle=[toggle.UID()];'>[(toggles220 & toggle.preftoggle_bitflag) ? "<span class='good'>Enabled</span>" : "<span class='bad'>Disabled</span>"]</a></td>"
// SS220 ADDITION - END
if(PREFTOGGLE_SOUND)
dat += "<td style='width: 20%'><a href='byond://?_src_=prefs;preference=preference_toggles;toggle=[toggle.UID()];'>[(sound & toggle.preftoggle_bitflag) ? "<span class='good'>Enabled</span>" : "<span class='bad'>Disabled</span>"]</a></td>"
if(PREFTOGGLE_LIGHT)
Expand Down
2 changes: 1 addition & 1 deletion config/example/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ipc_screens = [
# Enable/disable the database on a whole
sql_enabled = false
# SQL version. If this is a mismatch, round start will be delayed
sql_version = 592206
sql_version = 592207
# SQL server address. Can be an IP or DNS name
sql_address = "127.0.0.1"
# SQL server port
Expand Down
1 change: 1 addition & 0 deletions modular_ss220/_defines220/_defines220.dme
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
#include "code/emote.dm"
#include "code/lists_TG.dm"
#include "code/species.dm"
#include "code/preferences_defines.dm"
5 changes: 5 additions & 0 deletions modular_ss220/_defines220/code/preferences_defines.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define PREFTOGGLE_220_WATCH_CREDITS (1<<0) // 1

#define TOGGLES_220_TOTAL 1 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined.

#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS)
4 changes: 4 additions & 0 deletions modular_ss220/cinematics/code/_cinematics.dm
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
if(!watching_client || (watching_client in watching))
return

// Do not show credits if it's disabled for the client and not forced.
if(istype(src, /datum/cinematic/credits) && !GLOB.credits_forced && !(watching_client.prefs.toggles220 & PREFTOGGLE_220_WATCH_CREDITS))
return

watching += watching_client
watching_mob.overlay_fullscreen("cinematic", backdrop_type)
watching_client.screen += screen
Expand Down
5 changes: 5 additions & 0 deletions modular_ss220/credits/_credits.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
name = "Credits"
desc = "Добавление титров в конце раунда, основа кода была взята из данного репозитория https://github.com/Baystation12/Baystation12"
author = "Legendaxe"

/datum/modpack/credits/initialize()
GLOB.admin_verbs_admin += list(
/client/proc/toggle_credits
)
1 change: 1 addition & 0 deletions modular_ss220/credits/_credits.dme
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "code\SScredits.dm"
#include "code\credits.dm"
#include "code\admin_procs.dm"
#include "code\halloween_credits.dm"
#include "code\new_year_credits.dm"
#include "code\aprils_fool_credits.dm"
Expand Down
20 changes: 20 additions & 0 deletions modular_ss220/credits/code/admin_procs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Force everyone to watch credits?
GLOBAL_VAR_INIT(credits_forced, FALSE)

/client/proc/toggle_credits()
set category = "Server"
set desc = "Просмотр титров по окончании раунда"
set name = "Toggle Credits"

if(!check_rights(R_ADMIN))
return

GLOB.credits_forced = !GLOB.credits_forced
if(GLOB.credits_forced)
to_chat(world, "<B>Все будут смотреть титры по окончании раунда.</B>")
message_admins("[key_name_admin(usr)] устанавливает принудительные титры.", 1)
else
to_chat(world, "<B>Игроки будут смотреть титры в зависимости от своих настроек.</B>")
message_admins("[key_name_admin(usr)] устанавливает титры по умолчанию.", 1)
log_admin("[key_name(usr)] toggled credits.")
SSblackbox.record_feedback("tally", "admin_verb", 1, "Toggle Credits")
1 change: 1 addition & 0 deletions modular_ss220/modular_ss220.dme
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

// --- MISC --- //
#include "administration/_administration.dme"
#include "preferences/_preferences.dme"
#include "aesthetics_sounds/_aesthetics_sounds.dme"
#include "agent_id_tgui/_agent_id_tgui.dme"
#include "balance/_balance.dme"
Expand Down
4 changes: 4 additions & 0 deletions modular_ss220/preferences/_preferences.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/modpack/preferences
name = "Кастомные настройки"
desc = "Игровые настройки, разработанные для проекта"
author = "Maxiemar"
4 changes: 4 additions & 0 deletions modular_ss220/preferences/_preferences.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "_preferences.dm"

#include "code/preferences.dm"
#include "code/preferences_toggles.dm"
59 changes: 59 additions & 0 deletions modular_ss220/preferences/code/preferences.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/datum/preferences
var/toggles220 = TOGGLES_220_DEFAULT

/datum/preferences/load_preferences(datum/db_query/query)
. = ..()
if(!.)
return

return load_custom_preferences()

/datum/preferences/save_preferences(client/C)
. = ..()
if(!.)
return

return save_custom_preferences(C)

/datum/preference_toggle/set_toggles(client/user)
var/datum/preferences/our_prefs = user.prefs
switch(preftoggle_toggle)
if(PREFTOGGLE_TOGGLE220)
our_prefs.toggles220 ^= preftoggle_bitflag
to_chat(user, "<span class='notice'>[(our_prefs.toggles220 & preftoggle_bitflag) ? enable_message : disable_message]</span>")
. = ..()

/datum/preferences/proc/load_custom_preferences()
var/datum/db_query/preferences_query = SSdbcore.NewQuery({"SELECT
toggles
FROM player_220
WHERE ckey=:ckey"}, list(
"ckey" = parent.ckey
))

if(!preferences_query.warn_execute())
qdel(preferences_query)
return FALSE

while(preferences_query.NextRow())
toggles220 = preferences_query.item[1]

toggles220 = sanitize_integer(toggles220, 0, TOGGLES_220_TOTAL, initial(toggles220))

qdel(preferences_query)
return TRUE

/datum/preferences/proc/save_custom_preferences(client/C)
var/datum/db_query/query = SSdbcore.NewQuery({"UPDATE player_220 SET
toggles=:toggles
WHERE ckey=:ckey"}, list(
"toggles" = num2text(toggles220, CEILING(log(10, (TOGGLES_220_TOTAL)), 1)),
"ckey" = C.ckey,
))

if(!query.warn_execute())
qdel(query)
return FALSE

qdel(query)
return TRUE
9 changes: 9 additions & 0 deletions modular_ss220/preferences/code/preferences_toggles.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/datum/preference_toggle/toggle_credits
name = "Показывать титры"
description = "Показывать титры по окончании раунда"
preftoggle_bitflag = PREFTOGGLE_220_WATCH_CREDITS
preftoggle_toggle = PREFTOGGLE_TOGGLE220
preftoggle_category = PREFTOGGLE_CATEGORY_LIVING
enable_message = "Вы будете видеть титры в конце раундов."
disable_message = "Вы не будете видеть титры в конце раундов."
blackbox_message = "Toggle Credits"

0 comments on commit 4d7d93a

Please sign in to comment.