public XCharacter loadCharacter(string singleLine) { XCharacter newCharacter = new XCharacter(); newCharacter.Selected += editableChar_Selected; try { int firstquote = singleLine.IndexOf('"') + 1; newCharacter.Content = singleLine.Substring(firstquote, singleLine.IndexOf('"', firstquote) - firstquote); newCharacter.Alias = singleLine.Substring(7, singleLine.IndexOf('=') - 7).TrimEnd(' '); string[] all = singleLine.Substring(firstquote).Replace("\"", "").Replace(" ", "").Split(','); for (int prop = 1; prop < all.Length; prop++) { if (all[prop].StartsWith("image")) { int indexIn = singleLine.LastIndexOf('/') + 1; int length = singleLine.LastIndexOf('.') - indexIn; newCharacter.Icon = sideListView.Items.OfType <XImage>().First(icon => (icon.Path.Substring(indexIn, length) == all[prop].Substring(all[prop].IndexOf('"')).Replace("\"", ""))); } else if (all[prop].StartsWith("kind") && all[prop].Contains("nvl")) { newCharacter.IsNvl = true; } else if (all[prop].StartsWith("color")) { newCharacter.NameColor = (Color)ColorConverter.ConvertFromString(all[prop].Substring(6)); } else if (all[prop].StartsWith("who_bold") && all[prop].Contains("True")) { newCharacter.NameIsBold = true; } else if (all[prop].StartsWith("who_italic") && all[prop].Contains("True")) { newCharacter.NameIsItalic = true; } else if (all[prop].StartsWith("what_color")) { newCharacter.TextColor = (Color)ColorConverter.ConvertFromString(all[prop].Substring(11)); } else if (all[prop].StartsWith("what_bold") && all[prop].Contains("True")) { newCharacter.TextIsBold = true; } else if (all[prop].StartsWith("what_italic") && all[prop].Contains("True")) { newCharacter.TextIsItalic = true; } } } catch (Exception) { MessageBox.Show("Error: Character loading", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } return(newCharacter); }
private void editCharacter_Click(object sender, RoutedEventArgs e) { if (characterListView.SelectedItem != null) { XCharacter edit = characterListView.SelectedItem as XCharacter; characterSetProperties(edit); if ((characterSelector.SelectedItem as ComboBoxItem).Tag == edit) { characterLabel.Content = edit.Content; } } else { MessageBox.Show("No character is selected!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void editableChar_Selected(object sender, RoutedEventArgs e) { XCharacter character = sender as XCharacter; iconCharacter.Source = null; editCharacter.IsEnabled = true; characterName.Text = character.Content.ToString(); charName_colorPicker.SelectedColor = character.NameColor; charText_colorPicker.SelectedColor = character.TextColor; characterNvl.IsChecked = character.IsNvl; characterNameBold.IsChecked = character.NameIsBold; characterNameItalic.IsChecked = character.NameIsItalic; characterTextBold.IsChecked = character.TextIsBold; characterTextItalic.IsChecked = character.TextIsItalic; if (character.Icon != null) { iconCharacter.Source = imageShow(character.IconSource); } }
private void addCharacter_Click(object sender, RoutedEventArgs e) { if (characterName.Text != "") { try { bool exist = false; foreach (XCharacter item in characterList) { if (item.Content.ToString() == characterName.Text) { if (MessageBox.Show("Already in use! Replace the character?", "Error", MessageBoxButton.YesNo, MessageBoxImage.Error) == MessageBoxResult.Yes) { characterSetProperties(item); exist = true; break; } } } if (!exist) { XCharacter character = new XCharacter() { }; characterSetProperties(character); character.Selected += editableChar_Selected; characterList.Add(character); characterSelector.Items.Add(character.CharView); } } catch (Exception) { MessageBox.Show("Some fields are empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("Character name is empty!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// /// </summary> private void saveScript() { projectExpander.IsExpanded = false; createDirectories(); FileStream fs = new FileStream(projectFolder + "script.rpy", FileMode.Create); StreamWriter writer = new StreamWriter(fs); writer.WriteLine(scriptstart + nextLine); //init writer.WriteLine(backgroundImages); foreach (XImage image in backImageListView.Items) { writer.WriteLine("image " + image.Alias + eQuote(image.Header)); } writer.WriteLine(characterImages); foreach (XImage image in imageListView.Items) { writer.WriteLine("image " + image.Alias + eQuote(image.Header)); } writer.WriteLine(musicAudio); foreach (XAudio audio in musicListView.Items) { writer.WriteLine(define + "audio." + audio.Alias + eQuote(musicFolder + audio.Header)); } writer.WriteLine(soundsAudio); foreach (XAudio audio in soundListView.Items) { writer.WriteLine(define + "audio." + audio.Alias + eQuote(soundsFolder + audio.Header)); } writer.WriteLine(voiceAudio); foreach (XAudio audio in voiceListView.Items) { writer.WriteLine(define + "audio." + audio.Alias + eQuote(voicesFolder + audio.Header)); } writer.WriteLine(Movies); foreach (XMovie movie in movieListView.Items) { string mask = ""; if (movie.MaskPath != null) { mask = ", mask" + eQuote(moviesFolder + movie.MaskPath); } writer.WriteLine("image " + movie.Alias + "=Movie(play" + eQuote(moviesFolder + movie.Header) + mask + ")"); } writer.WriteLine(Characters); for (int i = 4; i < characterList.Count; i++) { XCharacter chosenCharacter = characterList[i] as XCharacter; string icon = "", color = "", nvl = "", bold = "", italic = "", what_color = "", what_bold = "", what_italic = ""; if (chosenCharacter.IsNvl) { nvl = ", kind=nvl"; } if (chosenCharacter.Icon != null) { icon = ", image" + eQuote(chosenCharacter.Alias); writer.WriteLine("image side " + chosenCharacter.Alias + eQuote(chosenCharacter.Content.ToString())); } if (chosenCharacter.NameColor.ToString() != "") { color = ", color" + eQuote(chosenCharacter.NameColor.ToString().Remove(1, 2)); } if (chosenCharacter.NameIsBold) { bold = ", who_bold=True"; } if (chosenCharacter.NameIsItalic) { italic = ", who_italic=True"; } if (chosenCharacter.TextColor.ToString() != "") { what_color = ", what_color" + eQuote(chosenCharacter.TextColor.ToString().Remove(1, 2)); } if (chosenCharacter.TextIsBold) { what_bold = ", what_bold=True"; } if (chosenCharacter.TextIsItalic) { what_italic = ", what_italic=True"; } writer.WriteLine(define + chosenCharacter.Alias + character + quote(chosenCharacter.Content.ToString()) + nvl + icon + color + bold + italic + what_color + what_bold + what_italic + ")"); } //end init //labels for (int chosenLabelNumber = 0; chosenLabelNumber < tabControlStruct.Items.Count - 1; chosenLabelNumber++) { writer.WriteLine(nextLine + label + (tabControlStruct.Items[chosenLabelNumber] as XLabel).Text + ':'); for (int chosenFrameNumber = 0; chosenFrameNumber < ((tabControlStruct.Items[chosenLabelNumber] as XLabel).Content as ListView).Items.Count; chosenFrameNumber++) { //все что касается конкретного кадра XFrame chosenFrame = ((tabControlStruct.Items[chosenLabelNumber] as XLabel).Content as ListView).Items[chosenFrameNumber] as XFrame; //background ImageBackProperties BackProp; if (BackInFrameProps.Any(prop => prop.StopFrame == chosenFrame)) { BackProp = BackInFrameProps.First(prop => prop.StopFrame == chosenFrame); string animationType = ""; if (BackProp.AnimationOutType != 0) { animationType = " with " + animationOutTypeComboBox.Items[BackProp.AnimationOutType]; } writer.WriteLine(tab + "hide " + BackProp.Image.Alias + animationType); } if (BackInFrameProps.Any(prop => prop.Frame == chosenFrame)) { BackProp = BackInFrameProps.First(prop => prop.Frame == chosenFrame); string animationType = ""; if (BackProp.AnimationInType != 0) { animationType = " with " + animationInTypeComboBox.Items[BackProp.AnimationInType]; } writer.WriteLine(tab + "scene " + BackProp.Image.Alias + animationType); } //images if (ImageInFrameProps.Any(prop => prop.StopFrame == chosenFrame)) { foreach (ImageCharProperties property in ImageInFrameProps.Where(prop => prop.StopFrame == chosenFrame)) { string animationType = ""; if (property.AnimationOutType != 0) { animationType = " with " + animationOutTypeComboBox.Items[property.AnimationOutType]; } writer.WriteLine(tab + "hide " + property.Image.Alias + animationType); } } if (ImageInFrameProps.Any(prop => prop.Frame == chosenFrame)) { foreach (ImageCharProperties property in ImageInFrameProps.Where(prop => prop.Frame == chosenFrame)) { string align = ""; string animationType = ""; if (property.Align != 0) { align = " at " + alignComboBox.Items[property.Align]; } if (property.AnimationInType != 0) { animationType = " with " + animationInTypeComboBox.Items[property.AnimationInType]; } writer.WriteLine(tab + "show " + property.Image.Alias + align + animationType); } } //audio if (AudioInFrameProps.Any(mus => mus.StopFrame == chosenFrame)) { foreach (AudioProperties property in AudioInFrameProps.Where(prop => (prop.StopFrame == chosenFrame))) { if (property.Audio.Type == "music ") { writer.WriteLine(tab + "stop music"); } else if (property.Audio.Type == "sound ") { writer.WriteLine(tab + "stop sound"); } else { writer.WriteLine(tab + "stop voice"); } } } if (AudioInFrameProps.Any(mus => mus.Frame == chosenFrame)) { string fadein = ""; string fadeout = ""; string loop = ""; foreach (AudioProperties property in AudioInFrameProps.Where(prop => (prop.Frame == chosenFrame))) { if (property.FadeIn != 0) { fadein = " fadein " + property.FadeIn; } if (property.FadeOut != 0) { fadeout = " fadeout " + property.FadeOut; } if (!property.Loop && property.Audio.Type == "music ") { loop = " noloop"; } else if (property.Loop && !(property.Audio.Type == "music ")) { loop = " loop"; } writer.WriteLine(tab + "play " + property.Audio.Type + property.Audio.Alias + fadein + fadeout + loop); } } //movie if (chosenFrame.Movie != null) { writer.WriteLine(tab + "$ renpy.movie_cutscene(" + quote(chosenFrame.Movie.Content.ToString()) + ")"); } //menu if (chosenFrame.MenuOptions != null) { writer.WriteLine(tab + "menu:"); if (chosenFrame.Text != "") { writer.WriteLine(tab + tab + quote(chosenFrame.Text)); } foreach (XMenuOption option in chosenFrame.MenuOptions) { string optionLabel = ""; writer.WriteLine(tab + tab + quote(option.Choice) + ':'); if (option.MenuAction.SelectedItem != passAction) { optionLabel = " " + (option.ActionLabel.SelectedItem as ComboBoxItem).Content.ToString(); } writer.WriteLine(tab + tab + tab + (option.MenuAction.SelectedItem as ComboBoxItem).Content + optionLabel); } } else { //Character and text string character = ""; if (chosenFrame.Character != charNone) { character = chosenFrame.Character.Alias + " "; } writer.WriteLine(tab + character + quote(chosenFrame.Text)); } } writer.WriteLine(tab + Return); } writer.Close(); fs.Close(); }
private void loadScript() { //код для загрузки script.rpy FileStream fs = new FileStream(projectFolder + "script.rpy", FileMode.Open); StreamReader readerlabels = new StreamReader(fs); while (!readerlabels.EndOfStream) { string label = readerlabels.ReadLine().TrimStart(' '); if (label.StartsWith("label")) { ListView newLabel = createLabel(label.Substring(6, label.Length - 7)); } } readerlabels.Dispose(); fs.Dispose(); fs = new FileStream(projectFolder + "script.rpy", FileMode.Open); StreamReader reader = new StreamReader(fs); //контент ОЧЕНЬ неоднозначен, потому для его правильного распознания нужен код и в init, и в метках string singleLine; while (!reader.EndOfStream) { singleLine = reader.ReadLine().TrimStart(' '); if (singleLine.StartsWith("define")) { if (singleLine.Contains("Character")) { XCharacter character = loadCharacter(singleLine); characterList.Add(character); } else if (singleLine.Contains("audio.")) { XAudio audio = new XAudio(); audio.loadAudio(singleLine, projectFolder + game); audioMouseActions(audio); musicListView.Items.Add(audio); } } else if (singleLine.StartsWith("image")) { if (!singleLine.Contains("Movie")) { XImage image = new XImage(); image.loadImage(singleLine, projectFolder + "images\\"); imageMouseActions(image); if (!singleLine.StartsWith("image side")) { backImageListView.Items.Add(image); } else { image.Checkbox.Visibility = Visibility.Hidden; sideListView.Items.Add(image); } } else { XMovie movie = new XMovie(); movie.loadMovie(singleLine, projectFolder + "movies\\"); movieMouseActions(movie); movieListView.Items.Add(movie); } } else if (singleLine.StartsWith("label")) { XLabel selectedLabel = tabControlStruct.Items.OfType <XLabel>().First(label => label.Text == singleLine.Substring(6, singleLine.Length - 7)); selectedLabel.IsSelected = true; XFrame frame; bool buildmenu = false; bool firstframe = true; singleLine = reader.ReadLine().Trim(' '); while (singleLine != "return" && !reader.EndOfStream) { frame = createFrame(); currentFrame = frame; (selectedLabel.Content as ListView).Items.Add(frame); if (firstframe) { setPreviousFrames(); firstframe = false; } else { previousFrames.Add(frame); } List <string> framebody = new List <string> { }; while (singleLine != "return" && !reader.EndOfStream) { if (singleLine.StartsWith("menu")) { buildmenu = true; frame.MenuOptions = new ObservableCollection <XMenuOption> { }; } else if (Regex.IsMatch(singleLine, @"[\S\s]*""[\S\s]*"":$")) { XMenuOption newmenuoption = createMenuOption(frame.MenuOptions.Count == 0); newmenuoption.Choice = value(singleLine); singleLine = reader.ReadLine().Trim(' '); if (singleLine.StartsWith("jump")) { newmenuoption.MenuAction.SelectedItem = jumpAction; newmenuoption.ActionLabel.SelectedIndex = menuLabelList.IndexOf(menuLabelList.First(label => label.Content.ToString() == singleLine.Substring(singleLine.IndexOf(' ') + 1))); (tabControlStruct.Items[newmenuoption.ActionLabel.SelectedIndex] as XLabel).MenuChoice = frame; } else if (singleLine.StartsWith("call")) { newmenuoption.MenuAction.SelectedItem = callAction; newmenuoption.ActionLabel.SelectedIndex = menuLabelList.IndexOf(menuLabelList.First(label => label.Content.ToString() == singleLine.Substring(singleLine.IndexOf(' ') + 1))); (tabControlStruct.Items[newmenuoption.ActionLabel.SelectedIndex] as XLabel).MenuChoice = frame; } else { newmenuoption.MenuAction.SelectedItem = passAction; } frame.MenuOptions.Add(newmenuoption); } else if (Regex.IsMatch(singleLine, @"[\S\s]*""[\S\s]*""$")) { if (buildmenu && frame.MenuOptions.Count != 0) { break; } loadText(frame, singleLine); if (!buildmenu) { break; } } else { if (!buildmenu) { framebody.Add(singleLine); } else { break; } } singleLine = reader.ReadLine().Trim(' '); } for (int line = 0; line < framebody.Count; line++) { if (framebody[line].StartsWith("scene")) { string[] all = framebody[line].Split(' '); XImage selectedImage = backImageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]); ImageBackProperties BackProp = new ImageBackProperties() { Frame = frame, Image = selectedImage }; if (all.Length > 2) { if (all[2] == "with") { BackProp.AnimationInType = (byte)animationInTypeComboBox.Items.IndexOf(animationInTypeComboBox.Items.OfType <string>().First(item => item == all[3])); } } //секция поиска if (BackInFrameProps.Any(prop => previousFrames.Contains(prop.Frame) && !previousFrames.Contains(prop.StopFrame))) { ImageBackProperties previous = BackInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && !previousFrames.Contains(prop.StopFrame)); //а вдруг меню, а мы неподготовлены? надо расставить все нужные метки if (previous.Frame.MenuOptions == null) { previous.StopFrame = frame; } else { if (previous.StopFrames == null) { previous.StopFrames = new List <XFrame> { } } ; previous.StopFrames.Add(frame); }; } //усьо BackInFrameProps.Add(BackProp); } else if (framebody[line].StartsWith("show")) { string[] all = framebody[line].Split(' '); XImage selectedImage; if (backImageListView.Items.OfType <XImage>().Any(item => item.Alias == all[1])) { selectedImage = backImageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]); backImageListView.Items.Remove(selectedImage); imageListView.Items.Add(selectedImage); } else { selectedImage = imageListView.Items.OfType <XImage>().First(item => item.Alias == all[1]); } ImageCharProperties props = new ImageCharProperties() { Frame = frame, Image = selectedImage, Displayable = newDisplayable() }; props.Displayable.Source = imageShow(selectedImage.Path); for (int i = 2; i < all.Length; i++) { if (all[i] == "with") { props.AnimationInType = (byte)animationInTypeComboBox.Items.IndexOf(animationInTypeComboBox.Items.OfType <string>().First(item => item == all[i + 1])); } else if (all[i] == "at") { props.Align = (byte)alignComboBox.Items.IndexOf(alignComboBox.Items.OfType <string>().First(item => item == all[i + 1])); } } ImageInFrameProps.Add(props); } else if (framebody[line].StartsWith("hide")) { string[] all = framebody[line].Split(' '); if (backImageListView.Items.OfType <XImage>().Any(prop => prop.Alias == all[1])) { ImageBackProperties previous = BackInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Image.Alias == all[1]); if (all.Length > 2) { if (all[2] == "with") { previous.AnimationOutType = (byte)animationOutTypeComboBox.Items.IndexOf(animationOutTypeComboBox.Items.OfType <string>().First(item => item == all[3])); } } if (previous.Frame.MenuOptions == null) { previous.StopFrame = frame; } else { if (previous.StopFrames == null) { previous.StopFrames = new List <XFrame> { } } ; previous.StopFrames.Add(frame); }; } else { ImageCharProperties previous = ImageInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Image.Alias == all[1]); if (all.Length > 2) { if (all[2] == "with") { previous.AnimationOutType = (byte)animationOutTypeComboBox.Items.IndexOf(animationOutTypeComboBox.Items.OfType <string>().First(item => item == all[3])); } } if (previous.Frame.MenuOptions == null) { previous.StopFrame = frame; } else { if (previous.StopFrames == null) { previous.StopFrames = new List <XFrame> { } } ; previous.StopFrames.Add(frame); }; } } else if (framebody[line].StartsWith("stop")) { string type = framebody[line].Substring(5) + " "; AudioProperties previous = AudioInFrameProps.Last(prop => previousFrames.Contains(prop.Frame) && prop.Audio.Type == type); if (previous.Frame.MenuOptions == null) { previous.StopFrame = frame; } else { if (previous.StopFrames == null) { previous.StopFrames = new List <XFrame> { } } ; previous.StopFrames.Add(frame); }; } else if (framebody[line].StartsWith("play")) { string[] all = framebody[line].Split(' '); XAudio audio = musicListView.Items.OfType <XAudio>().First(item => item.Alias == all[2]); if (all[1] != "music") { musicListView.Items.Remove(audio); if (all[1] == "sound") { soundListView.Items.Add(audio); } else { voiceListView.Items.Add(audio); } } AudioProperties props = new AudioProperties() { Frame = frame, Audio = audio }; for (int i = 2; i < all.Length; i++) { if (all[i] == "fadein") { props.FadeIn = float.Parse(all[i + 1]); } else if (all[i] == "fadeout") { props.FadeOut = float.Parse(all[i + 1]); } else if (all[i] == "noloop") { props.Loop = false; } } AudioInFrameProps.Add(props); } } if (singleLine != "return") { if (buildmenu) { buildmenu = false; } else { frame.IsSelected = true; singleLine = reader.ReadLine().TrimStart(' '); } } } } } previousFrames.Clear(); fs.Close(); }
private void characterSetProperties(XCharacter character) { character.Content = characterName.Text; character.ContentToAlias(); if (characterNvl.IsChecked == true) { character.IsNvl = true; } try { character.NameColor = (Color)charName_colorPicker.SelectedColor; } catch (Exception) { }; try { character.TextColor = (Color)charText_colorPicker.SelectedColor; } catch (Exception) { }; if (characterNameBold.IsChecked == true) { character.NameIsBold = true; } else { character.NameIsBold = false; } if (characterNameItalic.IsChecked == true) { character.NameIsItalic = true; } else { character.NameIsItalic = false; } if (characterTextBold.IsChecked == true) { character.TextIsBold = true; } else { character.TextIsBold = false; } if (characterTextItalic.IsChecked == true) { character.TextIsItalic = true; } else { character.TextIsItalic = false; } if (iconCharacter.Source != null) { character.Icon = sideListView.Items.OfType <XImage>().First(sideimage => (new Uri(sideimage.Path).ToString() == iconCharacter.Source.ToString())); } if (charText_colorPicker.SelectedColor != Brushes.Transparent.Color) { character.Background = new SolidColorBrush((Color)charText_colorPicker.SelectedColor); } else { character.Background = null; } if (charName_colorPicker.SelectedColor != Brushes.Transparent.Color) { character.Foreground = new SolidColorBrush((Color)charName_colorPicker.SelectedColor); } else { character.Foreground = Brushes.Black; } }