Skip to content

Commit

Permalink
improved responsiveness and look of Item Component windows
Browse files Browse the repository at this point in the history
  • Loading branch information
djrecipe committed Aug 16, 2016
1 parent 4d9e3fe commit bc15605
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 48 deletions.
112 changes: 84 additions & 28 deletions RiotPls/UI/Controls/DropSlot.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using RiotPls.API.Serialization.Champions;
using RiotPls.API.Serialization.Interfaces;
Expand Down Expand Up @@ -43,6 +44,7 @@ public enum DataTypes : uint
private ToolStripMenuItem mnuitmPricing;
private ToolStripMenuItem mnuitmFullPricing;
private ToolStripMenuItem mnuitmUpgradePricing;
private formItemComponents componentsForm = null;
private Button btnComponents;
#endregion
#region Events
Expand Down Expand Up @@ -71,10 +73,6 @@ public string NullText
this.UpdateData();
}
}
/// <summary>
/// Drop slot is currently showing item components
/// </summary>
public bool ShowingComponents { get; private set; }
private DataTypes _Type = DataTypes.Champion;
/// <summary>
/// Type of entity being represented by this control
Expand Down Expand Up @@ -235,8 +233,6 @@ private void InitializeComponent()
this.btnComponents.Size = new System.Drawing.Size(17, 16);
this.btnComponents.TabIndex = 3;
this.btnComponents.UseVisualStyleBackColor = false;
this.btnComponents.Click += new System.EventHandler(this.btnComponents_Click);
this.btnComponents.MouseLeave += new System.EventHandler(this.btnComponents_MouseLeave);
this.btnComponents.MouseHover += new System.EventHandler(this.btnComponents_MouseHover);
//
// picMain
Expand All @@ -253,6 +249,7 @@ private void InitializeComponent()
this.picMain.TabIndex = 0;
this.picMain.TabStop = false;
this.picMain.MouseDown += new System.Windows.Forms.MouseEventHandler(this.picMain_MouseDown);
this.picMain.MouseHover += new System.EventHandler(this.picMain_MouseHover);
//
// DropSlot
//
Expand All @@ -261,9 +258,11 @@ private void InitializeComponent()
this.Controls.Add(this.btnComponents);
this.Controls.Add(this.lblMain);
this.Controls.Add(this.picMain);
this.DoubleBuffered = true;
this.MinimumSize = new System.Drawing.Size(80, 110);
this.Name = "DropSlot";
this.Size = new System.Drawing.Size(80, 110);
this.LocationChanged += new System.EventHandler(this.DropSlot_LocationChanged);
this.cmenItem.ResumeLayout(false);
this.cmenChampion.ResumeLayout(false);
this.cmenItemBuy.ResumeLayout(false);
Expand Down Expand Up @@ -302,6 +301,32 @@ public void Set(IRiotDroppable new_drop)
return;
}

private void ShowComponents()
{
// do not show over top of context menu
if (this.ContextMenuStrip?.Visible ?? false)
return;
// only show item components if content is an item
if (this.Type == DataTypes.ItemBuy || this.Type == DataTypes.Item)
{
ItemInfo item = this.drop as ItemInfo;
if (item != null && item.ComponentIDs.Length > 0)
{
// drop slot area
Rectangle rect = this.ClientRectangle;
rect.Location = this.PointToScreen(rect.Location);
// show form
this.componentsForm = new formItemComponents(item, rect);
this.componentsForm.VisibleChanged += this.formItemComponents_VisibleChanged;
this.componentsForm.FormClosing += this.formItemComponents_FormClosing;
this.componentsForm.Show(this);
this.componentsForm.Location = this.Parent.PointToScreen(new Point(this.Left - this.componentsForm.Width/2 + this.Width/2, this.Bottom-1));
}
}
return;
}


private void UpdateContextMenu()
{
switch (this.Type)
Expand Down Expand Up @@ -332,7 +357,7 @@ private void UpdateHoverButtonVisibility()
{
ItemInfo item = this.drop as ItemInfo;
if ((this.Type == DataTypes.Item || this.Type == DataTypes.ItemBuy) && item != null)
{
{
this.btnComponents.Visible = item.ComponentIDs.Length > 0;
}
else
Expand All @@ -342,6 +367,13 @@ private void UpdateHoverButtonVisibility()
return;
}

private void UpdateOwner()
{
formItemComponents owner = this.Parent as formItemComponents;
if (owner != null)
owner.ChildrenVisible = this.componentsForm != null && this.componentsForm.Visible;
return;
}
private void UpdatePrice()
{
ItemInfo item = this.drop as ItemInfo;
Expand All @@ -352,38 +384,43 @@ private void UpdatePrice()
: ItemInfo.PricingStyles.Upgrade;
}
}
#region Event Methods
private void btnComponents_Click(object sender, EventArgs e)
#region Event Methods
#region Button Events
private void btnComponents_MouseHover(object sender, EventArgs e)
{
this.ContextMenuStrip?.Show(this, new Point(0, this.Height));
this.ShowComponents();
return;
}
private void btnComponents_MouseHover(object sender, EventArgs e)
#region DropSlot Events
private void DropSlot_LocationChanged(object sender, EventArgs e)
{
// do not show over top of context menu
if (this.ContextMenuStrip?.Visible ?? false)
return;
// only show item components if content is an item
if (this.Type == DataTypes.ItemBuy || this.Type == DataTypes.Item)
if (this.componentsForm != null)
{
ItemInfo item = this.drop as ItemInfo;
if (item != null)
{

formItemComponents form = new formItemComponents(item);
form.Location = this.Parent.PointToScreen(new Point(this.Left, this.Bottom));
this.ShowingComponents = true;
form.ShowDialog(this);
this.ShowingComponents = false;
}
Rectangle rect = this.ClientRectangle;
rect.Location = this.PointToScreen(rect.Location);
this.componentsForm.ParentRectangle = rect;
}
return;
}
private void btnComponents_MouseLeave(object sender, EventArgs e)
#endregion
#region Form Events
private void formItemComponents_FormClosing(object sender, FormClosingEventArgs e)
{
this.BeginInvoke((MethodInvoker) delegate
{
this.Invalidate();
this.UpdateOwner();
});
return;
}
private void formItemComponents_VisibleChanged(object sender, EventArgs e)
{
//formItemComponents.HideForm();
this.Invalidate();
this.UpdateOwner();
return;
}
#endregion
#endregion
#region Menu Events
private void mnuitmFullPricing_CheckedChanged(object sender, EventArgs e)
{
Expand Down Expand Up @@ -439,13 +476,20 @@ private void mnuitmUpgradePricing_CheckedChanged(object sender, EventArgs e)
this.UpdatePrice();
return;
}
#endregion
#region PictureBox Events
private void picMain_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left || this.drop == null)
return;
this.BeginInvoke((MethodInvoker)delegate { this.DoDragDrop(this.drop.Clone() as IRiotDroppable, DragDropEffects.Copy); });
return;
}
private void picMain_MouseHover(object sender, EventArgs e)
{
this.ShowComponents();
return;
}
#endregion
#endregion
#endregion
Expand Down Expand Up @@ -487,6 +531,18 @@ protected override void OnDragEnter(DragEventArgs e)
}
return;
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (this.componentsForm != null && this.componentsForm.Visible)
{
e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
e.Graphics.DrawLine(Pens.Blue, new Point(this.picMain.Left, this.picMain.Bottom), new Point(0, this.Height));
e.Graphics.DrawLine(Pens.Blue, new Point(this.picMain.Right, this.picMain.Bottom), new Point(this.Width, this.Height));
}
return;
}
#endregion

}
Expand Down
26 changes: 8 additions & 18 deletions RiotPls/UI/Views/formItemComponents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ public class formItemComponents : Form
private formItemComponentsModel model = null;
private ItemInfo item = null;
#endregion
#region Instance Properties
public bool ChildrenVisible { get; set; } = false;
public Rectangle ParentRectangle { get; set; } = Rectangle.Empty;
#endregion
#region Instance Methods
public formItemComponents(ItemInfo item_in)
public formItemComponents(ItemInfo item_in, Rectangle rect)
{
if(item_in == null)
throw new ArgumentNullException("item_in", "Invalid item");
this.item = item_in;
this.ParentRectangle = rect;
this.InitializeComponent();
return;
}
Expand Down Expand Up @@ -67,7 +72,6 @@ private void InitializeComponent()
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "formItemComponents";
this.Load += new System.EventHandler(this.formItemComponents_Load);
this.MouseLeave += new System.EventHandler(this.formItemComponents_MouseLeave);
this.ResumeLayout(false);

}
Expand All @@ -78,32 +82,18 @@ private void formItemComponents_Load(object sender, System.EventArgs e)
this.model = new formItemComponentsModel(this.item);
List<DropSlot> slots = this.model.GenerateDropSlots();
this.Size = this.AddSlots(slots);
Console.WriteLine("Width: {0}", this.DisplayRectangle.Width);
this.Width += 20;
if (this.Owner is formItemComponents)
this.timerFocus.Start();
return;
}
private void formItemComponents_MouseLeave(object sender, EventArgs e)
{
this.timerFocus.Start();
return;
}
private void timerFocus_Tick(object sender, EventArgs e)
{
if (this.IsDisposed)
if (this.IsDisposed || this.ChildrenVisible)
return;
// this rect
Rectangle rect = this.ClientRectangle;
rect.Location = this.PointToScreen(rect.Location);
// parent rect
Rectangle parent_rect = Rectangle.Empty;
if (this.Owner is formItemComponents)
{
parent_rect = this.Owner.ClientRectangle;
parent_rect.Location = this.Owner.PointToScreen(parent_rect.Location);
}
if (!rect.Contains(Control.MousePosition) && !parent_rect.Contains(Control.MousePosition))
if (!rect.Contains(Control.MousePosition) && !this.ParentRectangle.Contains(Control.MousePosition))
this.Close();
return;
}
Expand Down
4 changes: 2 additions & 2 deletions SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
// 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("0.1.9.0")]
[assembly: AssemblyFileVersion("0.1.9.0")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]

0 comments on commit bc15605

Please sign in to comment.