1.Add auto hidden feature to Virtual Keyboard

2.Bug fix
3.Disable smapi update check
This commit is contained in:
ZaneYork 2020-03-30 17:21:13 +08:00
parent ffd5fa7832
commit bce7021668
8 changed files with 60 additions and 36 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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",

View File

@ -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)
{

View File

@ -62,7 +62,7 @@ namespace StardewModdingAPI.Patches
{
try
{
if (value.tapToMove == null)
if (value != null && value.tapToMove == null)
{
if (value.map != null)
{

View File

@ -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 { }
}
}
}

View File

@ -24,7 +24,7 @@
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;ANDROID_TARGET_SAMSUNG</DefineConstants>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>latest</LangVersion>

View File

@ -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 { }