-
Notifications
You must be signed in to change notification settings - Fork 2
/
TopCommodities.cs
151 lines (137 loc) · 4.34 KB
/
TopCommodities.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
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Rails
{
/// <summary>
/// Summary description for TopCommodities.
/// </summary>
[System.Runtime.InteropServices.ComVisible(false)]
public class TopCommodities : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private Game game;
private Map map;
private double[] score;
private System.Windows.Forms.VScrollBar vScrollBar1;
private int[] index;
int dy = 56;
public TopCommodities(Form owner, Game game, Map map)
{
this.game = game;
this.map = map;
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.Owner = owner;
int n = Products.Count;
score = map.AveragePayoff;
index = new int[n];
for (int i=0; i<n; i++)
{
index[i] = i;
}
Array.Sort(score, index);
vScrollBar1.Maximum = dy * Products.Count - 1;
vScrollBar1.LargeChange = this.ClientRectangle.Height;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TopCommodities));
this.vScrollBar1 = new System.Windows.Forms.VScrollBar();
this.SuspendLayout();
//
// vScrollBar1
//
this.vScrollBar1.Dock = System.Windows.Forms.DockStyle.Right;
this.vScrollBar1.Location = new System.Drawing.Point(183, 0);
this.vScrollBar1.Maximum = 28;
this.vScrollBar1.Name = "vScrollBar1";
this.vScrollBar1.Size = new System.Drawing.Size(17, 448);
this.vScrollBar1.SmallChange = 10;
this.vScrollBar1.TabIndex = 0;
this.vScrollBar1.Resize += new System.EventHandler(this.vScrollBar1_Resize);
this.vScrollBar1.ValueChanged += new System.EventHandler(this.vScrollBar1_ValueChanged);
//
// TopCommodities
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.Black;
this.ClientSize = new System.Drawing.Size(200, 448);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.vScrollBar1});
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(208, 2000);
this.MinimumSize = new System.Drawing.Size(208, 0);
this.Name = "TopCommodities";
this.Text = "Average Payoffs";
this.Paint += new System.Windows.Forms.PaintEventHandler(this.TopCommodities_Paint);
this.ResumeLayout(false);
}
#endregion
protected override void OnPaintBackground(PaintEventArgs e)
{
}
private void TopCommodities_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Bitmap bmp = new Bitmap(this.ClientRectangle.Width, this.ClientRectangle.Height);
Graphics g = Graphics.FromImage(bmp);
g.FillRectangle(Brushes.Black, 0, 0, bmp.Width, bmp.Height);
int x0 = 8;
int y0 = 0;
Font font = new Font("Tahoma", 10);
for (int i=0; i<Products.Count; i++)
{
int y = y0 + i * dy - vScrollBar1.Value;
int j = Products.Count - 1 - i;
if (j >= 0)
{
int p = index[j];
g.DrawImageUnscaled(Products.Icon[p], x0 + 8, y + 4);
g.DrawString(Products.Name[p], font, Brushes.White, x0 + 64, y + 8);
g.DrawString(Utility.CurrencyString(score[j]), font, Brushes.White, x0 + 64, y + 24);
}
}
font.Dispose();
g.Dispose();
e.Graphics.DrawImageUnscaled(bmp, 0, 0);
bmp.Dispose();
}
private void vScrollBar1_Resize(object sender, System.EventArgs e)
{
vScrollBar1.LargeChange = this.ClientRectangle.Height;
}
private void vScrollBar1_ValueChanged(object sender, System.EventArgs e)
{
this.Invalidate();
}
}
}