Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions DarkUI/DarkUI.WPF.Demo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
</ToggleButton>
</StackPanel>
</StackPanel>

<StackPanel>
<StackPanel.Margin>
<Thickness Bottom="{x:Static darkUI:Defaults.LargeThicknessWidth}" />
Expand Down Expand Up @@ -944,6 +945,43 @@
</StackPanel>
</GroupBox>
</StackPanel>

<StackPanel>
<StackPanel.Margin>
<Thickness Bottom="{x:Static darkUI:Defaults.LargeThicknessWidth}" />
</StackPanel.Margin>

<TextBlock FontSize="{x:Static local:LocalDefaults.LargeFontSize}" Text="MaterialMapPreview">
<TextBlock.Margin>
<Thickness Bottom="{x:Static darkUI:Defaults.SmallThicknessWidth}" />
</TextBlock.Margin>
</TextBlock>

<StackPanel Orientation="Horizontal">
<StackPanel>
<StackPanel.Margin>
<Thickness Right="{x:Static darkUI:Defaults.MediumThicknessWidth}" />
</StackPanel.Margin>

<Label>Normal (40x40):</Label>
<controls:MaterialMapPreview />
</StackPanel>

<StackPanel>
<StackPanel.Margin>
<Thickness Right="{x:Static darkUI:Defaults.MediumThicknessWidth}" />
</StackPanel.Margin>

<Label>Large (64x64):</Label>
<controls:MaterialMapPreview Width="64" Height="64" />
</StackPanel>

<StackPanel>
<Label>Small (24x24):</Label>
<controls:MaterialMapPreview Width="24" Height="24" />
</StackPanel>
</StackPanel>
</StackPanel>
</StackPanel>

<WindowsFormsHost
Expand Down
86 changes: 86 additions & 0 deletions DarkUI/DarkUI.WPF/CustomControls/MaterialMapPreview.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace DarkUI.WPF.CustomControls;

/// <summary>
/// A custom control for displaying material map previews with a checker pattern background.
/// Displays an image preview with a standardized checker pattern background for transparency visualization.
/// </summary>
public class MaterialMapPreview : Control
{
#region Dependency Properties

/// <summary>
/// The image source to display in the preview.
/// </summary>
public static readonly DependencyProperty ImageSourceProperty =
DependencyProperty.Register(
nameof(ImageSource),
typeof(ImageSource),
typeof(MaterialMapPreview),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));

/// <summary>
/// The stretch mode for the image.
/// </summary>
public static readonly DependencyProperty StretchProperty =
DependencyProperty.Register(
nameof(Stretch),
typeof(Stretch),
typeof(MaterialMapPreview),
new FrameworkPropertyMetadata(Stretch.Uniform, FrameworkPropertyMetadataOptions.AffectsRender));

/// <summary>
/// The stretch direction for the image.
/// </summary>
public static readonly DependencyProperty StretchDirectionProperty =
DependencyProperty.Register(
nameof(StretchDirection),
typeof(StretchDirection),
typeof(MaterialMapPreview),
new FrameworkPropertyMetadata(StretchDirection.Both, FrameworkPropertyMetadataOptions.AffectsRender));

#endregion Dependency Properties

#region Properties

/// <summary>
/// Gets or sets the image source to display in the preview.
/// </summary>
public ImageSource? ImageSource
{
get => (ImageSource?)GetValue(ImageSourceProperty);
set => SetValue(ImageSourceProperty, value);
}

/// <summary>
/// Gets or sets the stretch mode for the image.
/// </summary>
public Stretch Stretch
{
get => (Stretch)GetValue(StretchProperty);
set => SetValue(StretchProperty, value);
}

/// <summary>
/// Gets or sets the stretch direction for the image.
/// </summary>
public StretchDirection StretchDirection
{
get => (StretchDirection)GetValue(StretchDirectionProperty);
set => SetValue(StretchDirectionProperty, value);
}

#endregion Properties

#region Constructor

static MaterialMapPreview()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MaterialMapPreview), new FrameworkPropertyMetadata(typeof(MaterialMapPreview)));
}

#endregion Constructor
}
1 change: 1 addition & 0 deletions DarkUI/DarkUI.WPF/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ResourceDictionary Source="Styles/GroupBox.xaml" />
<ResourceDictionary Source="Styles/Label.xaml" />
<ResourceDictionary Source="Styles/ListBox.xaml" />
<ResourceDictionary Source="Styles/MaterialMapPreview.xaml" />
<ResourceDictionary Source="Styles/Menu.xaml" />
<ResourceDictionary Source="Styles/NumericUpDown.xaml" />
<ResourceDictionary Source="Styles/ProgressBar.xaml" />
Expand Down
66 changes: 66 additions & 0 deletions DarkUI/DarkUI.WPF/Styles/MaterialMapPreview.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:DarkUI.WPF.CustomControls"
xmlns:local="clr-namespace:DarkUI.WPF">

<Style TargetType="{x:Type controls:MaterialMapPreview}">
<!-- Control properties -->
<Setter Property="Focusable" Value="False" />

<!-- Layout -->
<Setter Property="Width" Value="40" />
<Setter Property="Height" Value="40" />
<Setter Property="SnapsToDevicePixels" Value="{x:Static local:Defaults.SnapsToDevicePixels}" />
<Setter Property="UseLayoutRounding" Value="{x:Static local:Defaults.UseLayoutRounding}" />

<!-- Brushes -->
<Setter Property="BorderBrush" Value="{DynamicResource Brush_Border}" />

<!-- Thicknesses -->
<Setter Property="BorderThickness" Value="{x:Static local:Defaults.BorderThickness}" />

<!-- Template -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:MaterialMapPreview}">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
UseLayoutRounding="{TemplateBinding UseLayoutRounding}">
<Border.Background>
<DrawingBrush
TileMode="Tile"
Viewport="0,0,8,8"
ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#FFCCCCCC">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,8,8" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="#FFAAAAAA">
<GeometryDrawing.Geometry>
<GeometryGroup>
<RectangleGeometry Rect="0,0,4,4" />
<RectangleGeometry Rect="4,4,4,4" />
</GeometryGroup>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Border.Background>

<Image
Source="{TemplateBinding ImageSource}"
Stretch="{TemplateBinding Stretch}"
StretchDirection="{TemplateBinding StretchDirection}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
19 changes: 13 additions & 6 deletions TombEditor/ToolWindows/TexturePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
using TombEditor.Controls.ContextMenus;
using TombEditor.Forms;
using TombLib.Forms;
using TombLib.Forms.ViewModels;
using TombLib.Forms.Views;
using TombLib.LevelData;
using TombLib.Utils;
using TombLib.WPF;

namespace TombEditor.ToolWindows
{
Expand Down Expand Up @@ -140,7 +143,7 @@ private void UpdateUI()
butAnimationRanges.Enabled =
butMaterialEditor.Enabled = comboCurrentTexture.SelectedItem != null;

butTextureSounds.Enabled = comboCurrentTexture.SelectedItem != null &&
butTextureSounds.Enabled = comboCurrentTexture.SelectedItem != null &&
_editor.Level.Settings.GameVersion.Native() >= TRVersion.Game.TR3;

butBumpMaps.Enabled = comboCurrentTexture.SelectedItem != null &&
Expand Down Expand Up @@ -281,11 +284,15 @@ protected override void OnMouseUp(MouseEventArgs e)
private void butMaterialEditor_Click(object sender, EventArgs e)
{
var list = comboCurrentTexture.Items.Cast<Texture>();
using (var form = new FormMaterialEditor(list, _editor.Configuration, comboCurrentTexture.SelectedItem as Texture))
{
if (form.ShowDialog() == DialogResult.OK && form.MaterialChanged)
_editor.SendMessage("Material settings for selected texture were saved to " + form.MaterialFileName + ".", PopupType.Info);
}

var viewModel = new MaterialEditorWindowViewModel(list.ToList(), comboCurrentTexture.SelectedItem as Texture);

var window = new MaterialEditorWindow { DataContext = viewModel };
window.SetOwner(this);
window.ShowDialog();

if (viewModel.DialogResult == true)
_editor.SendMessage("Material settings for selected texture were saved to " + viewModel.MaterialFileName + ".", PopupType.Info);
}
}
}
Loading