Skip to content

Commit

Permalink
Implemented Icons for weapons, items and functions to show in the map…
Browse files Browse the repository at this point in the history
…browser
  • Loading branch information
netquick committed Jul 16, 2024
1 parent 9e34251 commit 73a019b
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 33 deletions.
174 changes: 162 additions & 12 deletions DeFRaG_Helper/Objects/Map.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DeFRaG_Helper.Objects;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace DeFRaG_Helper
Expand Down Expand Up @@ -395,32 +396,181 @@ public List<string> Functions
}
}
}

public List<MapIcon> GenerateIcons()
private ObservableCollection<MapIcon>? weaponIcons;
public ObservableCollection<MapIcon> WeaponIcons
{
get
{
if (weaponIcons == null || !weaponIcons.Any())
{
weaponIcons = GenerateWeaponIcons();
}
return weaponIcons;
}
set
{
if (weaponIcons != value)
{
weaponIcons = value;
OnPropertyChanged(nameof(weaponIcons));
}
}
}
private ObservableCollection<MapIcon>? itemIcons;
public ObservableCollection<MapIcon> ItemIcons
{
List<MapIcon> icons = new List<MapIcon>();
get
{
if (itemIcons == null || !itemIcons.Any())
{
itemIcons = GenerateItemIcons();
}
return itemIcons;
}
set
{
if (itemIcons != value)
{
itemIcons = value;
OnPropertyChanged(nameof(itemIcons));
}
}
}
private ObservableCollection<MapIcon>? functionIcons;
public ObservableCollection<MapIcon> FunctionIcons
{
get
{
if (functionIcons == null || !functionIcons.Any())
{
functionIcons = GenerateFunctionIcons();
}
return functionIcons;
}
set
{
if (functionIcons != value)
{
functionIcons = value;
OnPropertyChanged(nameof(functionIcons));
}
}
}
public ObservableCollection<MapIcon> GenerateWeaponIcons()
{
ObservableCollection<MapIcon> newWeaponIcons = new ObservableCollection<MapIcon>();

// Example mapping for demonstration purposes
Dictionary<string, (string path, string color)> iconMapping = new Dictionary<string, (string, string)>
{
{"Rocket Launcher", ("Icons/Weapons/iconw_rocket.svg", "Red")},
{"Plasmagun", ("Icons/Weapons/iconw_plasma.svg", "Blue")},
// Add mappings for other weapons, items, and functions
};
{
{"Rocket Launcher", ("Icons/Weapons/iconw_rocket.svg", "Red")},
{"Plasmagun", ("Icons/Weapons/iconw_plasma.svg", "Blue")},
{"Railgun", ("Icons/Weapons/iconw_railgun.svg", "Green") },
{"Shotgun", ("Icons/Weapons/iconw_shotgun.svg", "Yellow") },
{"Lightning Gun", ("Icons/Weapons/iconw_lightning.svg", "Orange") },
{"Big fucking gun", ("Icons/Weapons/iconw_bfg.svg", "Black") },
{"Gauntlet", ("Icons/Wepons/iconw_gauntlet.svg", "Cyan") },
{"Grappling hook", ("Icons/Weapons/iconw_grapple.svg", "Green") },
{"Grenade Launcher", ("Icons/Weapons/iconw_grenade.svg", "Green") },
{"Machinegun", ("Icons/Weapons/iconsw_machinegun", "yellow") },
{"Proximity Mine Launcher (Team Arena)", ("Icons/Weapons/proxmine.svg", "Red") },
{"Chaingun (Team Arena)", ("Icons/Weapons/chaingun.svg", "Black") },
{"Nailgun (Team Arena)", ("Icons/Weapons/nailgun.svg", "Green") }

};

foreach (var weapon in Weapons)
{
if (iconMapping.TryGetValue(weapon, out var iconInfo))
{
icons.Add(new MapIcon { SvgPath = iconInfo.path, Color = iconInfo.color });
newWeaponIcons.Add(new MapIcon { SvgPath = iconInfo.path, Color = iconInfo.color });
}
}
return newWeaponIcons;
}
public ObservableCollection<MapIcon> GenerateItemIcons()
{
ObservableCollection<MapIcon> newItemIcons = new ObservableCollection<MapIcon>();

// Repeat for Items and Functions if necessary

return icons;
// Example mapping for demonstration purposes
Dictionary<string, (string path, string color)> iconMapping = new Dictionary<string, (string, string)>
{
{"Body Armor (Red Armor)", ("Icons/Items/iconr_red.svg", "Red") },
{"Combat Armor (Yellow Armor)", ("Icons(Items/iconr_yellow.svg", "Yellow") },
{"Battle Suit", ("Icons/Items/envirosuit.svg", "Orange") },
{"Shard Armor", ("Icons/Items/iconr_shard.svg", "Green") },
{"Flight", ("Icons/Items/flight.svg", "Purple") },
{"Haste", ("Icons/Items/haste.svg", "Yellow") },
{"Health", ("Icons/Items/iconh_red", "Red") },
{"Large health", ("Icons/Items/iconh_yellow.svg", "Yellow") },
{"Mega health", ("Icons/Items/iconh_mega.svg", "Blue") },
{"Small health", ("Icons/Items/iconh_green.svg", "Green") },
{"Invisibility", ("Icons/Items/invis.svg", "Purple") },
{"Quad-damage", ("Icons/Items/quad.svg", "Cyan") },
{"Regeneration", ("Icons/Items/regen.svg", "Green") },
{"Personal Teleporter", ("Icons/Items/teleporter.svg", "Blue") },
{"Medikit", ("Icons/Items/medkit.svg", "Red") },
{"Ammo Regen (Team Arena)", ("Icons/Items/ammo_regen.svg", "Yellow") },
{"Scout (Team Arena)", ("Icons/Items/scout.svg", "Green") },
{"Doubler (Team Arena)", ("Icons/Items/doubler.svg", "Red") },
{"Guard (Team Arena)", ("Icons/Items/guard.svg", "Blue") },
{"Kamikaze (Team Arena)", ("Icons/Items/kamikaze.svg", "Red") },
{"Invulnerability (Team Arena)", ("Icons/Items/invulnerability.svg", "Blue") },
{"Green Armor (CPMA)", ("Icons/Items/iconr_green.svg", "Green") }




};

foreach (var item in Items)
{
if (iconMapping.TryGetValue(item, out var iconInfo))
{
newItemIcons.Add(new MapIcon { SvgPath = iconInfo.path, Color = iconInfo.color });
}
}
return newItemIcons;
}
public ObservableCollection<MapIcon> GenerateFunctionIcons()
{
ObservableCollection<MapIcon> newFunctionIcons = new ObservableCollection<MapIcon>();

// Example mapping for demonstration purposes
Dictionary<string, (string path, string color)> iconMapping = new Dictionary<string, (string, string)>
{
{"Door/Gate", ("Icons/Functions/door.svg", "Red") },
{"Button", ("Icons/Functions/button.svg", "Red") },
{"Teleporter/Portal", ("Icons/Functions/tele.svg", "Blue") },
{"Jumppad/Launchramp", ("Icons/Functions/push.svg", "Yellow") },
{"Moving object/platform", ("Icons/Functions/moving.svg", "Gray") },
{"Shooter Grenade", ("Icons/Functions/shootergl.svg", "Green") },
{"Shooter Plasma", ("Icons/Functions/shooterpg.svg", "Purple") },
{"Shooter Rocket", ("Icons/Functions/shooterrl.svg", "Red") },
{"Slick", ("Icons/Functions/slick.svg", "Yellow") },
{"Water", ("Icons/Functions/water.svg", "Blue") },
{"Fog", ("Icons/Functions/fog.svg", "Gray") },
{"Slime", ("Icons/Functions/slime.svg", "Green") },
{"Lava", ("Icons/Functions/lava.svg", "Red") },
{"breakable", ("Icons/Functions/break.svg", "Gray") },
{"Ambient sounds", ("Icons/Functions/Speaker_Icon.svg", "Gray") },
{"Timer", ("Icons/Functions/timer.svg", "Gray") }


};

foreach (var function in Functions)
{
if (iconMapping.TryGetValue(function, out var iconInfo))
{
newFunctionIcons.Add(new MapIcon { SvgPath = iconInfo.path, Color = iconInfo.color });
}
}
return newFunctionIcons;
}

}


}

86 changes: 69 additions & 17 deletions DeFRaG_Helper/UserControls/MapCard.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
xmlns:converters="clr-namespace:DeFRaG_Helper.Converters"

d:DesignHeight="100" d:DesignWidth="1000">
<UserControl.Resources>
<converters:SvgPathAndColorConverter x:Key="SvgPathAndColorConverter"/>
</UserControl.Resources>
<Border CornerRadius="10" Background="#2c2c2c">
<Grid>
<Grid.ColumnDefinitions>
Expand All @@ -27,7 +30,7 @@
</Grid.RowDefinitions>

<!-- Name TextBlock, now correctly spanning only the left half -->
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Name" Text="{Binding Name}" FontFamily="Segoe UI" FontSize="20" Foreground="White" Margin="10, 5, 0, 5"/>
<TextBlock Grid.Row="0" Grid.Column="0" x:Name="Name" Text="{Binding Name}" FontFamily="Segoe UI" FontSize="20" Foreground="{DynamicResource ThemeColor}" Margin="10, 5, 0, 5"/>

Check warning on line 34 in DeFRaG_Helper/UserControls/MapCard.xaml

View workflow job for this annotation

GitHub Actions / build-and-test

'MapCard.Name' hides inherited member 'FrameworkElement.Name'. Use the new keyword if hiding was intended.
<!-- Nested Grid for detailed information, placed in the second row of the main grid -->
<Grid Grid.Row="1" Grid.Column="0">
Expand Down Expand Up @@ -62,21 +65,70 @@
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- add right content -->
<ItemsControl ItemsSource="{Binding Icons, RelativeSource={RelativeSource AncestorType=UserControl}}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Width="30" Height="30">
<Image.Source>
<MultiBinding Converter="{StaticResource SvgPathAndColorConverter}">
<Binding Path="SvgPath"/>
<Binding Path="Color"/>
</MultiBinding>
</Image.Source>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<ItemsControl Grid.Row="0" ItemsSource="{Binding WeaponIcons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Width="18" Height="18" Margin="0, 2, 5, 0">
<Image.Source>
<MultiBinding Converter="{StaticResource SvgPathAndColorConverter}">
<Binding Path="SvgPath"/>
<Binding Path="Color"/>
</MultiBinding>
</Image.Source>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl Grid.Row="1" ItemsSource="{Binding ItemIcons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Width="18" Height="18" Margin="0, 2, 5, 0">
<Image.Source>
<MultiBinding Converter="{StaticResource SvgPathAndColorConverter}">
<Binding Path="SvgPath"/>
<Binding Path="Color"/>
</MultiBinding>
</Image.Source>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl Grid.Row="2" ItemsSource="{Binding FunctionIcons}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Width="18" Height="18" Margin="0, 2, 5, 0">
<Image.Source>
<MultiBinding Converter="{StaticResource SvgPathAndColorConverter}">
<Binding Path="SvgPath"/>
<Binding Path="Color"/>
</MultiBinding>
</Image.Source>
</Image>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>

<Image Grid.Column="1" Source="{Binding ImagePath}" MaxHeight="70" Width="120" MaxWidth="120" Margin="5" ></Image>
<CheckBox Grid.Column="2" Name="chkFav" IsChecked="{Binding IsFavorite}" Style="{StaticResource FavoriteCheckBoxStyle}" VerticalAlignment="Center" Margin="20, 0, 20, 0" Checked="FavoriteCheckBox_Checked" Unchecked="FavoriteCheckBox_Unchecked"/>
Expand Down Expand Up @@ -119,7 +171,7 @@
<TextBlock Text="" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Name="btnEdit" Grid.Column="5" Width="40" Margin="5, 10, 5, 10"
<Button Name="btnEdit" Grid.Column="5" Width="40" Margin="5, 10, 10, 10"
Command="{Binding ElementName=MapsList, Path=DataContext.DownloadMapCommand}"
CommandParameter="{Binding}"
IsEnabled="{Binding IsDownloaded, Converter={StaticResource IntToInverseBooleanConverter}}">
Expand Down
22 changes: 18 additions & 4 deletions DeFRaG_Helper/ViewModels/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,23 @@ private async Task LoadMapsFromDatabase()
Maps.isDownloaded,
Maps.isInstalled,
Maps.isFavorite,
GROUP_CONCAT(DISTINCT MapWeapon.WeaponID) AS Weapons,
GROUP_CONCAT(DISTINCT MapItem.ItemID) AS Items,
GROUP_CONCAT(DISTINCT MapFunction.FunctionID) AS Functions
GROUP_CONCAT(DISTINCT Weapon.Weapon) AS Weapons,
GROUP_CONCAT(DISTINCT Item.Item) AS Items,
GROUP_CONCAT(DISTINCT Function.Function) AS Functions
FROM
Maps
LEFT JOIN
MapWeapon ON Maps.ID = MapWeapon.MapID
LEFT JOIN
Weapon ON MapWeapon.WeaponID = Weapon.WeaponID
LEFT JOIN
MapItem ON Maps.ID = MapItem.MapID
LEFT JOIN
Item ON MapItem.ItemID = Item.ItemID
LEFT JOIN
MapFunction ON Maps.ID = MapFunction.MapID
LEFT JOIN
Function ON MapFunction.FunctionID = Function.FunctionID
GROUP BY
Maps.ID,
Maps.Name,
Expand All @@ -222,7 +228,7 @@ GROUP BY
Maps.Style,
Maps.isDownloaded,
Maps.isInstalled,
Maps.isFavorite;
Maps.isFavorite
", connection))
{
using (var reader = await command.ExecuteReaderAsync())
Expand Down Expand Up @@ -252,6 +258,9 @@ GROUP BY


};



// Since we're on a background thread, ensure UI updates are dispatched on the UI thread
App.Current.Dispatcher.Invoke(() => Maps.Add(map));

Expand All @@ -262,11 +271,16 @@ GROUP BY
// Update progress bar and potentially refresh the UI here
App.Current.Dispatcher.Invoke(() =>
{
map.GenerateWeaponIcons();
map.GenerateItemIcons();
map.GenerateFunctionIcons();

MainWindow.Instance.UpdateProgressBar(progress);
MapsBatchLoaded?.Invoke(this, EventArgs.Empty);

// Optionally, refresh the UI to show the newly loaded maps
});
OnPropertyChanged(nameof(Maps));

}
}
Expand Down
7 changes: 7 additions & 0 deletions DeFRaG_Helper/Views/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
<ComboBoxItem Content="MetroBrown" Background="#996633"/>
<ComboBoxItem Content="MetroGray" Background="#666666"/>
<ComboBoxItem Content="MetroBlue" Background="#0066cc"/>
<ComboBoxItem Content="MetroCyan" Background="#0099cc"/>
<ComboBoxItem Content="MetroLime" Background="#99cc00"/>
<ComboBoxItem Content="MetroMagenta" Background="#cc0066"/>
<ComboBoxItem Content="MetroTeal" Background="#339999"/>
<ComboBoxItem Content="MetroIndigo" Background="#003399"/>
<ComboBoxItem Content="MetroViolet" Background="#663399"/>


</ComboBox>
<Button Name="btnSync" Content="Sync maps" Margin="636,10,10,0" VerticalAlignment="Top" Height="35" Click="btnSync_Click" IsEnabled="False"/>
Expand Down

0 comments on commit 73a019b

Please sign in to comment.