gametec

Member
So I was talking to a friend of mine who wanted me to make a gump for a calculator. He said that he was tired of having to go out of game and use the windows calculator lol. Anyway after laughing at his plight for a few minutes I decided to see what I could come up with.

as24.postimg.org_8bs03blnp_calc.jpg

The problem now is that I need to insert the code for it. Only I don't know the TextEntry call.. I know how to add a TextEntry box but I don't know how to display the numbers in that box. I figured it was something like TextEntry.Text but that didn't work, then I tried TextBox.Text because this is what I named it in GumpStudio. Anyway... does anyone know what this box is called in UO or how to find out?

Here is the code I am working off... It might be a little skewed because opr needs to be defined and it's not. Making this on a Windows Forms Application is a lot easier than in GumpStudio rofl.

Code:
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Server;
using Server.Gumps;
using Server.Network;
using Server.Commands;

namespace Server.Gumps
{
    public class CalculatorGump : Gump
    {
        private Mobile caller;

        public static void Initialize()
        {
            CommandSystem.Register("calc", AccessLevel.Administrator, new CommandEventHandler(calc_OnCommand));
        }

        [Usage("calc")]
        [Description("Makes a call to your custom gump.")]
        public static void calc_OnCommand(CommandEventArgs e)
        {
            if (e.Mobile.HasGump(typeof (CalculatorGump)))
                e.Mobile.CloseGump(typeof (CalculatorGump));
            e.Mobile.SendGump(new CalculatorGump(e.Mobile));
        }

        public CalculatorGump(Mobile from) : this()
        {
            caller = from;
        }

        public CalculatorGump() : base(0, 0)
        {
            this.Closable = true;
            this.Disposable = true;
            this.Dragable = true;
            this.Resizable = false;

            AddPage(0);
            AddBackground(89, 46, 294, 381, 9200);
            AddAlphaRegion(97, 53, 274, 361);
            AddBackground(103, 61, 264, 345, 9270);
            AddImageTiled(127, 90, 216, 35, 2524);
            AddTextEntry(129, 90, 212, 33, 0, 0, @"");
            AddButton(132, 172, 9721, 9722, (int) Buttons.ButtonNum01, GumpButtonType.Reply, 0);
            AddButton(187, 172, 9721, 9722, (int) Buttons.ButtonNum02, GumpButtonType.Reply, 0);
            AddButton(243, 172, 9721, 9722, (int) Buttons.ButtonNum03, GumpButtonType.Reply, 0);
            AddLabel(160, 161, 0, @"1");
            AddLabel(216, 161, 0, @"2");
            AddLabel(271, 160, 0, @"3");
            AddButton(132, 217, 9721, 9722, (int) Buttons.ButtonNum04, GumpButtonType.Reply, 0);
            AddButton(187, 217, 9721, 9722, (int) Buttons.ButtonNum05, GumpButtonType.Reply, 0);
            AddButton(243, 217, 9721, 9722, (int) Buttons.ButtonNum06, GumpButtonType.Reply, 0);
            AddLabel(160, 206, 0, @"4");
            AddLabel(216, 206, 0, @"5");
            AddLabel(271, 205, 0, @"6");
            AddButton(131, 262, 9721, 9722, (int) Buttons.ButtonNum07, GumpButtonType.Reply, 0);
            AddButton(186, 262, 9721, 9722, (int) Buttons.ButtonNum08, GumpButtonType.Reply, 0);
            AddButton(243, 262, 9721, 9722, (int) Buttons.ButtonNum09, GumpButtonType.Reply, 0);
            AddLabel(160, 251, 0, @"7");
            AddLabel(215, 251, 0, @"8");
            AddLabel(270, 250, 0, @"9");
            AddButton(131, 312, 9721, 9722, (int) Buttons.ButtonNum00, GumpButtonType.Reply, 0);
            AddButton(186, 313, 9721, 9722, (int) Buttons.ButtonDecimal, GumpButtonType.Reply, 0);
            AddButton(243, 312, 9721, 9722, (int) Buttons.ButtonNegPos, GumpButtonType.Reply, 0);
            AddLabel(160, 301, 0, @"0");
            AddLabel(217, 298, 0, @".");
            AddLabel(269, 300, 0, @"±");
            AddButton(303, 172, 9727, 9728, (int) Buttons.ButtonDivide, GumpButtonType.Reply, 0);
            AddLabel(331, 160, 0, @"/");
            AddButton(303, 217, 9727, 9728, (int) Buttons.ButtonMultiply, GumpButtonType.Reply, 0);
            AddLabel(331, 205, 0, @"x");
            AddButton(303, 262, 9727, 9728, (int) Buttons.ButtonAdd, GumpButtonType.Reply, 0);
            AddLabel(330, 250, 0, @"+");
            AddButton(303, 312, 9727, 9728, (int) Buttons.ButtonSubtract, GumpButtonType.Reply, 0);
            AddLabel(330, 300, 0, @"-");
            AddButton(265, 364, 12010, 12011, (int) Buttons.ButtonEquals, GumpButtonType.Reply, 0);
            AddButton(129, 364, 12004, 12005, (int) Buttons.ButtonClear, GumpButtonType.Reply, 0);
        }

        public enum Buttons
        {
            ButtonNum01,
            ButtonNum02,
            ButtonNum03,
            ButtonNum04,
            ButtonNum05,
            ButtonNum06,
            ButtonNum07,
            ButtonNum08,
            ButtonNum09,
            ButtonNum00,
            ButtonDecimal,
            ButtonNegPos,
            ButtonDivide,
            ButtonMultiply,
            ButtonAdd,
            ButtonSubtract,
            ButtonEquals,
            ButtonClear,
        }

        public override void OnResponse(NetState sender, RelayInfo info)
        {
            Mobile from = sender.Mobile;
            double oparand1, oparand2, result;

            switch (info.ButtonID)
            {
                case (int) Buttons.ButtonNum01:
                {
                    TextBox.Text = TextBox.Text + "1";
                    break;
                }
                case (int) Buttons.ButtonNum02:
                {
                    TextBox.Text = TextBox.Text + "2";
                    break;
                }
                case (int) Buttons.ButtonNum03:
                {
                    TextBox.Text = TextBox.Text + "3";
                    break;
                }
                case (int) Buttons.ButtonNum04:
                {
                    TextBox.Text = TextBox.Text + "4";
                    break;
                }
                case (int) Buttons.ButtonNum05:
                {
                    TextBox.Text = TextBox.Text + "5";
                    break;
                }
                case (int) Buttons.ButtonNum06:
                {
                    TextBox.Text = TextBox.Text + "6";
                    break;
                }
                case (int) Buttons.ButtonNum07:
                {
                    TextBox.Text = TextBox.Text + "7";
                    break;
                }
                case (int) Buttons.ButtonNum08:
                {
                    TextBox.Text = TextBox.Text + "8";
                    break;
                }
                case (int) Buttons.ButtonNum09:
                {
                    TextBox.Text = TextBox.Text + "9";
                    break;
                }
                case (int) Buttons.ButtonNum00:
                {
                    TextBox.Text = TextBox.Text + "0";
                    break;
                }
                case (int) Buttons.ButtonDecimal:
                {
                    if (TextBox.Text.Contains("."))
                    {
                        TextBox.Text = TextBox.Text;
                    }
                    else
                    {
                        TextBox.Text = TextBox.Text + ".";
                    }
                    break;
                }
                case (int) Buttons.ButtonNegPos:
                {
                    if (TextBox.Text.Contains("-"))
                    {
                        TextBox.Text = TextBox.Text.Remove(0, 1);
                    }
                    else
                    {
                        TextBox.Text = "-" + TextBox.Text;
                    }
                    break;
                }
                case (int) Buttons.ButtonDivide:
                {
                    oparand1 = Convert.ToDouble(TextBox.Text);
                    opr = "/";
                    TextBox.Clear();
                    break;
                }
                case (int) Buttons.ButtonMultiply:
                {
                    oparand1 = Convert.ToDouble(TextBox.Text);
                    opr = "*";
                    TextBox.Clear();
                    break;
                }
                case (int) Buttons.ButtonAdd:
                {
                    oparand1 = Convert.ToDouble(TextBox.Text);
                    opr = "+";
                    TextBox.Clear();
                    break;
                }
                case (int) Buttons.ButtonSubtract:
                {
                    oparand1 = Convert.ToDouble(TextBox.Text);
                    opr = "-";
                    TextBox.Clear();
                    break;
                }
                case (int) Buttons.ButtonEquals:
                {
                    oparand2 = Convert.ToDouble(TextEntry.Text);

                    switch (opr)
                    {
                        case "+":
                            result = oparand1 + oparand2;
                            TextBox.Text = Convert.ToString(result);
                            break;

                        case "-":
                            result = oparand1 - oparand2;
                            TextBox.Text = Convert.ToString(result);
                            break;
                        case "*":
                            result = oparand1*oparand2;
                            TextBox.Text = Convert.ToString(result);
                            break;
                        case "/":
                            if (oparand2 == 0)
                            {
                                TextBox.Text = "0.0";
                                break;
                            }
                            else
                            {
                                result = oparand1/oparand2;
                                TextBox.TextEntry = Convert.ToString(result);

                                break;
                            }
                        case (int) Buttons.ButtonClear:
                        {
                            TextBox.Clear();
                            break;
                        }
                    }
                }
            }
        }
    }
}
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back