public override bool OnMouse(MouseButton button, PressType type) { if (type == PressType.Pressed) { var moused = this.GetMousedComponent(); if (this.ContextMenu != null && moused != this.ContextMenu) { this.ContextMenu.Close(); } if (button == MouseButton.Right) { var slot = moused as ItemSlot; if (slot?.Items[slot.Index] != null) { this.ContextMenu = new InvContextMenu(this, slot, MousePos); this.AddComponent(this.ContextMenu); return(true); } } } return(base.OnMouse(button, type)); }
public virtual IEnumerable <ComponentButton> GetContextMenu(ItemSlot slot, InvContextMenu menu) { var game = GameImpl.Instance; yield return(new ComponentButton(menu, new RectangleF(Vector2.Zero, new Size2(20, 6)), Locale.GetInterface("Drop"), (button, pressType) => { if (button == MouseButton.Left && pressType == PressType.Pressed) { var pos = ItemObject.GetFeasibleDropPos(game.CurrentMap, game.Player.Position); if (pos == Vector2.Zero) { return false; } var item = new ItemObject(this, game.CurrentMap, pos); game.CurrentMap.AddObject(item); slot.Items[slot.Index] = null; menu.Close(); return true; } return false; })); }
public override IEnumerable <ComponentButton> GetContextMenu(ItemSlot slot, InvContextMenu menu) { var map = GameImpl.Instance.CurrentMap; if (map != null && map.CanHaveFurniture) { yield return(new ComponentButton(menu, new RectangleF(Vector2.Zero, new Size2(20, 6)), Locale.GetInterface("Place"), (button, pressType) => { if (button == MouseButton.Left && pressType == PressType.Pressed) { InterfaceManager.Overlay.CursorItem = this; slot.Items[slot.Index] = null; InterfaceManager.SetInterface(null); return true; } return false; })); } foreach (var comp in base.GetContextMenu(slot, menu)) { yield return(comp); } }