1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace FLY.Weight.UI.Client
{
public class WeighterColorDB
{
class WeighterColor
{
public Brush Self;
public List<Brush> Items = new List<Brush>();
public WeighterColor()
{
}
}
static List<WeighterColor> mWeighters;
static WeighterColorDB()
{
//if (File.Exists("default/weighterColorDb.json"))
//{
// string json = File.ReadAllText("default/weighterColorDb.json");
// try
// {
// mWeighters = Newtonsoft.Json.JsonConvert.DeserializeObject<List<WeighterColor>>(json);
// }
// catch {
// //异常,从本地读取
// }
//}
//if(mWeighters == null || mWeighters.Count()==0)
{
ResourceDictionary r = new ResourceDictionary()
{
Source = new Uri("pack://application:,,,/FLY.Weight.UI.Client;component/Themes/Dictionary_CellColor.xaml")
};
mWeighters = new List<WeighterColor>();
for (int i = 0; i < 7; i++)
{
WeighterColor c = new WeighterColor();
string color_name = $"Color_g{i+1}#0";
c.Self = r[color_name] as Brush;
for (int j = 0; j < 7; j++)
{
int i2 = i + 1 + j;
if (i2 > 7) i2 -= 7;
color_name = $"Color_g{i2}#0";
c.Items.Add(r[color_name] as Brush);
}
mWeighters.Add(c);
}
}
}
public static Brush GetSelf(int index)
{
if(index<0 || index>=mWeighters.Count())
return null;
return mWeighters[index].Self;
}
public static Brush GetItem(int numberIndex, int index)
{
if (numberIndex < 0 || numberIndex >= mWeighters.Count())
return null;
int cnt = mWeighters[numberIndex].Items.Count();
if (index >= cnt || index < 0)
{
Random r = new Random();
index = r.Next(cnt - 1);
}
return mWeighters[numberIndex].Items[index];
}
}
public class Number2ColorValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int index = (int)value;
return WeighterColorDB.GetSelf(index);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class Number2ColorItemValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
int number_index = (int)value;
int index = (int)parameter;
return WeighterColorDB.GetItem(number_index, index);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}