/
TopTableSamplePlugin.cs_
184 lines (166 loc) · 8.05 KB
/
TopTableSamplePlugin.cs_
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
namespace Turbo.Plugins.Jack.Labs
{
using System;
using Turbo.Plugins.Default;
using Turbo.Plugins.Jack.Decorators.TopTables;
public class TopTableSamplePlugin : BasePlugin, IInGameTopPainter, IAfterCollectHandler
{
public TopTable Table { get; set; }
// only used for the demo purpose
private Random rng;
private long lastTick;
private int lastLineIndex = -1;
private int lastColumnIndex;
public TopTableSamplePlugin()
{
Enabled = true;
Order = int.MaxValue;
}
public override void Load(IController hud)
{
base.Load(hud);
// only used for the demo purpose
rng = new Random(Hud.Game.CurrentGameTick);
// create the table with options
Table = new TopTable(Hud)
{
RatioPositionX = 0.2f,
RatioPositionY = 0.3f,
HorizontalCenter = true,
VerticalCenter = false,
PositionFromRight = false,
PositionFromBottom = false,
ShowHeaderLeft = true,
ShowHeaderTop = true,
ShowHeaderRight = true,
ShowHeaderBottom = true,
DefaultCellDecorator = new TopTableCellDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 0, 0),
BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
},
DefaultHighlightDecorator = new TopTableCellDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, 0, 0, 242, 0),
BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
},
DefaultHeaderDecorator = new TopTableCellDecorator(Hud)
{
//BackgroundBrush = Hud.Render.CreateBrush(0, 0, 0, 0, 0),
//BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, 1),
TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, false, false, true),
}
};
// define columns.. talk about useful comments ;p
Table.DefineColumns(
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioHeight = 22 / 1080f, // define only once on first column, value on others will be ignored
RatioWidth = 108 / 1080f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
},
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioWidth = 0.1f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
},
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioWidth = 0.1f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
},
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioWidth = 0.1f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
},
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioWidth = 0.1f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
},
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Col"))
{
RatioWidth = 0.1f,
HighlightFunc = (pos, curPos) => lastColumnIndex == pos,
TextAlign = RandomHorizontalAlign(),
}
);
// add lines
for (var i = 0; i < 10; i++)
{
var r = rng.Next(0, 255);
var g = rng.Next(0, 255);
var b = rng.Next(0, 255);
var align = RandomHorizontalAlign();
Table.AddLine(
new TopTableHeader(Hud, (pos, curPos) => GetHeaderText(pos, curPos, "Line"))
{
RatioWidth = 62 / 1080f, // define only once on first line, value on other will be ignored
RatioHeight = 22 / 1080f,
HighlightFunc = (pos, curPos) => lastLineIndex == pos,
TextAlign = align,
HighlightDecorator = new TopTableCellDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, r, g, b, 0),
BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
},
CellHighlightDecorator = new TopTableCellDecorator(Hud)
{
BackgroundBrush = Hud.Render.CreateBrush(255, r, g, b, 0),
BorderBrush = Hud.Render.CreateBrush(255, 255, 255, 255, -1),
TextFont = Hud.Render.CreateFont("tahoma", 8, 255, 255, 255, 255, true, false, true),
},
},
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align },
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align },
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align },
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align },
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align },
new TopTableCell(Hud, (line, column, lineSorted, columnSorted) => GetCellText(line, column)) { TextAlign = align }
);
}
}
private HorizontalAlign RandomHorizontalAlign()
{
var alignRng = rng.Next(0, 31);
if (alignRng < 10)
{
return Default.HorizontalAlign.Left;
}
return alignRng < 20 ? Default.HorizontalAlign.Center : Default.HorizontalAlign.Right;
}
// well..
public void PaintTopInGame(ClipState clipState)
{
if (clipState != ClipState.BeforeClip) return;
Table.Paint();
}
// dumb method to demonstrate the usage
public string GetHeaderText(int pos, int curPos, string text)
{
return string.Format("{0} {1}", text, pos);
}
// dumb method to demonstrate the usage
public string GetCellText(int line, int column)
{
return string.Format("Line {0} / Col {1}", line, column);
}
// only used for the demo purpose
public void AfterCollect()
{
if (lastTick + 500 > Hud.Game.CurrentRealTimeMilliseconds && Hud.Game.CurrentRealTimeMilliseconds > lastTick) return;
lastTick = Hud.Game.CurrentRealTimeMilliseconds;
lastLineIndex = (lastLineIndex + 1) % Table.Lines.Count;
lastColumnIndex = (lastColumnIndex + 1) % Table.Columns.Count;
}
}
}