Calculator finished
This commit is contained in:
parent
e26453ebee
commit
9aa549e2b9
3 changed files with 192 additions and 32 deletions
55
ShiftOS.WinForms/Applications/Calculator.Designer.cs
generated
55
ShiftOS.WinForms/Applications/Calculator.Designer.cs
generated
|
@ -67,6 +67,10 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.buttonPlus = new System.Windows.Forms.Button();
|
||||
this.buttonMinus = new System.Windows.Forms.Button();
|
||||
this.buttonMultiply = new System.Windows.Forms.Button();
|
||||
this.buttonDivide = new System.Windows.Forms.Button();
|
||||
this.buttonC = new System.Windows.Forms.Button();
|
||||
this.buttonCE = new System.Windows.Forms.Button();
|
||||
this.buttonDecimal = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// numBox
|
||||
|
@ -208,6 +212,7 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.buttonMinus.TabIndex = 14;
|
||||
this.buttonMinus.Text = "-";
|
||||
this.buttonMinus.UseVisualStyleBackColor = true;
|
||||
this.buttonMinus.Click += new System.EventHandler(this.buttonMinus_Click);
|
||||
//
|
||||
// buttonMultiply
|
||||
//
|
||||
|
@ -217,11 +222,57 @@ namespace ShiftOS.WinForms.Applications
|
|||
this.buttonMultiply.TabIndex = 15;
|
||||
this.buttonMultiply.Text = "x";
|
||||
this.buttonMultiply.UseVisualStyleBackColor = true;
|
||||
this.buttonMultiply.Click += new System.EventHandler(this.buttonMultiply_Click);
|
||||
//
|
||||
// buttonDivide
|
||||
//
|
||||
this.buttonDivide.Location = new System.Drawing.Point(125, 123);
|
||||
this.buttonDivide.Name = "buttonDivide";
|
||||
this.buttonDivide.Size = new System.Drawing.Size(22, 22);
|
||||
this.buttonDivide.TabIndex = 16;
|
||||
this.buttonDivide.Text = "/";
|
||||
this.buttonDivide.UseVisualStyleBackColor = true;
|
||||
this.buttonDivide.Click += new System.EventHandler(this.buttonDivide_Click);
|
||||
//
|
||||
// buttonC
|
||||
//
|
||||
this.buttonC.Location = new System.Drawing.Point(88, 39);
|
||||
this.buttonC.Name = "buttonC";
|
||||
this.buttonC.Size = new System.Drawing.Size(31, 22);
|
||||
this.buttonC.TabIndex = 17;
|
||||
this.buttonC.Text = "C";
|
||||
this.buttonC.UseVisualStyleBackColor = true;
|
||||
this.buttonC.Click += new System.EventHandler(this.buttonC_Click);
|
||||
//
|
||||
// buttonCE
|
||||
//
|
||||
this.buttonCE.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.buttonCE.Location = new System.Drawing.Point(88, 67);
|
||||
this.buttonCE.Name = "buttonCE";
|
||||
this.buttonCE.Size = new System.Drawing.Size(31, 22);
|
||||
this.buttonCE.TabIndex = 18;
|
||||
this.buttonCE.Text = "CE";
|
||||
this.buttonCE.UseVisualStyleBackColor = true;
|
||||
this.buttonCE.Click += new System.EventHandler(this.buttonCE_Click);
|
||||
//
|
||||
// buttonDecimal
|
||||
//
|
||||
this.buttonDecimal.Location = new System.Drawing.Point(32, 123);
|
||||
this.buttonDecimal.Name = "buttonDecimal";
|
||||
this.buttonDecimal.Size = new System.Drawing.Size(22, 22);
|
||||
this.buttonDecimal.TabIndex = 19;
|
||||
this.buttonDecimal.Text = ".";
|
||||
this.buttonDecimal.UseVisualStyleBackColor = true;
|
||||
this.buttonDecimal.Click += new System.EventHandler(this.buttonDecimal_Click);
|
||||
//
|
||||
// Calculator
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.buttonDecimal);
|
||||
this.Controls.Add(this.buttonCE);
|
||||
this.Controls.Add(this.buttonC);
|
||||
this.Controls.Add(this.buttonDivide);
|
||||
this.Controls.Add(this.buttonMultiply);
|
||||
this.Controls.Add(this.buttonMinus);
|
||||
this.Controls.Add(this.buttonPlus);
|
||||
|
@ -261,5 +312,9 @@ namespace ShiftOS.WinForms.Applications
|
|||
private System.Windows.Forms.Button buttonPlus;
|
||||
private System.Windows.Forms.Button buttonMinus;
|
||||
private System.Windows.Forms.Button buttonMultiply;
|
||||
private System.Windows.Forms.Button buttonDivide;
|
||||
private System.Windows.Forms.Button buttonC;
|
||||
private System.Windows.Forms.Button buttonCE;
|
||||
private System.Windows.Forms.Button buttonDecimal;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ namespace ShiftOS.WinForms.Applications
|
|||
private int activeoperation = 0;
|
||||
private float operationnumber = 0;
|
||||
private float currentnumber = 0;
|
||||
private bool multiop = false;
|
||||
|
||||
public Calculator()
|
||||
{
|
||||
|
@ -57,6 +58,10 @@ namespace ShiftOS.WinForms.Applications
|
|||
buttonPlus.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_plus_button");
|
||||
buttonMinus.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_minus_button");
|
||||
buttonMultiply.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_multiply_button");
|
||||
buttonDivide.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_divide_button");
|
||||
buttonC.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_clear_button");
|
||||
buttonCE.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_ce_button");
|
||||
buttonDecimal.Visible = ShiftoriumFrontend.UpgradeInstalled("calc_decimal_button");
|
||||
}
|
||||
|
||||
public void OnLoad()
|
||||
|
@ -81,57 +86,73 @@ namespace ShiftOS.WinForms.Applications
|
|||
|
||||
private void numBox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
currentnumber = float.Parse(numBox.Text);
|
||||
if (numBox.Text.EndsWith("."))
|
||||
{
|
||||
if (numBox.Text == ".") { currentnumber = 0; }
|
||||
else { currentnumber = float.Parse(numBox.Text.Replace(".", "")); }
|
||||
}
|
||||
else if (numBox.Text == "") { currentnumber = 0; }
|
||||
else { currentnumber = float.Parse(numBox.Text); }
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "1";
|
||||
if (multiop) { numBox.Text = "1"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "1"; }
|
||||
}
|
||||
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "2";
|
||||
if (multiop) { numBox.Text = "2"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "2"; }
|
||||
}
|
||||
|
||||
private void button3_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "3";
|
||||
if (multiop) { numBox.Text = "3"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "3"; }
|
||||
}
|
||||
|
||||
private void button4_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "4";
|
||||
if (multiop) { numBox.Text = "4"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "4"; }
|
||||
}
|
||||
|
||||
private void button5_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "5";
|
||||
if (multiop) { numBox.Text = "5"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "5"; }
|
||||
}
|
||||
|
||||
private void button6_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "6";
|
||||
if (multiop) { numBox.Text = "6"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "6"; }
|
||||
}
|
||||
|
||||
private void button7_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "7";
|
||||
if (multiop) { numBox.Text = "7"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "7"; }
|
||||
}
|
||||
|
||||
private void button8_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "8";
|
||||
if (multiop) { numBox.Text = "8"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "8"; }
|
||||
}
|
||||
|
||||
private void button9_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "9";
|
||||
if (multiop) { numBox.Text = "9"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "9"; }
|
||||
}
|
||||
|
||||
private void button10_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Text = numBox.Text + "0";
|
||||
if (multiop) { numBox.Text = "0"; multiop = false; }
|
||||
else { numBox.Text = numBox.Text + "0"; }
|
||||
}
|
||||
|
||||
private void buttonPlus_Click(object sender, EventArgs e)
|
||||
|
@ -146,6 +167,7 @@ namespace ShiftOS.WinForms.Applications
|
|||
operationnumber = currentnumber;
|
||||
activeoperation = 1;
|
||||
}
|
||||
multiop = true;
|
||||
}
|
||||
|
||||
private void solve()
|
||||
|
@ -156,6 +178,18 @@ namespace ShiftOS.WinForms.Applications
|
|||
numBox.Text = (currentnumber + operationnumber).ToString();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
numBox.Text = (operationnumber - currentnumber).ToString();
|
||||
break;
|
||||
|
||||
case 3:
|
||||
numBox.Text = (operationnumber * currentnumber).ToString();
|
||||
break;
|
||||
|
||||
case 4:
|
||||
numBox.Text = (operationnumber / currentnumber).ToString();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -167,5 +201,72 @@ namespace ShiftOS.WinForms.Applications
|
|||
operationnumber = 0;
|
||||
activeoperation = 0;
|
||||
}
|
||||
|
||||
private void buttonMinus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (operationnumber == 0 && activeoperation == 0)
|
||||
{
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
solve();
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 2;
|
||||
}
|
||||
multiop = true;
|
||||
}
|
||||
|
||||
private void buttonMultiply_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (operationnumber == 0 && activeoperation == 0)
|
||||
{
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
solve();
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 3;
|
||||
}
|
||||
multiop = true;
|
||||
}
|
||||
|
||||
private void buttonDivide_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (operationnumber == 0 && activeoperation == 0)
|
||||
{
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
solve();
|
||||
operationnumber = currentnumber;
|
||||
activeoperation = 4;
|
||||
}
|
||||
multiop = true;
|
||||
}
|
||||
|
||||
private void buttonC_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Clear();
|
||||
}
|
||||
|
||||
private void buttonCE_Click(object sender, EventArgs e)
|
||||
{
|
||||
numBox.Clear();
|
||||
operationnumber = 0;
|
||||
activeoperation = 0;
|
||||
multiop = false;
|
||||
}
|
||||
|
||||
private void buttonDecimal_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (multiop) { numBox.Text = "."; multiop = false; }
|
||||
else if (!numBox.Text.Contains(".")) numBox.Text = numBox.Text + ".";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
Dependencies: "calculator",
|
||||
Description: "Right now, you can only type numbers, but this equals button opens the door to solving equations!"
|
||||
},
|
||||
{
|
||||
Name: "Calc Decimal Button",
|
||||
Cost: 600,
|
||||
Dependencies: "calculator",
|
||||
Description: "Whole numbers can get boring. With this button, you can type decimal numbers!"
|
||||
},
|
||||
{
|
||||
Name: "Calc Plus Button",
|
||||
Cost: 700,
|
||||
|
@ -36,6 +42,24 @@
|
|||
Dependencies: "calc_plus_button",
|
||||
Description: "You can add numbers together, but it must be tiring to add the same number over and over. This multiplication button will make it easier for you!"
|
||||
},
|
||||
{
|
||||
Name: "Calc Divide Button",
|
||||
Cost: 800,
|
||||
Dependencies: "calc_multiply_button",
|
||||
Description: "You can multiply, but what about reversing multiplication? This divide button will sort that out!"
|
||||
},
|
||||
{
|
||||
Name: "Calc Clear Button",
|
||||
Cost: 750,
|
||||
Dependencies: "calc_equals_button",
|
||||
Description: "Typed the wrong number? No worries! With this Clear button, you can clear the number field, without messing up the equation you're trying to solve!"
|
||||
},
|
||||
{
|
||||
Name: "Calc CE Button",
|
||||
Cost: 750,
|
||||
Dependencies: "calc_clear_button",
|
||||
Description: "Wanna start all over with a new equation? With this CE (Clear Everything) button, you get rid of not only the numbers in the number field, but also the equation!"
|
||||
},
|
||||
{
|
||||
Name: "MUD Fundamentals",
|
||||
Cost: 50,
|
||||
|
@ -737,26 +761,6 @@
|
|||
Cost: 2500,
|
||||
Dependencies: "shiftorium_gui",
|
||||
Description: "In the shiftorium GUI but dont know what you can spend because you can't see how many code points are on hand? Well shop easy, because with this upgrade that is now possible! You have to restart the shiftorium for it to work."
|
||||
},
|
||||
|
||||
// CALCULATOR UPGRADES
|
||||
{
|
||||
Name: "Calculator",
|
||||
Cost: 1000,
|
||||
Dependencies: "wm_free_placement;desktop",
|
||||
Description: "Crazy math problems getting you down? Well, this calculator will take care of that!"
|
||||
},
|
||||
{
|
||||
Name: "AL Calculator",
|
||||
Cost: 350,
|
||||
Dependencies: "calculator;app_launcher",
|
||||
Description: "Add an App Launcher Entry for the Calculator!"
|
||||
},
|
||||
{
|
||||
Name: "Calc Equals Button",
|
||||
Cost: 600,
|
||||
Dependencies: "calculator",
|
||||
Description: "Right now, you can only type numbers, but this equals button opens the door to solving equations!"
|
||||
}
|
||||
}
|
||||
|
||||
]
|
Reference in a new issue