Skip to content
This repository
tree: 3485f16dd8
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 370 lines (307 sloc) 10.253 kb
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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Extensions;
using MOTHER3;

namespace MOTHER3Funland
{
    public partial class frmItemEditor : M3Form
    {
        bool loading = false;

        // Ailment stuff
        Label[] lblAilment = new Label[11];
        TextBox[] txtAilment = new TextBox[11];

        // PSI stuff
        Label[] lblPsi = new Label[5];
        TextBox[] txtPsi = new TextBox[5];

        // Equipper stuff
        CheckBox[] chkEquip = new CheckBox[8];

        string[] itemNames = new string[TextItemNames.Entries];
        string[] itemTypes = null;
        string[] equippers = null;

        public frmItemEditor()
        {
            InitializeComponent();

            // Load item names
            for (int i = 0; i < itemNames.Length; i++)
                itemNames[i] = TextItemNames.GetName(i);

            // Draw the ailments stuff
            string[] weaknesses = Properties.Resources.weaknesses.SplitN();
            for (int i = 0; i < 11; i++)
            {
                Label l = new Label();

                l.AutoSize = true;
                l.Text = weaknesses[i];
                l.Left = 6;
                l.Top = (i * 27) + 9;

                tabAilments.Controls.Add(l);
                lblAilment[i] = l;

                TextBox t = new TextBox();

                t.Width = 64;
                t.Left = l.Left + 96;
                t.Top = (i * 27) + 7;
                t.MaxLength = 6;

                tabAilments.Controls.Add(t);
                txtAilment[i] = t;
            }
            
            // Draw the PSI stuff
            string[] psi = { "PK Love", "PK Fire", "PK Freeze", "PK Thunder", "Bomb" };
            for (int i = 0; i < 5; i++)
            {
                Label l = new Label();

                l.AutoSize = true;
                l.Text = psi[i];
                l.Left = 6;
                l.Top = (i * 27) + 9;

                tabPsi.Controls.Add(l);
                lblPsi[i] = l;

                TextBox t = new TextBox();

                t.Width = 64;
                t.Left = l.Left + 96;
                t.Top = (i * 27) + 7;
                t.MaxLength = 4;

                tabPsi.Controls.Add(t);
                txtPsi[i] = t;
            }

            // Draw the equipper stuff
            equippers = Properties.Resources.equippernames.SplitN();
            for (int i = 0; i < 8; i++)
            {
                CheckBox cb = new CheckBox();

                cb.AutoSize = true;
                cb.Text = equippers[i] + " can equip";
                cb.Left = lblItemType.Left + 5;
                cb.Top = lblHp.Top + (i * 26);

                tabBasic.Controls.Add(cb);
                chkEquip[i] = cb;
            }

            // Item types
            itemTypes = Properties.Resources.itemtypes.SplitN();
            cboItemType.Items.AddRange(itemTypes);

            Helpers.CheckFont(cboItem);
            Helpers.CheckFont(txtName);
            Helpers.CheckFont(txtDescription);
            cboItem.JapaneseSearch = M3Rom.Version == RomVersion.Japanese;

            // Load the item data
            ItemData.Init();

            loading = true;
            for (int i = 0; i < ItemData.Entries; i++)
                cboItem.Items.Add("[" + i.ToString("X2") + "] " + itemNames[i]);
            loading = false;
            cboItem.SelectedIndex = 0;
        }

        public override void SelectIndex(int[] index)
        {
            cboItem.SelectedIndex = index[0];
        }

        public override int[] GetIndex()
        {
            return new int[] { cboItem.SelectedIndex };
        }

        private void HighlightControl(Control c)
        {
            var tp = c.Parent as TabPage;
            tabMain.SelectedTab = tp;
            c.Focus();

            if (c is TextBox)
            {
                var t = c as TextBox;
                t.SelectAll();
            }

            else if ((c is ComboBox) || (c is CheckBox))
            {
                Color bc = c.BackColor;
                c.BackColor = Color.Blue;
                Thread.Sleep(200);
                c.BackColor = bc;
            }
        }

        private void cboItem_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (loading) return;

            int index = cboItem.SelectedIndex;
            ItemData id = ItemData.Items[index];

            txtName.Text = itemNames[index];
            txtSell.Text = id.Sell.ToString();
            txtHp.Text = id.Hp.ToString();
            txtPp.Text = id.Pp.ToString();
            txtOff.Text = id.Off.ToString();
            txtDef.Text = id.Def.ToString();
            txtIq.Text = id.Iq.ToString();
            txtSpeed.Text = id.Speed.ToString();
            txtHp1.Text = id.Hp1.ToString();
            txtHp2.Text = id.Hp2.ToString();
            txtDescription.Text = TextItemDescriptions.GetDescription(index);

            if ((id.ItemType >= 0) && (id.ItemType < cboItemType.Items.Count))
                cboItemType.SelectedIndex = id.ItemType;
            else
                cboItemType.SelectedIndex = -1;

            chkKeyItem.Checked = id.KeyItem;

            for (int i = 0; i < 8; i++)
                chkEquip[i].Checked = ((id.EquipOwner >> i) & 1) == 1;

            for (int i = 0; i < 11; i++)
                txtAilment[i].Text = id.ProtectionAilment[i].ToString();

            for (int i = 0; i < 5; i++)
                txtPsi[i].Text = id.ProtectionPsi[i].ToString();

            pIcon.Image = GfxItems.GetImage(index);
            pIcon.Refresh();
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            int index = cboItem.SelectedIndex;
            ItemData id = ItemData.Items[index];

            loading = true;

            TextItemNames.SetName(index, txtName.Text);
            string newName = TextItemNames.GetName(index);
            itemNames[index] = newName;
            cboItem.Items[index] = "";
            cboItem.Items[index] = "[" + index.ToString("X2") + "] " + newName;

            loading = false;

            // Sell
            try
            {
                id.Sell = ushort.Parse(txtSell.Text);
            }
            catch
            {
                HighlightControl(txtSell);
                return;
            }
            
            // HP
            try
            {
                id.Hp = int.Parse(txtHp.Text);
            }
            catch
            {
                HighlightControl(txtHp);
                return;
            }

            // PP
            try
            {
                id.Pp = short.Parse(txtPp.Text);
            }
            catch
            {
                HighlightControl(txtPp);
                return;
            }

            // Offense
            try
            {
                id.Off = sbyte.Parse(txtOff.Text);
            }
            catch
            {
                HighlightControl(txtOff);
                return;
            }

            // Defense
            try
            {
                id.Def = sbyte.Parse(txtDef.Text);
            }
            catch
            {
                HighlightControl(txtDef);
                return;
            }

            // IQ
            try
            {
                id.Iq = sbyte.Parse(txtIq.Text);
            }
            catch
            {
                HighlightControl(txtIq);
                return;
            }

            // Speed
            try
            {
                id.Speed = sbyte.Parse(txtSpeed.Text);
            }
            catch
            {
                HighlightControl(txtSpeed);
                return;
            }

            // HP1
            try
            {
                id.Hp1 = ushort.Parse(txtHp1.Text);
            }
            catch
            {
                HighlightControl(txtHp1);
                return;
            }

            // HP2
            try
            {
                id.Hp2 = ushort.Parse(txtHp2.Text);
            }
            catch
            {
                HighlightControl(txtHp2);
                return;
            }
            
            // Item type
            id.ItemType = (byte)cboItemType.SelectedIndex;

            // Key item
            id.KeyItem = chkKeyItem.Checked;

            // Equip
            id.EquipOwner = 0;
            for (int i = 0; i < 8; i++)
            {
                if (chkEquip[i].Checked)
                    id.EquipOwner |= (byte)(1 << i);
            }

            // Ailment protection
            for (int i = 0; i < 11; i++)
            {
                try
                {
                    id.ProtectionAilment[i] = short.Parse(txtAilment[i].Text);
                }
                catch
                {
                    HighlightControl(txtAilment[i]);
                    return;
                }
            }

            // PSI protection
            for (int i = 0; i < 5; i++)
            {
                try
                {
                    id.ProtectionPsi[i] = sbyte.Parse(txtPsi[i].Text);
                }
                catch
                {
                    HighlightControl(txtPsi[i]);
                    return;
                }
            }

            // Save changes
            id.Save();

            // Refresh
            cboItem_SelectedIndexChanged(null, null);
        }

        private void mnuGraphicsSave_Click(object sender, EventArgs e)
        {
            Helpers.GraphicsSave(sender, dlgSaveImage);
        }

        private void mnuGraphicsCopy_Click(object sender, EventArgs e)
        {
            Helpers.GraphicsCopy(sender);
        }
    }
}
Something went wrong with that request. Please try again.