示例#1
0
 //Game title textbox
 private void Name_Textbox_LostFocus(object sender, RoutedEventArgs e)
 {
     Console.WriteLine(title);
     if (title != Name_Textbox.Text)
     {
         title             = GameProfile.Rename(title, Name_Textbox.Text);
         Name_Textbox.Text = title;
         Console.WriteLine(title);
     }
 }
示例#2
0
        //Catch created textbox key presses
        private void TitleEditBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            List <string> chars = new List <string>();

            //Remove unsupported characters
            {
                var tempText = TitleEditBox.Text;
                foreach (var illegal in new[] { "/", "\\", ":", "|", "*", "<", ">" })
                {
                    tempText = tempText.Replace(illegal, string.Empty);
                }
                TitleEditBox.Text = tempText;
            }

            Console.WriteLine(e.Key.ToString());

            //This is the only way to save the name
            if (e.Key == Key.Enter)
            {
                //Save old name to a variable
                string _oldName = Header_title.Text;
                string _newName;

                //Hide the textbox
                TitleEditBox.Visibility = Visibility.Collapsed;

                //Pass text to label
                Header_title.Text = TitleEditBox.Text;

                //Show real label
                Header_title.Visibility = Visibility.Visible;

                //Save new name to the variable
                _newName = Header_title.Text;

                //Check, if old directory exists
                if (Directory.Exists(BaseDirectory + @"\resources\configs\" + _oldName))
                {
                    try
                    {
                        //Move old folder to new folder
                        GameProfile.Rename(_oldName, _newName);

                        //Rename game tile
                        renameTile(_oldName, _newName);

                        Console.WriteLine($"Renamed profile '{_oldName}' to '{_newName}'");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Couldn't rename the folder");
                        Console.WriteLine(ex);
                    }
                }
            }

            if (e.Key == Key.Escape)
            {
                //Hide the textbox
                TitleEditBox.Visibility = Visibility.Collapsed;

                //Show real label
                Header_title.Visibility = Visibility.Visible;
            }
        }