From fc56582e9a886743cc839acdb4f928b87aaba340 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 21 Sep 2019 00:01:58 -0400 Subject: [PATCH] sync to match main repo in some cases --- ...rdewModdingAPI.Mods.VirtualKeyboard.csproj | 0 .../ModLoading/AssemblyDefinitionResolver.cs | 3 +- .../Rewriters/FieldToPropertyRewriter.cs | 1 + src/SMAPI/SButton.cs | 3 +- .../KeyButton.cs | 149 ------------------ .../ModConfig.cs | 67 -------- .../ModEntry.cs | 16 -- .../Properties/AssemblyInfo.cs | 36 ----- .../VirtualToggle.cs | 115 -------------- .../assets/togglebutton.png | Bin 275 -> 0 bytes .../manifest.json | 10 -- 11 files changed, 3 insertions(+), 397 deletions(-) rename src/{StardewModdingAPI.Mods.VirtualKeyboard => SMAPI.Mods.VirtualKeyboard}/StardewModdingAPI.Mods.VirtualKeyboard.csproj (100%) delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/KeyButton.cs delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/ModConfig.cs delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/ModEntry.cs delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/Properties/AssemblyInfo.cs delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/VirtualToggle.cs delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/assets/togglebutton.png delete mode 100644 src/StardewModdingAPI.Mods.VirtualKeyboard/manifest.json diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/StardewModdingAPI.Mods.VirtualKeyboard.csproj b/src/SMAPI.Mods.VirtualKeyboard/StardewModdingAPI.Mods.VirtualKeyboard.csproj similarity index 100% rename from src/StardewModdingAPI.Mods.VirtualKeyboard/StardewModdingAPI.Mods.VirtualKeyboard.csproj rename to src/SMAPI.Mods.VirtualKeyboard/StardewModdingAPI.Mods.VirtualKeyboard.csproj diff --git a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs index 5d629bf7..aefb0126 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using Mono.Cecil; @@ -13,6 +12,7 @@ namespace StardewModdingAPI.Framework.ModLoading /// The known assemblies. private readonly IDictionary Lookup = new Dictionary(); + /********* ** Public methods *********/ @@ -31,7 +31,6 @@ namespace StardewModdingAPI.Framework.ModLoading /// Resolve an assembly reference. /// The assembly name. public override AssemblyDefinition Resolve(AssemblyNameReference name) => this.ResolveName(name.Name) ?? base.Resolve(name); - /// Resolve an assembly reference. /// The assembly name. diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs index d65f7a5b..a43c5e9a 100644 --- a/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs +++ b/src/SMAPI/Framework/ModLoading/Rewriters/FieldToPropertyRewriter.cs @@ -17,6 +17,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters /// The property name. private readonly string PropertyName; + /********* ** Public methods *********/ diff --git a/src/SMAPI/SButton.cs b/src/SMAPI/SButton.cs index bd1fcfdd..bc76c91d 100644 --- a/src/SMAPI/SButton.cs +++ b/src/SMAPI/SButton.cs @@ -586,8 +586,7 @@ namespace StardewModdingAPI Z = Keys.Z, /// The Zoom button on a keyboard. - Zoom = Keys.Zoom, - + Zoom = Keys.Zoom } /// Provides extension methods for . diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/KeyButton.cs b/src/StardewModdingAPI.Mods.VirtualKeyboard/KeyButton.cs deleted file mode 100644 index e68e880b..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/KeyButton.cs +++ /dev/null @@ -1,149 +0,0 @@ -using System; -using Microsoft.Xna.Framework; -using StardewModdingAPI.Events; -using StardewValley; -using StardewValley.Menus; -using static StardewModdingAPI.Mods.VirtualKeyboard.ModConfig; -using System.Reflection; -using Microsoft.Xna.Framework.Input; - -namespace StardewModdingAPI.Mods.VirtualKeyboard -{ - class KeyButton - { - private readonly IModHelper helper; - private readonly IMonitor Monitor; - private readonly Rectangle buttonRectangle; - - private object buttonPressed; - private object buttonReleased; - private object legacyButtonPressed; - private object legacyButtonReleased; - - private readonly MethodBase RaiseButtonPressed; - private readonly MethodBase RaiseButtonReleased; - private readonly MethodBase Legacy_KeyPressed; - private readonly MethodBase Legacy_KeyReleased; - - private readonly SButton buttonKey; - private readonly float transparency; - private readonly string alias; - public bool hidden; - private bool raisingPressed = false; - private bool raisingReleased = false; - - public KeyButton(IModHelper helper, VirtualButton buttonDefine, IMonitor monitor) - { - this.Monitor = monitor; - this.helper = helper; - this.hidden = true; - this.buttonRectangle = new Rectangle(buttonDefine.rectangle.X, buttonDefine.rectangle.Y, buttonDefine.rectangle.Width, buttonDefine.rectangle.Height); - this.buttonKey = buttonDefine.key; - - if (buttonDefine.alias == null) - this.alias = this.buttonKey.ToString(); - else - this.alias = buttonDefine.alias; - - if (buttonDefine.transparency <= 0.01f || buttonDefine.transparency > 1f) - { - buttonDefine.transparency = 0.5f; - } - this.transparency = buttonDefine.transparency; - - helper.Events.Display.RenderingHud += this.OnRenderingHud; - helper.Events.Input.ButtonReleased += this.EventInputButtonReleased; - helper.Events.Input.ButtonPressed += this.EventInputButtonPressed; - - MainActivity activity = this.helper.Reflection.GetField(typeof(MainActivity), "instance").GetValue(); - object score = activity.GetType().GetField("core", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(activity); - object eventManager = score.GetType().GetField("EventManager", BindingFlags.Public | BindingFlags.Instance).GetValue(score); - - this.buttonPressed = eventManager.GetType().GetField("ButtonPressed", BindingFlags.Public | BindingFlags.Instance).GetValue(eventManager); - this.buttonReleased = eventManager.GetType().GetField("ButtonReleased", BindingFlags.Public | BindingFlags.Instance).GetValue(eventManager); - - this.legacyButtonPressed = eventManager.GetType().GetField("Legacy_KeyPressed", BindingFlags.Public | BindingFlags.Instance).GetValue(eventManager); - this.legacyButtonReleased = eventManager.GetType().GetField("Legacy_KeyReleased", BindingFlags.Public | BindingFlags.Instance).GetValue(eventManager); - - this.RaiseButtonPressed = this.buttonPressed.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance); - this.RaiseButtonReleased = this.buttonReleased.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance); - - this.Legacy_KeyPressed = this.legacyButtonPressed.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance); - this.Legacy_KeyReleased = this.legacyButtonReleased.GetType().GetMethod("Raise", BindingFlags.Public | BindingFlags.Instance); - } - - private bool shouldTrigger(Vector2 screenPixels) - { - if (this.buttonRectangle.Contains(screenPixels.X * Game1.options.zoomLevel, screenPixels.Y * Game1.options.zoomLevel)) - { - return true; - } - return false; - } - - private void EventInputButtonPressed(object sender, ButtonPressedEventArgs e) - { - if (this.raisingPressed) - { - return; - } - - Vector2 screenPixels = e.Cursor.ScreenPixels; - if (this.shouldTrigger(screenPixels) && !this.hidden) - { - object inputState = e.GetType().GetField("InputState", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(e); - - object buttonPressedEventArgs = Activator.CreateInstance(typeof(ButtonPressedEventArgs), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { this.buttonKey, e.Cursor, inputState }, null); - EventArgsKeyPressed eventArgsKey = new EventArgsKeyPressed((Keys)this.buttonKey); - try - { - this.raisingPressed = true; - - this.RaiseButtonPressed.Invoke(this.buttonPressed, new object[] { buttonPressedEventArgs }); - this.Legacy_KeyPressed.Invoke(this.legacyButtonPressed, new object[] { eventArgsKey }); - } - finally - { - this.raisingPressed = false; - } - } - } - - private void EventInputButtonReleased(object sender, ButtonReleasedEventArgs e) - { - if (this.raisingReleased) - { - return; - } - - Vector2 screenPixels = e.Cursor.ScreenPixels; - if (this.shouldTrigger(screenPixels)) - { - object inputState = e.GetType().GetField("InputState", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(e); - object buttonReleasedEventArgs = Activator.CreateInstance(typeof(ButtonReleasedEventArgs), BindingFlags.NonPublic | BindingFlags.Instance, null, new object[] { this.buttonKey, e.Cursor, inputState }, null); - EventArgsKeyPressed eventArgsKeyReleased = new EventArgsKeyPressed((Keys)this.buttonKey); - try - { - this.raisingReleased = true; - this.RaiseButtonReleased.Invoke(this.buttonReleased, new object[] { buttonReleasedEventArgs }); - this.Legacy_KeyReleased.Invoke(this.legacyButtonReleased, new object[] { eventArgsKeyReleased }); - } - finally - { - this.raisingReleased = false; - } - } - } - - /// Raised before drawing the HUD (item toolbar, clock, etc) to the screen. - /// The event sender. - /// The event arguments. - private void OnRenderingHud(object sender, EventArgs e) - { - if (!Game1.eventUp && !this.hidden && Game1.activeClickableMenu is GameMenu == false && Game1.activeClickableMenu is ShopMenu == false && Game1.activeClickableMenu is IClickableMenu == false) - { - IClickableMenu.drawButtonWithText(Game1.spriteBatch, Game1.smallFont, this.alias, this.buttonRectangle.X, this.buttonRectangle.Y, this.buttonRectangle.Width, this.buttonRectangle.Height, Color.BurlyWood * this.transparency); - } - } - } -} diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/ModConfig.cs b/src/StardewModdingAPI.Mods.VirtualKeyboard/ModConfig.cs deleted file mode 100644 index 352a54b4..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/ModConfig.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Xna.Framework; -using StardewValley; -using StardewValley.Menus; - -namespace StardewModdingAPI.Mods.VirtualKeyboard -{ - class ModConfig - { - public Toggle vToggle = new Toggle(new Rectangle(36, 12, 64, 64)); - - public VirtualButton[] buttons { get; set; } = new VirtualButton[] { - new VirtualButton(SButton.Q, new Rect(192, 150, 90, 90, 6), 0.5f), - new VirtualButton(SButton.I, new Rect(288, 150, 90, 90, 6), 0.5f), - new VirtualButton(SButton.O, new Rect(384, 150, 90, 90, 6), 0.5f), - new VirtualButton(SButton.P, new Rect(480, 150, 90, 90, 6), 0.5f), - new VirtualButton(SButton.MouseRight, new Rect(580, 150, 150, 90, 6), 0.5f, "RightMouse") - }; - internal class VirtualButton - { - public SButton key; - public Rect rectangle; - public float transparency; - public string alias; - public VirtualButton(SButton key, Rect rectangle, float transparency, string alias = null) - { - this.key = key; - this.rectangle = rectangle; - this.transparency = transparency; - this.alias = alias; - } - } - - internal class Toggle - { - public Rectangle rectangle; - //public float scale; - - public Toggle(Rectangle rectangle) - { - this.rectangle = rectangle; - //this.scale = scale; - } - } - internal class Rect - { - public int X; - public int Y; - public int Width; - public int Height; - public int Padding; - - public Rect(int x, int y, int width, int height, int padding) - { - this.X = x; - this.Y = y; - this.Width = width; - this.Height = height; - this.Padding = padding; - } - } - } -} diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/ModEntry.cs b/src/StardewModdingAPI.Mods.VirtualKeyboard/ModEntry.cs deleted file mode 100644 index 06ac1de8..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/ModEntry.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Tools; - -namespace StardewModdingAPI.Mods.VirtualKeyboard -{ - public class ModEntry : Mod - { - public override void Entry(IModHelper helper) - { - new VirtualToggle(helper, this.Monitor); - } - } -} diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/Properties/AssemblyInfo.cs b/src/StardewModdingAPI.Mods.VirtualKeyboard/Properties/AssemblyInfo.cs deleted file mode 100644 index ae750e04..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("StardewModdingAPI.Mods.VirtualKeyboard")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("StardewModdingAPI.Mods.VirtualKeyboard")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("29cce9c9-6811-415d-a681-a6d47073924d")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/VirtualToggle.cs b/src/StardewModdingAPI.Mods.VirtualKeyboard/VirtualToggle.cs deleted file mode 100644 index e6809c58..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/VirtualToggle.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; -using StardewModdingAPI.Events; -using StardewValley; -using StardewValley.Menus; - -namespace StardewModdingAPI.Mods.VirtualKeyboard -{ - class VirtualToggle - { - private readonly IModHelper helper; - private readonly IMonitor Monitor; - - private bool enabled = false; - private bool isDefault = true; - private ClickableTextureComponent virtualToggleButton; - - private List keyboard = new List(); - private ModConfig modConfig; - private Texture2D texture; - - public VirtualToggle(IModHelper helper, IMonitor monitor) - { - this.Monitor = monitor; - this.helper = helper; - this.texture = this.helper.Content.Load("assets/togglebutton.png", ContentSource.ModFolder); - - this.modConfig = helper.ReadConfig(); - for (int i = 0; i < this.modConfig.buttons.Length; i++) - this.keyboard.Add(new KeyButton(helper, this.modConfig.buttons[i], this.Monitor)); - - if (this.modConfig.vToggle.rectangle.X != 36 || this.modConfig.vToggle.rectangle.Y != 12) - this.isDefault = false; - - 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.RenderingHud += this.OnRenderingHUD; - this.helper.Events.Input.ButtonPressed += this.VirtualToggleButtonPressed; - } - - private void VirtualToggleButtonPressed(object sender, ButtonPressedEventArgs e) - { - Vector2 screenPixels = e.Cursor.ScreenPixels; - if (!this.enabled && this.shouldTrigger(screenPixels)) - { - this.hiddenKeys(true, false); - } - else if (this.enabled && this.shouldTrigger(screenPixels)) - { - this.hiddenKeys(false, true); - if (Game1.activeClickableMenu is IClickableMenu menu) - { - menu.exitThisMenu(); - } - } - } - - private void hiddenKeys(bool enabled, bool hidden) - { - this.enabled = enabled; - foreach (var keys in this.keyboard) - { - keys.hidden = hidden; - } - } - - private bool shouldTrigger(Vector2 screenPixels) - { - if (this.virtualToggleButton.containsPoint((int)(screenPixels.X * Game1.options.zoomLevel), (int)(screenPixels.Y * Game1.options.zoomLevel))) - { - Toolbar.toolbarPressed = true; - return true; - } - return false; - } - - private void OnRenderingHUD(object sender, EventArgs e) - { - if (this.isDefault) - { - if (Game1.options.verticalToolbar) - this.virtualToggleButton.bounds.X = Game1.toolbarPaddingX + Game1.toolbar.itemSlotSize + 200; - else - this.virtualToggleButton.bounds.X = Game1.toolbarPaddingX + Game1.toolbar.itemSlotSize + 50; - - if (Game1.toolbar.alignTop == true && !Game1.options.verticalToolbar) - { - object toolbarHeight = this.helper.Reflection.GetField(Game1.toolbar, "toolbarHeight").GetValue(); - this.virtualToggleButton.bounds.Y = (int)toolbarHeight + 50; - } - else - { - this.virtualToggleButton.bounds.Y = 12; - } - } - else - { - this.virtualToggleButton.bounds.X = this.modConfig.vToggle.rectangle.X; - this.virtualToggleButton.bounds.Y = this.modConfig.vToggle.rectangle.Y; - } - - float scale = 1f; - if (!this.enabled) - { - scale = 0.5f; - } - if(!Game1.eventUp && Game1.activeClickableMenu is GameMenu == false && Game1.activeClickableMenu is ShopMenu == false) - this.virtualToggleButton.draw(Game1.spriteBatch, Color.White * scale, 0.000001f); - } - } -} diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/assets/togglebutton.png b/src/StardewModdingAPI.Mods.VirtualKeyboard/assets/togglebutton.png deleted file mode 100644 index abce001d3ad14d089a29a190aa4e15275170cba0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 275 zcmV+u0qp*XP)pp>UfwgDUI7NtBjP&c4Jrpqa{6lPxBAe}Cd zR?7_J+XbjOzXqCnjX}JF@Uk`9Oe0MEqpr^FoejA3nWp&iT!FB4czAE30hKf<5=w(G Z%WnpvQ!#laeOUki002ovPDHLkV1gxuZ}b2F diff --git a/src/StardewModdingAPI.Mods.VirtualKeyboard/manifest.json b/src/StardewModdingAPI.Mods.VirtualKeyboard/manifest.json deleted file mode 100644 index ffd121a6..00000000 --- a/src/StardewModdingAPI.Mods.VirtualKeyboard/manifest.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Name": "VirtualKeyboard", - "Author": "MartyrPher", - "Version": "0.9.6", - "MinimumApiVersion": "2.10.1", - "Description": "A much needed Virtual Keyboard for SMAPI Android.", - "UniqueID": "VirtualKeyboard", - "EntryDll": "VirtualKeyboard.dll", - "UpdateKeys": [ "Nexus: null" ] -}