Skip to content

Commit

Permalink
Merge pull request #4 from kirillovmr/master
Browse files Browse the repository at this point in the history
Localization & item quality management & crafted by tag toggler
  • Loading branch information
Wufflez authored Apr 21, 2021
2 parents 8cd5562 + dbdf44a commit 6edeaf4
Show file tree
Hide file tree
Showing 17 changed files with 2,887 additions and 180 deletions.
24 changes: 12 additions & 12 deletions Loki/Beard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ public readonly struct Beard
{
private static readonly Beard[] SensibleBeards =
{
new Beard("No beard", "BeardNone"),
new Beard("Braided 1", "Beard5"),
new Beard("Braided 2", "Beard6"),
new Beard("Braided 3", "Beard9"),
new Beard("Braided 4", "Beard10"),
new Beard("Long 1", "Beard1"),
new Beard("Long 2", "Beard2"),
new Beard("Short 1", "Beard3"),
new Beard("Short 2", "Beard4"),
new Beard("Short 3", "Beard7"),
new Beard("Thick 1", "Beard8"),
new Beard(Loki.Properties.Resources.B_No_beard, "BeardNone"),
new Beard(Loki.Properties.Resources.B_Braided_2, "Beard5"),
new Beard(Loki.Properties.Resources.B_Braided_2, "Beard6"),
new Beard(Loki.Properties.Resources.B_Braided_3, "Beard9"),
new Beard(Loki.Properties.Resources.B_Braided_4, "Beard10"),
new Beard(Loki.Properties.Resources.B_Long_1, "Beard1"),
new Beard(Loki.Properties.Resources.B_Long_2, "Beard2"),
new Beard(Loki.Properties.Resources.B_Short_1, "Beard3"),
new Beard(Loki.Properties.Resources.B_Short_2, "Beard4"),
new Beard(Loki.Properties.Resources.B_Short_3, "Beard7"),
new Beard(Loki.Properties.Resources.B_Thick_1, "Beard8"),
};

private static readonly IEnumerable<Beard> SillyBeards =
Expand All @@ -29,7 +29,7 @@ public readonly struct Beard
public string DisplayName { get; }
public string Code { get; }

public static Beard Default = new Beard("No beard", "BeardNone");
public static Beard Default = new Beard(Loki.Properties.Resources.B_No_beard, "BeardNone");

public Beard(string name, string code)
{
Expand Down
34 changes: 17 additions & 17 deletions Loki/Hair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ public readonly struct Hair
{
private static readonly Hair[] SensibleHairs =
{
new Hair("No hair", "HairNone"),
new Hair("Braided 1", "Hair3"),
new Hair("Braided 2", "Hair11"),
new Hair("Braided 3", "Hair12"),
new Hair("Braided 4", "Hair6"),
new Hair("Long 1", "Hair1"),
new Hair("Ponytail 1", "Hair2"),
new Hair("Ponytail 2", "Hair4"),
new Hair("Ponytail 3", "Hair7"),
new Hair("Ponytail 4", "Hair5"),
new Hair("Short 1", "Hair8"),
new Hair("Short 2", "Hair13"),
new Hair("Side Swept 1", "Hair9"),
new Hair("Side Swept 2", "Hair10"),
new Hair("Side Swept 3", "Hair14"),
new Hair("Blob hair", "TrophyBlob"),
new Hair(Loki.Properties.Resources.No_hair, "HairNone"),
new Hair(Loki.Properties.Resources.Braided_1, "Hair3"),
new Hair(Loki.Properties.Resources.Braided_2, "Hair11"),
new Hair(Loki.Properties.Resources.Braided_3, "Hair12"),
new Hair(Loki.Properties.Resources.Braided_4, "Hair6"),
new Hair(Loki.Properties.Resources.Long_1, "Hair1"),
new Hair(Loki.Properties.Resources.Ponytail_1, "Hair2"),
new Hair(Loki.Properties.Resources.Ponytail_2, "Hair4"),
new Hair(Loki.Properties.Resources.Ponytail_3, "Hair7"),
new Hair(Loki.Properties.Resources.Ponytail_4, "Hair5"),
new Hair(Loki.Properties.Resources.Short_1, "Hair8"),
new Hair(Loki.Properties.Resources.Short_2, "Hair13"),
new Hair(Loki.Properties.Resources.Side_Swept_1, "Hair9"),
new Hair(Loki.Properties.Resources.Side_Swept_2, "Hair10"),
new Hair(Loki.Properties.Resources.Side_Swept_3, "Hair14"),
new Hair(Loki.Properties.Resources.Blob_hair, "TrophyBlob"),
};

private static readonly IEnumerable<Hair> SillyHairs =
Expand All @@ -34,7 +34,7 @@ public readonly struct Hair
public string DisplayName { get; }
public string Code { get; }

public static Hair Default = new Hair("No hair", "HairNone");
public static Hair Default = new Hair(Loki.Properties.Resources.No_hair, "HairNone");

public Hair(string name, string code)
{
Expand Down
42 changes: 21 additions & 21 deletions Loki/InventoryListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ private static InventoryListItem CreateListItem(SharedItemData itemData)

string category = itemData.ItemType switch
{
ItemType.None => "Unknown",
ItemType.Material => "Material",
ItemType.Consumable => "Consumable",
ItemType.OneHandedWeapon => "One Handed Weapon",
ItemType.Bow => "Bow",
ItemType.Shield => "Shield",
ItemType.Helmet => "Helmet",
ItemType.Chest => "Chest",
ItemType.Ammo => "Ammo",
ItemType.Customization => "Customisation",
ItemType.Legs => "Legs",
ItemType.Hands => "Hands",
ItemType.Trophy => "Trophy",
ItemType.TwoHandedWeapon => "Two Handed Weapon",
ItemType.Torch => "Torch",
ItemType.Misc => "Miscellaneous",
ItemType.Shoulder => "Shoulder",
ItemType.Utility => "Utility",
ItemType.Tool => "Tool",
ItemType.AttachAtgeir => "Attach Atgeir",
_ => "Unknown",
ItemType.None => Loki.Properties.Resources.Unknown,
ItemType.Material => Loki.Properties.Resources.Material,
ItemType.Consumable => Loki.Properties.Resources.Consumable,
ItemType.OneHandedWeapon => Loki.Properties.Resources.One_Handed_Weapon,
ItemType.Bow => Loki.Properties.Resources.Bow,
ItemType.Shield => Loki.Properties.Resources.Shield,
ItemType.Helmet => Loki.Properties.Resources.Helmet,
ItemType.Chest => Loki.Properties.Resources.Chest,
ItemType.Ammo => Loki.Properties.Resources.Ammo,
ItemType.Customization => Loki.Properties.Resources.Customisation,
ItemType.Legs => Loki.Properties.Resources.Legs,
ItemType.Hands => Loki.Properties.Resources.Hands,
ItemType.Trophy => Loki.Properties.Resources.Trophy,
ItemType.TwoHandedWeapon => Loki.Properties.Resources.Trophy,
ItemType.Torch => Loki.Properties.Resources.Torch,
ItemType.Misc => Loki.Properties.Resources.Miscellaneous,
ItemType.Shoulder => Loki.Properties.Resources.Shoulder,
ItemType.Utility => Loki.Properties.Resources.Utility,
ItemType.Tool => Loki.Properties.Resources.Tool,
ItemType.AttachAtgeir => Loki.Properties.Resources.Attach_Atgeir,
_ => Loki.Properties.Resources.Unknown,
};
return new InventoryListItem(displayName, category, itemData);
}
Expand Down
48 changes: 47 additions & 1 deletion Loki/InventorySlot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Input;
Expand All @@ -15,6 +16,9 @@ public InventorySlot(Vector2i position)
Position = position;
RepairItem = new RelayCommand(RepairExecuted, RepairCanExecute);
DeleteItem = new RelayCommand(_ => Item = null);
QualityUp = new RelayCommand(QualityUpExecuted, QualityUpCanExecute);
QualityDown = new RelayCommand(QualityDownExecuted, QualityDownCanExecute);
ToggleCrafter = new RelayCommand(ToggleCrafterExecuted);
if (position.Y == 0) QuickSlotNumber = position.X + 1;
}

Expand All @@ -26,6 +30,40 @@ public InventorySlot(Vector2i position)

public RelayCommand RepairItem { get; }

public RelayCommand QualityUp { get; }

public RelayCommand QualityDown { get; }

public RelayCommand ToggleCrafter { get; }

private bool QualityUpCanExecute(object _)
{
return Item != null && Item.HasQualityLevels && Item.Quality < Item.SharedData.MaxQuality;
}

private void QualityUpExecuted(object _)
{
Item.Quality = Item.Quality + 1;
Item.MaxDurability = 1; // Force-recalculating max durability
RepairExecuted(this);
QualityUp.OnCanExecuteChanged();
QualityDown.OnCanExecuteChanged();
}

private bool QualityDownCanExecute(object _)
{
return Item != null && Item.HasQualityLevels && Item.Quality > 1;
}

private void QualityDownExecuted(object _)
{
Item.Quality = Item.Quality - 1;
Item.MaxDurability = 1; // Force-recalculating max durability
RepairExecuted(this);
QualityUp.OnCanExecuteChanged();
QualityDown.OnCanExecuteChanged();
}

private bool RepairCanExecute(object _)
{
return Item != null && Item.Durability < Item.MaxDurability;
Expand All @@ -37,6 +75,12 @@ private void RepairExecuted(object _)
RepairItem.OnCanExecuteChanged();
}

private void ToggleCrafterExecuted(object _)
{
Item.CrafterName = Item.CrafterId == 0 ? MainWindow.selectedPlayerProfile.PlayerName : "";
Item.CrafterId = Item.CrafterId == 0 ? MainWindow.selectedPlayerProfile.PlayerId : 0;
}

public Item Item
{
get => _item;
Expand All @@ -46,6 +90,8 @@ public Item Item
_item = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsEmpty));
QualityUp.OnCanExecuteChanged();
QualityDown.OnCanExecuteChanged();
}
}

Expand Down
76 changes: 55 additions & 21 deletions Loki/InventorySlotEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
<DataTrigger Binding="{Binding IsEmpty}" Value="True">
<Setter Property="Background" Value="Gray"/>
</DataTrigger>
<DataTrigger Binding="{Binding Item.Equiped}" Value="True">
<Setter Property="Background" Value="#FF7D8989"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
Expand Down Expand Up @@ -203,7 +206,7 @@
<TextBlock Margin="6,0"
Visibility="{Binding Item.HasQualityLevels, Converter={StaticResource BoolToVis}}"
FontWeight="Bold" FontSize="26"
Foreground="#DC871A"
Foreground="#DC871B"
Text="{Binding Item.Quality, FallbackValue='X'}"
HorizontalAlignment="Right" VerticalAlignment="Top" />

Expand Down Expand Up @@ -308,29 +311,60 @@
Visibility="{Binding Item.SharedData.UsesDurability, Converter={StaticResource BoolToVis}}">
<Image Source="Resources/wrench-32.ico" />
</Button>

<!-- Quality button up -->
<Button Padding="0" Cursor="Hand" Margin="0,2,0,0"
ToolTip="Quality up"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
Command="{Binding QualityUp}"
Style="{StaticResource LittleSquareCoolButton}"
Visibility="{Binding Item.HasQualityLevels, Converter={StaticResource BoolToVis}}">
<Path Data="M 50,5 95,97.5 5,97.5 z" Stroke="Blue" Stretch="Fill"
StrokeThickness="4" StrokeEndLineCap="Round" StrokeStartLineCap="Round" />
</Button>

<!-- Quality button down -->
<Button Padding="0" Cursor="Hand" Margin="0,2,0,0"
ToolTip="Quality down"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
Command="{Binding QualityDown}"
Style="{StaticResource LittleSquareCoolButton}"
Visibility="{Binding Item.HasQualityLevels, Converter={StaticResource BoolToVis}}">
<Path Data="M 50,97.5 95,5 5,5 z" Stroke="Blue" Stretch="Fill"
StrokeThickness="4" StrokeEndLineCap="Round" StrokeStartLineCap="Round" />
</Button>
</StackPanel>

<!-- Tag in top middle -->
<Image HorizontalAlignment="Center" VerticalAlignment="Top" Margin="6"
Visibility="{Binding Item.HasCrafterTag, Converter={StaticResource BoolToVis}}"
Source="Resources/tag-32.png" Width="24">
<Image.ToolTip>
<StackPanel>
<TextBlock Foreground="DarkRed" FontWeight="DemiBold" HorizontalAlignment="Center">Crafted By</TextBlock>
<DockPanel>
<Image
VerticalAlignment="Center"
Width="16" Source="Resources/viking-24.png" DockPanel.Dock="Left" Margin="8"/>
<StackPanel>
<TextBlock FontSize="14" Text="{Binding Item.CrafterName}" />
<TextBlock Text="{Binding Item.CrafterId, StringFormat='ID: {0}'}"
FontSize="8" Foreground="Gray"/>
</StackPanel>
</DockPanel>
</StackPanel>
</Image.ToolTip>
</Image>

<StackPanel>
<Image HorizontalAlignment="Center" VerticalAlignment="Top" Margin="6"

Source="Resources/tag-32.png" Width="24">
<Image.ToolTip>
<StackPanel>
<TextBlock Foreground="DarkRed" FontWeight="DemiBold" HorizontalAlignment="Center">Crafted By</TextBlock>
<DockPanel>
<Image
VerticalAlignment="Center"
Width="16" Source="Resources/viking-24.png" DockPanel.Dock="Left" Margin="8"/>
<StackPanel>
<TextBlock FontSize="14" Text="{Binding Item.CrafterName}" />
<TextBlock Text="{Binding Item.CrafterId, StringFormat='ID: {0}'}"
FontSize="8" Foreground="Gray"/>
</StackPanel>
</DockPanel>
</StackPanel>
</Image.ToolTip>
</Image>
<!-- Toggle crafter button -->
<Button Padding="0" Cursor="Hand" Margin="0,2,0,0"
ToolTip="Toggle crafter"
HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"
Command="{Binding ToggleCrafter}"
Style="{StaticResource LittleSquareCoolButton}">
<Image Source="Resources/tag-32.png" />
</Button>
</StackPanel>
</Grid>


Expand Down
2 changes: 1 addition & 1 deletion Loki/InventorySlotEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void BorderDrop(object sender, DragEventArgs e)
if (this.DataContext is InventorySlot slot)
{
slot.Item = new Item(itemData.ItemName, itemData.MaxStack, (float)itemData.MaxDurability, slot.Position,
false, 1, 0, 0, "Loki");
false, 1, 0, 0, ""); ;
}
}
}
Expand Down
45 changes: 40 additions & 5 deletions Loki/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class Item: INotifyPropertyChanged
{
private int _stack;
private float _durability;
private double _maxDurability;
private int _quality;
private string _crafterName;
private long _crafterId;
public string Name { get; }

public int Stack
Expand Down Expand Up @@ -39,17 +43,48 @@ public float Durability
}
}

public int Quality
{
get => _quality;
set
{
if (value.Equals(_quality)) return;
_quality = value;
OnPropertyChanged();
}
}

public Vector2i Pos { get; }
public bool Equiped { get; }
public int Quality { get; }
public int Variant { get; }
public long CrafterId { get; }
public string CrafterName { get; set; }
public long CrafterId {
get => _crafterId;
set
{
_crafterId = value;
OnPropertyChanged();
}
}
public string CrafterName {
get => _crafterName;
set
{
_crafterName = value;
OnPropertyChanged();
}
}

public bool HasCrafterTag => CrafterId != 0;

public double MaxDurability =>
SharedData.MaxDurability + Math.Max(0, Quality - 1) * SharedData.DurabilityPerLevel;
public double MaxDurability
{
get => _maxDurability;
set
{
_maxDurability = SharedData.MaxDurability + Math.Max(0, Quality - 1) * SharedData.DurabilityPerLevel;
OnPropertyChanged();
}
}

public Item(string name, int stack, float durability, Vector2i pos, bool equiped, int quality, int variant, long crafterId, string crafterName)
{
Expand Down
Loading

0 comments on commit 6edeaf4

Please sign in to comment.