forked from AloneFancy/AOE-4-Team-Overlay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
208 lines (184 loc) · 8.32 KB
/
Form1.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using WindowsFormsApp6.Properties;
//using MongoDB.Driver;
namespace WindowsFormsApp6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
static string get_request(string url)
{
string html = string.Empty;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
/*if (request.ContentLength < 30)
return null;*/
request.AutomaticDecompression = DecompressionMethods.GZip;
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
}
}catch (WebException ex)
{
return String.Empty;
}
return html;
}
class players{
private string name;
private int civ,elo;
public players(string name,int civ,int elo)
{
this.civ = civ;
this.name = name;
this.elo = elo;
}
public string Name
{
get { return name; }
set { name = value; }
}
public int Civ
{
get { return civ; }
set { civ = value; }
}
public int Elo
{
get { return elo; }
set { elo = value; }
}
}
Bitmap getCivFlag(int civ)
{
switch (civ)
{
case 0: return Resources.Abbasid_Dynasty;
case 1: return Resources.Chinese;
case 2: return Resources.Delhi_Sultanate;
case 3: return Resources.English;
case 4: return Resources.French;
case 5: return Resources.Holy_Roman;
case 6: return Resources.Mongols;
case 7: return Resources.Rus;
default:break;
}
return Resources.Chinese;
}
private void button1_Click(object sender, EventArgs e)
{
String url = "https://aoeiv.net/api/player/matches?game=aoe4" + "&profile_id=" + textBox1.Text + "&count=1";
Console.WriteLine(url);
String url_guide = "https://aoeiv.net/api/strings?game=aoe4&language=en";
dynamic guide = JObject.Parse(get_request(url_guide));
dynamic data;
try
{
data = JArray.Parse(get_request(url));
}
catch (Exception ex)
{
return;
}
if (data.Count == 0 || data == null)
return;
var guide_map = guide["map_type"];
String query = "$.[?(@.id==" + data[0]["map_type"] + ")]";
var maps = guide_map.SelectToken(query);
String result = "Map: " + maps["string"] + "\n";
String test = data[0]["num_players"];
int team_players = Int32.Parse(test);
List<players> team1 = new List<players>();
List<players> team2 = new List<players>();
for (int i = 0; i < team_players; i++)
{
String temp = data[0]["players"][i]["civ"];
int civ = Int32.Parse(temp);
String eloz = data[0]["players"][i]["rating"];
int elo = Int32.Parse(eloz);
String name = data[0]["players"][i]["name"];
players temp1 = new players(name, civ, elo);
if (data[0]["players"][i]["team"] == 1)
team1.Add(temp1);
else
team2.Add(temp1);
}
//MessageBox.Show(result);
Point tablePosition = new Point();
tablePosition.X = textBox2.Location.X;
tablePosition.Y = 100;
createTableLayoutPanel(tablePosition, team1, team2);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void createTableLayoutPanel(Point XY,List<players>team1,List<players>team2)
{
TableLayoutPanel panel = new TableLayoutPanel();
panel.BackgroundImage = Resources.scoreboard;
panel.CellBorderStyle = TableLayoutPanelCellBorderStyle.InsetDouble;
panel.Location = new System.Drawing.Point(XY.X,XY.Y);
int resize_height = 25 * (team1.Count) + 65;
panel.Size = new System.Drawing.Size(600, resize_height);
Controls.Add(panel);
panel.ColumnCount = 6;
panel.RowCount = 1;
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 2F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1.5F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 5F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 1.5F));
panel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 2F));
panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "ELO", BackColor = System.Drawing.Color.Transparent }, 0, 0);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "CIV", BackColor = System.Drawing.Color.Transparent }, 1, 0);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "Team 1", BackColor = System.Drawing.Color.Transparent }, 2, 0);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "Team 2", BackColor = System.Drawing.Color.Transparent }, 3, 0);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "CIV", BackColor = System.Drawing.Color.Transparent }, 4, 0);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = "ELO", BackColor = System.Drawing.Color.Transparent }, 5, 0);
for (int i = 0; i < team1.Count; i++)
{
panel.RowCount = panel.RowCount + 1;
panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F));
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = team1[i].Elo.ToString(), BackColor = System.Drawing.Color.Transparent}, 0, panel.RowCount - 1);
panel.Controls.Add(new PictureBox() { Image = getCivFlag(team1[i].Civ), SizeMode = PictureBoxSizeMode.StretchImage}, 1, panel.RowCount - 1);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = team1[i].Name, BackColor = System.Drawing.Color.Transparent }, 2, panel.RowCount - 1);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = team2[i].Name, BackColor = System.Drawing.Color.Transparent },3, panel.RowCount - 1);
panel.Controls.Add(new PictureBox() { Image = getCivFlag(team2[i].Civ), SizeMode = PictureBoxSizeMode.StretchImage }, 4, panel.RowCount - 1);
panel.Controls.Add(new Label() { ForeColor=Color.White, Text = team2[i].Elo.ToString(), BackColor = System.Drawing.Color.Transparent }, 5, panel.RowCount - 1);
}
}
private void tableLayoutPanel1_Paint_1(object sender, PaintEventArgs e)
{
}
}
}