More Time Settings

This commit is contained in:
JacobTech 2024-04-06 22:42:31 -04:00
parent 6748e7548d
commit 149c893d3b
8 changed files with 104 additions and 54 deletions

View File

@ -46,6 +46,9 @@ public class Settings
[JsonInclude] [JsonInclude]
[JsonPropertyName("message_font_line_space_px")] [JsonPropertyName("message_font_line_space_px")]
public uint MessageFontLineSpacePX { get; set; } = 5; public uint MessageFontLineSpacePX { get; set; } = 5;
[JsonInclude]
[JsonPropertyName("24hour_time")]
public bool DayTime { get; set; } = false;
} }

View File

@ -1,6 +1,6 @@
using GraphicsManager.Objects; using GraphicsManager.Objects;
using Luski.net.Structures.Public; using Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums; using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI.LuskiControls; namespace Luski.GUI.MainScreen.UI.LuskiControls;
@ -55,7 +55,7 @@ public class RoleView : FlowLayout
public void RemoveUser(long id) public void RemoveUser(long id)
{ {
Size = new(Size.X, Size.Y - uuu[id].Size.Y); Vector2i Sizes = new(Size.X, Size.Y - uuu[id].Size.Y);
i--; i--;
l.Text = " " + n + " — " + i; l.Text = " " + n + " — " + i;
Users.Remove(uuu[id].User); Users.Remove(uuu[id].User);
@ -63,7 +63,8 @@ public class RoleView : FlowLayout
uuu.Remove(id); uuu.Remove(id);
for (int j = 0; j < Controls.Length; j++) for (int j = 0; j < Controls.Length; j++)
{ {
ReportSizeUpdate(Controls[i]); ReportSizeUpdate(Controls[j]);
} }
Size = Sizes;
} }
} }

View File

@ -38,8 +38,6 @@ public class ChatMessage : UserControl
private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, IUser Author, IRenderObject UserIcon, Color4 UserNameColor) private ChatMessage(PublicChat p, SocketMessage message, SocketChannel chan, IUser Author, IRenderObject UserIcon, Color4 UserNameColor)
{ {
pc = p; pc = p;
Label label1; Label label1;
base.Size = new(723.5.ScaleInt(), 37.ScaleInt()); base.Size = new(723.5.ScaleInt(), 37.ScaleInt());
@ -48,20 +46,38 @@ public class ChatMessage : UserControl
Msg = message; Msg = message;
Anchor = ObjectAnchor.Left | ObjectAnchor.Right; Anchor = ObjectAnchor.Left | ObjectAnchor.Right;
DateTime time = chan.Epoch.AddMilliseconds(Msg.ID >> 20).ToLocalTime(); DateTime time = chan.Epoch.AddMilliseconds(Msg.TimeStamp).ToLocalTime();
string time_str; string time_str;
if (time.Date == DateTime.Now.ToLocalTime().Date) if (Globals.Settings.DayTime)
{ {
time_str = $"Today at {time.ToShortTimeString()}"; if (time.Date == DateTime.Now.ToLocalTime().Date)
} {
else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date) time_str = $"Today at {time:HH:mm}";
{ }
time_str = $"Yesterday at {time.ToShortTimeString()}"; else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date)
{
time_str = $"Yesterday at {time:HH:mm}";
}
else
{
time_str = $"{time:M/dd/yyyy HH:mm}";
}
} }
else else
{ {
time_str = $"{time:M/dd/yyyy h:mm tt}"; if (time.Date == DateTime.Now.ToLocalTime().Date)
{
time_str = $"Today at {time.ToShortTimeString().Replace('\u202f', ' ')}";
}
else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date)
{
time_str = $"Yesterday at {time.ToShortTimeString().Replace('\u202f', ' ')}";
}
else
{
time_str = $"{time:M/dd/yyyy h:mm tt}";
}
} }
UserIcon.Location = new(10.ScaleInt(), 2.ScaleInt(), 0); UserIcon.Location = new(10.ScaleInt(), 2.ScaleInt(), 0);
@ -195,12 +211,14 @@ public class ChatMessage : UserControl
} }
readonly List<Label> Labels = new(); readonly List<Label> Labels = new();
private Task NewLabel_MouseLeave(IRenderObject sender) private async Task NewLabel_MouseLeave(IRenderObject sender)
{ {
if (sender is not Label label) return Task.CompletedTask; if (sender is not Label label) return;
if (label.Tag is not MainSocketMessage Message) return Task.CompletedTask; if (label.Tag is not SocketMessage Message) return;
DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); DateTime time = (await Message.GetParent(CancellationToken.None)).Epoch.AddMilliseconds(Message.TimeStamp).ToLocalTime();
string b = time.ToString("h:mm tt"); string b;
if (!Globals.Settings.DayTime) b = time.ToString("h:mm tt");
else b = time.ToString("HH:mm");
Label[] l = Labels.Where(s => s.Text == b).ToArray(); Label[] l = Labels.Where(s => s.Text == b).ToArray();
if (l.Any()) if (l.Any())
{ {
@ -208,23 +226,29 @@ public class ChatMessage : UserControl
Labels.Remove(l.First()); Labels.Remove(l.First());
} }
Window!.TryDraw(); Window!.TryDraw();
return Task.CompletedTask;
} }
private Task NewLabel_MouseEnter(IRenderObject sender) private async Task NewLabel_MouseEnter(IRenderObject sender)
{ {
if (sender is not Label label) return Task.CompletedTask; if (sender is not Label label) return;
if (label.Tag is not MainSocketMessage Message) return Task.CompletedTask; if (label.Tag is not SocketMessage Message) return;
DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); DateTime time = (await Message.GetParent(CancellationToken.None)).Epoch.AddMilliseconds(Message.TimeStamp).ToLocalTime();
Label m = new(Globals.DefaultFont) Label m;
if (!Globals.Settings.DayTime) m = new( Globals.SmallTimeFont)
{ {
Text = time.ToString("h:mm tt"), Text = time.ToString("h:mm tt"),
Location = new(7.5.ScaleInt(), label.Location.Y - 13 + (int)label.Font.PixelHeight, 0),
}; };
else m = new( Globals.SmallTimeFont)
{
Text = time.ToString("HH:mm"),
};
m.Location = new(
label.Location.X - m.Size.X - 5.ScaleInt(),
(int)(label.Location.Y + label.Font.PixelHeight - Globals.SmallTimeFont.PixelHeight),
0);
Controls.Add(m); Controls.Add(m);
Labels.Add(m); Labels.Add(m);
Window!.TryDraw(); Window!.TryDraw();
return Task.CompletedTask;
} }
} }

View File

@ -246,8 +246,6 @@ public class PublicChat : UserControl
Controls.Add(memberflow); Controls.Add(memberflow);
} }
if (memberflow.Controls.Length == 0) if (memberflow.Controls.Length == 0)
{ {
Dictionary<long, RoleView> Roles = new(); Dictionary<long, RoleView> Roles = new();
@ -293,12 +291,13 @@ public class PublicChat : UserControl
} }
} }
Channel!.Server.StatusUpdate += async (status, user) => async Task OnServerOnStatusUpdate(UserStatus status, SocketUser user)
{ {
if (!SeperateOffline && !Users.ContainsKey(user.Id)) return; if (!SeperateOffline && !Users.ContainsKey(user.Id)) return;
Role top_role2 = (await user.GetRoles())[0]; Role top_role2 = (await user.GetRoles())[0];
Globals.ms.Invoke(async () => Globals.ms.Invoke(async () =>
{ {
BlockDraw = true;
if (status == UserStatus.Offline && user.Status != UserStatus.Offline) if (status == UserStatus.Offline && user.Status != UserStatus.Offline)
{ {
Offline!.RemoveUser(user.Id); Offline!.RemoveUser(user.Id);
@ -311,7 +310,7 @@ public class PublicChat : UserControl
{ {
Roles.Add(top_role2.ID, new(top_role2)); Roles.Add(top_role2.ID, new(top_role2));
int _index_ = 0; int _index_ = 0;
for (int index_ = memberflow.Controls.Length-1; index_ >= 0; index_--) for (int index_ = memberflow.Controls.Length - 1; index_ >= 0; index_--)
{ {
RoleView r = ((RoleView)memberflow.Controls[index_]); RoleView r = ((RoleView)memberflow.Controls[index_]);
if (r.r is null) continue; if (r.r is null) continue;
@ -321,6 +320,7 @@ public class PublicChat : UserControl
break; break;
} }
} }
memberflow.Controls.Insert(_index_, Roles[top_role2.ID]); memberflow.Controls.Insert(_index_, Roles[top_role2.ID]);
} }
@ -329,27 +329,36 @@ public class PublicChat : UserControl
if (Offline is not null) memberflow.ReportSizeUpdate(Offline); if (Offline is not null) memberflow.ReportSizeUpdate(Offline);
Users[user.Id] = Roles[top_role2.ID]; Users[user.Id] = Roles[top_role2.ID];
} }
if (status != UserStatus.Offline && user.Status == UserStatus.Offline) if (status != UserStatus.Offline && user.Status == UserStatus.Offline)
{ {
Users[user.Id].RemoveUser(user.Id); Users[user.Id].RemoveUser(user.Id);
bool g = true;
if (Users[user.Id].i == 0) if (Users[user.Id].i == 0)
{ {
if (Roles.ContainsKey(top_role2.ID)) Roles.Remove(top_role2.ID); if (Roles.ContainsKey(top_role2.ID)) Roles.Remove(top_role2.ID);
g = false;
memberflow.Controls.Remove(Users[user.Id]); memberflow.Controls.Remove(Users[user.Id]);
} }
if (Offline is null) if (Offline is null)
{ {
Offline = new(); Offline = new();
memberflow.Controls.Add(Offline); memberflow.Controls.Add(Offline);
} }
await Offline.AddUser(user, top_role2); await Offline.AddUser(user, top_role2);
memberflow.ReportSizeUpdate(Offline); memberflow.ReportSizeUpdate(Offline);
memberflow.ReportSizeUpdate(Users[user.Id]); if (g) memberflow.ReportSizeUpdate(Users[user.Id]);
Users[user.Id] = Offline; Users[user.Id] = Offline;
} }
BlockDraw = false;
Globals.ms.DrawFrame(); Globals.ms.DrawFrame();
}); });
}; }
Channel!.Server.StatusUpdate += OnServerOnStatusUpdate;
} }
TryDraw(); TryDraw();
memberflow.Visible = true; memberflow.Visible = true;
@ -383,13 +392,13 @@ public class PublicChat : UserControl
public async Task LoadChannel(SocketChannel channel) public async Task LoadChannel(SocketChannel channel)
{ {
Channel = channel; Channel = channel;
BlockDraw = true;
Globals.ms.BlockDraw = true;
if (memberflow is not null) if (memberflow is not null)
{ {
BlockDraw = true;
await UserConOnClicked(UserCon!); await UserConOnClicked(UserCon!);
memberflow.Controls.Clear(); memberflow.Controls.Clear();
await UserConOnClicked(UserCon!); await UserConOnClicked(UserCon!);
BlockDraw = false;
} }
title.Text = channel.Name; title.Text = channel.Name;
var five = 5.ScaleInt(); var five = 5.ScaleInt();
@ -410,6 +419,9 @@ public class PublicChat : UserControl
tb.Text = ""; tb.Text = "";
tb.CursorLocation = 0; tb.CursorLocation = 0;
tb.Focus(); tb.Focus();
Globals.ms.BlockDraw = false;
BlockDraw = false;
TryDraw();
} }
public void ClearChat() public void ClearChat()
@ -458,9 +470,13 @@ public class PublicChat : UserControl
if (first is null) first = Message; if (first is null) first = Message;
bool hasbeentenmin = false; bool hasbeentenmin = false;
if (lastm is not null) if (lastm is not null)
{
DateTime chan = Channel!.Epoch.AddMilliseconds(lastm.ID >> 22).ToLocalTime();
hasbeentenmin = hasbeentenmin =
Channel!.Epoch.AddMilliseconds(lastm.ID >> 22).ToLocalTime().AddMinutes(10) < Channel!.Epoch.AddMilliseconds(lastm.ID >> 22).ToLocalTime().AddMinutes(10) <
Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime(); Channel!.Epoch.AddMilliseconds(Message.ID >> 22).ToLocalTime();
}
lastm = Message; lastm = Message;
if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile) if (lastUser is null || lastUser != Message.AuthorID || hasbeentenmin || fake != Message.IsProfile)
{ {
@ -472,9 +488,9 @@ public class PublicChat : UserControl
} }
else else
{ {
LastChatMessage = await ChatMessage.MakeChatMessage(this, Message); Globals.ms.Invoke(async () =>
Globals.ms.Invoke(() =>
{ {
LastChatMessage = await ChatMessage.MakeChatMessage(this, Message);
MessageFlow.Controls.Add(LastChatMessage); MessageFlow.Controls.Add(LastChatMessage);
if (scrool) MessageFlow.ScrollToBottom(); if (scrool) MessageFlow.ScrollToBottom();
Window.TryDraw(); Window.TryDraw();

View File

@ -23,7 +23,7 @@ public class SettingsMenu : UserControl
LuskiExperiments.Settings.Theme.EventToggled += ThemeOnEventToggled; LuskiExperiments.Settings.Theme.EventToggled += ThemeOnEventToggled;
BehindName = Globals.ms.Title; BehindName = Globals.ms.Title;
Globals.ms.Title = "Settings - Luski"; Globals.ms.Title = "Settings - Luski";
BackgroundColor = new(34, 34, 34, 255); base.BackgroundColor = new(34, 34, 34, 255);
base.Size = Globals.ms.Size; base.Size = Globals.ms.Size;
Anchor = ObjectAnchor.All; Anchor = ObjectAnchor.All;
if (CategoryButton.seltec is null) if (CategoryButton.seltec is null)
@ -143,8 +143,17 @@ public class SettingsMenu : UserControl
fl.Controls.Insert(0, AppSettings); fl.Controls.Insert(0, AppSettings);
fl.ScrollToBottom(); fl.ScrollToBottom();
} }
page = new()
{
BackgroundColor = this.BackgroundColor,
Location = new(fl.Size.X + 40.ScaleInt(), 0, 0),
Size = new(Globals.ms.Size.X - fl.Size.X - 80.ScaleInt(), Globals.ms.Size.Y),
AllowHoverFromBehind = true,
Anchor = ObjectAnchor.All,
HScrollPixels = Globals.Settings.PerScrollPixels
};
Controls.Add(page);
page.ForceDistanceUpdate(this);
Category As = new("ADVANCED SETTINGS"); Category As = new("ADVANCED SETTINGS");
CategoryButton cb = new("Experiments", this) CategoryButton cb = new("Experiments", this)
{ {
@ -196,29 +205,23 @@ public class SettingsMenu : UserControl
TextLocation = TextLocation.LineCenter, TextLocation = TextLocation.LineCenter,
AllowMultiLine = false AllowMultiLine = false
}); });
t.ForceDistanceUpdate(page);
t.KeyPress += args => t.KeyPress += args =>
{ {
Globals.UpdaterSettings.Updater = t.Text; Globals.UpdaterSettings.Updater = t.Text;
Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings);
return Task.CompletedTask; return Task.CompletedTask;
}; };
Globals.ms.ForceUpdate(new(Globals.ms.Size));
} }
}; };
As.AddButton(cb); As.AddButton(cb);
As.AddButton(us); As.AddButton(us);
fl.Controls.Add(As); fl.Controls.Add(As);
page = new()
{
BackgroundColor = this.BackgroundColor,
Location = new(fl.Size.X + 40.ScaleInt(), 0, 0),
Size = new(Globals.ms.Size.X - fl.Size.X - 80.ScaleInt(), Globals.ms.Size.Y),
AllowHoverFromBehind = true,
Anchor = ObjectAnchor.All,
HScrollPixels = Globals.Settings.PerScrollPixels
};
Controls.Add(page);
_ = cb.ToggleSelected();
fl.ForceDistanceUpdate(this); fl.ForceDistanceUpdate(this);
_ = cb.ToggleSelected();
Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png")) Rectangle closebtn = new(Globals.ms.TextureManager.GetTextureResource("close.png"))
{ {

View File

@ -132,6 +132,7 @@ public class MainScreenWindow : Window
Globals.MessageFont.ExtraLinePixels = Globals.Settings.MessageFontLineSpacePX.ScaleFont(); Globals.MessageFont.ExtraLinePixels = Globals.Settings.MessageFontLineSpacePX.ScaleFont();
Globals.MessageFont.FontSize = FontSize.Regular; Globals.MessageFont.FontSize = FontSize.Regular;
Globals.SmallTimeFont = Globals.DefaultFont.Clone(); Globals.SmallTimeFont = Globals.DefaultFont.Clone();
Globals.SmallTimeFont.PixelHeight = ((uint)11).ScaleFont();
Globals.LuskiTexture = TextureManager.GetTextureResource("Luski.png"); Globals.LuskiTexture = TextureManager.GetTextureResource("Luski.png");
try try
{ {
@ -178,6 +179,7 @@ public class MainScreenWindow : Window
{ {
ServerLoginOverlay SLO = new(Server.Domain); ServerLoginOverlay SLO = new(Server.Domain);
Controls.Add(SLO); Controls.Add(SLO);
ForceUpdate(new(Size));
return; return;
} }
BlockDraw = true; BlockDraw = true;

View File

@ -285,8 +285,9 @@ public static class Globals
Color = c.ToColor4() Color = c.ToColor4()
}; };
l.Text = User.DisplayName[0].ToString(); l.Text = User.DisplayName[0].ToString();
var y = l.GetSizeOfChar(0);
l.Location = new((r.Size.X - l.Size.X)/2, l.Location = new((r.Size.X - l.Size.X)/2,
(int)(r.Location.Y + (r.Size.Y / 2) - (l.Font.CurrentFonts[0].Face.Size.Metrics.NominalHeight / 2) - l.Size.Y + l.Font.PixelHeight), (int)(r.Size.Y - (l.Font.PixelHeight - y.Y) - (r.Size.Y / 2) - (y.Y/2)),
0); 0);
r.Controls.Add(l); r.Controls.Add(l);
return r; return r;

View File

@ -21,8 +21,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="GraphicsManager" Version="1.0.9-alpha24" /> <PackageReference Include="GraphicsManager" Version="1.0.9-alpha26" />
<PackageReference Include="Luski.net" Version="2.0.0-alpha80" /> <PackageReference Include="Luski.net" Version="2.0.0-alpha83" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>