From bce70216688e39fc0d446d2b7e08620cc207b555 Mon Sep 17 00:00:00 2001 From: ZaneYork Date: Mon, 30 Mar 2020 17:21:13 +0800 Subject: [PATCH] 1.Add auto hidden feature to Virtual Keyboard 2.Bug fix 3.Disable smapi update check --- src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs | 18 +++++---- .../VirtualToggle.cs | 20 +++++++++- src/SMAPI.Mods.VirtualKeyboard/manifest.json | 6 +-- src/SMAPI/Framework/SCore.cs | 7 ++-- src/SMAPI/Patches/LocationSwitchPatch.cs | 2 +- src/SMAPI/SAlertDialogUtil.cs | 38 +++++++++---------- src/SMAPI/SMAPI.csproj | 2 +- src/SMAPI/SMainActivity.cs | 3 ++ 8 files changed, 60 insertions(+), 36 deletions(-) diff --git a/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs b/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs index 445c3d86..a8b687e9 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/ModConfig.cs @@ -2,7 +2,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard { class ModConfig { - public Toggle vToggle = new Toggle(new Rect(36, 12, 64, 64)); + public Toggle vToggle { get; set; } = new Toggle(new Rect(36, 12, 64, 64), true); public VirtualButton[] buttons { get; set;} = new VirtualButton[] { new VirtualButton(SButton.Q, new Rect(190, 80, 90, 90), 0.5f), new VirtualButton(SButton.I, new Rect(290, 80, 90, 90), 0.5f), @@ -16,11 +16,11 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard new VirtualButton(SButton.RightControl, new Rect(630, 170, 162, 90), 0.5f, "Console") }; internal class VirtualButton { - public SButton key; - public Rect rectangle; - public float transparency; - public string alias; - public string command; + public SButton key { get;set; } + public Rect rectangle { get; set; } + public float transparency { get; set; } = 0.5f; + public string alias { get; set; } = null; + public string command { get; set; } = null; public VirtualButton(SButton key, Rect rectangle, float transparency, string alias = null, string command = null) { this.key = key; @@ -32,12 +32,14 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard } internal class Toggle { - public Rect rectangle; + public Rect rectangle { get; set; } + public bool autoHidden { get; set; } = true; //public float scale; - public Toggle(Rect rectangle) + public Toggle(Rect rectangle, bool autoHidden) { this.rectangle = rectangle; + this.autoHidden = autoHidden; //this.scale = scale; } } diff --git a/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs b/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs index b6608d0f..511c8cce 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs +++ b/src/SMAPI.Mods.VirtualKeyboard/VirtualToggle.cs @@ -14,6 +14,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard private readonly IMonitor Monitor; private int enabledStage = 0; + private bool autoHidden = true; private bool isDefault = true; private ClickableTextureComponent virtualToggleButton; @@ -37,14 +38,31 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard if (this.modConfig.vToggle.rectangle.X != 36 || this.modConfig.vToggle.rectangle.Y != 12) this.isDefault = false; + this.autoHidden = this.modConfig.vToggle.autoHidden; this.virtualToggleButton = new ClickableTextureComponent(new Rectangle(Game1.toolbarPaddingX + 64, 12, 128, 128), this.texture, new Rectangle(0, 0, 16, 16), 5.75f, false); helper.WriteConfig(this.modConfig); this.helper.Events.Display.Rendered += this.OnRendered; + this.helper.Events.Display.MenuChanged += this.OnMenuChanged; this.helper.Events.Input.ButtonPressed += this.VirtualToggleButtonPressed; } + private void OnMenuChanged(object sender, MenuChangedEventArgs e) + { + if(this.autoHidden && e.NewMenu != null) { + foreach (var keys in this.keyboard) + { + keys.hidden = true; + } + foreach (var keys in this.keyboardExtend) + { + keys.hidden = true; + } + this.enabledStage = 0; + } + } + private void VirtualToggleButtonPressed(object sender, ButtonPressedEventArgs e) { Vector2 screenPixels = e.Cursor.ScreenPixels; @@ -80,7 +98,7 @@ namespace StardewModdingAPI.Mods.VirtualKeyboard keys.hidden = true; } this.enabledStage = 0; - if (Game1.activeClickableMenu is IClickableMenu menu) + if (Game1.activeClickableMenu is IClickableMenu menu && !(Game1.activeClickableMenu is DialogueBox)) { menu.exitThisMenu(); Toolbar.toolbarPressed = true; diff --git a/src/SMAPI.Mods.VirtualKeyboard/manifest.json b/src/SMAPI.Mods.VirtualKeyboard/manifest.json index c88b9494..5e39e0fd 100644 --- a/src/SMAPI.Mods.VirtualKeyboard/manifest.json +++ b/src/SMAPI.Mods.VirtualKeyboard/manifest.json @@ -1,8 +1,8 @@ { "Name": "VirtualKeyboard", - "Author": "MartyrPher", - "Version": "3.1.0", - "MinimumApiVersion": "3.1.0", + "Author": "SMAPI", + "Version": "3.2.2", + "MinimumApiVersion": "3.4.0", "Description": "A much needed Virtual Keyboard for SMAPI Android.", "UniqueID": "VirtualKeyboard", "EntryDll": "VirtualKeyboard.dll", diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index b0768f58..f1b71043 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -627,6 +627,7 @@ namespace StardewModdingAPI.Framework this.Monitor.Log("Checking for updates...", LogLevel.Trace); // check SMAPI version +#if DO_ANDROID_SMAPI_UPDATE_CHECK ISemanticVersion updateFound = null; try { @@ -658,7 +659,7 @@ namespace StardewModdingAPI.Framework // show update message on next launch if (updateFound != null) File.WriteAllText(Constants.UpdateMarker, updateFound.ToString()); - +#endif // check mod versions if (mods.Any()) { @@ -1296,8 +1297,8 @@ namespace StardewModdingAPI.Framework errors.Add($"{file.Name} file couldn't be read"); // should never happen, since we're iterating files that exist continue; } - - translations[locale] = data; + if(data != null) + translations[locale] = data; } catch (Exception ex) { diff --git a/src/SMAPI/Patches/LocationSwitchPatch.cs b/src/SMAPI/Patches/LocationSwitchPatch.cs index 06c041a0..599e9305 100644 --- a/src/SMAPI/Patches/LocationSwitchPatch.cs +++ b/src/SMAPI/Patches/LocationSwitchPatch.cs @@ -62,7 +62,7 @@ namespace StardewModdingAPI.Patches { try { - if (value.tapToMove == null) + if (value != null && value.tapToMove == null) { if (value.map != null) { diff --git a/src/SMAPI/SAlertDialogUtil.cs b/src/SMAPI/SAlertDialogUtil.cs index 0bfb8247..b0b9c72b 100644 --- a/src/SMAPI/SAlertDialogUtil.cs +++ b/src/SMAPI/SAlertDialogUtil.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - using Android.App; -using Android.Content; using Android.OS; -using Android.Runtime; -using Android.Views; -using Android.Widget; using Java.Lang; +using Microsoft.AppCenter.Crashes; namespace StardewModdingAPI { @@ -17,21 +9,29 @@ namespace StardewModdingAPI { public static void AlertMessage(string message, string title = "Error") { - Handler handler = new Handler((msg) => throw new RuntimeException()); - Dialog dialog = new AlertDialog.Builder(SMainActivity.Instance) - .SetTitle(title) - .SetMessage(message) - .SetCancelable(false) - .SetPositiveButton("OK", (senderAlert, arg) => { handler.SendEmptyMessage(0); }).Create(); - if (!SMainActivity.Instance.IsFinishing) + try { - dialog.Show(); - try + Handler handler = new Handler((msg) => throw new RuntimeException()); + Dialog dialog = new AlertDialog.Builder(SMainActivity.Instance) + .SetTitle(title) + .SetMessage(message) + .SetCancelable(false) + .SetPositiveButton("OK", (senderAlert, arg) => { handler.SendEmptyMessage(0); }).Create(); + if (!SMainActivity.Instance.IsFinishing) { + dialog.Show(); + try + { + Looper.Prepare(); + } + catch (System.Exception e) + { + Crashes.TrackError(e); + } Looper.Loop(); } - catch { } } + catch { } } } } diff --git a/src/SMAPI/SMAPI.csproj b/src/SMAPI/SMAPI.csproj index fba30c51..501245aa 100644 --- a/src/SMAPI/SMAPI.csproj +++ b/src/SMAPI/SMAPI.csproj @@ -24,7 +24,7 @@ portable false bin\Debug\ - TRACE;DEBUG;ANDROID_TARGET_SAMSUNG + TRACE;DEBUG prompt 4 latest diff --git a/src/SMAPI/SMainActivity.cs b/src/SMAPI/SMainActivity.cs index 5bec9c78..6392eccc 100644 --- a/src/SMAPI/SMainActivity.cs +++ b/src/SMAPI/SMainActivity.cs @@ -104,6 +104,9 @@ namespace StardewModdingAPI SAlertDialogUtil.AlertMessage(System.IO.File.ReadAllText(errorLog.AbsolutePath), "Crash Detected"); } Type[] services = new Type[] { typeof(Microsoft.AppCenter.Analytics.Analytics), typeof(Microsoft.AppCenter.Crashes.Crashes) }; + CustomProperties properties = new CustomProperties(); + properties.Set("SMAPI", Constants.ApiVersion.ToString()); + AppCenter.SetCustomProperties(properties); AppCenter.Start(Constants.MicrosoftAppSecret, services); } catch { }