mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Add window for showing server information
This commit is contained in:
parent
ce1c2bc88f
commit
fbd5692df4
@ -21,7 +21,7 @@
|
|||||||
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
<MenuItem x:Name="VersionMenuItem" IsEnabled="False" />
|
||||||
<Separator />
|
<Separator />
|
||||||
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" Visibility="Collapsed" Click="RichPresenceMenuItem_Click" />
|
<MenuItem x:Name="RichPresenceMenuItem" Header="Discord Rich Presence" IsCheckable="True" Visibility="Collapsed" Click="RichPresenceMenuItem_Click" />
|
||||||
<MenuItem x:Name="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" Click="ServerDetailsMenuItem_Click" />
|
<MenuItem x:Name="ServerDetailsMenuItem" Header="See server details" Visibility="Collapsed" />
|
||||||
<MenuItem x:Name="TestMenuItem" Header="Test" IsCheckable="True" Click="TestMenuItem_Click" />
|
<MenuItem x:Name="TestMenuItem" Header="Test" IsCheckable="True" Click="TestMenuItem_Click" />
|
||||||
</ContextMenu>
|
</ContextMenu>
|
||||||
</ui:UiWindow.ContextMenu>
|
</ui:UiWindow.ContextMenu>
|
||||||
|
@ -48,11 +48,6 @@ namespace Bloxstrap.UI.Elements.ContextMenu
|
|||||||
Controls.ShowMessageBox($"hi how u doing i am {RichPresenceMenuItem.IsChecked}", MessageBoxImage.Warning);
|
Controls.ShowMessageBox($"hi how u doing i am {RichPresenceMenuItem.IsChecked}", MessageBoxImage.Warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ServerDetailsMenuItem_Click(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
Controls.ShowMessageBox($"hi how u doing i am {RichPresenceMenuItem.IsChecked}", MessageBoxImage.Warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void TestMenuItem_Click(object sender, RoutedEventArgs e)
|
private void TestMenuItem_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Controls.ShowMessageBox($"hi how u doing i am {TestMenuItem.IsChecked}", MessageBoxImage.Warning);
|
Controls.ShowMessageBox($"hi how u doing i am {TestMenuItem.IsChecked}", MessageBoxImage.Warning);
|
||||||
|
46
Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml
Normal file
46
Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<ui:UiWindow x:Class="Bloxstrap.UI.Elements.ContextMenu.ServerInformation"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:local="clr-namespace:Bloxstrap.UI.Elements.ContextMenu"
|
||||||
|
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||||
|
xmlns:models="clr-namespace:Bloxstrap.UI.ViewModels.ContextMenu"
|
||||||
|
d:DataContext="{d:DesignInstance Type=models:ServerInformationViewModel}"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="Server information"
|
||||||
|
MinWidth="0"
|
||||||
|
MinHeight="0"
|
||||||
|
Width="400"
|
||||||
|
Height="230"
|
||||||
|
ResizeMode="NoResize"
|
||||||
|
Background="{ui:ThemeResource ApplicationBackgroundBrush}"
|
||||||
|
ExtendsContentIntoTitleBar="True"
|
||||||
|
WindowStartupLocation="CenterScreen">
|
||||||
|
<Grid>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<ui:TitleBar Grid.Row="0" Grid.ColumnSpan="2" Padding="8" x:Name="RootTitleBar" Title="Server information" ShowMinimize="False" ShowMaximize="False" CanMaximize="False" KeyboardNavigation.TabNavigation="None" Icon="pack://application:,,,/Bloxstrap.ico" />
|
||||||
|
|
||||||
|
<StackPanel Grid.Row="1" Margin="12">
|
||||||
|
<TextBlock Text="Instance ID" FontSize="16" FontWeight="Medium" />
|
||||||
|
<TextBlock Text="{Binding InstanceId, Mode=OneWay}" />
|
||||||
|
|
||||||
|
<TextBlock Margin="0,16,0,0" Text="Server location" FontSize="16" FontWeight="Medium" />
|
||||||
|
<TextBlock Text="{Binding ServerLocation, Mode=OneWay}" />
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
||||||
|
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
|
||||||
|
<Button MinWidth="100" Content="Copy instance ID" Command="{Binding CopyInstanceIdCommand, Mode=OneTime}" />
|
||||||
|
<Button Margin="12,0,0,0" MinWidth="100" Content="Close" Command="{Binding CloseWindowCommand, Mode=OneTime}" />
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</ui:UiWindow>
|
30
Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml.cs
Normal file
30
Bloxstrap/UI/Elements/ContextMenu/ServerInformation.xaml.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
|
using Bloxstrap.UI.ViewModels.ContextMenu;
|
||||||
|
|
||||||
|
namespace Bloxstrap.UI.Elements.ContextMenu
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for ServerInformation.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class ServerInformation
|
||||||
|
{
|
||||||
|
public ServerInformation(RobloxActivity activityWatcher)
|
||||||
|
{
|
||||||
|
DataContext = new ServerInformationViewModel(this, activityWatcher);
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,7 +36,7 @@
|
|||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
<Border Grid.Row="2" Margin="0,10,0,0" Padding="15" Background="{ui:ThemeResource SolidBackgroundFillColorSecondaryBrush}">
|
||||||
<StackPanel Grid.Row="2" Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
|
<StackPanel Orientation="Horizontal" FlowDirection="LeftToRight" HorizontalAlignment="Right">
|
||||||
<Button x:Name="ButtonOne" MinWidth="100" Content="Button 1" />
|
<Button x:Name="ButtonOne" MinWidth="100" Content="Button 1" />
|
||||||
<Button x:Name="ButtonTwo" MinWidth="100" Margin="12,0,0,0" Content="Button 2" />
|
<Button x:Name="ButtonTwo" MinWidth="100" Margin="12,0,0,0" Content="Button 2" />
|
||||||
<Button x:Name="ButtonThree" MinWidth="100" Margin="12,0,0,0" Content="Button 3" />
|
<Button x:Name="ButtonThree" MinWidth="100" Margin="12,0,0,0" Content="Button 3" />
|
||||||
|
@ -7,12 +7,16 @@ namespace Bloxstrap.UI
|
|||||||
{
|
{
|
||||||
public class NotifyIconWrapper : IDisposable
|
public class NotifyIconWrapper : IDisposable
|
||||||
{
|
{
|
||||||
|
// lol who needs properly structured mvvm and xaml when you have the absolute catastrophe that this is
|
||||||
|
|
||||||
bool _disposed = false;
|
bool _disposed = false;
|
||||||
|
|
||||||
private readonly System.Windows.Forms.NotifyIcon _notifyIcon;
|
private readonly System.Windows.Forms.NotifyIcon _notifyIcon;
|
||||||
private readonly MenuContainer _menuContainer = new();
|
private readonly MenuContainer _menuContainer = new();
|
||||||
private RobloxActivity? _activityWatcher;
|
private RobloxActivity? _activityWatcher;
|
||||||
|
|
||||||
|
private ServerInformation? _serverInformationWindow;
|
||||||
|
|
||||||
public DiscordRichPresence? RichPresenceIntegration;
|
public DiscordRichPresence? RichPresenceIntegration;
|
||||||
|
|
||||||
EventHandler? _alertClickHandler;
|
EventHandler? _alertClickHandler;
|
||||||
@ -31,6 +35,9 @@ namespace Bloxstrap.UI
|
|||||||
_notifyIcon.MouseClick += MouseClickEventHandler;
|
_notifyIcon.MouseClick += MouseClickEventHandler;
|
||||||
|
|
||||||
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
_menuContainer.Dispatcher.BeginInvoke(_menuContainer.ShowDialog);
|
||||||
|
|
||||||
|
_menuContainer.ServerDetailsMenuItem.Click += (_, _) => ShowServerInformationWindow();
|
||||||
|
|
||||||
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
_menuContainer.Closing += (_, _) => App.Logger.WriteLine("[NotifyIconWrapper::NotifyIconWrapper] Context menu container closed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,17 +53,22 @@ namespace Bloxstrap.UI
|
|||||||
|
|
||||||
public async void OnGameJoin()
|
public async void OnGameJoin()
|
||||||
{
|
{
|
||||||
string serverLocation = await _activityWatcher!.GetServerLocation();
|
|
||||||
|
|
||||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Visible);
|
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Visible);
|
||||||
|
|
||||||
if (App.Settings.Prop.ShowServerDetails)
|
if (App.Settings.Prop.ShowServerDetails)
|
||||||
ShowAlert("Connnected to server", $"Location: {serverLocation}", 10, (_, _) => Clipboard.SetText(_activityWatcher.ActivityJobId));
|
{
|
||||||
|
string serverLocation = await _activityWatcher!.GetServerLocation();
|
||||||
|
ShowAlert("Connnected to server", $"Location: {serverLocation}\nClick for more information", 10, (_, _) => ShowServerInformationWindow());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnGameLeave(object? sender, EventArgs e)
|
public void OnGameLeave(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Collapsed);
|
_menuContainer.Dispatcher.Invoke(() => _menuContainer.ServerDetailsMenuItem.Visibility = Visibility.Collapsed);
|
||||||
|
|
||||||
|
if (_serverInformationWindow is not null && _serverInformationWindow.IsVisible)
|
||||||
|
_serverInformationWindow.Dispatcher.Invoke(_serverInformationWindow.Close);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
public void MouseClickEventHandler(object? sender, System.Windows.Forms.MouseEventArgs e)
|
||||||
@ -68,6 +80,20 @@ namespace Bloxstrap.UI
|
|||||||
_menuContainer.ContextMenu.IsOpen = true;
|
_menuContainer.ContextMenu.IsOpen = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ShowServerInformationWindow()
|
||||||
|
{
|
||||||
|
if (_serverInformationWindow is null)
|
||||||
|
{
|
||||||
|
_serverInformationWindow = new ServerInformation(_activityWatcher!);
|
||||||
|
_serverInformationWindow.Closed += (_, _) => _serverInformationWindow = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_serverInformationWindow.IsVisible)
|
||||||
|
_serverInformationWindow.Show();
|
||||||
|
|
||||||
|
_serverInformationWindow.Activate();
|
||||||
|
}
|
||||||
|
|
||||||
public void ShowAlert(string caption, string message, int duration, EventHandler? clickHandler)
|
public void ShowAlert(string caption, string message, int duration, EventHandler? clickHandler)
|
||||||
{
|
{
|
||||||
string id = Guid.NewGuid().ToString()[..8];
|
string id = Guid.NewGuid().ToString()[..8];
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
|
using Bloxstrap.UI.Elements.ContextMenu;
|
||||||
|
|
||||||
|
namespace Bloxstrap.UI.ViewModels.ContextMenu
|
||||||
|
{
|
||||||
|
internal class ServerInformationViewModel : NotifyPropertyChangedViewModel
|
||||||
|
{
|
||||||
|
private readonly ServerInformation _window;
|
||||||
|
private readonly RobloxActivity _activityWatcher;
|
||||||
|
|
||||||
|
public string InstanceId => _activityWatcher.ActivityJobId;
|
||||||
|
public string ServerLocation { get; private set; } = "Loading, please wait...";
|
||||||
|
|
||||||
|
public ICommand CopyInstanceIdCommand => new RelayCommand(CopyInstanceId);
|
||||||
|
public ICommand CloseWindowCommand => new RelayCommand(_window.Close);
|
||||||
|
|
||||||
|
public ServerInformationViewModel(ServerInformation window, RobloxActivity activityWatcher)
|
||||||
|
{
|
||||||
|
_window = window;
|
||||||
|
_activityWatcher = activityWatcher;
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
ServerLocation = await _activityWatcher.GetServerLocation();
|
||||||
|
OnPropertyChanged(nameof(ServerLocation));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CopyInstanceId() => Clipboard.SetText(InstanceId);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user