static void CreateNullChange(string file, string message) { StartTroopChange change = new StartTroopChange(Path.GetFileNameWithoutExtension(file).Replace("UCP.Startup.Resources.Troops.", "UCP."), false) { new DefaultHeader("s_" + file, false) { new BinaryEdit(troopBlockFile) { new BinSkip(0x50), }, new BinaryEdit(lordStrengthBlockFile) { new BinSkip(0x80), }, new BinaryEdit(lordTypeBlockFile) { new BinSkip(0x16), } } }; change.description = message; change.IsValid = false; changes.Add(change); }
private void Refresh(object s, RoutedEventArgs e, TreeView view) { String activeChange = StartTroopChange.activeChange == null ? String.Empty : StartTroopChange.activeChange.TitleIdent; for (int i = 0; i < StartTroopChange.changes.Count; i++) { view.Items.Remove(StartTroopChange.changes.ElementAt(i).UIElement); Localization.Remove(StartTroopChange.changes.ElementAt(i).TitleIdent + "_descr"); } StartTroopChange.Refresh(s, e); foreach (StartTroopChange change in StartTroopChange.changes) { change.InitUI(); view.Items.Add(change.UIElement); } if (StartTroopChange.changes.Select(x => x.TitleIdent).Contains(activeChange)) { foreach (StartTroopChange change in StartTroopChange.changes) { if (change.TitleIdent == activeChange) { change.IsChecked = true; } } } }
protected override void TitleBox_Unchecked(object sender, RoutedEventArgs e) { base.TitleBox_Unchecked(sender, e); if (activeChange == this) { selectedChange = String.Empty; activeChange = null; } }
protected override void TitleBox_Checked(object sender, RoutedEventArgs e) { base.TitleBox_Checked(sender, e); if (activeChange != null) { activeChange.IsChecked = false; } selectedChange = this.TitleIdent; activeChange = this; }
private static void Load(string fileName) { StreamReader reader; if (fileName.StartsWith("UCP.Startup")) { reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(fileName), Encoding.UTF8); } else { reader = new StreamReader(new FileStream(fileName, FileMode.Open), Encoding.UTF8); } string starttroopsText = reader.ReadToEnd(); reader.Close(); string startTroopConfigName = Path.GetFileNameWithoutExtension(fileName); JavaScriptSerializer serializer = new JavaScriptSerializer(); Dictionary <String, Dictionary <String, Object> > startTroopConfig; try { startTroopConfig = serializer.Deserialize <Dictionary <String, Dictionary <String, Object> > >(starttroopsText); } catch (Exception) { CreateNullChange(Path.GetFileNameWithoutExtension(startTroopConfigName), "Invalid JSON detected"); return; } try { string description = GetLocalizedDescription(startTroopConfigName, startTroopConfig); StartTroopChange change = new StartTroopChange(startTroopConfigName.Replace("UCP.Startup.Resources.Troops.", "UCP."), false) { CreateStartTroopHeader(startTroopConfigName.Replace("UCP.Startup.Resources.Troops.", "UCP."), startTroopConfig), }; change.description = description; changes.Add(change); } //TODO error handling! catch (Exception e) { CreateNullChange(Path.GetFileNameWithoutExtension(startTroopConfigName).Replace(" ", ""), e.Message); File.AppendAllText("StartTroopsParsing.log", "\n" + startTroopConfigName + ": " + e.Message + "\n"); } }
public override void InitUI() { Localization.Add(this.TitleIdent + "_descr", this.description); base.InitUI(); if (this.IsChecked) { activeChange = this; } ((TextBlock)this.titleBox.Content).Text = this.TitleIdent.Substring(2).Replace("UCP.", ""); if (this.IsValid == false) { ((TextBlock)this.titleBox.Content).TextDecorations = TextDecorations.Strikethrough; this.titleBox.IsEnabled = false; this.titleBox.ToolTip = this.description; ((TextBlock)this.titleBox.Content).Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } else { this.titleBox.IsChecked = selectedChange.Equals(this.TitleIdent); } this.titleBox.Background = this.TitleIdent.Substring(2).StartsWith("UCP.") ? new SolidColorBrush(Colors.White) : new SolidColorBrush(Colors.Bisque); if (this.TitleIdent.Substring(2).StartsWith("UCP.")) { Button exportButton = new Button() { //Width = 40, Height = 20, Content = Localization.Get("ui_aicexport"), HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Bottom, Margin = new Thickness(0, 0, 5, 5), }; exportButton.Click += (s, e) => this.ExportFile(); grid.Height += 15; this.grid.Children.Add(exportButton); } }
public override void InitUI() { Localization.Add(this.TitleIdent + "_descr", this.description); base.InitUI(); if (this.IsChecked) { activeChange = this; } ((TextBlock)this.titleBox.Content).Text = this.TitleIdent.Substring(2); if (this.IsValid == false) { ((TextBlock)this.titleBox.Content).TextDecorations = TextDecorations.Strikethrough; this.titleBox.IsEnabled = false; this.titleBox.ToolTip = this.description; ((TextBlock)this.titleBox.Content).Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); } else { this.titleBox.IsChecked = selectedChange.Equals(this.TitleIdent); } this.titleBox.Background = new SolidColorBrush(Colors.White); }