public WindowColors() { InitializeComponent(); FontSize = 14; colors = new List <ColorRow>(); var AddColor = new Action <string, object, Color, Action <Color> >((key, o, color, action) => { string content; if (o is L4D2MM.ModState) { content = o.GetString(); } else { content = StringAdapter.GetResource(o.ToString()); } colors.Add(new ColorRow(StringAdapter.GetResource(key) + '.' + content, color, action)); }); AddColor("Indicator", "Normal", Configure.View.IndicatorNormal, c => Configure.View.IndicatorNormal = c); AddColor("Indicator", "Ignored", Configure.View.IndicatorIgnore, c => Configure.View.IndicatorIgnore = c); AddColor("Indicator", "Conflicted", Configure.View.IndicatorCollision, c => Configure.View.IndicatorCollision = c); AddColor("State", L4D2MM.ModState.Unregisted, Configure.View.StateUnregisted, c => Configure.View.StateUnregisted = c); AddColor("State", L4D2MM.ModState.Unsubscribed, Configure.View.StateUnsubscribed, c => Configure.View.StateUnsubscribed = c); AddColor("State", L4D2MM.ModState.Miss, Configure.View.StateMiss, c => Configure.View.StateMiss = c); AddColor("State", L4D2MM.ModState.Off, Configure.View.StateOff, c => Configure.View.StateOff = c); AddColor("State", L4D2MM.ModState.On, Configure.View.StateOn, c => Configure.View.StateOn = c); int Col = 3; int Row = colors.Count; while (Col-- > 0) { ColumnDefinition cd = new ColumnDefinition(); cd.Width = new GridLength(); ctlGrid.ColumnDefinitions.Add(cd); } while (Row-- > 0) { RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(); ctlGrid.RowDefinitions.Add(rd); } var GirdAction = new Action <UIElement, int, int>((ctl, col, row) => { ctlGrid.Children.Add(ctl); Grid.SetColumn(ctl, col); Grid.SetRow(ctl, row); }); foreach (var c in colors) { var row = colors.IndexOf(c); GirdAction(c.Label, 0, row); GirdAction(c.Border, 1, row); GirdAction(c.TextBox, 2, row); } }
private void OnTextBoxLostFocus(object sender, RoutedEventArgs e) { string text = TextBox.Text; object color = null; try { color = Newtonsoft.Json.JsonConvert.DeserializeObject <Color>('"' + text + '"'); } catch { color = null; } if (color == null) { MessageBox.Show(StringAdapter.GetResource("Invalid_Value") + "\r\n" + text); } else { if (!Color.Equals((Color)color)) { SetColor((Color)color); Callback((Color)color); } } }
private void ButtonOkClick(object sender, RoutedEventArgs e) { bool valid = false; bool convert = true; object o = null; try { o = Newtonsoft.Json.JsonConvert.DeserializeObject(ctlTextBox.Text, InitializeValue.GetType()); } catch { convert = false; } if (convert && Verify(o)) { InputValue = o; valid = true; this.Close(); } if (!valid) { var msg = StringAdapter.GetResource("Invalid_Value"); if (VerifyErrorMsg != null) { msg += "\r\n" + VerifyErrorMsg; } MessageBox.Show(msg); } }
private void MenuItemAboutClick(object sender, RoutedEventArgs e) { MessageBox.Show( StringAdapter.GetInfo("About") + '.' + "\r\n" + StringAdapter.GetResource("License") + " : MIT" + "\r\n" + StringAdapter.GetResource("Project") + " : https://github.com/XavierCai1996/L4D2ModManager" + "\r\n" + StringAdapter.GetResource("Contact") + " : [email protected]" , StringAdapter.GetResource("About")); }
private void MenuItemLocalModClassificationRuleClick(object sender, RoutedEventArgs e) { var window = new WindowClassify(); window.Title = StringAdapter.GetResource("Menu_LocalModClassificationRule"); window.FontSize = FontSize; window.Owner = this; window.ShowDialog(); }
public ComboItem(object value, object category, bool special = false) { Value = value; Category = category; if (!special) { Converter = o => (o as L4D2Type.Category)?.Name; } else { Converter = o => "---" + StringAdapter.GetResource(Value as string) + "---"; } }
private void MenuItemCustomCategoryClick(object sender, RoutedEventArgs e) { var window = new WindowCategory(); window.Title = StringAdapter.GetResource("Menu_CustomCategory"); window.FontSize = FontSize; window.Owner = this; window.ShowDialog(); m_categorySelected.Refresh(); LoadModInfo(LoadedModInfo); foreach (var mod in m_manager.Mods.Values) { mod.RefreshResources(); } }
private bool SetGamePath() { //require [Windows API Code Pack] //in Visual Studio, open [Tool->Package Manager Consol] //input the command [Install-Package WindowsAPICodePack-Shell] var dialog = new Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog(); dialog.IsFolderPicker = true; Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult result = dialog.ShowDialog(); if (result != Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Ok) { return(false); } Configure.InstallPath = dialog.FileName; WindowCallbacks.Print(StringAdapter.GetResource("Menu_SetPath") + " : " + dialog.FileName); return(true); }
private void MenuItemFontSizeClick(object sender, RoutedEventArgs e) { double oldFontSize = FontSize; var window = new WindowSetValue(); window.Owner = this; window.Initialize(FontSize, StringAdapter.GetResource("Menu_FontSize"), StringAdapter.GetResource("Font_Size")); window.Verify = o => (double)o >= 6 && (double)o <= 30; window.VerifyErrorMsg = "-> [6.0, 30.0]"; window.FontSize = FontSize; window.ShowDialog(); if (window.InputValue != null) { this.FontSize = (double)window.InputValue; ctlMenu.FontSize = this.FontSize; Configure.View.FontSize = this.FontSize; } }
public MainWindow() { InitializeComponent(); //UI this.FontSize = Configure.View.FontSize; ctlMenu.FontSize = Configure.View.FontSize; this.SetSize(Configure.View.WindowSize); foreach (var col in CustomInformation.Instance.ViewLists) { if (CheckModInfoReflection(col.Reflection)) { var textBlockFactory = new FrameworkElementFactory(typeof(TextBlock)); textBlockFactory.SetValue(TextElement.ForegroundProperty, Brushes.Black); textBlockFactory.SetBinding(TextBlock.TextProperty, new System.Windows.Data.Binding("Mod") { Converter = new StringDisplayConverter(), ConverterParameter = "Mod." + col.Reflection }); textBlockFactory.SetValue(TextBlock.TextAlignmentProperty, col.TextAlignment); GridViewColumn column = new GridViewColumn(); column.Header = col.TryTranslate ? StringAdapter.GetResource(col.Header) : col.Header; column.Width = col.Width; column.CellTemplate = new DataTemplate { VisualTree = textBlockFactory }; ctlGridView.Columns.Add(column); SortReflectionMap.Add(column, col.Reflection); } } //new m_manager = new L4D2MM(); m_categorySelected = new CategorySelecter(ctlCategoryList, ctlSubcategoryList, ctlTextSearch, ctlListView); //initialize property ctlPrintText.AppendText(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + " [version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + ']'); ctlProgressBar.SetValue(ProgressBar.ValueProperty, 100.0); InitializeListViewMenu(); InitializeWindowMenu(); }
private bool CheckConfig(string path) { //check path valid if (path == null) { Logging.Log("invalid path"); return(false); } WindowCallbacks.Print(StringAdapter.GetResource("Path") + " : " + path); if (!Directory.Exists(path + m_dirCore)) { Logging.Log("can not find main directory"); return(false); } if (!File.Exists(path + m_fileList)) { Logging.Log("can not find addons list file"); WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_fileList); File.WriteAllText(path + m_fileList, "\"AddonList\"\n{\n}\n"); //create it //return false; } if (!Directory.Exists(path + m_dirAddons)) { Logging.Log("can not find addons directory"); Directory.CreateDirectory(path + m_dirAddons); WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_dirAddons); //return false; } if (!Directory.Exists(path + m_dirWorkshop)) { Logging.Log("can not find addons directory"); Directory.CreateDirectory(path + m_dirWorkshop); WindowCallbacks.Print(StringAdapter.GetResource("Create") + " : " + path + m_dirWorkshop); //return false; } return(true); }
public void Initialize <T>(T value) { Initialize(value, "", StringAdapter.GetResource("Value")); }
private void InitializeListViewMenu() { ContextMenu menu = new ContextMenu(); var menuItemConfirm = new Dictionary <string, Func <bool> >(); var menuItemClick = new Dictionary <string, Func <L4D2MM.ModInfo, bool> >(); RoutedEventHandler OnMenuItemClick = (o, e) => { var name = (o as MenuItem).Name; if (!menuItemClick.ContainsKey(name)) { return; } if (menuItemConfirm.ContainsKey(name)) { if (!menuItemConfirm[name]()) { return; } } var items = ctlListView.SelectedItems; if (items == null || items.Count <= 0) { return; } var func = menuItemClick[name]; int count = 0; object[] copy = new object[items.Count]; items.CopyTo(copy, 0); string firstName = (items[0] as ViewItem).Key; foreach (var item in copy) { if (func((item as ViewItem).Mod)) { count++; } } StringBuilder sb = new StringBuilder(); sb.Append(StringAdapter.GetResource("Operation") + " : " + (o as MenuItem).Header as string + " : "); if (copy.Length > 1) { sb.Append(StringAdapter.GetResource("Success") + ' ' + count.ToString() + " / " + StringAdapter.GetResource("Selected") + ' ' + copy.Length.ToString()); } else { sb.Append(firstName); } WindowCallbacks.Print(sb.ToString()); ctlListView.Items.Refresh(); m_manager.SaveModState(); }; var menuItemMap = new Dictionary <string, MenuItem>(); Func <string, Func <bool>, Func <L4D2MM.ModInfo, bool>, MenuItem> GenerateMenuItem = (name, confirm, func) => { MenuItem btn = new MenuItem(); btn.Name = name; btn.Click += OnMenuItemClick; btn.Header = StringAdapter.GetResource(name); menuItemConfirm.Add(name, confirm); menuItemClick.Add(name, func); menuItemMap.Add(name, btn); return(btn); }; Func <string, Func <L4D2MM.ModInfo, bool>, MenuItem> GenerateMenuItemWithoutConfirm = (name, func) => { return(GenerateMenuItem(name, () => { return true; }, func)); }; menu.Items.Add(GenerateMenuItemWithoutConfirm("On", o => { return(o.SetOn()); })); menu.Items.Add(GenerateMenuItemWithoutConfirm("Off", o => { return(o.SetOff()); })); menu.Items.Add(new Separator()); menu.Items.Add(GenerateMenuItemWithoutConfirm("Subscribe", o => { return(o.Subscribe()); })); menu.Items.Add(GenerateMenuItemWithoutConfirm("Unsubscribe", o => { return(o.Unsubscribe()); })); menu.Items.Add(new Separator()); menu.Items.Add(GenerateMenuItemWithoutConfirm("Ignore_Collision", o => { return(o.IgnoreCollision()); })); menu.Items.Add(GenerateMenuItemWithoutConfirm("Detect_Collision", o => { return(o.DetectCollision()); })); menu.Items.Add(new Separator()); menu.Items.Add(GenerateMenuItem("Delete", () => { return(CtlExtension.ConfirmBox(StringAdapter.GetInfo("ConfirmDeleteFile"))); }, o => { bool ret = o.Delete(); m_categorySelected.Update(m_manager); return(ret); })); ctlListView.ContextMenu = menu; FindListViewMenuItem = name => menuItemMap[name]; }
void GridViewColumnHeaderClickedHandler(object sender, RoutedEventArgs e) { var headerClicked = e.OriginalSource as GridViewColumnHeader; if (headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) { Comparison <ViewItem> method = null; if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModId"))) { method = (a, b) => a.ID.CompareTo(b.ID); } else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModSource"))) { method = (a, b) => a.Source.CompareTo(b.Source); } else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModState"))) { method = (a, b) => a.State.CompareTo(b.State); } else if (headerClicked.Content.Equals(StringAdapter.GetResource("Col_ModSize"))) { method = (a, b) => a.Mod.Mod.FileSize.CompareTo(b.Mod.Mod.FileSize); } else if (SortReflectionMap.ContainsKey(headerClicked.Column)) { method = (a, b) => { var reflection = SortReflectionMap[headerClicked.Column]; var oa = typeof(L4D2Mod).InvokeMember(reflection, System.Reflection.BindingFlags.GetProperty, null, a.Mod.Mod, null); var ob = typeof(L4D2Mod).InvokeMember(reflection, System.Reflection.BindingFlags.GetProperty, null, b.Mod.Mod, null); if (oa is IComparable && ob is IComparable) { return((oa as IComparable).CompareTo(ob)); } return(oa.Display().CompareTo(ob.Display())); } } ; else { return; } if (method == null) { return; } else { if (SortMethodId.Equals(0)) { m_categorySelected.Sort(null); } else { m_categorySelected.Sort((a, b) => SortMethodId * method(a, b)); } } SortMethodId += 1; if (SortMethodId > 1) { SortMethodId = -1; } } }
private void LoadModInfo(L4D2MM.ModInfo mod) { if (mod == null) { return; } LoadedModInfo = mod; var fontSize = this.FontSize; m_displayedKey = mod.Key; ctlFrameText.Document.Blocks.Clear(); if (mod.Mod.ImageMemoryStream != null) { ctlImage.SetSource(mod.Mod.GetAndResetImageMemoryStream()); } else { ctlImage.SetSource(null);//or show the default image } if (mod.Mod.Title.Length > 0) { Run run = new Run(mod.Mod.Title); run.FontSize = fontSize + 4; run.Foreground = new SolidColorBrush(Colors.Black); run.FontWeight = FontWeights.Bold; ctlFrameText.Document.Blocks.Add(new Paragraph(run)); } if (mod.Mod.Category.Count > 0) { Run run = new Run(StringAdapter.GetResource("Category") + " : " + mod.Mod.Category.Aggregate("", (s, c) => s += ", " + c.ToString()).Substring(2)); run.FontSize = fontSize; run.Foreground = new SolidColorBrush(Colors.Gray); run.FontWeight = FontWeights.Normal; ctlFrameText.Document.Blocks.Add(new Paragraph(run)); } foreach (var box in CustomInformation.Instance.ViewBoxes) { if (CheckModInfoReflection(box.Reflection)) { string content = (box.TryTranslate ? StringAdapter.GetResource(box.Header) : box.Header) + " : \r\n"; string reflection = typeof(L4D2Mod).InvokeMember(box.Reflection, System.Reflection.BindingFlags.GetProperty, null, mod.Mod, null).Display(); if (reflection.Length > 0) { Run run = new Run(content + reflection); run.FontSize = fontSize; run.Foreground = new SolidColorBrush(box.Color); run.FontWeight = FontWeights.Normal; ctlFrameText.Document.Blocks.Add(new Paragraph(run)); } } } if (ctlFrameText.Document.Blocks.Count <= 0) { Run run = new Run('(' + StringAdapter.GetResource("No_Information") + ')'); run.FontSize = fontSize; run.Foreground = new SolidColorBrush(Colors.Gray); run.FontWeight = FontWeights.Normal; ctlFrameText.Document.Blocks.Add(new Paragraph(run)); } }