Skip to content

Commit

Permalink
Discord button go to mainmenu
Browse files Browse the repository at this point in the history
  • Loading branch information
cydyn committed Mar 6, 2024
1 parent 0a842c8 commit ae825d2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 58 deletions.
57 changes: 0 additions & 57 deletions Intersect.Client/Interface/Menu/LoginWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public partial class LoginWindow : IMainMenuWindow

private bool mUseSavedPass;

private Button mDiscordButton; // Discord button

//Init
public LoginWindow(Canvas parent, MainMenu mainMenu)
{
Expand Down Expand Up @@ -123,13 +121,6 @@ public LoginWindow(Canvas parent, MainMenu mainMenu)
};
mBackBtn.Clicked += BackBtn_Clicked;

// Discord Button
mDiscordButton = new Button(mLoginWindow, "DiscordButton")
{
Text = "Discord", // Button text
};
mDiscordButton.Clicked += DiscordButton_Clicked;

LoadCredentials();

mLoginWindow.LoadJsonUi(GameContentManager.UI.Menu, Graphics.Renderer.GetResolutionString());
Expand Down Expand Up @@ -234,54 +225,6 @@ void LoginBtn_Clicked(Base sender, ClickedEventArgs arguments)
TryLogin();
}

void DiscordButton_Clicked(Base sender, ClickedEventArgs arguments)
{
try
{
// Spróbuj otworzyć link za pomocą odpowiedniego polecenia dla danego systemu operacyjnego
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "cmd",
Arguments = $"/c start https://discord.gg/ztKp93zvzb",
UseShellExecute = false,
CreateNoWindow = true
});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "xdg-open",
Arguments = $"\"https://discord.gg/ztKp93zvzb\"",
UseShellExecute = false,
CreateNoWindow = true
});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "open",
Arguments = $"\"https://discord.gg/ztKp93zvzb\"",
UseShellExecute = false,
CreateNoWindow = true
});
}
else
{
// Obsługa błędu dla nieobsługiwanego systemu operacyjnego
Console.WriteLine("Unsupported operating system.");
}
}
catch (Exception ex)
{
// Obsłużanie błędu, jeśli nie udało się otworzyć linku
Console.WriteLine($"Error opening Discord link: {ex.Message}");
}
}

public void TryLogin()
{
if (Globals.WaitingOnServer)
Expand Down
59 changes: 58 additions & 1 deletion Intersect.Client/Interface/Menu/MainMenuWindow.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using Intersect.Client.Core;
Expand All @@ -20,6 +22,7 @@ public partial class MainMenuWindow : Window
private readonly Button _buttonRegister;
private readonly Button _buttonSettings;
private readonly Button _buttonStart;
private readonly Button _buttonDiscord;
private readonly MainMenu _mainMenu;

// ReSharper disable once SuggestBaseTypeForParameterInConstructor
Expand Down Expand Up @@ -77,8 +80,16 @@ public MainMenuWindow(Canvas canvas, MainMenu mainMenu) : base(canvas, Strings.M
Text = Strings.MainMenu.Start,
};
_buttonStart.Clicked += ButtonStartOnClicked;

_buttonDiscord = new Button(this, nameof(_buttonDiscord))
{
IsTabable = true,
Text = "Discord", // Tekst przycisku Discord
};
_buttonDiscord.Clicked += ButtonDiscordOnClicked;
}


private void ButtonCreditsOnClicked(Base sender, ClickedEventArgs arguments) =>
_mainMenu.SwitchToWindow<CreditsWindow>();

Expand Down Expand Up @@ -178,7 +189,53 @@ private void ButtonStartOnClicked(Base sender, ClickedEventArgs arguments)
const string singleplayer = "singleplayer";
PacketSender.SendLogin(singleplayer, Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(singleplayer))));
}

void ButtonDiscordOnClicked(Base sender, ClickedEventArgs arguments)
{
try
{
// Spróbuj otworzyć link za pomocą odpowiedniego polecenia dla danego systemu operacyjnego
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "cmd",
Arguments = $"/c start https://discord.gg/ztKp93zvzb",
UseShellExecute = false,
CreateNoWindow = true
});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "xdg-open",
Arguments = $"\"https://discord.gg/ztKp93zvzb\"",
UseShellExecute = false,
CreateNoWindow = true
});
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
System.Diagnostics.Process.Start(new ProcessStartInfo
{
FileName = "open",
Arguments = $"\"https://discord.gg/ztKp93zvzb\"",
UseShellExecute = false,
CreateNoWindow = true
});
}
else
{
// Obsługa błędu dla nieobsługiwanego systemu operacyjnego
Console.WriteLine("Unsupported operating system.");
}
}
catch (Exception ex)
{
// Obsłużanie błędu, jeśli nie udało się otworzyć linku
Console.WriteLine($"Error opening Discord link: {ex.Message}");
}
}
internal void Reset()
{
_buttonSettings.Show();
Expand Down

0 comments on commit ae825d2

Please sign in to comment.