Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Abstract resource paths more. Allows easier renaming of assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryochan7 committed Nov 11, 2023
1 parent e914d66 commit 750f2fa
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 33 deletions.
8 changes: 4 additions & 4 deletions DS4Windows/DS4Control/ScpUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,10 @@ public static string getX360ControlString(X360Controls key, OutContType conType)

public static Dictionary<TrayIconChoice, string> iconChoiceResources = new Dictionary<TrayIconChoice, string>
{
[TrayIconChoice.Default] = "/DS4Windows;component/Resources/DS4W.ico",
[TrayIconChoice.Colored] = "/DS4Windows;component/Resources/DS4W.ico",
[TrayIconChoice.White] = "/DS4Windows;component/Resources/DS4W - White.ico",
[TrayIconChoice.Black] = "/DS4Windows;component/Resources/DS4W - Black.ico",
[TrayIconChoice.Default] = $"{Global.RESOURCES_PREFIX}/DS4W.ico",
[TrayIconChoice.Colored] = $"{Global.RESOURCES_PREFIX}/DS4W.ico",
[TrayIconChoice.White] = $"{Global.RESOURCES_PREFIX}/DS4W - White.ico",
[TrayIconChoice.Black] = $"{Global.RESOURCES_PREFIX}/DS4W - Black.ico",
};

public static void SaveWhere(string path)
Expand Down
9 changes: 6 additions & 3 deletions DS4Windows/DS4Forms/BindingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
mc:Ignorable="d"
Title="Select action" Height="540" Width="1020" Closing="Window_Closing"
Style="{DynamicResource WindowStyle}">
<Window.Resources>
<local:BindingWinResourcePaths x:Key="resourcePaths" />
</Window.Resources>
<DockPanel x:Name="fullPanel" Margin="4">
<StackPanel x:Name="extrasSidePanel" Width="160" Orientation="Vertical" DockPanel.Dock="Right">
<StackPanel.Resources>
Expand Down Expand Up @@ -122,7 +125,7 @@
<StackPanel x:Name="outConPanel" Width="630" Orientation="Vertical" DockPanel.Dock="Right" HorizontalAlignment="Center" Margin="0">
<Canvas Height="247" Margin="0,10,0,0">
<Canvas.Background>
<ImageBrush x:Name="conImageBrush" ImageSource="/DS4Windows;component/Resources/360 map.png" Stretch="Uniform"/>
<ImageBrush x:Name="conImageBrush" ImageSource="{Binding Source={StaticResource resourcePaths}, Path=Xbox360MapPNG}" Stretch="Uniform"/>
</Canvas.Background>
<Canvas.Resources>
<Style TargetType="{x:Type Button}" x:Key="NoBGHoverBtn">
Expand All @@ -139,7 +142,7 @@
</Style>
</Canvas.Resources>

<Image x:Name="highlightImg" Width="20" Height="20" Source="/DS4Windows;component/Resources/360 highlight.png" Canvas.Left="622" Canvas.Top="11" IsEnabled="False" />
<Image x:Name="highlightImg" Width="20" Height="20" Source="{Binding Source={StaticResource resourcePaths}, Path=Xbox360HighlightPNG}" Canvas.Left="622" Canvas.Top="11" IsEnabled="False" />
<Label x:Name="highlightLb" Content="A" Background="Black" Foreground="White" IsEnabled="False" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />

<!--<Button x:Name="guideBtn2" Width="16" Height="30" Tag="Ni" Style="{StaticResource NoBGHoverBtn}" Canvas.Left="212" Canvas.Top="112" />-->
Expand Down Expand Up @@ -551,7 +554,7 @@
</Grid>
<Canvas x:Name="mouseCanvas" Width="120" Height="170" Grid.Column="2">
<StackPanel Width="120">
<Image Source="/DS4Windows;component/Resources/mouse.png" Stretch="Uniform"
<Image Source="{Binding Source={StaticResource resourcePaths}, Path=MousePNG}" Stretch="Uniform"
Width="100" Height="{Binding Path=Height, ElementName=mouseCanvas}" HorizontalAlignment="Center" />
</StackPanel>

Expand Down
9 changes: 8 additions & 1 deletion DS4Windows/DS4Forms/BindingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ private void FindCurrentHighlightButton()

private void InitInfoMaps()
{
foreach(KeyValuePair<Button, BindAssociation> pair in associatedBindings)
foreach (KeyValuePair<Button, BindAssociation> pair in associatedBindings)
{
Button button = pair.Key;
BindAssociation binding = pair.Value;
Expand Down Expand Up @@ -948,4 +948,11 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
bindingVM.WriteBinds();
}
}

public class BindingWinResourcePaths
{
public string Xbox360MapPNG { get => $"{DS4Windows.Global.RESOURCES_PREFIX}/360 map.png"; }
public string Xbox360HighlightPNG { get => $"{DS4Windows.Global.RESOURCES_PREFIX}/360 highlight.png"; }
public string MousePNG { get => $"{DS4Windows.Global.RESOURCES_PREFIX}/mouse.png"; }
}
}
12 changes: 6 additions & 6 deletions DS4Windows/DS4Forms/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1744,22 +1744,22 @@ private void RenameProfBtn_Click(object sender, RoutedEventArgs e)

public class ImageLocationPaths
{
public string NewProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("NewProfileImg")}"; }
public string NewProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("NewProfileImg")}"; }
public event EventHandler NewProfileChanged;

public string EditProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("EditImg")}"; }
public string EditProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("EditImg")}"; }
public event EventHandler EditProfileChanged;

public string DeleteProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("DeleteImg")}"; }
public string DeleteProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("DeleteImg")}"; }
public event EventHandler DeleteProfileChanged;

public string DuplicateProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("CopyImg")}"; }
public string DuplicateProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("CopyImg")}"; }
public event EventHandler DuplicateProfileChanged;

public string ExportProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("ExportImg")}"; }
public string ExportProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("ExportImg")}"; }
public event EventHandler ExportProfileChanged;

public string ImportProfile { get => $"/DS4Windows;component/Resources/{App.Current.FindResource("ImportImg")}"; }
public string ImportProfile { get => $"{Global.RESOURCES_PREFIX}/{App.Current.FindResource("ImportImg")}"; }
public event EventHandler ImportProfileChanged;

public ImageLocationPaths()
Expand Down
13 changes: 7 additions & 6 deletions DS4Windows/DS4Forms/ProfileEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<UserControl.Resources>
<xctk:InverseBoolConverter x:Key="InverseBoolConverter"/>
<local:ControlIndexCheck x:Key="controlIndexCheck" />
<local:ResourcePaths x:Key="resourcesPaths" />
</UserControl.Resources>
<DockPanel>
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="0,4,0,10">
Expand All @@ -25,7 +26,7 @@
<Button x:Name="presetBtn" Content="Select Preset" Margin="10,0,0,0" Click="PresetBtn_Click" />
<Button x:Name="keepSizeBtn" Margin="10,0,0,0" Click="KeepSizeBtn_Click">
<StackPanel Orientation="Horizontal" Margin="0">
<Image x:Name="sizeImage" Source="/DS4Windows;component/Resources/size.png" Width="20" Height="20"/>
<Image x:Name="sizeImage" Source="{Binding Source={StaticResource resourcesPaths}, Path=SizePNG}" Width="20" Height="20"/>
<TextBlock x:Name="sizeMsg" Text="Keep this window size after closing" Margin="4,0,0,0" VerticalAlignment="Center" />
</StackPanel>

Expand Down Expand Up @@ -94,7 +95,7 @@
</ContextMenu>
</Canvas.Resources>

<Image Source="/DS4Windows;component/Resources/DS4 Config.png" Width="440" Height="220" Stretch="Uniform"/>
<Image Source="{Binding Source={StaticResource resourcesPaths}, Path=DS4ConfigPNG}" Width="440" Height="220" Stretch="Uniform"/>

<Button x:Name="ds4LightbarColorBtn" Width="138" Height="12" Canvas.Left="150" Canvas.Top="28"
Background="{x:Null}" BorderBrush="{x:Null}" MouseEnter="Ds4LightbarColorBtn_MouseEnter" MouseLeave="Ds4LightbarColorBtn_MouseLeave" Click="Ds4LightbarColorBtn_Click">
Expand All @@ -119,13 +120,13 @@
<Rectangle x:Name="lightbarRect" Fill="{Binding LightbarBrush,FallbackValue=Green}" Width="{Binding Path=Width, ElementName=ds4LightbarColorBtn}"
Height="{Binding Path=Height, ElementName=ds4LightbarColorBtn}">
<Rectangle.OpacityMask>
<ImageBrush ImageSource="/DS4Windows;component/Resources/DS4 lightbar.png" />
<ImageBrush ImageSource="{Binding Source={StaticResource resourcesPaths}, Path=DS4LightbarPNG}" />
</Rectangle.OpacityMask>
</Rectangle>
</Button>

<Image x:Name="picBoxHover" IsEnabled="False" Source="/DS4Windows;component/Resources/DS4-Config_RS.png" Height="48" Width="48" Canvas.Left="447" Canvas.Top="5" />
<Image x:Name="picBoxHover2" IsEnabled="False" Source="/DS4Windows;component/Resources/DS4-Config_RS.png" Height="48" Width="48" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" />
<Image x:Name="picBoxHover" IsEnabled="False" Source="{Binding Source={StaticResource resourcesPaths}, Path=DS4ConfigRSPNG}" Height="48" Width="48" Canvas.Left="447" Canvas.Top="5" />
<Image x:Name="picBoxHover2" IsEnabled="False" Source="{Binding Source={StaticResource resourcesPaths}, Path=DS4ConfigRSPNG}" Height="48" Width="48" Canvas.Left="0" Canvas.Top="0" Stretch="Fill" />

<Button Content="Cross" x:Name="crossConBtn" Canvas.Left="330" Canvas.Top="125" Width="26" Height="26" Click="HoverConBtn_Click" Style="{StaticResource NoBGHoverBtn}" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
<Button Content="Circle" x:Name="circleConBtn" Canvas.Left="357" Canvas.Top="99" Width="26" Height="26" Style="{StaticResource NoBGHoverBtn}" Click="HoverConBtn_Click" MouseEnter="ContBtn_MouseEnter" MouseLeave="ContBtn_MouseLeave" MouseRightButtonUp="ConBtn_MouseRightButtonUp" />
Expand Down Expand Up @@ -1186,7 +1187,7 @@
<Button x:Name="rainbowBtn" Height="20" Width="20"
ToolTip="{lex:Loc Resources:AlwaysRainbow}" Click="RainbowBtn_Click">
<Button.Content>
<Image Source="/DS4Windows;component/Resources/rainbow.png" />
<Image Source="{Binding Source={StaticResource resourcesPaths}, Path=DS4LightbarPNG}" />
</Button.Content>
</Button>
<xctk:IntegerUpDown MinWidth="30" Height="30" Minimum="0" Maximum="60" Increment="1" Margin="8,0,0,0"
Expand Down
9 changes: 9 additions & 0 deletions DS4Windows/DS4Forms/ProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,15 @@ private void StickOuterBindButton_Click(object sender, RoutedEventArgs e)
}
}

public class ResourcePaths
{
public string SizePNG { get => $"{Global.RESOURCES_PREFIX}/size.png"; }
public string DS4ConfigPNG { get => $"{Global.RESOURCES_PREFIX}/DS4 Config.png"; }
public string DS4LightbarPNG { get => $"{Global.RESOURCES_PREFIX}/DS4 lightbar.png"; }
public string DS4ConfigRSPNG { get => $"{Global.RESOURCES_PREFIX}/DS4-Config_RS.png"; }
public string RainbowPNG { get => $"{Global.RESOURCES_PREFIX}/rainbow.png"; }
}

public class ControlIndexCheck
{
public int TiltUp { get => (int)DS4Controls.GyroZNeg; }
Expand Down
6 changes: 4 additions & 2 deletions DS4Windows/DS4Forms/RecordBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
<xctk:IntegerUpDown x:Name="lightRumbleUD" Value="{Binding RumbleLight,UpdateSourceTrigger=Explicit}" Minimum="0" Maximum="255" />
</StackPanel>
</DataTemplate>

<local:RecordBoxResourcePaths x:Key="resourcePaths" />
</UserControl.Resources>
<DockPanel Margin="4">
<DockPanel DockPanel.Dock="Right" Width="200" LastChildFill="False" Margin="4,0">
Expand Down Expand Up @@ -75,12 +77,12 @@
<StackPanel x:Name="extraConPanel">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,30,0,0">
<Button x:Name="addRumbleBtn" Content="Add Rumble" Width="124" Click="AddRumbleBtn_Click" />
<Image Source="/DS4Windows;component/Resources/left touch.png" Width="43" Visibility="Collapsed" />
<Image Source="{Binding Source={StaticResource resourcePaths}, Path=LeftTouch}" Width="43" Visibility="Collapsed" />
</StackPanel>

<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10">
<Button x:Name="changeLightBtn" Content="Change Lightbar Color" Width="124" Click="ChangeLightBtn_Click" />
<Image Source="/DS4Windows;component/Resources/left touch.png" Width="43" Visibility="Collapsed" />
<Image Source="{Binding Source={StaticResource resourcePaths}, Path=LeftTouch}" Width="43" Visibility="Collapsed" />
</StackPanel>
</StackPanel>
</StackPanel>
Expand Down
5 changes: 5 additions & 0 deletions DS4Windows/DS4Forms/RecordBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,4 +625,9 @@ private void AddWaitTimeBtn_Click(object sender, RoutedEventArgs e)
}
}
}

public class RecordBoxResourcePaths
{
public string LeftTouch { get => $"{DS4Windows.Global.RESOURCES_PREFIX}/left touch.png"; }
}
}
8 changes: 4 additions & 4 deletions DS4Windows/DS4Forms/ViewModels/ControllerListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public string StatusSource
get
{
string imgName = (string)App.Current.FindResource(device.ConnectionType == ConnectionType.USB ? "UsbImg" : "BtImg");
string source = $"/DS4Windows;component/Resources/{imgName}";
string source = $"{Global.RESOURCES_PREFIX}/{imgName}";
return source;
}
}
Expand All @@ -283,17 +283,17 @@ public string ExclusiveSource
get
{
string imgName = (string)App.Current.FindResource("CancelImg");
string source = $"/DS4Windows;component/Resources/{imgName}";
string source = $"{Global.RESOURCES_PREFIX}/{imgName}";
switch(device.CurrentExclusiveStatus)
{
case DS4Device.ExclusiveStatus.Exclusive:
imgName = (string)App.Current.FindResource("CheckedImg");
source = $"/DS4Windows;component/Resources/{imgName}";
source = $"{Global.RESOURCES_PREFIX}/{imgName}";
break;
case DS4Device.ExclusiveStatus.HidHideAffected:
case DS4Device.ExclusiveStatus.HidGuardAffected:
imgName = (string)App.Current.FindResource("KeyImageImg");
source = $"/DS4Windows;component/Resources/{imgName}";
source = $"{Global.RESOURCES_PREFIX}/{imgName}";
break;
default:
break;
Expand Down
12 changes: 6 additions & 6 deletions DS4Windows/DS4Forms/ViewModels/RecordBoxViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,18 @@ public class MacroStepItem
{
private static string[] imageSources = new string[]
{
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("KeyDownImg")}",
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("KeyUpImg")}",
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("ClockImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("KeyDownImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("KeyUpImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("ClockImg")}",
};

public static void CacheImgLocations()
{
imageSources = new string[]
{
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("KeyDownImg")}",
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("KeyUpImg")}",
$"/DS4Windows;component/Resources/{(string)App.Current.FindResource("ClockImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("KeyDownImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("KeyUpImg")}",
$"{Global.RESOURCES_PREFIX}/{(string)App.Current.FindResource("ClockImg")}",
};
}

Expand Down
4 changes: 3 additions & 1 deletion DS4Windows/DS4Forms/WelcomeDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<Style TargetType="{x:Type TextBlock}" x:Key="CommonMarginTxt" BasedOn="{StaticResource {x:Type TextBlock}}">
<Setter Property="Margin" Value="0,10,0,0" />
</Style>

<local:WelcomeDialogResourcePaths x:Key="resourcePaths" />
</Window.Resources>
<ScrollViewer>
<DockPanel Margin="10,10,10,10" LastChildFill="False">
Expand Down Expand Up @@ -44,7 +46,7 @@
connect to "Wireless Controller". If asked, enter pair code 0000.
Once paired, you're ready. Have fun!
</TextBlock>
<Image Source="/DS4Windows;component/Resources/Pairmode.png" Height="80" DockPanel.Dock="Top" />
<Image Source="{Binding Source={StaticResource resourcePaths}, Path=PairmodePNG}" Height="80" DockPanel.Dock="Top" />
</DockPanel>

<StackPanel x:Name="step4HidHidePanel" DockPanel.Dock="Top" Margin="0,8,0,0">
Expand Down
5 changes: 5 additions & 0 deletions DS4Windows/DS4Forms/WelcomeDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,9 @@ private void LateControlsCheck()
step5FakerInputPanel.IsEnabled = IsFakerInputControlCompatible();
}
}

public class WelcomeDialogResourcePaths
{
public string PairmodePNG { get => $"{DS4Windows.Global.RESOURCES_PREFIX}/Pairmode.png"; }
}
}

0 comments on commit 750f2fa

Please sign in to comment.