Skip to content

Commit

Permalink
Core\UI\IMenu\Skins\Default: DefaultKeyBind: Fixing issues 1 and 3 from
Browse files Browse the repository at this point in the history
#25; IMenu: MenuManager: Fixing issue 5 from #25.
  • Loading branch information
L33T committed Aug 28, 2015
1 parent 14d3091 commit fee6f75
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 51 deletions.
31 changes: 16 additions & 15 deletions Core/UI/IMenu/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Menu Interface class, used to control the menu.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace LeagueSharp.SDK.Core.UI.IMenu
{
using System;
Expand Down Expand Up @@ -46,8 +47,8 @@ public class MenuManager
public static readonly DirectoryInfo ConfigFolder =
Directory.CreateDirectory(
Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LS" + Environment.UserName.GetHashCode().ToString("X"),
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"LS" + Environment.UserName.GetHashCode().ToString("X"),
"MenuConfigSDK"));

/// <summary>
Expand Down Expand Up @@ -268,6 +269,17 @@ protected virtual void FireOnOpen()
}
}

/// <summary>
/// OnUpdate event.
/// </summary>
/// <param name="args">
/// The event data
/// </param>
private static void Game_OnUpdate(EventArgs args)
{
// Do nothing.
}

/// <summary>
/// On Draw event.
/// </summary>
Expand Down Expand Up @@ -326,10 +338,10 @@ private void Game_OnWndProc(WndEventArgs args)
var keys = new WindowsKeys(args);
if (!this.ForcedOpen)
{
if (keys.SingleKey == Keys.ShiftKey)
if (keys.SingleKey == Keys.ShiftKey || keys.Key == (Keys.Return | Keys.Shift))
{
var keyDown = keys.Msg == WindowsMessages.KEYDOWN;
var keyUp = keys.Msg == WindowsMessages.KEYUP;
var keyUp = keys.Msg == WindowsMessages.KEYUP || keys.Msg == WindowsMessages.CHAR;

if (keyDown)
{
Expand Down Expand Up @@ -386,17 +398,6 @@ private void SaveSettings()
}
}

/// <summary>
/// OnUpdate event.
/// </summary>
/// <param name="args">
/// The event data
/// </param>
private static void Game_OnUpdate(EventArgs args)
{
// Do nothing.
}

#endregion
}
}
82 changes: 46 additions & 36 deletions Core/UI/IMenu/Skins/Default/DefaultKeyBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// A default implementation of <see cref="ADrawable{MenuKeyBind}" />
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace LeagueSharp.SDK.Core.UI.IMenu.Skins.Default
{
using System.Windows.Forms;
Expand Down Expand Up @@ -71,9 +72,9 @@ public DefaultKeyBind(MenuKeyBind component)
public Rectangle ButtonBoundaries(MenuKeyBind component)
{
return new Rectangle(
(int)(component.Position.X + component.MenuWidth - MenuSettings.ContainerHeight),
(int)component.Position.Y,
MenuSettings.ContainerHeight,
(int)(component.Position.X + component.MenuWidth - MenuSettings.ContainerHeight),
(int)component.Position.Y,
MenuSettings.ContainerHeight,
MenuSettings.ContainerHeight);
}

Expand All @@ -96,22 +97,22 @@ public override void Draw()
.GetCenteredText(null, MenuSettings.Font, this.Component.DisplayName, CenteredFlags.VerticalCenter)
.Y;
MenuSettings.Font.DrawText(
MenuManager.Instance.Sprite,
this.Component.Interacting ? "Press a key" : this.Component.DisplayName,
(int)(this.Component.Position.X + MenuSettings.ContainerTextOffset),
centerY,
MenuManager.Instance.Sprite,
this.Component.Interacting ? "Press a key" : this.Component.DisplayName,
(int)(this.Component.Position.X + MenuSettings.ContainerTextOffset),
centerY,
MenuSettings.TextColor);

if (!this.Component.Interacting)
{
var keyString = "[" + this.Component.Key + "]";
MenuSettings.Font.DrawText(
MenuManager.Instance.Sprite,
keyString,
MenuManager.Instance.Sprite,
keyString,
(int)
(this.Component.Position.X + this.Component.MenuWidth - MenuSettings.ContainerHeight
- DefaultUtilities.CalcWidthText(keyString) - MenuSettings.ContainerTextOffset),
centerY,
- DefaultUtilities.CalcWidthText(keyString) - MenuSettings.ContainerTextOffset),
centerY,
MenuSettings.TextColor);
}

Expand All @@ -122,32 +123,32 @@ public override void Draw()
{
new Vector2(
(this.Component.Position.X + this.Component.MenuWidth - MenuSettings.ContainerHeight)
+ MenuSettings.ContainerHeight / 2f,
this.Component.Position.Y + 1),
+ MenuSettings.ContainerHeight / 2f,
this.Component.Position.Y + 1),
new Vector2(
(this.Component.Position.X + this.Component.MenuWidth - MenuSettings.ContainerHeight)
+ MenuSettings.ContainerHeight / 2f,
+ MenuSettings.ContainerHeight / 2f,
this.Component.Position.Y + MenuSettings.ContainerHeight)
},
},
this.Component.Active ? new ColorBGRA(0, 100, 0, 255) : new ColorBGRA(255, 0, 0, 255));
Line.End();

var centerX =
(int)
new Rectangle(
(int)(this.Component.Position.X + this.Component.MenuWidth - MenuSettings.ContainerHeight),
(int)this.Component.Position.Y,
MenuSettings.ContainerHeight,
(int)(this.Component.Position.X + this.Component.MenuWidth - MenuSettings.ContainerHeight),
(int)this.Component.Position.Y,
MenuSettings.ContainerHeight,
MenuSettings.ContainerHeight).GetCenteredText(
null,
MenuSettings.Font,
this.Component.Active ? "ON" : "OFF",
null,
MenuSettings.Font,
this.Component.Active ? "ON" : "OFF",
CenteredFlags.HorizontalCenter).X;
MenuSettings.Font.DrawText(
MenuManager.Instance.Sprite,
this.Component.Active ? "ON" : "OFF",
centerX,
centerY,
MenuManager.Instance.Sprite,
this.Component.Active ? "ON" : "OFF",
centerX,
centerY,
MenuSettings.TextColor);
}

Expand Down Expand Up @@ -238,9 +239,9 @@ public override void OnWndProc(WindowsKeys args)
var content = this.KeyBindBoundaries(this.Component);

if (args.Cursor.IsUnderRectangle(
container.X,
container.Y,
container.Width,
container.X,
container.Y,
container.Width,
container.Height))
{
this.Component.Active = !this.Component.Active;
Expand Down Expand Up @@ -302,6 +303,11 @@ private static void ChangeKey(MenuKeyBind component, Keys newKey)
/// </param>
private static void HandleDown(MenuKeyBind component, Keys expectedKey)
{
if (component.Key == Keys.ControlKey && expectedKey == (Keys.Control | Keys.ControlKey))
{
expectedKey = Keys.ControlKey;
}

if (!component.Interacting && expectedKey == component.Key && component.Type == KeyBindType.Press)
{
component.Active = true;
Expand All @@ -317,17 +323,21 @@ private static void HandleDown(MenuKeyBind component, Keys expectedKey)
/// </param>
private static void HandleUp(MenuKeyBind component, Keys expectedKey)
{
if (expectedKey == component.Key)
switch (component.Type)
{
switch (component.Type)
{
case KeyBindType.Press:
case KeyBindType.Press:
if ((expectedKey.HasFlag(Keys.Shift) && expectedKey.HasFlag(component.Key))
|| (expectedKey == component.Key))
{
component.Active = false;
break;
case KeyBindType.Toggle:
}
break;
case KeyBindType.Toggle:
if (expectedKey == component.Key)
{
component.Active = !component.Active;
break;
}
}
break;
}
}

Expand Down

0 comments on commit fee6f75

Please sign in to comment.