Skip to content

Commit

Permalink
custom paint can price
Browse files Browse the repository at this point in the history
  • Loading branch information
katycat5e committed Jan 24, 2025
1 parent 9d60a53 commit 2cf07b1
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
1 change: 1 addition & 0 deletions SMShared/Json/ThemeConfigJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ThemeConfigItem
public string Name;
public bool HideFromStores;
public bool PreventRandomSpawning;
public float? CanPrice;

public string LabelTextureFile;
public string LabelBaseColor;
Expand Down
29 changes: 27 additions & 2 deletions SkinConfigurator/ThemeConfigEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
Expand All @@ -44,7 +45,31 @@
ItemsSource="{Binding AvailableSkinNames}"
SelectionChanged="ComboBox_SelectionChanged"/>

<UniformGrid Grid.Row="1" Grid.Column="0" Rows="4">
<Label Grid.Row="1" Grid.Column="0" Content="Can Price:" ToolTip="Leave blank to use default of $15000"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="7,0,0,0" x:Name="PriceInput">
<TextBox.Resources>
<local:FloatStringConverter x:Key="floatStringConverter"/>
</TextBox.Resources>
<TextBox.Text>
<Binding Path="CanPrice" UpdateSourceTrigger="LostFocus" Converter="{StaticResource floatStringConverter}">
<Binding.ValidationRules>
<local:FloatStringRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>

<TextBox.Style>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</TextBox.Style>
</TextBox>

<UniformGrid Grid.Row="2" Grid.Column="0" Rows="4">
<CheckBox Content="Hide From Stores" IsChecked="{Binding HideFromStores}" VerticalAlignment="Center"
ToolTip="Whether or not to allow this theme to spawn as a paint can"/>
<CheckBox Content="Don't Auto-Apply" IsChecked="{Binding PreventRandomSpawning}" VerticalAlignment="Center"
Expand All @@ -53,7 +78,7 @@
<Button Content="Remove Texture" Click="ClickRemoveTexture" IsEnabled="{Binding HasValidImage}"/>
</UniformGrid>

<UniformGrid Grid.Row="1" Grid.Column="1" Rows="3" Cursor="Hand" Margin="7,0,0,0">
<UniformGrid Grid.Row="2" Grid.Column="1" Rows="3" Cursor="Hand" Margin="7,0,0,0">
<Border Style="{StaticResource LabelColorStyle}" x:Name="SelectAccentB" MouseDown="ClickAccentB"
Background="{Binding LabelAccentColorB, Converter={StaticResource colorBrushConverter}}" d:Background="DarkRed">
<Label Content="Top Band" Foreground="{Binding LabelAccentColorB, Converter={StaticResource textColorConverter}}" HorizontalAlignment="Center"/>
Expand Down
53 changes: 53 additions & 0 deletions SkinConfigurator/ThemeConfigEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
using SMShared;
using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;

Expand Down Expand Up @@ -103,5 +105,56 @@ private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs
{
Model.ThemeName = (string?)ThemeNameCombo.SelectedItem;
}

private void PriceInput_LostFocus(object sender, RoutedEventArgs e)
{
if (float.TryParse(PriceInput.Text, out float value))
{

}
}
}

public class FloatStringRule : ValidationRule
{
public override ValidationResult Validate(object value, CultureInfo cultureInfo)
{
string strVal = (string)value;

if (string.IsNullOrWhiteSpace(strVal)) return ValidationResult.ValidResult;

if (float.TryParse(strVal, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out _))
{
return ValidationResult.ValidResult;
}
return new ValidationResult(false, "Not a valid decimal number");
}
}

public class FloatStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is float f)
{
return f.ToString("F0", CultureInfo.CurrentCulture);
}
return string.Empty;
}

public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
string strVal = (string)value;
if (string.IsNullOrWhiteSpace(strVal))
{
return null;
}

if (float.TryParse(strVal, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.CurrentCulture, out float result))
{
return (float)Math.Round(Math.Abs(result));
}
return null;
}
}
}
11 changes: 11 additions & 0 deletions SkinConfigurator/ViewModels/ThemeConfigModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ public bool PreventRandomSpawning
DependencyProperty.Register("PreventRandomSpawning", typeof(bool), typeof(ThemeConfigModel), new PropertyMetadata(false));


public float? CanPrice
{
get { return (float?)GetValue(CanPriceProperty); }
set { SetValue(CanPriceProperty, value); }
}

// Using a DependencyProperty as the backing store for CanPrice. This enables animation, styling, binding, etc...
public static readonly DependencyProperty CanPriceProperty =
DependencyProperty.Register("CanPrice", typeof(float?), typeof(ThemeConfigModel), new PropertyMetadata(defaultValue: null));


public event PropertyChangedEventHandler? PropertyChanged;

Expand Down Expand Up @@ -192,6 +202,7 @@ public ThemeConfigItem JsonModel()
Name = ThemeName,
HideFromStores = HideFromStores,
PreventRandomSpawning = PreventRandomSpawning,
CanPrice = CanPrice,
};

if (HasValidImage)
Expand Down
9 changes: 7 additions & 2 deletions SkinManagerMod/Items/PaintFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,13 +470,18 @@ public static void InjectShopData()
// global shop data
Main.LogVerbose($"Injecting shop data for theme {theme.name}");

if (!SkinProvider.TryGetThemeSettings(theme.name, out var settings))
{
settings = null;
}

var newShopData = new ShopItemData()
{
item = newItemSpec,
shelfItem = DefaultCanShopData.shelfItem,

amount = 20,
basePrice = DefaultCanShopData.basePrice,
amount = 50,
basePrice = settings?.CanPrice ?? DefaultCanShopData.basePrice,

isGlobal = true,
careerOnly = false,
Expand Down
4 changes: 4 additions & 0 deletions SkinManagerMod/ThemeSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ThemeSettings
public Version HighestVersion;
public bool HideFromStores;
public bool PreventRandomSpawning;
public float? CanPrice;

public SkinTexture CanLabel;
public Color? LabelBaseColor;
Expand All @@ -28,6 +29,8 @@ public void Merge(ThemeSettings other)
bool otherIsNewer = other.HighestVersion > HighestVersion;

ReplaceIfNewer(ref HideFromStores, other.HideFromStores, otherIsNewer);
ReplaceIfNewer(ref PreventRandomSpawning, other.PreventRandomSpawning, otherIsNewer);
ReplaceIfNewer(ref CanPrice, other.CanPrice, otherIsNewer);
ReplaceIfNewer(ref CanLabel, other.CanLabel, otherIsNewer);

ReplaceIfNewer(ref LabelBaseColor, other.LabelBaseColor, otherIsNewer);
Expand All @@ -51,6 +54,7 @@ public static ThemeSettings Create(string basePath, ThemeConfigItem data, Versio
{
HideFromStores = data.HideFromStores,
PreventRandomSpawning = data.PreventRandomSpawning,
CanPrice = data.CanPrice,
};

TryParseColor(data.LabelBaseColor, basePath, ref result.LabelBaseColor);
Expand Down

0 comments on commit 2cf07b1

Please sign in to comment.