private string GetValue(string tagName) { string retVal = ""; ControlData cData = iniControls[tagName]; string ctrlName = cData.CtrlName; Control ctrl = Controls.Find(ctrlName, true)[0]; if (ctrl.GetType() == typeof(CheckBox)) { retVal = (((CheckBox)ctrl).Checked ? "1" : "0"); } else if (ctrl.GetType() == typeof(ComboBox)) { retVal = ((ComboBox)ctrl).SelectedIndex.ToString(); } else if (ctrl.GetType() == typeof(DataGridView)) { foreach (DataGridViewRow dgRow in ((DataGridView)ctrl).Rows) { if (dgRow.Cells.Count > 1) { if (dgRow.Cells[0].Value.ToString() == cData.CtrlDesc) { retVal = dgRow.Cells[1].Value.ToString(); break; } } } } else if (ctrl.GetType() == typeof(MaskedTextBox)) { retVal = ((MaskedTextBox)ctrl).Text; } else if (ctrl.GetType() == typeof(RadioButton)) { retVal = (((RadioButton)ctrl).Checked ? "1" : "0"); } else if (ctrl.GetType() == typeof(TextBox)) { retVal = ((TextBox)ctrl).Text; } return(retVal); }
private void OpenFile(string fileName) { Clear(); txtINIFile.Text = fileName; UOXData.Script.UOXIni iniFile = new UOXData.Script.UOXIni(fileName); foreach (UOXData.Script.ScriptSection mSect in iniFile.Sections) { if (mSect.SectionName == "play server list") { foreach (UOXData.Script.TagDataPair sRow in mSect.TagDataPairs) { dataGridServers.Rows.Add(sRow.Data.ToString().Split(",".ToCharArray())); } } else if (mSect.SectionName == "start locations") { foreach (UOXData.Script.TagDataPair lRow in mSect.TagDataPairs) { dataGridLocations.Rows.Add(lRow.Data.ToString().Split(",".ToCharArray())); } } else if (mSect.SectionName == "directories") { for (UOXData.Script.UOXIni.DirectoryPaths dPath = UOXData.Script.UOXIni.DirectoryPaths.Root; dPath != UOXData.Script.UOXIni.DirectoryPaths.COUNT; ++dPath) { dataGridDirectories.Rows.Add(dPath.ToString(), iniFile.Directory(dPath)); } } else { foreach (UOXData.Script.TagDataPair mPair in mSect.TagDataPairs) { try { ControlData mControl = iniControls[mPair.Tag.ToString()]; Control ctrl = Controls.Find(mControl.CtrlName, true)[0]; if (ctrl.GetType() == typeof(CheckBox)) { ((CheckBox)ctrl).Checked = (mPair.Data.ToInt08() == 1); } else if (ctrl.GetType() == typeof(ComboBox)) { int aSound = mPair.Data.ToInt08(); if (aSound < ((ComboBox)ctrl).Items.Count) { ((ComboBox)ctrl).SelectedIndex = aSound; } } else if (ctrl.GetType() == typeof(DataGridView)) { ((DataGridView)ctrl).Rows.Add(mControl.CtrlDesc, mPair.Data.ToString()); } else if (ctrl.GetType() == typeof(MaskedTextBox)) { ((MaskedTextBox)ctrl).Text = mPair.Data.ToString(); } else if (ctrl.GetType() == typeof(RadioButton)) { ((RadioButton)ctrl).Checked = (mPair.Data.ToInt08() == 1); } else if (ctrl.GetType() == typeof(TextBox)) { ((TextBox)ctrl).Text = mPair.Data.ToString(); } } catch (KeyNotFoundException) { switch (mPair.Tag.ToString()) { case "BACKGROUNDPIC": mtxtGumpBackground.Text = mPair.Data.ToString(); break; case "BUTTONCANCEL": gumpButtons[0] = mPair.Data.ToUInt16(); break; case "BUTTONLEFT": gumpButtons[1] = mPair.Data.ToUInt16(); break; case "BUTTONRIGHT": gumpButtons[2] = mPair.Data.ToUInt16(); break; case "CLIENTFEATURES": BitVector32 sCFeat = new BitVector32(mPair.Data.ToUInt16()); int cmask = BitVector32.CreateMask(); for (ClientFeatures cEnum = ClientFeatures.Chat_Button; cEnum < ClientFeatures.COUNT; ++cEnum) { dataGridClientFeatures.Rows.Add(cEnum.ToString().Replace("_", " "), sCFeat[cmask]); cmask = BitVector32.CreateMask(cmask); if (cEnum.ToString().Contains("UNKNOWN")) { dataGridClientFeatures.Rows[dataGridClientFeatures.Rows.Count - 1].Visible = false; } } break; case "LEFTTEXTCOLOUR": gumpText[1] = mPair.Data.ToUInt16(); break; case "RIGHTTEXTCOLOUR": gumpText[2] = mPair.Data.ToUInt16(); break; case "SERVERFEATURES": BitVector32 sSFeat = new BitVector32(mPair.Data.ToInt32()); int smask = BitVector32.CreateMask(); for (ServerFeatures sEnum = ServerFeatures.UNKNOWN1; sEnum < ServerFeatures.COUNT; ++sEnum) { dataGridServerFeatures.Rows.Add(sEnum.ToString().Replace("_", " "), sSFeat[smask]); smask = BitVector32.CreateMask(smask); if (sEnum.ToString().Contains("UNKNOWN")) { dataGridServerFeatures.Rows[dataGridServerFeatures.Rows.Count - 1].Visible = false; } } break; case "STARTGOLD": mtxtStartGold.Text = mPair.Data.ToString(); break; case "STARTPRIVS": BitVector32 sPriv = new BitVector32(mPair.Data.ToUInt16()); int pmask = BitVector32.CreateMask(); for (StartPrivs pEnum = StartPrivs.GM; pEnum < StartPrivs.COUNT; ++pEnum) { dataGridPrivs.Rows.Add(pEnum.ToString().Replace("_", " "), sPriv[pmask]); pmask = BitVector32.CreateMask(pmask); } break; case "TITLECOLOUR": gumpText[0] = mPair.Data.ToUInt16(); break; default: dataGridUncategorized.Rows.Add(mPair.Tag.ToString(), mPair.Data.ToString()); break; } } } } } comboGumpText.SelectedIndex = 0; comboGumpButtons.SelectedIndex = 0; Text = title + " - " + Path.GetFileName(txtINIFile.Text); }