Skip to content

Commit

Permalink
Get rid of obsolete warning when compiling GUI, partially fix scale 1…
Browse files Browse the repository at this point in the history
…/2 not working
  • Loading branch information
UnknownShadow200 committed Nov 10, 2021
1 parent dad908c commit 8ee32ba
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 55 deletions.
2 changes: 1 addition & 1 deletion GUI/Controls/ColoredTextBox.cs
Expand Up @@ -129,7 +129,7 @@ public class ColoredTextBox : RichTextBox {

void HandleLinkClicked(object sender, System.Windows.Forms.LinkClickedEventArgs e) {
if (!Popup.OKCancel("Never open links from people that you don't trust!", "Warning!!")) return;
Program.OpenBrowser(e.LinkText);
GuiUtils.OpenBrowser(e.LinkText);
}

/// <summary> Scrolls to the end of the log </summary>
Expand Down
7 changes: 4 additions & 3 deletions GUI/GuiPerms.cs
Expand Up @@ -19,9 +19,10 @@
using System.Collections.Generic;
using System.Windows.Forms;

namespace MCGalaxy.Gui {
internal static class GuiPerms {

namespace MCGalaxy.Gui
{
internal static class GuiPerms
{
internal static string[] RankNames;
internal static LevelPermission[] RankPerms;

Expand Down
64 changes: 64 additions & 0 deletions GUI/GuiUtils.cs
@@ -0,0 +1,64 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace MCGalaxy.Gui
{
/// <summary> Shortcuts for MessageBox.Show </summary>
public static class Popup
{
public static void Message(string message, string title = "") {
MessageBox.Show(message, title);
}

public static void Error(string message) {
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

public static void Warning(string message) {
MessageBox.Show(message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

public static bool OKCancel(string message, string title) {
return MessageBox.Show(message, title, MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning) == DialogResult.OK;
}

public static bool YesNo(string message, string title) {
return MessageBox.Show(message, title, MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes;
}
}

public static class GuiUtils
{
/// <summary> Opens the given url in the system's default web browser </summary>
/// <remarks> Catches and logs any unhandled errors </remarks>
public static void OpenBrowser(string url) {
try {
Process.Start(url);
} catch (Exception ex) {
Logger.LogError("Opening url in browser", ex);
Popup.Error("Failed to open " + url);
}
}
}
}

1 change: 1 addition & 0 deletions GUI/MCGalaxyGUI.csproj
Expand Up @@ -56,6 +56,7 @@
<Compile Include="Controls\HackyPropertyGrid.cs" />
<Compile Include="Controls\TimespanUpDown.cs" />
<Compile Include="GuiPerms.cs" />
<Compile Include="GuiUtils.cs" />
<Compile Include="Popups\ColorSelector.cs" />
<Compile Include="Popups\ColorSelector.Designer.cs">
<DependentUpon>ColorSelector.cs</DependentUpon>
Expand Down
4 changes: 2 additions & 2 deletions GUI/Popups/PortTools.cs
Expand Up @@ -40,15 +40,15 @@ public partial class PortTools : Form {
}

void linkManually_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
Program.OpenBrowser("https://www.canyouseeme.org/");
GuiUtils.OpenBrowser("https://www.canyouseeme.org/");
}

void PortChecker_FormClosing(object sender, FormClosingEventArgs e) {
worker.CancelAsync();
}

void linkHelpForward_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
Program.OpenBrowser("https://portforward.com");
GuiUtils.OpenBrowser("https://portforward.com");
}

void btnForward_Click(object sender, EventArgs e) {
Expand Down
42 changes: 4 additions & 38 deletions GUI/Program.cs
Expand Up @@ -16,40 +16,15 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace MCGalaxy.Gui {

public static class Popup {
public static void Message(string message, string title = "") {
MessageBox.Show(message, title);
}

public static void Error(string message) {
MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

public static void Warning(string message) {
MessageBox.Show(message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

public static bool OKCancel(string message, string title) {
return MessageBox.Show(message, title, MessageBoxButtons.OKCancel,
MessageBoxIcon.Warning) == DialogResult.OK;
}

public static bool YesNo(string message, string title) {
return MessageBox.Show(message, title, MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes;
}
}

public static class Program {

namespace MCGalaxy.Gui
{
public static class Program
{
[STAThread]
public static void Main(string[] args) {
Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Expand Down Expand Up @@ -96,15 +71,6 @@ public static class Program {
static void ThreadExHandler(object sender, ThreadExceptionEventArgs e) {
LogAndRestart(e.Exception);
}

public static void OpenBrowser(string url) {
try {
Process.Start(url);
} catch (Exception ex) {
Logger.LogError("Opening url in browser", ex);
Popup.Error("Failed to open " + url);
}
}
}
}

2 changes: 1 addition & 1 deletion GUI/PropertyWindow/PropertyWindow.Misc.cs
Expand Up @@ -100,7 +100,7 @@ public partial class PropertyWindow : Form {
}

void sql_linkDownload_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
Program.OpenBrowser("https://dev.mysql.com/downloads/");
GuiUtils.OpenBrowser("https://dev.mysql.com/downloads/");
}

void sql_chkUseSQL_CheckedChanged(object sender, EventArgs e) {
Expand Down
2 changes: 1 addition & 1 deletion GUI/PropertyWindow/PropertyWindow.Relay.cs
Expand Up @@ -134,7 +134,7 @@ public partial class PropertyWindow : Form {
}

void dis_lnkHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {
Program.OpenBrowser(Updater.SourceURL + "/wiki/Discord-relay-bot/");
GuiUtils.OpenBrowser(Updater.SourceURL + "/wiki/Discord-relay-bot/");
}
}
}
3 changes: 1 addition & 2 deletions GUI/Settings/LevelProperties.cs
Expand Up @@ -134,8 +134,7 @@ public sealed class LevelProperties {

void SetAutoload(bool value) {
if (value) {
// Use AddOrReplace for backwards compatibility
Server.AutoloadMaps.AddOrReplace(lvl.name, lvl.physics.ToString());
Server.AutoloadMaps.Update(lvl.name, lvl.physics.ToString());
} else {
Server.AutoloadMaps.Remove(lvl.name);
}
Expand Down
7 changes: 4 additions & 3 deletions GUI/UPnP.cs
Expand Up @@ -22,9 +22,10 @@
using MCGalaxy.Network;
//This upnp class comes from http://www.codeproject.com/Articles/27992/NAT-Traversal-with-UPnP-in-C, Modified for use with MCForge

namespace MCGalaxy {
public static class UPnP {

namespace MCGalaxy
{
public static class UPnP
{
public static TimeSpan Timeout = TimeSpan.FromSeconds(3);

const string req =
Expand Down
2 changes: 1 addition & 1 deletion GUI/Window/Window.Main.cs
Expand Up @@ -138,7 +138,7 @@ public partial class Window : Form {

void main_TxtUrl_DoubleClick(object sender, EventArgs e) {
if (!Main_IsUsingUrl()) return;
Program.OpenBrowser(main_txtUrl.Text);
GuiUtils.OpenBrowser(main_txtUrl.Text);
}

void main_BtnSaveAll_Click(object sender, EventArgs e) {
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Drawing/Transform/SimpleTransforms.cs
Expand Up @@ -43,9 +43,9 @@ public sealed class ScaleTransform : Transform

public void CheckScales() {
// Need to reverse direction for negative scales
signX = Math.Sign(XMul / XDiv);
signY = Math.Sign(YMul / YDiv);
signZ = Math.Sign(ZMul / ZDiv);
signX = Math.Sign(XMul * XDiv); // using * instead of /,
signY = Math.Sign(YMul * YDiv); // as otherwise scales < 1
signZ = Math.Sign(ZMul * ZDiv); // don't work (e.g. 1/2)

XMul = Math.Abs(XMul); XDiv = Math.Abs(XDiv);
YMul = Math.Abs(YMul); YDiv = Math.Abs(YDiv);
Expand Down

0 comments on commit 8ee32ba

Please sign in to comment.