Skip to content

Commit

Permalink
GUI: Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Jan 18, 2021
1 parent 65a05f8 commit 7dbfb5c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 75 deletions.
16 changes: 6 additions & 10 deletions GUI/Controls/TimespanUpDown.cs
Expand Up @@ -25,13 +25,9 @@ namespace MCGalaxy.Gui {
[DefaultBindingProperty("Seconds"), DefaultEvent("ValueChanged"), DefaultProperty("Seconds")]
public class TimespanUpDown : UpDownBase, ISupportInitialize {
long totalSecs;
EventHandler onValueChanged;
bool initializing;
bool initialising;

public event EventHandler ValueChanged {
add { onValueChanged = (EventHandler)Delegate.Combine(onValueChanged, value); }
remove { onValueChanged = (EventHandler)Delegate.Remove(onValueChanged, value); }
}
public event EventHandler ValueChanged;

[Bindable(true)]
public long Seconds {
Expand All @@ -44,7 +40,7 @@ public class TimespanUpDown : UpDownBase, ISupportInitialize {
if (value < 0) value = 0;

totalSecs = value;
if (onValueChanged != null) onValueChanged(this, EventArgs.Empty);
if (ValueChanged != null) ValueChanged(this, EventArgs.Empty);
UpdateEditText();
}
}
Expand All @@ -55,10 +51,10 @@ public class TimespanUpDown : UpDownBase, ISupportInitialize {
}

public TimespanUpDown() { Text = "0s"; }
public void BeginInit() { initializing = true; }
public void BeginInit() { initialising = true; }

public void EndInit() {
initializing = false;
initialising = false;
Seconds = totalSecs;
UpdateEditText();
}
Expand Down Expand Up @@ -105,7 +101,7 @@ public class TimespanUpDown : UpDownBase, ISupportInitialize {
}

protected override void UpdateEditText() {
if (initializing) return;
if (initialising) return;
if (UserEdit) ParseEditText();
Text = TimeSpan.FromSeconds(totalSecs).Shorten(true, true);
}
Expand Down
90 changes: 45 additions & 45 deletions GUI/PropertyWindow/PropertyWindow.Designer.cs

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

24 changes: 12 additions & 12 deletions GUI/PropertyWindow/PropertyWindow.Economy.cs
Expand Up @@ -32,12 +32,12 @@ public partial class PropertyWindow : Form {
Eco_UpdateEnables();

foreach (Item item in Economy.Items) {
eco_cbCfg.Items.Add(item.Name);
eco_cmbCfg.Items.Add(item.Name);
}
eco_cbCfg.Items.Add("(none)");
eco_cbCfg.SelectedIndex = eco_cbCfg.Items.Count - 1;
eco_cmbCfg.Items.Add("(none)");
eco_cmbCfg.SelectedIndex = eco_cmbCfg.Items.Count - 1;

eco_cbItemRank.Items.AddRange(GuiPerms.RankNames);
eco_cmbItemRank.Items.AddRange(GuiPerms.RankNames);
eco_colRankPrice.CellTemplate = new NumericalCell();
eco_dgvRanks.DataError += eco_dgv_DataError;

Expand Down Expand Up @@ -83,7 +83,7 @@ class ThemeCell : DataGridViewComboBoxCell {
eco_lblCurrency.Enabled = eco_cbEnabled.Checked;
eco_txtCurrency.Enabled = eco_cbEnabled.Checked;
eco_lblCfg.Enabled = eco_cbEnabled.Checked;
eco_cbCfg.Enabled = eco_cbEnabled.Checked;
eco_cmbCfg.Enabled = eco_cbEnabled.Checked;

eco_gbItem.Enabled = eco_cbEnabled.Checked;
eco_gbLvl.Enabled = eco_cbEnabled.Checked;
Expand All @@ -94,10 +94,10 @@ class ThemeCell : DataGridViewComboBoxCell {
Eco_UpdateEnables();
}

void Eco_cbCfg_SelectedIndexChanged(object sender, EventArgs e) {
void Eco_cmbCfg_SelectedIndexChanged(object sender, EventArgs e) {
string text = "(none)";
if (eco_cbCfg.SelectedIndex != -1) {
text = eco_cbCfg.SelectedItem.ToString();
if (eco_cmbCfg.SelectedIndex != -1) {
text = eco_cmbCfg.SelectedItem.ToString();
}

eco_gbItem.Visible = false;
Expand Down Expand Up @@ -129,15 +129,15 @@ class ThemeCell : DataGridViewComboBoxCell {
eco_lblItemPrice.Enabled = eco_cbItem.Checked;
eco_numItemPrice.Enabled = eco_cbItem.Checked;
eco_lblItemRank.Enabled = eco_cbItem.Checked;
eco_cbItemRank.Enabled = eco_cbItem.Checked;
eco_cmbItemRank.Enabled = eco_cbItem.Checked;
}

void Eco_UpdateItem() {
eco_gbItem.Text = eco_curItem.Name;
eco_numItemPrice.Value = eco_curItem.Price;
Eco_UpdateItemEnables();

GuiPerms.SetDefaultIndex(eco_cbItemRank, eco_curItem.PurchaseRank);
GuiPerms.SetDefaultIndex(eco_cmbItemRank, eco_curItem.PurchaseRank);
}

void eco_cbItem_CheckedChanged(object sender, EventArgs e) {
Expand All @@ -149,9 +149,9 @@ class ThemeCell : DataGridViewComboBoxCell {
eco_curItem.Price = (int)eco_numItemPrice.Value;
}

void eco_cbItemRank_SelectedIndexChanged(object sender, EventArgs e) {
void eco_cmbItemRank_SelectedIndexChanged(object sender, EventArgs e) {
const LevelPermission perm = LevelPermission.Guest;
eco_curItem.PurchaseRank = GuiPerms.GetPermission(eco_cbItemRank, perm);
eco_curItem.PurchaseRank = GuiPerms.GetPermission(eco_cmbItemRank, perm);
}


Expand Down
16 changes: 8 additions & 8 deletions GUI/PropertyWindow/PropertyWindow.IRCSql.cs
Expand Up @@ -35,10 +35,10 @@ public partial class PropertyWindow : Form {
irc_cbAFK.Checked = Server.Config.IRCShowAFK;
ToggleIrcSettings(Server.Config.UseIRC);

irc_cbRank.Items.AddRange(GuiPerms.RankNames);
GuiPerms.SetDefaultIndex(irc_cbRank, Server.Config.IRCControllerRank);
irc_cbVerify.Items.AddRange(Enum.GetNames(typeof(IRCControllerVerify)));
irc_cbVerify.SelectedIndex = (int)Server.Config.IRCVerify;
irc_cmbRank.Items.AddRange(GuiPerms.RankNames);
GuiPerms.SetDefaultIndex(irc_cmbRank, Server.Config.IRCControllerRank);
irc_cmbVerify.Items.AddRange(Enum.GetNames(typeof(IRCControllerVerify)));
irc_cmbVerify.SelectedIndex = (int)Server.Config.IRCVerify;
irc_txtPrefix.Text = Server.Config.IRCCommandPrefix;

sql_chkUseSQL.Checked = Server.Config.UseMySQL;
Expand All @@ -64,8 +64,8 @@ public partial class PropertyWindow : Form {
Server.Config.IRCShowWorldChanges = irc_cbWorldChanges.Checked;
Server.Config.IRCShowAFK = irc_cbAFK.Checked;

Server.Config.IRCControllerRank = GuiPerms.GetPermission(irc_cbRank, LevelPermission.Nobody);
Server.Config.IRCVerify = (IRCControllerVerify)irc_cbVerify.SelectedIndex;
Server.Config.IRCControllerRank = GuiPerms.GetPermission(irc_cmbRank, LevelPermission.Nobody);
Server.Config.IRCVerify = (IRCControllerVerify)irc_cmbVerify.SelectedIndex;
Server.Config.IRCCommandPrefix = irc_txtPrefix.Text;

Server.Config.UseMySQL = sql_chkUseSQL.Checked;
Expand All @@ -92,8 +92,8 @@ public partial class PropertyWindow : Form {
irc_cbTitles.Enabled = enabled;
irc_cbWorldChanges.Enabled = enabled;
irc_cbAFK.Enabled = enabled;
irc_lblRank.Enabled = enabled; irc_cbRank.Enabled = enabled;
irc_lblVerify.Enabled = enabled; irc_cbVerify.Enabled = enabled;
irc_lblRank.Enabled = enabled; irc_cmbRank.Enabled = enabled;
irc_lblVerify.Enabled = enabled; irc_cmbVerify.Enabled = enabled;
irc_lblPrefix.Enabled = enabled; irc_txtPrefix.Enabled = enabled;
}

Expand Down

0 comments on commit 7dbfb5c

Please sign in to comment.