Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
qubqub committed Nov 12, 2023
1 parent cc447a5 commit 9e97173
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 75 deletions.
57 changes: 43 additions & 14 deletions Controls/ImageComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using MetroFramework;

namespace FallGuysStats {
public class ImageComboBox : ComboBox {
public sealed class ImageComboBox : ComboBox {
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
Expand All @@ -25,34 +25,59 @@ public MetroThemeStyle Theme {
_theme = value;
SetBlur();
Invalidate();
Update();
}
}
}

private string _name = String.Empty;
public string SelectedName {
get { return _name; }
set {
if (_name != value) {
_name = value;
}
}
}

private Image _image;
public Image SelectedImage {
get { return _image; }
set {
if (_image != value) {
_image = value;
}
}
}

private Color _borderColor = Color.Gray;
public Color BorderColor {
private Color BorderColor {
get { return _borderColor; }
set {
if (_borderColor != value) {
_borderColor = value;
Invalidate();
Update();
}
}
}
public string ImageName { get; set; }
private Color buttonColor = Color.DarkGray;
public Color ButtonColor

private Color _buttonColor = Color.DarkGray;
private Color ButtonColor
{
get { return buttonColor; }
get { return _buttonColor; }
set {
if (buttonColor != value) {
buttonColor = value;
if (_buttonColor != value) {
_buttonColor = value;
Invalidate();
Update();
}
}
}

protected override void WndProc(ref Message m) {
if (m.Msg == WM_PAINT && DropDownStyle != ComboBoxStyle.Simple) {
// if (m.Msg == WM_PAINT && DropDownStyle != ComboBoxStyle.Simple) {
if (m.Msg == WM_PAINT) {
Rectangle clientRect = ClientRectangle;
int dropDownButtonWidth = SystemInformation.HorizontalScrollBarArrowWidth;
Rectangle outerBorder = new Rectangle(clientRect.Location, new Size(clientRect.Width - 1, clientRect.Height - 1));
Expand Down Expand Up @@ -118,10 +143,12 @@ protected override void WndProc(ref Message m) {
}

private const int WM_PAINT = 0xF;

[StructLayout(LayoutKind.Sequential)]
public struct RECT {
public int L, T, R, B;
}

[StructLayout(LayoutKind.Sequential)]
public struct PAINTSTRUCT {
public IntPtr hdc;
Expand Down Expand Up @@ -212,6 +239,8 @@ public void SetImageItemData(List<ImageItem> imageItemArray) {
this.GotFocus += ImageItemComboBox_GotFocus;
this.LostFocus += ImageItemComboBox_LostFocus;

this.SelectedIndexChanged += ImageItemComboBox_SelectedIndexChanged;

SetBlur();
}
#endregion
Expand All @@ -233,7 +262,6 @@ private void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e) {
);

ComboBox comboBox = sender as ComboBox;
this.ImageName = comboBox.SelectedText;
Color color = (Color)comboBox.Items[e.Index];

using(SolidBrush brush = new SolidBrush(color)) {
Expand Down Expand Up @@ -264,7 +292,6 @@ private void ImageComboBox_MeasureItem(object sender, MeasureItemEventArgs e) {
if (e.Index < 0) { return; }

ComboBox comboBox = sender as ComboBox;
this.ImageName = comboBox.SelectedText;
Image image = (Image)comboBox.Items[e.Index];

e.ItemHeight = image.Height + 2 * IMAGE_ITEM_MARGIN_HEIGHT;
Expand All @@ -278,7 +305,6 @@ private void ImageComboBox_DrawItem(object sender, DrawItemEventArgs e) {

e.DrawBackground();
ComboBox comboBox = sender as ComboBox;
this.ImageName = comboBox.SelectedText;
Image image = (Image)comboBox.Items[e.Index];

float height = e.Bounds.Height - 2 * IMAGE_ITEM_MARGIN_HEIGHT;
Expand Down Expand Up @@ -306,7 +332,6 @@ private void ImageItemComboBox_MeasureItem(object sender, MeasureItemEventArgs e

ComboBox comboBox = sender as ComboBox;
ImageItem item = (ImageItem)comboBox.Items[e.Index];
this.ImageName = item.Text;
item.MeasureItem(e);
}
#endregion
Expand All @@ -317,7 +342,6 @@ private void ImageItemComboBox_DrawItem(object sender, DrawItemEventArgs e) {

ComboBox comboBox = sender as ComboBox;
ImageItem item = (ImageItem)comboBox.Items[e.Index];
this.ImageName = item.Text;
item.DrawItem(e, this.ForeColor, this.Theme == MetroThemeStyle.Light ? Color.White : Color.FromArgb(17, 17, 17));
}

Expand All @@ -336,6 +360,11 @@ private void ImageItemComboBox_GotFocus(object sender, EventArgs e) {
private void ImageItemComboBox_LostFocus(object sender, EventArgs e) {
this.SetBlur();
}

private void ImageItemComboBox_SelectedIndexChanged(object sender, EventArgs e) {
this.SelectedName = ((ImageItem)((ImageComboBox)sender).SelectedItem).Text;
this.SelectedImage = ((ImageItem)((ImageComboBox)sender).SelectedItem).Image;
}

private void SetFocus() {
this.ForeColor = this.Theme == MetroThemeStyle.Light ? Color.Black : Color.FromArgb(204, 204, 204);
Expand Down
6 changes: 3 additions & 3 deletions Entities/ImageItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace FallGuysStats {
public class ImageItem {
#region Public Field
public Image Image { get; set; }
public string[] DataArray { get; set; }
public string[] Data { get; set; }
public string Text { get; set; }
public Font Font { get; set; }
public bool IsCustomized { get; set; }
Expand All @@ -20,13 +20,13 @@ public class ImageItem {
private const int MARGIN_HEIGHT = 2;
private int width;
private int height;
private bool sizeCalculated = false;
private bool sizeCalculated;
#endregion

#region Public Constructor - ImageItem(image, text, font)
public ImageItem(Image image, string text, Font font, string[] dataArray = null, bool isCustomized = false) {
this.Image = image;
this.DataArray = dataArray;
this.Data = dataArray;
this.Text = text;
this.Font = font;
this.IsCustomized = isCustomized;
Expand Down
25 changes: 15 additions & 10 deletions Views/LeaderboardDisplay.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions Views/LeaderboardDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private void LeaderboardDisplay_Resize(object sender, EventArgs e) {

private void SetTheme(MetroThemeStyle theme) {
this.SuspendLayout();
this.cboRoundList.Theme = theme;
this.lblTotalPlayers.Theme = theme;
this.lblTotalPlayers.Location = new Point(this.cboRoundList.Right + 15, this.cboRoundList.Location.Y);
this.lblSearchDescription.Theme = theme;
Expand All @@ -54,12 +55,12 @@ private void SetTheme(MetroThemeStyle theme) {
this.mpsSpinner.BackColor = theme == MetroThemeStyle.Light ? Color.White : Color.FromArgb(17, 17, 17);
// this.mpsSpinner.Location = new Point(this.cboRoundList.Right + 15, this.cboRoundList.Location.Y);
this.mpsSpinner.Location = new Point((this.ClientSize.Width - this.mpsSpinner.Width) / 2, (this.ClientSize.Height - this.mpsSpinner.Height) / 2 + 20);
this.cboRoundList.Theme = theme;

this.gridDetails.Theme = theme;
this.gridDetails.BackgroundColor = theme == MetroThemeStyle.Light ? Color.White : Color.FromArgb(17, 17, 17);
this.gridDetails.ColumnHeadersDefaultCellStyle = this.dataGridViewCellStyle1;
this.gridDetails.DefaultCellStyle = this.dataGridViewCellStyle2;
this.gridDetails.RowTemplate.Height = 32;

this.dataGridViewCellStyle1.Font = Overlay.GetMainFont(12);
this.dataGridViewCellStyle1.Alignment = DataGridViewContentAlignment.MiddleLeft;
Expand All @@ -79,7 +80,8 @@ private void SetTheme(MetroThemeStyle theme) {

this.gridDetails.SetContextMenuTheme();

this.mlVisitFallalytics.Theme = theme;
// this.mlVisitFallalytics.Theme = theme;
this.mlVisitFallalytics.BackColor = theme == MetroThemeStyle.Light ? Color.White : Color.FromArgb(17, 17, 17);
this.mlVisitFallalytics.Text = $@" {Multilingual.GetWord("leaderboard_see_full_rankings_in_fallalytics")}";
switch (Stats.CurrentLanguage) {
case Language.English:
Expand All @@ -104,26 +106,30 @@ private void SetTheme(MetroThemeStyle theme) {

this.Theme = theme;
this.ResumeLayout();
this.Refresh();
}

private void cboRoundList_SelectedIndexChanged(object sender, EventArgs e) {
if ((ImageItem)((ImageComboBox)sender).SelectedItem == null || ((ImageItem)((ImageComboBox)sender).SelectedItem).DataArray[0].Equals(this.key)) { return; }
this.key = ((ImageItem)((ImageComboBox)sender).SelectedItem).DataArray[0];
if ((ImageItem)((ImageComboBox)sender).SelectedItem == null || ((ImageItem)((ImageComboBox)sender).SelectedItem).Data[0].Equals(this.key)) { return; }
this.key = ((ImageItem)((ImageComboBox)sender).SelectedItem).Data[0];
this.cboRoundList.Enabled = false;
this.lblTotalPlayers.Visible = false;
this.lblTotalPlayers.Text = "";
this.lblSearchDescription.Visible = false;
this.mpsSpinner.Visible = true;
this.gridDetails.DataSource = null;
this.gridDetails.DataSource = this.nodata;
Task.Run(() => this.DataLoad(this.key)).ContinueWith(prevTask => {
this.BeginInvoke((MethodInvoker)delegate {
if (prevTask.Result) {
this.Text = $@" {Multilingual.GetWord("leaderboard_menu_title")} - {((ImageItem)((ImageComboBox)sender).SelectedItem).Text}";
this.Text = $@" {Multilingual.GetWord("leaderboard_menu_title")} - {((ImageComboBox)sender).SelectedName}";
this.mpsSpinner.Visible = false;
this.gridDetails.DataSource = this.recordholders;
// this.lblTotalPlayers.Location = new Point(this.cboRoundList.Right + 15, this.cboRoundList.Location.Y);
this.lblTotalPlayers.Text = $"{Multilingual.GetWord("leaderboard_total_players_prefix")}{this.totalPlayers}{Multilingual.GetWord("leaderboard_total_players_suffix")}";
this.lblTotalPlayers.Visible = true;
// this.mlVisitFallalytics.Image = ((ImageComboBox)sender).SelectedImage;
this.mlVisitFallalytics.Visible = true;
this.cboRoundList.Enabled = true;
this.Refresh();
} else {
this.Text = $@" {Multilingual.GetWord("leaderboard_menu_title")}";
Expand Down Expand Up @@ -159,10 +165,10 @@ private void SetRoundList() {
roundItemList.Sort((x, y) => String.CompareOrdinal(x.Text, y.Text));
this.cboRoundList.SetImageItemData(roundItemList);
this.cboRoundList.Enabled = true;
this.cboRoundList.Invalidate();
this.cboRoundList.Refresh();
} else {
this.mpsSpinner.Visible = false;
this.cboRoundList.Invalidate();
this.cboRoundList.Refresh();
}
});
});
Expand Down
Loading

0 comments on commit 9e97173

Please sign in to comment.