Skip to content

Commit

Permalink
Config Elements state if they required a reload (#3362)
Browse files Browse the repository at this point in the history
* Make tooltip and label say if a reload is required

* Fix compilation, null issue

* Fix logic to use load time configs. Change tooltip

---------

Co-authored-by: JavidPack <javidpack@gmail.com>
  • Loading branch information
Destructor-Ben and JavidPack committed Aug 22, 2023
1 parent bf65973 commit c7245fd
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "Du kannst keinen Mod der in einer alten tModLoader Version erstellt wurde veröffentlichen",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Neu laden erforderlich",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Neu laden erzwingen",
"ModIsServerSide": "Dies ist ein serverseitiger Mod",
"ModsByline": "Mod von: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "You cannot publish a Mod built on an old version of tModLoader",
"WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Reload Required",
"ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Reload Forced",
"ModIsServerSide": "This is a server side mod",
"ModsByline": "By: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "No puedes publicar un mod creado para una versión antigua de tModLoader",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Recarga necesaria",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Recarga forzada",
"ModIsServerSide": "Este es un mod del lado del servidor",
"ModsByline": "De: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "Vous ne pouvez pas publier un Mod compilé avec une version obsolète de tModLoader",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Relance requise",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Relance forcée",
"ModIsServerSide": "Ceci est un mod côté serveur",
"ModsByline": "Par : {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
// "OutdatedModCantPublishError": "You cannot publish a Mod built on an old version of tModLoader",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
// "ModReloadRequired": "Reload Required",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
// "ModReloadForced": "Reload Forced",
// "ModIsServerSide": "This is a server side mod",
// "ModsByline": "By: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "Nie możesz opublikować moda zbudowanego na starszej wersji tModLoadera",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Wymagane przeładowanie",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Przeładowanie wymuszone",
"ModIsServerSide": "To jest mod serwerowy",
"ModsByline": "Autor: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "Você não pode publicar um Mod construído em uma versão antiga do tModLoader",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Recarregamento Necessário",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Recarregamento Forçado",
"ModIsServerSide": "Este é um mod do lado do servidor",
"ModsByline": "Por: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OutdatedModCantPublishError": "Вы не можете опубликовать мод, собранный на устаревшей версии tModLoader",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "Требуется перезагрузка",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "Принудительная перезагрузка",
"ModIsServerSide": "Это серверный мод",
"ModsByline": "Автор: {0}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"OutdatedModCantPublishError": "你无法发布基于旧版本tModLoader的模组",
// "WrongVersionCantPublishError": "You cannot publish a Mod built on a different version of tModLoader than what it was built with",
"ModReloadRequired": "需要重新加载",
// "ModReloadRequiredMemberTooltip": "Changing this will necessitate a reload",
"ModReloadForced": "强制重新加载",
"ModIsServerSide": "这是一个服务器的模组",
"ModsByline": "作者: {0}",
Expand Down
50 changes: 30 additions & 20 deletions patches/tModLoader/Terraria/ModLoader/Config/UI/ConfigElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using Terraria.GameContent;
using Terraria.Localization;
using Terraria.ModLoader.UI;
using Terraria.UI;
using Terraria.UI.Chat;
Expand Down Expand Up @@ -52,6 +53,10 @@ public abstract class ConfigElement : UIElement
protected internal Func<string> TextDisplayFunction { get; set; }
protected Func<string> TooltipFunction { get; set; }
protected bool DrawLabel { get; set; } = true;
protected bool ReloadRequired { get; set; }
protected bool ShowReloadRequiredTooltip { get; set; }
protected object OldValue { get; set; }
protected bool ValueChanged => !ConfigManager.ObjectEquals(OldValue, GetObject());

public ConfigElement()
{
Expand Down Expand Up @@ -94,6 +99,15 @@ public virtual void OnBind()
IncrementAttribute = ConfigManager.GetCustomAttributeFromMemberThenMemberType<IncrementAttribute>(MemberInfo, Item, List);
NullAllowed = ConfigManager.GetCustomAttributeFromMemberThenMemberType<NullAllowedAttribute>(MemberInfo, Item, List) != null;
JsonDefaultValueAttribute = ConfigManager.GetCustomAttributeFromMemberThenMemberType<JsonDefaultValueAttribute>(MemberInfo, Item, List);
ShowReloadRequiredTooltip = ConfigManager.GetCustomAttributeFromMemberThenMemberType<ReloadRequiredAttribute>(MemberInfo, Item, List) != null;

if (ShowReloadRequiredTooltip && List == null && Item is ModConfig modConfig) {
// Default ModConfig.NeedsReload logic currently only checks members of the ModConfig class, this mirrors that logic.
ReloadRequired = true;
// We need to check against the value in the load time config, not the value at the time of binding.
ModConfig loadTimeConfig = ConfigManager.GetLoadTimeConfig(modConfig.Mod, modConfig.Name);
OldValue = MemberInfo.GetValue(loadTimeConfig);
}
}

protected virtual void SetObject(object value)
Expand Down Expand Up @@ -140,32 +154,28 @@ protected override void DrawSelf(SpriteBatch spriteBatch)
if (DrawLabel) {
position.X += 8f;
position.Y += 8f;

string label = TextDisplayFunction();
if (ReloadRequired && ValueChanged) {
label += " - [c/FF0000:" + Language.GetTextValue("tModLoader.ModReloadRequired") + "]";
}

// TODO: Support chat tag hover?
ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, TextDisplayFunction(), position, color, 0f, Vector2.Zero, baseScale, settingsWidth, 2f);
ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, label, position, color, 0f, Vector2.Zero, baseScale, settingsWidth, 2f);
}

if (IsMouseHovering && TooltipFunction != null) {
UIModConfig.Tooltip = TooltipFunction();
/*
string hoverText = _TooltipFunction(); // TODO: Fix, draw order prevents this from working correctly
float x = FontAssets.MouseText.Value.MeasureString(hoverText).X;
vector = new Vector2((float)Main.mouseX, (float)Main.mouseY) + new Vector2(16f);
if (vector.Y > (float)(Main.screenHeight - 30)) {
vector.Y = (float)(Main.screenHeight - 30);
}
if (vector.X > (float)(Parent.GetDimensions().Width + Parent.GetDimensions().X - x - 16)) {
vector.X = (float)(Parent.GetDimensions().Width + Parent.GetDimensions().X - x - 16);
string tooltip = TooltipFunction();

// TODO - Add line for default value?

if (ShowReloadRequiredTooltip) {
tooltip += string.IsNullOrEmpty(tooltip) ? "" : "\n";
tooltip += $"[c/{Color.Orange.Hex3()}:" + Language.GetTextValue("tModLoader.ModReloadRequiredMemberTooltip") + "]";
}
Utils.DrawBorderStringFourWay(spriteBatch, FontAssets.MouseText.Value, hoverText, vector.X, vector.Y, new Color((int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor, (int)Main.mouseTextColor), Color.Black, Vector2.Zero, 1f);
*/
}

/*
if (IsMouseHovering) {
Rectangle hitbox = GetInnerDimensions().ToRectangle();
Main.spriteBatch.Draw(TextureAssets.MagicPixel, hitbox, Color.Green * 0.6f);
UIModConfig.Tooltip = tooltip;
}
*/
}

public static void DrawPanel2(SpriteBatch spriteBatch, Vector2 position, Texture2D texture, float width, float height, Color color)
Expand Down Expand Up @@ -210,4 +220,4 @@ protected override void DrawSelf(SpriteBatch spriteBatch)

ChatManager.DrawColorCodedStringWithShadow(spriteBatch, FontAssets.ItemStack.Value, header, position, Color.White, 0f, Vector2.Zero, new Vector2(1f), settingsWidth - 20, 2f);
}
}
}
16 changes: 8 additions & 8 deletions solutions/TranslationsNeeded.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
zh-Hans 63
ru-RU 10
pt-BR 32
pl-PL 393
it-IT 833
fr-FR 448
es-ES 357
de-DE 378
zh-Hans 64
ru-RU 11
pt-BR 33
pl-PL 394
it-IT 834
fr-FR 449
es-ES 358
de-DE 379

0 comments on commit c7245fd

Please sign in to comment.