sync to match main repo in some cases
This commit is contained in:
parent
4fa0048b84
commit
fc56582e9a
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
|
||||
|
@ -13,6 +12,7 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
/// <summary>The known assemblies.</summary>
|
||||
private readonly IDictionary<string, AssemblyDefinition> Lookup = new Dictionary<string, AssemblyDefinition>();
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
|
@ -31,7 +31,6 @@ namespace StardewModdingAPI.Framework.ModLoading
|
|||
/// <summary>Resolve an assembly reference.</summary>
|
||||
/// <param name="name">The assembly name.</param>
|
||||
public override AssemblyDefinition Resolve(AssemblyNameReference name) => this.ResolveName(name.Name) ?? base.Resolve(name);
|
||||
|
||||
|
||||
/// <summary>Resolve an assembly reference.</summary>
|
||||
/// <param name="name">The assembly name.</param>
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
|
|||
/// <summary>The property name.</summary>
|
||||
private readonly string PropertyName;
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
*********/
|
||||
|
|
|
@ -586,8 +586,7 @@ namespace StardewModdingAPI
|
|||
Z = Keys.Z,
|
||||
|
||||
/// <summary>The Zoom button on a keyboard.</summary>
|
||||
Zoom = Keys.Zoom,
|
||||
|
||||
Zoom = Keys.Zoom
|
||||
}
|
||||
|
||||
/// <summary>Provides extension methods for <see cref="SButton"/>.</summary>
|
||||
|
|
|
@ -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<MainActivity>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Raised before drawing the HUD (item toolbar, clock, etc) to the screen.</summary>
|
||||
/// <param name="sender">The event sender.</param>
|
||||
/// <param name="e">The event arguments.</param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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")]
|
|
@ -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<KeyButton> keyboard = new List<KeyButton>();
|
||||
private ModConfig modConfig;
|
||||
private Texture2D texture;
|
||||
|
||||
public VirtualToggle(IModHelper helper, IMonitor monitor)
|
||||
{
|
||||
this.Monitor = monitor;
|
||||
this.helper = helper;
|
||||
this.texture = this.helper.Content.Load<Texture2D>("assets/togglebutton.png", ContentSource.ModFolder);
|
||||
|
||||
this.modConfig = helper.ReadConfig<ModConfig>();
|
||||
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<int>(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);
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 275 B |
|
@ -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" ]
|
||||
}
|
Loading…
Reference in New Issue