Skip to content

Commit 8c9af44

Browse files
committed
Player and World Definitions now more similar
+ Utilities is moved into Core folder + fixed some bugs with name display
1 parent 74ec535 commit 8c9af44

14 files changed

Lines changed: 74 additions & 79 deletions

Common/Configs/Config.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using ModReloader.Common.Configs.ConfigElements.ModsConfigElements;
22
using ModReloader.Common.Configs.ConfigElements.PlayerPicker;
33
using ModReloader.Common.Configs.ConfigElements.WorldPicker;
4+
using ModReloader.Core.Features;
45
using ModReloader.Core.Features.MainMenuFeatures;
5-
using ModReloader.Core.Features.Reload;
66
using System;
77
using System.Collections.Generic;
88
using System.ComponentModel;

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinition.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModReloader.Core.Features.Reload;
1+
using ModReloader.Core.Features;
22
using Terraria.ModLoader.Config;
33

44

@@ -29,9 +29,5 @@ public PlayerDefinition(string path) : base()
2929
{
3030
Name = path;
3131
}
32-
public override string ToString()
33-
{
34-
return $"{(Utilities.FindPlayer(Name) != null ? Utilities.FindPlayer(Name).Name : "null")}";
35-
}
3632
}
3733

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinitionElement.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModReloader.Core.Features.Reload;
1+
using ModReloader.Core.Features;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
@@ -108,15 +108,12 @@ protected override List<DefinitionOptionElement<PlayerDefinition>> GetPassedOpti
108108

109109
private void RemoveScrollbar()
110110
{
111-
if (ChooserGrid != null)
112-
{
113-
ChooserGrid.SetScrollbar(null);
114-
ChooserGrid.Width.Set(0f, 1f);
115-
}
116-
117111
if (ChooserPanel == null)
118112
return;
119113

114+
ChooserGrid.SetScrollbar(null);
115+
ChooserGrid.Width.Set(0f, 1f);
116+
120117
foreach (var c in ChooserPanel.Children.ToArray())
121118
{
122119
if (c is UIScrollbar)

Common/Configs/ConfigElements/PlayerPicker/PlayerDefinitionOptionElement.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
using Microsoft.Xna.Framework.Graphics;
2+
using ModReloader.Core.Features;
23
using System;
34
using System.Linq;
45
using Terraria.GameContent.UI.Elements;
56
using Terraria.ID;
67
using Terraria.IO;
78
using Terraria.ModLoader.Config.UI;
89
using Terraria.UI;
10+
using static System.Net.Mime.MediaTypeNames;
911

1012
namespace ModReloader.Common.Configs.ConfigElements.PlayerPicker;
1113

12-
internal sealed class PlayerDefinitionOptionElement: DefinitionOptionElement<PlayerDefinition>
14+
internal sealed class PlayerDefinitionOptionElement : DefinitionOptionElement<PlayerDefinition>
1315
{
1416
private UICharacter _preview;
1517
private bool isActiveSelection;
1618

17-
public PlayerDefinitionOptionElement(PlayerDefinition definition,float scale = 0.75f, bool isActiveSelection=false): base(definition, scale)
19+
public PlayerDefinitionOptionElement(PlayerDefinition definition, float scale = 0.75f, bool isActiveSelection = false) : base(definition, scale)
1820
{
1921
this.isActiveSelection = isActiveSelection;
2022
OverflowHidden = true;
23+
NullID = -1;
2124
}
2225

2326
public override void SetItem(PlayerDefinition definition)
@@ -27,21 +30,27 @@ public override void SetItem(PlayerDefinition definition)
2730
RemoveAllChildren();
2831
_preview = null;
2932

30-
string path = definition?.Name;
31-
if (string.IsNullOrEmpty(path)) { Tooltip = "UnknownPlayer"; return; }
32-
3333
Main.LoadPlayers();
34-
PlayerFileData file = Main.PlayerList.FirstOrDefault(p => string.Equals(p.Path, path, StringComparison.OrdinalIgnoreCase));
35-
if (file?.Player == null) { Tooltip = definition?.ToString() ?? "UnknownPlayer"; return; }
34+
if (definition == null || definition.IsUnloaded)
35+
{
36+
Tooltip = "No Player Selected";
37+
Recalculate();
38+
return;
39+
}
40+
41+
PlayerFileData file = Utilities.FindPlayer(definition.Type);
3642

37-
Tooltip = definition?.ToString() ?? "UnknownPlayer";
38-
if (file.Player.difficulty == PlayerDifficultyID.Creative) { Color c = Main.creativeModeColor; Tooltip += $" [c/{c.R:X2}{c.G:X2}{c.B:X2}:(Journey)]"; }
43+
Player player = file.Player;
44+
player.dead = false;
3945

40-
Player p = file.Player;
41-
p.dead = false;
46+
Tooltip = player.name;
47+
if (player.difficulty == PlayerDifficultyID.Creative)
48+
{
49+
Tooltip += Utilities.ColorToTerrariaString(Main.creativeModeColor, " (Journey)");
50+
}
4251

4352
float charScale = isActiveSelection ? 0.6f : 0.8f;
44-
_preview = new UICharacter(p, animated: false, hasBackPanel: false, characterScale: charScale, useAClone: true);
53+
_preview = new UICharacter(player, animated: false, hasBackPanel: false, characterScale: charScale, useAClone: true);
4554
_preview.Top.Set(-6f, 0f);
4655

4756
Append(_preview);
@@ -55,22 +64,18 @@ public override void Update(GameTime gameTime)
5564
// Animate when hovering
5665
if (_preview != null)
5766
{
58-
// HOT RELOAD TESTING
59-
//_preview.Top.Set(-6, 0);
60-
//_preview._characterScale = 0.5f;
61-
6267
_preview.SetAnimated(IsMouseHovering);
6368
}
64-
69+
6570
}
6671

6772
protected override void DrawSelf(SpriteBatch spriteBatch)
6873
{
6974
base.DrawSelf(spriteBatch);
7075

7176
// Position
72-
CalculatedStyle dimensions = GetInnerDimensions();
73-
Vector2 position = dimensions.Position();
77+
CalculatedStyle dimensions = GetInnerDimensions();
78+
Vector2 position = dimensions.Position();
7479
Vector2 size = BackgroundTexture.Size() * Scale;
7580
Rectangle destination = new((int)position.X, (int)position.Y, (int)size.X, (int)size.Y);
7681

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModReloader.Core.Features.Reload;
1+
using ModReloader.Core.Features;
22
using System.IO;
33
using Terraria.ModLoader.Config;
44

@@ -10,23 +10,11 @@ public class WorldDefinition : EntityDefinition
1010
/// <summary>
1111
/// The index of the world in Main.WorldList. -1 if not found.
1212
/// </summary>
13-
public override int Type
14-
{
15-
get
16-
{
17-
Main.LoadWorlds();
18-
return Utilities.FindWorldId(Name);
19-
}
20-
}
13+
public override int Type => Utilities.FindWorldId(Name);
2114

2215
public override bool IsUnloaded
2316
=> Type <= -1 || Name == null;
2417

25-
public override string DisplayName =>
26-
string.IsNullOrEmpty(Name)
27-
? "UnknownWorld"
28-
: Path.GetFileNameWithoutExtension(Name);
29-
3018
public WorldDefinition() : base()
3119
{
3220

@@ -41,6 +29,5 @@ public WorldDefinition(string path) : base()
4129
{
4230
Name = path;
4331
}
44-
public override string ToString() => DisplayName;
4532
}
4633

Common/Configs/ConfigElements/WorldPicker/WorldDefinitionElement.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ModReloader.Core.Features.Reload;
1+
using ModReloader.Core.Features;
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;

Common/Configs/ConfigElements/WorldPicker/WorldDefinitionOptionElement.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.Xna.Framework.Graphics;
2+
using ModReloader.Core.Features;
23
using ReLogic.Content;
34
using System;
45
using System.Linq;
@@ -11,7 +12,6 @@ namespace ModReloader.Common.Configs.ConfigElements.WorldPicker;
1112

1213
internal sealed class WorldDefinitionOptionElement : DefinitionOptionElement<WorldDefinition>
1314
{
14-
private WorldFileData _file;
1515
private Asset<Texture2D> _iconAsset;
1616

1717
public WorldDefinitionOptionElement(WorldDefinition definition, float scale = 0.75f) : base(definition, scale) { OverflowHidden = true; }
@@ -21,26 +21,29 @@ public override void SetItem(WorldDefinition definition)
2121
{
2222
base.SetItem(definition);
2323

24-
_file = null;
2524
_iconAsset = null;
2625

27-
if (definition?.Name is not string worldPath || string.IsNullOrEmpty(worldPath)) { Tooltip = "UnknownWorld"; return; }
28-
2926
Main.LoadWorlds();
30-
_file = Main.WorldList.FirstOrDefault(w => string.Equals(w.Path, worldPath, StringComparison.OrdinalIgnoreCase));
31-
if (_file == null) { Tooltip = definition.DisplayName ?? "UnknownWorld"; return; }
27+
if (definition == null || definition.IsUnloaded)
28+
{
29+
Tooltip = "No World Selected";
30+
Recalculate();
31+
return;
32+
}
33+
34+
var file = Utilities.FindWorld(definition.Type);
3235

3336
// Get icon asset
34-
_iconAsset = GetIconAsset(_file);
37+
_iconAsset = GetIconAsset(file);
3538

3639
// Get world info
37-
string worldName = definition.DisplayName ?? "UnknownWorld";
38-
int diffId = GetDifficultyId(_file);
39-
string diffName = GetDifficultyName(_file);
40+
string worldName = file.GetWorldName() ?? "UnknownWorld";
41+
int diffId = GetDifficultyId(file);
42+
string diffName = $" ({GetDifficultyName(file)})";
4043
Color diffColor = GetDifficultyColor(diffId);
4144

4245
// Tooltip
43-
Tooltip = $"{worldName} [c/{ToHex(diffColor)}:({diffName})]";
46+
Tooltip = $"{worldName} {Utilities.ColorToTerrariaString(diffColor, diffName)}";
4447
}
4548

4649
protected override void DrawSelf(SpriteBatch spriteBatch)
@@ -73,14 +76,15 @@ private void DrawWorldIcon(SpriteBatch spriteBatch, Rectangle target)
7376
private static int GetDifficultyId(WorldFileData data)
7477
{
7578
if (data.GameMode == 3) return 0; // Journey
76-
int id = data.GameMode switch
77-
{
79+
int id = data.GameMode switch
80+
{
7881
0 => 1, // Normal
7982
1 => 2, // Expert
8083
2 => 3, // Master
81-
_ => 1 };
84+
_ => 1
85+
};
8286

83-
if (data.ForTheWorthy)
87+
if (data.ForTheWorthy)
8488
id++; // FTW / Legendary
8589

8690
return Math.Clamp(id, 0, 4);
@@ -103,11 +107,11 @@ private static string GetDifficultyName(WorldFileData data)
103107
{
104108
if (data.GameMode == 3) return Language.GetTextValue("UI.Creative");
105109

106-
int tier = data.GameMode switch
107-
{
108-
1 => 2,
109-
2 => 3,
110-
_ => 1
110+
int tier = data.GameMode switch
111+
{
112+
1 => 2,
113+
2 => 3,
114+
_ => 1
111115
};
112116
if (data.ForTheWorthy) tier++;
113117

@@ -120,8 +124,6 @@ private static string GetDifficultyName(WorldFileData data)
120124
};
121125
}
122126

123-
private static string ToHex(Color c) => $"{c.R:X2}{c.G:X2}{c.B:X2}";
124-
125127
private static Asset<Texture2D> GetIconAsset(WorldFileData data)
126128
{
127129
if (data.ZenithWorld) return Main.Assets.Request<Texture2D>("Images/UI/Icon" + (data.IsHardMode ? "Hallow" : "") + "Everything");

Common/PacketHandlers/RefreshServerPacketHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.IO;
33
using System.Threading.Tasks;
4+
using ModReloader.Core.Features;
45
using ModReloader.Core.Features.Reload;
56
using Terraria.ID;
67
namespace ModReloader.Common.PacketHandlers

Core/Features/LogFeatures/LogLevelSettingsJson.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using ModReloader.Core.Features.Reload;
54
using Newtonsoft.Json;
65

76
namespace ModReloader.Core.Features.LogFeatures

Core/Features/Publicizer/CompileSystem.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using Microsoft.CodeAnalysis;
1212
using Microsoft.CodeAnalysis.CSharp;
1313
using Microsoft.CodeAnalysis.Emit;
14-
using ModReloader.Core.Features.Reload;
1514
using MonoMod.RuntimeDetour;
1615

1716
namespace ModReloader.Core.Features.Publicizer

0 commit comments

Comments
 (0)