152 lines
5.4 KiB
C#
152 lines
5.4 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
using GameLauncher.Models;
|
|
using GameLauncher.Engines.Tkool;
|
|
using GameLauncher.Engines.Unity;
|
|
|
|
namespace GameLauncher.Helpers
|
|
{
|
|
/// <summary>
|
|
/// 値が null の場合に Visible、非 null の場合に Collapsed を返すコンバーター
|
|
/// </summary>
|
|
public class NullToVisibleConverter : IValueConverter
|
|
{
|
|
public static readonly NullToVisibleConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value == null ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 値が null の場合に Collapsed、非 null の場合に Visible を返すコンバーター
|
|
/// </summary>
|
|
public class NullToCollapsedConverter : IValueConverter
|
|
{
|
|
public static readonly NullToCollapsedConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value != null ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// UnityGameItem から "CompanyName / ProductName" の表示文字列を生成するコンバーター
|
|
/// </summary>
|
|
public class CompanyProductConverter : IValueConverter
|
|
{
|
|
public static readonly CompanyProductConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is UnityGameItem game)
|
|
{
|
|
if (!string.IsNullOrEmpty(game.CompanyName) && !string.IsNullOrEmpty(game.ProductName))
|
|
{
|
|
return $"{game.CompanyName} / {game.ProductName}";
|
|
}
|
|
if (!string.IsNullOrEmpty(game.ProductName))
|
|
{
|
|
return game.ProductName;
|
|
}
|
|
}
|
|
return "(app.info なし)";
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// アイテムが TkoolGameItem の場合に Visible を返すコンバーター
|
|
/// </summary>
|
|
public class IsTkoolToVisibilityConverter : IValueConverter
|
|
{
|
|
public static readonly IsTkoolToVisibilityConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value is TkoolGameItem ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// アイテムが UnityGameItem の場合に Visible を返すコンバーター
|
|
/// </summary>
|
|
public class IsUnityToVisibilityConverter : IValueConverter
|
|
{
|
|
public static readonly IsUnityToVisibilityConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value is UnityGameItem ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 文字列が null または空文字(空白のみ含む)の場合に Collapsed、文字が存在する場合に Visible を返すコンバーター
|
|
/// </summary>
|
|
public class StringNotEmptyToVisibilityConverter : IValueConverter
|
|
{
|
|
public static readonly StringNotEmptyToVisibilityConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is string s && !string.IsNullOrWhiteSpace(s))
|
|
{
|
|
return Visibility.Visible;
|
|
}
|
|
return Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// bool値が true の場合に Visible、false または null の場合に Collapsed を返すコンバーター
|
|
/// </summary>
|
|
public class BooleanToVisibilityConverter : IValueConverter
|
|
{
|
|
public static readonly BooleanToVisibilityConverter Instance = new();
|
|
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value is true ? Visibility.Visible : Visibility.Collapsed;
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
return value is Visibility v && v == Visibility.Visible;
|
|
}
|
|
}
|
|
}
|