ConvertStringToInt() 공개 정적인 메소드

Converts string to int with Hex recognition
public static ConvertStringToInt ( string text, int &result ) : bool
text string string to parse
result int out result
리턴 bool
예제 #1
0
 private void onClickAdd(object sender, EventArgs e)
 {
     if (selData != null)
     {
         int  index;
         bool candone = Utils.ConvertStringToInt(textBoxAddFrame.Text, out index);
         if (checkBoxRelative.Checked)
         {
             index += CurrAnim;
         }
         if ((index >= Art.StaticLength) || (index < 0))
         {
             candone = false;
         }
         if (candone)
         {
             if (Art.IsValidStatic(index))
             {
                 selData.FrameData[selData.FrameCount] = (sbyte)(index - CurrAnim);
                 selData.FrameCount++;
                 TreeNode node = new TreeNode();
                 node.Text = String.Format("0x{0:X4} {1}", index, TileData.ItemTable[index].Name);
                 treeViewFrames.Nodes.Add(node);
                 TreeNode subnode = new TreeNode();
                 subnode.Tag  = selData.FrameCount - 1;
                 subnode.Text = String.Format("0x{0:X4} {1}", index, TileData.ItemTable[index].Name);
                 if (treeView1.SelectedNode.Parent == null)
                 {
                     treeView1.SelectedNode.Nodes.Add(subnode);
                 }
                 else
                 {
                     treeView1.SelectedNode.Parent.Nodes.Add(subnode);
                 }
                 Options.ChangedUltimaClass["Animdata"] = true;
             }
         }
     }
 }
예제 #2
0
파일: HueEdit.cs 프로젝트: v0icer/poltools
 private void onKeyDownAnim(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(TextBoxAnim.Text, out index, 1, 10000))
         {
             if (!Animations.IsActionDefined(index, 0, 0))
             {
                 return;
             }
             contextMenuStrip1.Close();
             int     hueref = 0;
             Frame[] frames = Animations.GetAnimation(index, 0, 1, ref hueref, false, true);
             if (frames == null)
             {
                 return;
             }
             preview = frames[0].Bitmap;
             RefreshPreview();
         }
     }
 }
예제 #3
0
파일: Light.cs 프로젝트: v0icer/poltools
        private void LightTileTextChanged(object sender, EventArgs e)
        {
            if (!Loaded)
            {
                return;
            }
            int index;

            if (Utils.ConvertStringToInt(LightTileText.Text, out index, 0, Ultima.Art.GetMaxItemID()))
            {
                if (!Ultima.Art.IsValidStatic(index))
                {
                    LightTileText.ForeColor = Color.Red;
                }
                else
                {
                    LightTileText.ForeColor = Color.Black;
                }
            }
            else
            {
                LightTileText.ForeColor = Color.Red;
            }
        }
예제 #4
0
파일: Light.cs 프로젝트: v0icer/poltools
        private void LandTileTextChanged(object sender, EventArgs e)
        {
            if (!Loaded)
            {
                return;
            }
            int index;

            if (Utils.ConvertStringToInt(LandTileText.Text, out index, 0, 0x3FFF))
            {
                if (!Ultima.Art.IsValidLand(index))
                {
                    LandTileText.ForeColor = Color.Red;
                }
                else
                {
                    LandTileText.ForeColor = Color.Black;
                }
            }
            else
            {
                LandTileText.ForeColor = Color.Red;
            }
        }
예제 #5
0
파일: Texture.cs 프로젝트: v0icer/poltools
 private void onKeyDownInsert(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Textures.GetIdxLength()))
         {
             if (Textures.TestTexture(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (((bmp.Width == 64) && (bmp.Height == 64)) || ((bmp.Width == 128) && (bmp.Height == 128)))
                     {
                         Textures.Replace(index, bmp);
                         FiddlerControls.Events.FireTextureChangeEvent(this, index);
                         ListViewItem item = new ListViewItem(index.ToString(), 0);
                         item.Tag = index;
                         bool done = false;
                         foreach (ListViewItem i in listView1.Items)
                         {
                             if ((int)i.Tag > index)
                             {
                                 listView1.Items.Insert(i.Index, item);
                                 done = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             listView1.Items.Add(item);
                         }
                         listView1.View = View.Details; // that works faszinating
                         listView1.View = View.Tile;
                         if (listView1.SelectedItems.Count == 1)
                         {
                             listView1.SelectedItems[0].Selected = false;
                         }
                         item.Selected = true;
                         item.Focused  = true;
                         item.EnsureVisible();
                         Options.ChangedUltimaClass["Texture"] = true;
                     }
                     else
                     {
                         MessageBox.Show("Height or Width Invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                     }
                 }
             }
         }
     }
 }
예제 #6
0
        private void onKeydown_InsertText(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Enter)
            {
                return;
            }

            int index;

            if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Gumps.GetCount()))
            {
                if (Gumps.IsValidIndex(index))
                {
                    return;
                }
                contextMenuStrip1.Close();
                using (OpenFileDialog dialog = new OpenFileDialog())
                {
                    dialog.Multiselect     = false;
                    dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                    dialog.CheckFileExists = true;
                    dialog.Filter          = "Image files (*.tif;*.tiff;*.bmp)|*.tif;*.tiff;*.bmp";
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        Bitmap bmp = new Bitmap(dialog.FileName);
                        if (dialog.FileName.Contains(".bmp"))
                        {
                            bmp = Utils.ConvertBmp(bmp);
                        }
                        Gumps.ReplaceGump(index, bmp);
                        FiddlerControls.Events.FireGumpChangeEvent(this, index);
                        bool done = false;
                        for (int i = 0; i < listBox.Items.Count; ++i)
                        {
                            int j = int.Parse(listBox.Items[i].ToString());
                            if (j > index)
                            {
                                listBox.Items.Insert(i, index);
                                listBox.SelectedIndex = i;
                                done = true;
                                break;
                            }
                            else if (ShowFreeSlots)
                            {
                                if (j == i)
                                {
                                    listBox.SelectedIndex = i;
                                    done = true;
                                    break;
                                }
                            }
                        }
                        if (!done)
                        {
                            listBox.Items.Add(index);
                            listBox.SelectedIndex = listBox.Items.Count - 1;
                        }
                        Options.ChangedUltimaClass["Gumps"] = true;
                    }
                }
            }
        }
예제 #7
0
        private void OnClickmeanColorFromTo(object sender, EventArgs e)
        {
            int from, to;

            if ((Utils.ConvertStringToInt(textBoxMeanFrom.Text, out from, 0, 0x4000)) &&
                (Utils.ConvertStringToInt(textBoxMeanTo.Text, out to, 0, 0x4000)))
            {
                if (to < from)
                {
                    int temp = from;
                    from = to;
                    to   = temp;
                }
                int gmeanr = 0;
                int gmeang = 0;
                int gmeanb = 0;
                for (int i = from; i < to; ++i)
                {
                    Bitmap image;
                    if (tabControl2.SelectedIndex == 0)
                    {
                        image = Art.GetStatic(i);
                    }
                    else
                    {
                        image = Art.GetLand(i);
                    }
                    if (image == null)
                    {
                        continue;
                    }
                    unsafe
                    {
                        BitmapData bd    = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                        ushort *   line  = (ushort *)bd.Scan0;
                        int        delta = bd.Stride >> 1;
                        ushort *   cur   = line;
                        int        meanr = 0;
                        int        meang = 0;
                        int        meanb = 0;
                        int        count = 0;
                        for (int y = 0; y < image.Height; ++y, line += delta)
                        {
                            cur = line;
                            for (int x = 0; x < image.Width; ++x)
                            {
                                if (cur[x] != 0)
                                {
                                    meanr += Ultima.Hues.HueToColorR((short)cur[x]);
                                    meang += Ultima.Hues.HueToColorG((short)cur[x]);
                                    meanb += Ultima.Hues.HueToColorB((short)cur[x]);
                                    ++count;
                                }
                            }
                        }
                        image.UnlockBits(bd);
                        meanr  /= count;
                        meang  /= count;
                        meanb  /= count;
                        gmeanr += meanr;
                        gmeang += meang;
                        gmeanb += meanb;
                    }
                }
                gmeanr /= (to - from);
                gmeang /= (to - from);
                gmeanb /= (to - from);
                Color col = Color.FromArgb(gmeanr, gmeang, gmeanb);
                CurrColor = Ultima.Hues.ColorToHue(col);
            }
        }
예제 #8
0
 private void onKeyDownInsertText(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Ultima.Art.GetMaxItemID()))
         {
             if (Art.IsValidStatic(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     Art.ReplaceStatic(index, bmp);
                     FiddlerControls.Events.FireItemChangeEvent(this, index);
                     Options.ChangedUltimaClass["Art"] = true;
                     if (ShowFreeSlots)
                     {
                         selected          = index;
                         vScrollBar.Value  = index / refMarker.col + 1;
                         namelabel.Text    = String.Format("Name: {0}", TileData.ItemTable[selected].Name);
                         graphiclabel.Text = String.Format("Graphic: 0x{0:X4} ({0})", selected);
                         UpdateDetail(selected);
                         pictureBox.Invalidate();
                     }
                     else
                     {
                         bool done = false;
                         for (int i = 0; i < ItemList.Count; ++i)
                         {
                             if (index < ItemList[i])
                             {
                                 ItemList.Insert(i, index);
                                 vScrollBar.Value = i / refMarker.col + 1;
                                 done             = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             ItemList.Add(index);
                             vScrollBar.Value = ItemList.Count / refMarker.col + 1;
                         }
                         selected          = index;
                         namelabel.Text    = String.Format("Name: {0}", TileData.ItemTable[selected].Name);
                         graphiclabel.Text = String.Format("Graphic: 0x{0:X4} ({0})", selected);
                         UpdateDetail(selected);
                         pictureBox.Invalidate();
                     }
                 }
             }
         }
     }
 }
예제 #9
0
 private void onKeyDown_Insert(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         int index;
         if (Utils.ConvertStringToInt(InsertText.Text, out index, 0, Ultima.Art.GetMaxItemID()))
         {
             if (Art.IsValidStatic(index))
             {
                 return;
             }
             contextMenuStrip1.Close();
             using (OpenFileDialog dialog = new OpenFileDialog())
             {
                 dialog.Multiselect     = false;
                 dialog.Title           = String.Format("Choose image file to insert at 0x{0:X}", index);
                 dialog.CheckFileExists = true;
                 dialog.Filter          = "image files (*.tiff;*.bmp)|*.tiff;*.bmp";
                 if (dialog.ShowDialog() == DialogResult.OK)
                 {
                     Bitmap bmp = new Bitmap(dialog.FileName);
                     if (dialog.FileName.Contains(".bmp"))
                     {
                         bmp = Utils.ConvertBmp(bmp);
                     }
                     Art.ReplaceStatic(index, bmp);
                     FiddlerControls.Events.FireItemChangeEvent(this, index);
                     ListViewItem item = new ListViewItem(index.ToString(), 0);
                     item.Tag = index;
                     if (ShowFreeSlots)
                     {
                         listView1.Items[index] = item;
                         listView1.Invalidate();
                     }
                     else
                     {
                         bool done = false;
                         foreach (ListViewItem i in listView1.Items)
                         {
                             if ((int)i.Tag > index)
                             {
                                 listView1.Items.Insert(i.Index, item);
                                 done = true;
                                 break;
                             }
                         }
                         if (!done)
                         {
                             listView1.Items.Add(item);
                         }
                     }
                     listView1.View = View.Details; // that works faszinating
                     listView1.View = View.Tile;
                     if (listView1.SelectedItems.Count == 1)
                     {
                         listView1.SelectedItems[0].Selected = false;
                     }
                     item.Selected = true;
                     item.Focused  = true;
                     item.EnsureVisible();
                     Options.ChangedUltimaClass["Art"] = true;
                 }
             }
         }
     }
 }
예제 #10
0
        private void OnClickAddReplace(object sender, EventArgs e)
        {
            int id;

            if (Utils.ConvertStringToInt(textBoxID.Text, out id, 0, 0xFFE))
            {
                string name = textBoxName.Text;
                if (name != null)
                {
                    if (name.Length > 32)
                    {
                        name = name.Substring(0, 32);
                    }
                    string filename = textBoxWav.Text;
                    if (File.Exists(filename))
                    {
                        Ultima.Sounds.Add(id, name, filename);

                        TreeNode node = new TreeNode(String.Format("0x{0:X3} {1}", id, name));
                        if (checkBox.Checked)
                        {
                            node.Text = String.Format("{1} 0x{0:X3}", id, name);
                        }
                        node.Tag = id;
                        bool done = false;
                        for (int i = 0; i < treeView.Nodes.Count; ++i)
                        {
                            if ((int)treeView.Nodes[i].Tag == id)
                            {
                                done = true;
                                treeView.Nodes.RemoveAt(i);
                                treeView.Nodes.Insert(i, node);
                                break;
                            }
                        }
                        if (!done)
                        {
                            treeView.Nodes.Add(node);
                            treeView.Sort();
                        }

                        node.EnsureVisible();
                        treeView.SelectedNode = node;
                        treeView.Invalidate();
                        Options.ChangedUltimaClass["Sound"] = true;
                    }
                    else
                    {
                        MessageBox.Show(
                            "Invalid Filename",
                            "Add/Replace",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Error,
                            MessageBoxDefaultButton.Button1);
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Invalid Name",
                        "Add/Replace",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error,
                        MessageBoxDefaultButton.Button1);
                }
            }
            else
            {
                MessageBox.Show(
                    "Invalid ID",
                    "Add/Replace",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error,
                    MessageBoxDefaultButton.Button1);
            }
        }