public static void SelectionMode() { try { bool CollectionChanged = false; if (A_Collection.Me.GearSwap.editModeEnabled) { A_Collection.Me.GearSwap.isEditing = true; if (!A_Collection.D3UI.isOpenInventory) { A_Collection.Me.GearSwap.editModeEnabled = false; } var SelectedAcdId = GetSelectedAcdId(); if (SelectedAcdId > -1) // Add/Remove Selected Items to/from Collection { int AcdId = SelectedAcdId; ActorCommonData ItemAcd = GetSelectedItemAcd(AcdId); double ItemSeed = GetItemSeed(ItemAcd); ItemSlotSize ItemSize = GetSlotSize(ItemAcd); long HeroId = A_Collection.Me.HeroGlobals.HeroID; if (A_Collection.Me.GearSwap.GearSwaps.FirstOrDefault(x => x.ItemSeed == ItemSeed) == null) { A_Collection.Me.GearSwap.GearSwaps.Add(new GearSwapItem(HeroId, A_Collection.Me.GearSwap.Selected_SwapId, ItemSeed, ItemAcd.x118_ItemSlotX, ItemAcd.x11C_ItemSlotY, ItemSize)); CollectionChanged = true; } else { var tryGetEntry = A_Collection.Me.GearSwap.GearSwaps.FirstOrDefault(x => x.ItemSeed == ItemSeed); A_Collection.Me.GearSwap.GearSwaps.Remove(tryGetEntry); CollectionChanged = true; } while (GetSelectedAcdId() == AcdId) { Thread.Sleep(50); } } //Thread.Sleep(50); } if (CollectionChanged) { A_Tools.T_ExternalFile.GearSwaps.Save(); } A_Collection.Me.GearSwap.isEditing = false; } catch { A_Collection.Me.GearSwap.isEditing = false; } }
public static void Load() { try { if (File.Exists(A_Collection.Me.GearSwap.GearSwaps_FilePath)) { List <GearSwapItem> _GearSwaps = new List <GearSwapItem>(); var Lines = File.ReadAllLines(A_Collection.Me.GearSwap.GearSwaps_FilePath); foreach (var line in Lines) { var splitContent = line.Split('\t'); long HeroId = long.Parse(splitContent[0]); double ItemSeed = double.Parse(splitContent[1]); ItemSlotSize ItemSize = (ItemSlotSize)System.Enum.Parse(typeof(ItemSlotSize), splitContent[2]); int ItemSlotX = int.Parse(splitContent[3]); int ItemSlotY = int.Parse(splitContent[4]); int SwapId = int.Parse(splitContent[5]); _GearSwaps.Add(new GearSwapItem(HeroId, SwapId, ItemSeed, ItemSlotX, ItemSlotY, ItemSize)); } A_Collection.Me.GearSwap.GearSwaps = _GearSwaps; } } catch { } }
public Rectangle GetEquipArea(ItemType type) { switch (type) { case ItemType.HELMET: return(new Rectangle(HelmetSlotPos.ToPoint(), ItemSlotSize.ToPoint())); case ItemType.CHEST: return(new Rectangle(ChestSlotPos.ToPoint(), ItemSlotSize.ToPoint())); case ItemType.LEGS: return(new Rectangle(LegsSlotPos.ToPoint(), ItemSlotSize.ToPoint())); case ItemType.TRINKET: return(new Rectangle(MiscSlotPos.ToPoint(), ItemSlotSize.ToPoint())); case ItemType.WEAPON: return(new Rectangle(WeaponSlotPos.ToPoint(), ItemSlotSize.ToPoint())); case ItemType.SHIELD: return(new Rectangle(ShieldSlotPos.ToPoint(), ItemSlotSize.ToPoint())); default: throw new ArgumentException(); } }
/// <summary>Reset the component to its initial state, so that it may be reused without side effects.</summary> public override void Reset() { base.Reset(); Size = ItemSlotSize.Small; Offset = Vector2.Zero; Rotation = 0f; }
/// <summary>Reset the component to its initial state, so that it may be reused without side effects.</summary> public override void Reset() { base.Reset(); Quality = ItemQuality.Common; RequiredSlotSize = ItemSlotSize.None; ModelOffset = Vector2.Zero; DrawBelowParent = false; }
public GearSwapItem(long heroID, int swapId, double itemSeed, int itemSlotX, int itemSlotY, ItemSlotSize itemSize) { this.HeroID = heroID; this.SwapId = swapId; this.ItemSeed = itemSeed; this.ItemSlotX = itemSlotX; this.ItemSlotY = itemSlotY; this.ItemSize = itemSize; }
/// <summary>Initializes the component to one primary equipment slot that allows the specified type id.</summary> /// <param name="typeId">The type id.</param> /// <param name="slotSize">Size of the slot.</param> /// <param name="offset">The offset.</param> /// <param name="rotation">The rotation.</param> /// <returns></returns> public SpaceItemSlot Initialize(int typeId, ItemSlotSize slotSize, Vector2 offset, float rotation) { Initialize(typeId); Size = slotSize; Offset = offset; Rotation = rotation; return(this); }
/// <summary>Creates a new item with the specified parameters.</summary> /// <param name="name">The logical base name of the item.</param> /// <param name="iconName">The name of the icon used for the item.</param> /// <param name="quality">The quality level of the item.</param> /// <param name="slotSize">Size of the slot.</param> /// <param name="modelOffset">The model offset.</param> /// <param name="drawBelowParent">Whether to draw below the parent item, when equipped.</param> /// <returns>This instance.</returns> public SpaceItem Initialize( string name, string iconName, ItemQuality quality, ItemSlotSize slotSize, Vector2 modelOffset, bool drawBelowParent) { Initialize(name, iconName); Quality = quality; RequiredSlotSize = slotSize; ModelOffset = modelOffset; DrawBelowParent = drawBelowParent; return(this); }
/// <summary>Returns the scale at which an object in that slot should be rendered.</summary> /// <param name="size">The slot size.</param> /// <returns>The scaling.</returns> public static float Scale(this ItemSlotSize size) { switch (size) { case ItemSlotSize.Small: return(0.5f); case ItemSlotSize.Medium: return(0.7f); case ItemSlotSize.Large: return(0.85f); default: return(1f); } }
/// <summary>Renders the equipment starting from the specified slot.</summary> private void RenderEquipment( SpaceItemSlot slot, Vector2 offset, int depth = 1, float order = 0.5f, ItemSlotSize parentSize = ItemSlotSize.Small, bool?mirrored = null) { // Nothing to do if there's no item in the slot. if (slot.Item <= 0) { return; } // Get item info. var item = (SpaceItem)Manager.GetComponent(slot.Item, Item.TypeId); // Adjust depth we want to render at. order -= (item.DrawBelowParent ? -0.25f : 0.25f) / depth; // See if we should mirror rendering (e.g. left wing). var slotOffset = slot.Offset; var itemOffset = item.ModelOffset; if (mirrored.HasValue) { if (mirrored.Value) { slotOffset.Y = -slotOffset.Y; } } // ReSharper disable CompareOfFloatsByEqualityOperator Intentional. else if (slotOffset.Y != 0.0f) // ReSharper restore CompareOfFloatsByEqualityOperator { mirrored = slot.Offset.Y < 0; } if (mirrored.HasValue && mirrored.Value) { itemOffset.Y = -itemOffset.Y; } // Move the offset according to rotation and accumulate it. var localOffset = offset + parentSize.Scale() * slotOffset; var renderOffset = localOffset + item.RequiredSlotSize.Scale() * itemOffset; // Render this particular item. foreach (SimpleTextureDrawable drawable in Manager.GetComponents(item.Entity, SimpleTextureDrawable.TypeId)) { drawable.Draw( _spriteBatch, renderOffset, 0f, item.RequiredSlotSize.Scale() / drawable.Scale, mirrored.HasValue && mirrored.Value ? SpriteEffects.FlipVertically : SpriteEffects.None, order); } // Render sub-items. foreach (SpaceItemSlot childSlot in Manager.GetComponents(item.Entity, ItemSlot.TypeId)) { RenderEquipment(childSlot, localOffset, depth + 1, order, item.RequiredSlotSize, mirrored); } }
/// <summary> /// Computes the size of the model, i.e. the area covered by the fully rendered equipment starting with the /// specified slot. /// </summary> private RectangleF ComputeModelSize( SpaceItemSlot slot, Vector2 offset, ItemSlotSize parentSize = ItemSlotSize.Small, bool?mirrored = null) { // Nothing to do if there's no item in the slot. if (slot.Item <= 0) { return(RectangleF.Empty); } // Get item info. var item = (SpaceItem)Manager.GetComponent(slot.Item, Item.TypeId); // Get required bounds to render this item. var bounds = Manager.GetComponents(item.Entity, SimpleTextureDrawable.TypeId) .Cast <SimpleTextureDrawable>() .Aggregate( RectangleF.Empty, (current, drawable) => { var b = (RectangleF)drawable.Texture.Bounds; b.Offset(-b.Width / 2f, -b.Height / 2f); return(RectangleF.Union(current, b)); }); // See if we should mirror rendering (e.g. left wing). var slotOffset = slot.Offset; var itemOffset = item.ModelOffset; if (mirrored.HasValue) { if (mirrored.Value) { slotOffset.Y = -slotOffset.Y; } } // ReSharper disable CompareOfFloatsByEqualityOperator Intentional. else if (slotOffset.Y != 0.0f) // ReSharper restore CompareOfFloatsByEqualityOperator { mirrored = slot.Offset.Y < 0; } if (mirrored.HasValue && mirrored.Value) { itemOffset.Y = -itemOffset.Y; } // Move the offset according to rotation and accumulate it. var localOffset = offset + parentSize.Scale() * slotOffset; var renderOffset = localOffset + item.RequiredSlotSize.Scale() * itemOffset; // Adjust to actual area the texture is rendered to. bounds.Offset(renderOffset); bounds.Inflate( -bounds.Width / 2f * (1 - item.RequiredSlotSize.Scale()), -bounds.Height / 2f * (1 - item.RequiredSlotSize.Scale())); // Check sub-items. return(Manager.GetComponents(item.Entity, ItemSlot.TypeId) .Cast <SpaceItemSlot>() .Aggregate(bounds, (current, childSlot) => RectangleF.Union(current, ComputeModelSize(childSlot, localOffset, item.RequiredSlotSize, mirrored)))); }