mirror of
https://github.com/tribufu/ServerManagers
synced 2026-05-06 15:17:34 +00:00
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace ServerManagerTool.Lib.ViewModel
|
|
{
|
|
public class PrimalItemClassNameToDisplayNameConverter : IValueConverter
|
|
{
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return Convert(value);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public static object Convert(object value)
|
|
{
|
|
try
|
|
{
|
|
var strVal = value as string;
|
|
var name = GameData.FriendlyNameForClass(strVal);
|
|
if (!string.IsNullOrWhiteSpace(name) && !name.Equals(strVal))
|
|
return name;
|
|
|
|
var firstIndex = strVal.IndexOf('_');
|
|
var lastIndex = strVal.LastIndexOf('_');
|
|
return strVal.Substring(firstIndex + 1, lastIndex - firstIndex - 1).Replace('_', ' ');
|
|
}
|
|
catch
|
|
{
|
|
return value;
|
|
}
|
|
}
|
|
}
|
|
}
|