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]
[JsonPropertyName("message_font_line_space_px")]
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 Luski.net.Structures.Public;
using Luski.Shared.PublicServers.V1.Enums;
using OpenTK.Mathematics;
namespace Luski.GUI.MainScreen.UI.LuskiControls;
@ -55,7 +55,7 @@ public class RoleView : FlowLayout
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--;
l.Text = " " + n + " — " + i;
Users.Remove(uuu[id].User);
@ -63,7 +63,8 @@ public class RoleView : FlowLayout
uuu.Remove(id);
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)
{
pc = p;
Label label1;
base.Size = new(723.5.ScaleInt(), 37.ScaleInt());
@ -48,20 +46,38 @@ public class ChatMessage : UserControl
Msg = message;
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;
if (time.Date == DateTime.Now.ToLocalTime().Date)
if (Globals.Settings.DayTime)
{
time_str = $"Today at {time.ToShortTimeString()}";
}
else if (time.Date == DateTime.Now.ToLocalTime().AddDays(-1).Date)
{
time_str = $"Yesterday at {time.ToShortTimeString()}";
if (time.Date == DateTime.Now.ToLocalTime().Date)
{
time_str = $"Today at {time:HH:mm}";
}
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
{
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);
@ -195,12 +211,14 @@ public class ChatMessage : UserControl
}
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 (label.Tag is not MainSocketMessage Message) return Task.CompletedTask;
DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime();
string b = time.ToString("h:mm tt");
if (sender is not Label label) return;
if (label.Tag is not SocketMessage Message) return;
DateTime time = (await Message.GetParent(CancellationToken.None)).Epoch.AddMilliseconds(Message.TimeStamp).ToLocalTime();
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();
if (l.Any())
{
@ -208,23 +226,29 @@ public class ChatMessage : UserControl
Labels.Remove(l.First());
}
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 (label.Tag is not MainSocketMessage Message) return Task.CompletedTask;
DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime();
Label m = new(Globals.DefaultFont)
if (sender is not Label label) return;
if (label.Tag is not SocketMessage Message) return;
DateTime time = (await Message.GetParent(CancellationToken.None)).Epoch.AddMilliseconds(Message.TimeStamp).ToLocalTime();
Label m;
if (!Globals.Settings.DayTime) m = new( Globals.SmallTimeFont)
{
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);
Labels.Add(m);
Window!.TryDraw();
return Task.CompletedTask;
}
}

View File

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

View File

@ -23,7 +23,7 @@ public class SettingsMenu : UserControl
LuskiExperiments.Settings.Theme.EventToggled += ThemeOnEventToggled;
BehindName = Globals.ms.Title;
Globals.ms.Title = "Settings - Luski";
BackgroundColor = new(34, 34, 34, 255);
base.BackgroundColor = new(34, 34, 34, 255);
base.Size = Globals.ms.Size;
Anchor = ObjectAnchor.All;
if (CategoryButton.seltec is null)
@ -143,8 +143,17 @@ public class SettingsMenu : UserControl
fl.Controls.Insert(0, AppSettings);
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");
CategoryButton cb = new("Experiments", this)
{
@ -196,29 +205,23 @@ public class SettingsMenu : UserControl
TextLocation = TextLocation.LineCenter,
AllowMultiLine = false
});
t.ForceDistanceUpdate(page);
t.KeyPress += args =>
{
Globals.UpdaterSettings.Updater = t.Text;
Globals.UpdaterSettings.SaveSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings);
return Task.CompletedTask;
};
Globals.ms.ForceUpdate(new(Globals.ms.Size));
}
};
As.AddButton(cb);
As.AddButton(us);
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);
_ = cb.ToggleSelected();
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.FontSize = FontSize.Regular;
Globals.SmallTimeFont = Globals.DefaultFont.Clone();
Globals.SmallTimeFont.PixelHeight = ((uint)11).ScaleFont();
Globals.LuskiTexture = TextureManager.GetTextureResource("Luski.png");
try
{
@ -178,6 +179,7 @@ public class MainScreenWindow : Window
{
ServerLoginOverlay SLO = new(Server.Domain);
Controls.Add(SLO);
ForceUpdate(new(Size));
return;
}
BlockDraw = true;

View File

@ -285,8 +285,9 @@ public static class Globals
Color = c.ToColor4()
};
l.Text = User.DisplayName[0].ToString();
var y = l.GetSizeOfChar(0);
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);
r.Controls.Add(l);
return r;

View File

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