Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Loki/InventorySlotEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
</UserControl.Resources>


<Border CornerRadius="4" x:Name="LayoutRoot" AllowDrop="True" Drop="BorderDrop">
<Border CornerRadius="4" x:Name="LayoutRoot" AllowDrop="True" Drop="BorderDrop" MouseMove="BorderMouseMove">
<Border.Style>
<Style TargetType="Border">
<Setter Property="Background" Value="DarkGray"/>
Expand Down
33 changes: 31 additions & 2 deletions Loki/InventorySlotEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,48 @@ private void BorderDrop(object sender, DragEventArgs e)
{
if (e.Data.GetData(typeof(SharedItemData)) is SharedItemData itemData)
{
// drop from item picker
if (this.DataContext is InventorySlot slot)
{
var customData = new List<(string, string)>();
slot.Item = new Item(itemData.ItemName, itemData.MaxStack, (float)itemData.MaxDurability, slot.Position,
false, 1, 0, MainWindow.selectedPlayerProfile.PlayerId, MainWindow.selectedPlayerProfile.PlayerName, customData);
}
}
else if (e.Data.GetData(typeof(InventorySlot)) is InventorySlot sourceSlot)
{
// drop from inventory slot
if (this.DataContext is InventorySlot slot && sourceSlot != slot)
{
var targetSlotItem = slot.Item;
slot.Item = sourceSlot.Item;
sourceSlot.Item = targetSlotItem;
}
}
}

private void BorderMouseMove(object sender, MouseEventArgs e)
{
if (e.Source is TextBox)
{
// TextBox has its own Drag&Drop functionality and would raise an InvalidOperationException
return;
}

if (sender is FrameworkElement element && e.LeftButton == MouseButtonState.Pressed)
{
if (element.DataContext is InventorySlot slot && slot.Item != null)
{
var data = new DataObject(slot);
DragDrop.DoDragDrop(element, data, DragDropEffects.Move);
}
}
}

private void StackEditPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
if (sender is TextBox {IsKeyboardFocusWithin: false} txtStack)
{
if (sender is TextBox { IsKeyboardFocusWithin: false } txtStack)
{
txtStack.SelectAll();
txtStack.Focus();
e.Handled = true;
Expand Down