-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trait icon lookup, handle image lookup in XAML Designer
- Loading branch information
Showing
5 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
|
||
namespace PalCalc.UI.Model | ||
{ | ||
internal static class ResourceLookup | ||
{ | ||
public static Stream Get(string pathInResources) | ||
{ | ||
if (DesignerProperties.GetIsInDesignMode(new DependencyObject())) | ||
{ | ||
return File.OpenRead($"PalCalc.UI/Resources/{pathInResources}"); | ||
} | ||
else | ||
{ | ||
return Application.GetResourceStream(new Uri($"/Resources/{pathInResources}", UriKind.Relative)).Stream; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace PalCalc.UI.Model | ||
{ | ||
internal static class TraitIcon | ||
{ | ||
private static Dictionary<int, ImageSource> images; | ||
public static Dictionary<int, ImageSource> Images | ||
{ | ||
get | ||
{ | ||
if (images == null) | ||
{ | ||
Stream IconStream(string iconName) => ResourceLookup.Get($"TraitRank/{iconName}"); | ||
ImageSource IconImage(string iconName) | ||
{ | ||
var source = new BitmapImage(); | ||
source.BeginInit(); | ||
source.StreamSource = IconStream(iconName); | ||
source.EndInit(); | ||
return source; | ||
} | ||
|
||
Images.Add(-3, IconImage("Passive_Negative_3_icon.png")); | ||
Images.Add(-2, IconImage("Passive_Negative_2_icon.png")); | ||
Images.Add(-1, IconImage("Passive_Negative_1_icon.png")); | ||
|
||
Images.Add(0, IconImage("Passive_Positive_1_icon.png")); | ||
|
||
Images.Add(1, IconImage("Passive_Positive_1_icon.png")); | ||
Images.Add(2, IconImage("Passive_Positive_2_icon.png")); | ||
Images.Add(3, IconImage("Passive_Positive_3_icon.png")); | ||
} | ||
|
||
return images; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters