Exemplo n.º 1
0
        private ToolTipLayout LayoutToolTip(Item item, Graphics g)
        {
            ToolTipLayout ret = new ToolTipLayout();
            int margin = 10;
            int height = margin + item.GetCurrentPicture().Height + margin;
            int maxWidth = 0;
            ret.NameString = item.Name;
            SizeF textSize = g.MeasureString(ret.NameString, SystemFonts.DefaultFont);
            ret.NameRect = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
            height += ret.NameRect.Height;
            maxWidth = Math.Max(maxWidth, ret.NameRect.Width);

            ret.ValueString = item.Value.ToString() + " Gold";
            textSize = g.MeasureString(ret.ValueString, SystemFonts.DefaultFont);
            ret.ValueRect = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
            height += ret.ValueRect.Height;
            maxWidth = Math.Max(maxWidth, ret.ValueRect.Width);

            ret.InfoString1 = null;
            ret.InfoString2 = null;
            ret.InfoRect1 = Rectangle.Empty;
            ret.InfoRect2 = Rectangle.Empty;

            if (item is Weapon)
            {
                Weapon weapon = item as Weapon;
                KeyValuePair<int, int> range = weapon.Stats.Damage.GetRange();
                ret.InfoString1 = weapon.Stats.Description + " " + range.Key + "-" + range.Value + " (" + range.Key * weapon.Stats.CritModifier + "-" + range.Value * weapon.Stats.CritModifier + ")";
                textSize = g.MeasureString(ret.InfoString1, SystemFonts.DefaultFont);
                ret.InfoRect1 = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
                height += ret.InfoRect1.Height;
                maxWidth = Math.Max(maxWidth, ret.InfoRect1.Width);

                //(20 - start)+1 then *100 / 20;
                ret.InfoString2 = "Crit " + (21 - weapon.Stats.CritRangeStart) * 5 + "%";
                textSize = g.MeasureString(ret.InfoString2, SystemFonts.DefaultFont);
                ret.InfoRect2 = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
                height += ret.InfoRect2.Height;
                maxWidth = Math.Max(maxWidth, ret.InfoRect2.Width);
            }
            else if (item is Armor)
            {
                Armor armor = item as Armor;
                ret.InfoString1 = "+" + armor.Modifier + " defense";
                textSize = g.MeasureString(ret.InfoString1, SystemFonts.DefaultFont);
                ret.InfoRect1 = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
                height += ret.InfoRect1.Height;
                maxWidth = Math.Max(maxWidth, ret.InfoRect1.Width);
            }
            else if (item is Edible)
            {
                Edible edible = item as Edible;
                ret.InfoString1 = "+" + edible.HealthGain + " health";
                textSize = g.MeasureString(ret.InfoString1, SystemFonts.DefaultFont);
                ret.InfoRect1 = new Rectangle(new Point(margin, height), RoundUpToSize(textSize));
                height += ret.InfoRect1.Height;
                maxWidth = Math.Max(maxWidth, ret.InfoRect1.Width);
            }

            ret.Image = item.GetCurrentPicture();
            maxWidth = Math.Max(maxWidth, ret.Image.Width);
            ret.ImageRect = new Rectangle(new Point(((maxWidth - ret.Image.Width)/2) + margin, margin), ret.Image.Size);
            ret.ComputeTotalSize(margin);
            return ret;
        }
Exemplo n.º 2
0
 private void OnPopup(object sender, PopupEventArgs e)
 {
     Item item = null;
     if (e.AssociatedControl.Tag is Item)
     {
         item = e.AssociatedControl.Tag as Item;
     }
     else
     {
         item = (e.AssociatedControl.Tag as List<Item>).First();
     }
     layout = LayoutToolTip(item, e.AssociatedControl.CreateGraphics());
     e.ToolTipSize = layout.TotalSize.Size;
 }