From 8ee32ba7809ab29310c17bbf51d2874ed93234de Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 10 Nov 2021 20:37:14 +1100 Subject: [PATCH] Get rid of obsolete warning when compiling GUI, partially fix scale 1/2 not working --- GUI/Controls/ColoredTextBox.cs | 2 +- GUI/GuiPerms.cs | 7 +- GUI/GuiUtils.cs | 64 +++++++++++++++++++ GUI/MCGalaxyGUI.csproj | 1 + GUI/Popups/PortTools.cs | 4 +- GUI/Program.cs | 42 ++---------- GUI/PropertyWindow/PropertyWindow.Misc.cs | 2 +- GUI/PropertyWindow/PropertyWindow.Relay.cs | 2 +- GUI/Settings/LevelProperties.cs | 3 +- GUI/UPnP.cs | 7 +- GUI/Window/Window.Main.cs | 2 +- .../Drawing/Transform/SimpleTransforms.cs | 6 +- 12 files changed, 87 insertions(+), 55 deletions(-) create mode 100644 GUI/GuiUtils.cs diff --git a/GUI/Controls/ColoredTextBox.cs b/GUI/Controls/ColoredTextBox.cs index e5a83c456..ca3d4a422 100644 --- a/GUI/Controls/ColoredTextBox.cs +++ b/GUI/Controls/ColoredTextBox.cs @@ -129,7 +129,7 @@ namespace MCGalaxy.Gui.Components { 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); } /// Scrolls to the end of the log diff --git a/GUI/GuiPerms.cs b/GUI/GuiPerms.cs index b81115de0..306545004 100644 --- a/GUI/GuiPerms.cs +++ b/GUI/GuiPerms.cs @@ -19,9 +19,10 @@ using System; 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; diff --git a/GUI/GuiUtils.cs b/GUI/GuiUtils.cs new file mode 100644 index 000000000..d021692d2 --- /dev/null +++ b/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 +{ + /// Shortcuts for MessageBox.Show + 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 + { + /// Opens the given url in the system's default web browser + /// Catches and logs any unhandled errors + 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); + } + } + } +} + diff --git a/GUI/MCGalaxyGUI.csproj b/GUI/MCGalaxyGUI.csproj index dd3997d31..fa5bc87c7 100644 --- a/GUI/MCGalaxyGUI.csproj +++ b/GUI/MCGalaxyGUI.csproj @@ -56,6 +56,7 @@ + ColorSelector.cs diff --git a/GUI/Popups/PortTools.cs b/GUI/Popups/PortTools.cs index f252e40e7..a698a9017 100644 --- a/GUI/Popups/PortTools.cs +++ b/GUI/Popups/PortTools.cs @@ -40,7 +40,7 @@ namespace MCGalaxy.Gui.Popups { } 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) { @@ -48,7 +48,7 @@ namespace MCGalaxy.Gui.Popups { } void linkHelpForward_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - Program.OpenBrowser("https://portforward.com"); + GuiUtils.OpenBrowser("https://portforward.com"); } void btnForward_Click(object sender, EventArgs e) { diff --git a/GUI/Program.cs b/GUI/Program.cs index aa8bebccc..5fbc3f7ec 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -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); @@ -96,15 +71,6 @@ namespace MCGalaxy.Gui { 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); - } - } } } diff --git a/GUI/PropertyWindow/PropertyWindow.Misc.cs b/GUI/PropertyWindow/PropertyWindow.Misc.cs index 1dc2d61d5..68afe31c2 100644 --- a/GUI/PropertyWindow/PropertyWindow.Misc.cs +++ b/GUI/PropertyWindow/PropertyWindow.Misc.cs @@ -100,7 +100,7 @@ namespace MCGalaxy.Gui { } 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) { diff --git a/GUI/PropertyWindow/PropertyWindow.Relay.cs b/GUI/PropertyWindow/PropertyWindow.Relay.cs index 33ab73b1a..f0a8a0976 100644 --- a/GUI/PropertyWindow/PropertyWindow.Relay.cs +++ b/GUI/PropertyWindow/PropertyWindow.Relay.cs @@ -134,7 +134,7 @@ namespace MCGalaxy.Gui { } void dis_lnkHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { - Program.OpenBrowser(Updater.SourceURL + "/wiki/Discord-relay-bot/"); + GuiUtils.OpenBrowser(Updater.SourceURL + "/wiki/Discord-relay-bot/"); } } } diff --git a/GUI/Settings/LevelProperties.cs b/GUI/Settings/LevelProperties.cs index 2c0c07c09..2f7102ff7 100644 --- a/GUI/Settings/LevelProperties.cs +++ b/GUI/Settings/LevelProperties.cs @@ -134,8 +134,7 @@ namespace MCGalaxy.Gui { 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); } diff --git a/GUI/UPnP.cs b/GUI/UPnP.cs index 928394c87..9b81d2e71 100644 --- a/GUI/UPnP.cs +++ b/GUI/UPnP.cs @@ -22,9 +22,10 @@ using System.Xml; 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 = diff --git a/GUI/Window/Window.Main.cs b/GUI/Window/Window.Main.cs index 091a751c4..a6149291c 100644 --- a/GUI/Window/Window.Main.cs +++ b/GUI/Window/Window.Main.cs @@ -138,7 +138,7 @@ namespace MCGalaxy.Gui { 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) { diff --git a/MCGalaxy/Drawing/Transform/SimpleTransforms.cs b/MCGalaxy/Drawing/Transform/SimpleTransforms.cs index 119660941..99964b800 100644 --- a/MCGalaxy/Drawing/Transform/SimpleTransforms.cs +++ b/MCGalaxy/Drawing/Transform/SimpleTransforms.cs @@ -43,9 +43,9 @@ namespace MCGalaxy.Drawing.Transforms 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);