Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新: EconomicsAPI 添加自定义显示信息位置 #110

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions EconomicsAPI/Configured/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public class Setting
[JsonProperty("显示信息")]
public bool StatusText = true;

[JsonProperty("显示信息左移")]
public int StatusTextShiftLeft = 60;

[JsonProperty("显示信息下移")]
public int StatusTextShiftDown = 0;

[JsonProperty("查询提示")]
public string QueryFormat = "[c/FFA500:你当前拥有{0}{1}个]";
}
14 changes: 7 additions & 7 deletions EconomicsAPI/Economics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public override void Initialize()

private void PlayerHandler_OnPlayerCountertop(PlayerCountertopArgs args)
{
args.Messages.Add(new($"当前延迟:{args.Ping.GetPing():F1}", 7));
args.Messages.Add(new($"玩家名称:{args.Player.Name}", 1));
args.Messages.Add(new($"{Setting.CurrencyName}数量:{CurrencyManager.GetUserCurrency(args.Player.Name)}", 3));
args.Messages.Add(new($"在线人数:{TShock.Utils.GetActivePlayerCount()}/{Main.maxPlayers}", 4));
args.Messages.Add(new($"世界名称:{Main.worldName}", 9));
args.Messages.Add(new($"当前生命:{args.Player.TPlayer.statLife}/{args.Player.TPlayer.statLifeMax}", 5));
args.Messages.Add(new($"当前魔力:{args.Player.TPlayer.statMana} / {args.Player.TPlayer.statManaMax}", 6));
args.Messages.Add(new($"当前延迟: {args.Ping.GetPing():F1}ms", 7));
args.Messages.Add(new($"玩家名称: {args.Player.Name}", 1));
args.Messages.Add(new($"{Setting.CurrencyName}数量: {CurrencyManager.GetUserCurrency(args.Player.Name)}", 3));
args.Messages.Add(new($"在线人数: {TShock.Utils.GetActivePlayerCount()}/{Main.maxPlayers}", 4));
args.Messages.Add(new($"世界名称: {Main.worldName}", 9));
args.Messages.Add(new($"当前生命: {args.Player.TPlayer.statLife}/{args.Player.TPlayer.statLifeMax}", 5));
args.Messages.Add(new($"当前魔力: {args.Player.TPlayer.statMana}/{args.Player.TPlayer.statManaMax}", 6));
}

private void OnKillMe(object? sender, GetDataHandlers.KillMeEventArgs e)
Expand Down
17 changes: 6 additions & 11 deletions EconomicsAPI/Utils/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using EconomicsAPI.Attributes;
using EconomicsAPI.EventArgs.PlayerEventArgs;
using EconomicsAPI.Extensions;
using EconomicsAPI.Model;
using Rests;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -39,16 +38,16 @@
if (!m.IsStatic)
{
var instance = types.TryGetValue(x, out var obj) && obj != null ? obj : Activator.CreateInstance(x);
types[x] = instance;

Check warning on line 41 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
var method = instance?.GetType().GetMethod(m.Name, flag);
if (method != null)
{
methods.Add(method, (instance, attribute));

Check warning on line 45 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Argument of type '(object? instance, T attribute)' cannot be used for parameter 'value' of type '(object, T)' in 'void Dictionary<MethodInfo, (object, T)>.Add(MethodInfo key, (object, T) value)' due to differences in the nullability of reference types.
}
}
else
{
methods.Add(m, (null, attribute));

Check warning on line 50 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Argument of type '(object?, T attribute)' cannot be used for parameter 'value' of type '(object, T)' in 'void Dictionary<MethodInfo, (object, T)>.Add(MethodInfo key, (object, T) value)' due to differences in the nullability of reference types.
}
}
}
Expand All @@ -74,17 +73,13 @@
public static void CountertopUpdate(PlayerCountertopArgs args)
{
StringBuilder sb = new();
string EndLine9 = new('\n', 9);
string EndLine15 = new('\n', 15);
sb.Append(EndLine9);
sb.Append("\n\n");
args.Messages.OrderBy(x => x.Order).ForEach(x => sb.AppendLine(x.Message));
sb.Append(EndLine15);
sb.Append(EndLine15);
sb.Append(EndLine15);
if (args.Ping.TSPlayer != null)
string down = new('\n', Economics.Setting.StatusTextShiftDown);
string Left = new(' ', Economics.Setting.StatusTextShiftLeft);
sb.AppendLine(down);
args.Messages.OrderBy(x => x.Order).ForEach(x => sb.AppendLine(x.Message + Left));
if (args.Player != null)
{
args.Ping.TSPlayer.SendData(PacketTypes.Status, sb.ToString(), 0, 0);
args.Player.SendData(PacketTypes.Status, sb.ToString(), 0, 1);
}
}

Expand Down
Loading