private static void DefaultPushButtonInput(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { // TODO: Capture input on mouse down. // TODO: Only fire click event when mouse was pressed and released inside same button. switch (message.MessageType) { case WndWindowMessageType.MouseEnter: element.CurrentState = WndWindowState.Highlighted; break; case WndWindowMessageType.MouseExit: element.CurrentState = WndWindowState.Enabled; break; case WndWindowMessageType.MouseDown: element.CurrentState = WndWindowState.HighlightedPushed; break; case WndWindowMessageType.MouseUp: element.CurrentState = WndWindowState.Highlighted; element.Parent.SystemCallback.Invoke( element, new WndWindowMessage(WndWindowMessageType.SelectedButton, element), context); break; } }
public static void PassSelectedButtonsToParentSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { if (message.MessageType != WndWindowMessageType.SelectedButton) { return; } element.Parent.SystemCallback.Invoke(element.Parent, message, context); }
protected WindowTransitionOperation(WndWindow element, TimeSpan startTime) { Element = element; StartTime = startTime; Duration = TimeSpan.FromSeconds(FrameDuration / 30.0); EndTime = startTime + Duration; }
public static void MainMenuInput(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { // Any input at all (mouse, keyboard) will trigger the main menu fade-in. if (!_doneMainMenuFadeIn) { context.WindowManager.TransitionManager.QueueTransition(null, element.Window, "MainMenuFade"); context.WindowManager.TransitionManager.QueueTransition(null, element.Window, "MainMenuDefaultMenu"); element.Window.Root.FindChild("MainMenu.wnd:MainMenuRuler").Show(); _doneMainMenuFadeIn = true; } }
private static WndWindow CreateElementRecursive(WndWindowDefinition wndWindow, ContentManager contentManager, WndCallbackResolver wndCallbackResolver) { var result = WndWindow.Create(wndWindow, contentManager, wndCallbackResolver); foreach (var childWindow in wndWindow.ChildWindows) { var child = CreateElementRecursive(childWindow, contentManager, wndCallbackResolver); child.Parent = result; result.Children.Add(child); } return(result); }
public static void QuitMessageBoxSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { switch (message.MessageType) { case WndWindowMessageType.SelectedButton: switch (message.Element.Name) { case "QuitMessageBox.wnd:ButtonCancel": context.WindowManager.PopWindow(); break; } break; } }
public static void OptionsMenuSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { switch (message.MessageType) { case WndWindowMessageType.SelectedButton: switch (message.Element.Name) { case "OptionsMenu.wnd:ButtonBack": context.WindowManager.PopWindow(); break; } break; } }
private static TreeItem CreateTreeItemRecursive(WndWindow element) { var result = new TreeItem { Text = element.DisplayName, Expanded = true, Tag = element }; foreach (var childElement in element.Children) { result.Children.Add(CreateTreeItemRecursive(childElement)); } return(result); }
public WndView(FileSystemEntry entry, Game game) { var scene = new Scene(); game.Scene = scene; var window = game.ContentManager.Load <WndTopLevelWindow>(entry.FilePath); scene.Scene2D.WndWindowManager.PushWindow(window); var treeItem = new TreeItem(); treeItem.Children.Add(CreateTreeItemRecursive(window.Root)); var treeView = new TreeView { Width = 400, DataStore = treeItem }; WndWindow selectedElement = null; treeView.SelectionChanged += (sender, e) => { if (selectedElement != null) { selectedElement.Highlighted = false; selectedElement = null; } selectedElement = (WndWindow)((TreeItem)treeView.SelectedItem).Tag; selectedElement.Highlighted = true; }; Panel1 = treeView; Panel2 = new GameControl { Game = game }; }
public static void ReplayMenuSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { switch (message.MessageType) { case WndWindowMessageType.SelectedButton: switch (message.Element.Name) { case "ReplayMenu.wnd:ButtonLoadReplay": // TODO: Handle no selected item. var listBox = (WndWindowListBox)element.Window.Root.FindChild("ReplayMenu.wnd:ListboxReplayFiles"); ReplayFile replayFile; using (var fileSystem = GetReplaysFileSystem(context.Game)) { var replayFileEntry = fileSystem.GetFile((string)listBox.ListBoxItems[listBox.SelectedIndex].DataItem); replayFile = ReplayFile.FromFileSystemEntry(replayFileEntry); } // TODO: This probably isn't right. var mapFilenameParts = replayFile.Header.Metadata.MapFile.Split('/'); var mapFilename = $"Maps\\{mapFilenameParts[1]}\\{mapFilenameParts[1]}.map"; // TODO: Loading screen. context.Game.Scene3D = context.Game.ContentManager.Load <Scene3D>(mapFilename); context.Game.NetworkMessageBuffer = new NetworkMessageBuffer( context.Game, new ReplayConnection(replayFile)); context.Game.Scene2D.WndWindowManager.PopWindow(); break; case "ReplayMenu.wnd:ButtonBack": context.WindowManager.SetWindow(@"Menus\MainMenu.wnd"); // TODO: Go back to Replay sub-menu break; } break; } }
private Image CreateImage(FrameworkElement parentElement, WndWindow window, int drawDataIndex, Stretch?stretch = null) { var image = new Image(); if (stretch != null) { image.Stretch = stretch.Value; } ; var style = new Style(typeof(Image)); style.Setters.Add(new Setter(Image.SourceProperty, CreateImageSource(window.EnabledDrawData.Items[drawDataIndex].Image))); var hoverImageSource = CreateImageSource(window.HiliteDrawData.Items[drawDataIndex].Image); if (hoverImageSource != null) { style.Triggers.Add(new DataTrigger { Binding = new Binding("IsMouseOver") { Source = parentElement }, Value = true, Setters = { new Setter(Image.SourceProperty, hoverImageSource), } }); } image.Style = style; return(image); }
public static void MainMenuSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { void QueueTransition(string transition) { context.WindowManager.TransitionManager.QueueTransition(null, element.Window, transition); } switch (message.MessageType) { case WndWindowMessageType.SelectedButton: switch (message.Element.Name) { case "MainMenu.wnd:ButtonSinglePlayer": QueueTransition("MainMenuDefaultMenuBack"); QueueTransition("MainMenuSinglePlayerMenu"); break; case "MainMenu.wnd:ButtonSingleBack": QueueTransition("MainMenuSinglePlayerMenuBack"); QueueTransition("MainMenuDefaultMenu"); break; case "MainMenu.wnd:ButtonMultiplayer": QueueTransition("MainMenuDefaultMenuBack"); QueueTransition("MainMenuMultiPlayerMenu"); break; case "MainMenu.wnd:ButtonMultiBack": QueueTransition("MainMenuMultiPlayerMenuReverse"); QueueTransition("MainMenuDefaultMenu"); break; case "MainMenu.wnd:ButtonLoadReplay": QueueTransition("MainMenuDefaultMenuBack"); QueueTransition("MainMenuLoadReplayMenu"); break; case "MainMenu.wnd:ButtonLoadReplayBack": QueueTransition("MainMenuLoadReplayMenuBack"); QueueTransition("MainMenuDefaultMenu"); break; case "MainMenu.wnd:ButtonReplay": context.WindowManager.SetWindow(@"Menus\ReplayMenu.wnd"); break; case "MainMenu.wnd:ButtonOptions": context.WindowManager.PushWindow(@"Menus\OptionsMenu.wnd"); break; case "MainMenu.wnd:ButtonExit": var exitWindow = context.WindowManager.PushWindow(@"Menus\QuitMessageBox.wnd"); exitWindow.Root.FindChild("QuitMessageBox.wnd:StaticTextTitle").Text = "EXIT?"; exitWindow.Root.FindChild("QuitMessageBox.wnd:StaticTextTitle").TextAlignment = TextAlignment.Leading; exitWindow.Root.FindChild("QuitMessageBox.wnd:StaticTextMessage").Text = "Are you sure you want to exit?"; exitWindow.Root.FindChild("QuitMessageBox.wnd:ButtonOk").Show(); exitWindow.Root.FindChild("QuitMessageBox.wnd:ButtonOk").Text = "YES"; exitWindow.Root.FindChild("QuitMessageBox.wnd:ButtonCancel").Show(); exitWindow.Root.FindChild("QuitMessageBox.wnd:ButtonCancel").Text = "NO"; break; } break; } }
public static void PassMessagesToParentSystem(WndWindow element, WndWindowMessage message, UIElementCallbackContext context) { element.Parent.SystemCallback.Invoke(element.Parent, message, context); }
public static void W3DNoDraw(WndWindow element, Game game) { }
public FlashTransition(WndWindow element, TimeSpan startTime) : base(element, startTime) { _startOpacity = element.Opacity; _endOpacity = element.Opacity == 1 ? 0 : 1; }
public WinScaleUpTransition(WndWindow element, TimeSpan startTime) : base(element, startTime) { }
public ReverseSoundTransition(WndWindow element, TimeSpan startTime) : base(element, startTime) { }
private UIElement CreateWindowElement(WndWindow window, FrameworkElement contentElement) { var result = new Border { Name = window.Name.Replace(".", string.Empty).Replace(":", string.Empty), DataContext = window }; var style = new Style(typeof(Border)); var hasBackground = !window.Status.HasFlag(WndWindowStatusFlags.Image); style.Setters.Add(new Setter(TextBlock.ForegroundProperty, new Binding("TextColor.Enabled") { Converter = WndColorToBrushConverter.Instance })); if (hasBackground) { style.Setters.Add(new Setter(Border.BackgroundProperty, new Binding("EnabledDrawData.Items[0].Color") { Converter = WndColorToBrushConverter.Instance })); style.Setters.Add(new Setter(Border.BorderBrushProperty, new Binding("EnabledDrawData.Items[0].BorderColor") { Converter = WndColorToBrushConverter.Instance })); } else { result.Background = Brushes.Transparent; } var trigger = new Trigger { Property = UIElement.IsMouseOverProperty, Value = true, }; trigger.Setters.Add(new Setter(TextBlock.ForegroundProperty, new Binding("TextColor.Hilite") { Converter = WndColorToBrushConverter.Instance })); if (hasBackground) { trigger.Setters.Add(new Setter(Border.BackgroundProperty, new Binding("HiliteDrawData.Items[0].Color") { Converter = WndColorToBrushConverter.Instance })); trigger.Setters.Add(new Setter(Border.BorderBrushProperty, new Binding("HiliteDrawData.Items[0].BorderColor") { Converter = WndColorToBrushConverter.Instance })); } style.Triggers.Add(trigger); result.Style = style; if (hasBackground || window.Status.HasFlag(WndWindowStatusFlags.Border)) { result.BorderThickness = new Thickness(1); } if (window.Status.HasFlag(WndWindowStatusFlags.Hidden) || window.InputCallback == "GameWinBlockInput") { result.Visibility = Visibility.Hidden; } var grid = new Grid(); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto }); //if (result.Name != "MainMenuwndEarthMap2" && result.Name != "MainMenuwndEarthMap") { switch (window.WindowType) { case WndWindowType.GenericWindow: grid.Children.Add(CreateImage(result, window, 0, Stretch.Fill)); Grid.SetColumnSpan(grid.Children[0], 3); break; case WndWindowType.PushButton: grid.Children.Add(CreateImage(result, window, 0)); Grid.SetColumn(grid.Children[0], 0); grid.Children.Add(CreateImage(result, window, 5, Stretch.Fill)); Grid.SetColumn(grid.Children[1], 1); grid.Children.Add(CreateImage(result, window, 6)); Grid.SetColumn(grid.Children[2], 2); break; } } if (contentElement != null) { Grid.SetColumnSpan(contentElement, 3); grid.Children.Add(contentElement); } result.Child = grid; var screenRect = window.ScreenRect; Canvas.SetLeft(result, screenRect.UpperLeft.X); Canvas.SetTop(result, screenRect.UpperLeft.Y); result.Width = screenRect.BottomRight.X - screenRect.UpperLeft.X; result.Height = screenRect.BottomRight.Y - screenRect.UpperLeft.Y; TextBlock.SetFontFamily(result, new FontFamily(window.Font.Name)); TextBlock.SetFontWeight(result, window.Font.Bold ? FontWeights.Bold : FontWeights.Normal); TextBlock.SetFontSize(result, window.Font.Size); return(result); }
private WndWindow ParseWindow() { NextToken(); var result = new WndWindow(); var childWindows = new List <WndWindow>(); while (Current.TokenType == WndTokenType.Identifier) { if (Current.StringValue == "END") { NextToken(); break; } switch (Current.StringValue) { case "WINDOWTYPE": result.WindowType = ParseProperty(ParseWindowType); break; case "SCREENRECT": result.ScreenRect = ParseProperty(ParseScreenRectValue); break; case "NAME": result.Name = ParseProperty(NextStringLiteralTokenValue); break; case "STATUS": result.Status = ParseProperty(ParseStatus); break; case "STYLE": result.Style = ParseProperty(ParseStyle); break; case "SYSTEMCALLBACK": result.SystemCallback = ParseProperty(NextStringLiteralTokenValue); break; case "INPUTCALLBACK": result.InputCallback = ParseProperty(NextStringLiteralTokenValue); break; case "TOOLTIPCALLBACK": result.TooltipCallback = ParseProperty(NextStringLiteralTokenValue); break; case "DRAWCALLBACK": result.DrawCallback = ParseProperty(NextStringLiteralTokenValue); break; case "FONT": result.Font = ParseProperty(ParseFont); break; case "HEADERTEMPLATE": result.HeaderTemplate = ParseProperty(NextStringLiteralTokenValue); break; case "TOOLTIPTEXT": result.TooltipText = ParseProperty(NextStringLiteralTokenValue); break; case "TOOLTIPDELAY": result.TooltipDelay = ParseProperty(NextIntegerLiteralTokenValue); break; case "TEXTCOLOR": result.TextColor = ParseProperty(ParseTextColor); break; case "ENABLEDDRAWDATA": result.EnabledDrawData = ParseProperty(ParseDrawData); break; case "DISABLEDDRAWDATA": result.DisabledDrawData = ParseProperty(ParseDrawData); break; case "HILITEDRAWDATA": result.HiliteDrawData = ParseProperty(ParseDrawData); break; case "CHILD": NextToken(); childWindows.Add(ParseWindow()); break; case "ENDALLCHILDREN": NextToken(); break; case "TEXT": result.Text = ParseProperty(NextStringLiteralTokenValue); break; case "TEXTENTRYDATA": result.TextEntryData = ParseProperty(ParseTextEntryData); break; case "STATICTEXTDATA": result.StaticTextData = ParseProperty(ParseStaticTextData); break; case "LISTBOXDATA": result.ListBoxData = ParseProperty(ParseListBoxData); break; case "LISTBOXENABLEDUPBUTTONDRAWDATA": result.ListBoxEnabledUpButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXDISABLEDUPBUTTONDRAWDATA": result.ListBoxDisabledUpButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXHILITEUPBUTTONDRAWDATA": result.ListBoxHiliteUpButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXENABLEDDOWNBUTTONDRAWDATA": result.ListBoxEnabledDownButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXDISABLEDDOWNBUTTONDRAWDATA": result.ListBoxDisabledDownButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXHILITEDOWNBUTTONDRAWDATA": result.ListBoxHiliteDownButtonDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXENABLEDSLIDERDRAWDATA": result.ListBoxEnabledSliderDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXDISABLEDSLIDERDRAWDATA": result.ListBoxDisabledSliderDrawData = ParseProperty(ParseDrawData); break; case "LISTBOXHILITESLIDERDRAWDATA": result.ListBoxHiliteSliderDrawData = ParseProperty(ParseDrawData); break; case "SLIDERTHUMBENABLEDDRAWDATA": result.SliderThumbEnabledDrawData = ParseProperty(ParseDrawData); break; case "SLIDERTHUMBDISABLEDDRAWDATA": result.SliderThumbDisabledDrawData = ParseProperty(ParseDrawData); break; case "SLIDERTHUMBHILITEDRAWDATA": result.SliderThumbHiliteDrawData = ParseProperty(ParseDrawData); break; case "RADIOBUTTONDATA": result.RadioButtonData = ParseProperty(ParseRadioButtonData); break; case "COMBOBOXDATA": result.ComboBoxData = ParseProperty(ParseComboBoxData); break; case "COMBOBOXDROPDOWNBUTTONENABLEDDRAWDATA": result.ComboBoxDropDownButtonEnabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXDROPDOWNBUTTONDISABLEDDRAWDATA": result.ComboBoxDropDownButtonDisabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXDROPDOWNBUTTONHILITEDRAWDATA": result.ComboBoxDropDownButtonHiliteDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXEDITBOXENABLEDDRAWDATA": result.ComboBoxEditBoxEnabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXEDITBOXDISABLEDDRAWDATA": result.ComboBoxEditBoxDisabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXEDITBOXHILITEDRAWDATA": result.ComboBoxEditBoxHiliteDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXLISTBOXENABLEDDRAWDATA": result.ComboBoxListBoxEnabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXLISTBOXDISABLEDDRAWDATA": result.ComboBoxListBoxDisabledDrawData = ParseProperty(ParseDrawData); break; case "COMBOBOXLISTBOXHILITEDRAWDATA": result.ComboBoxListBoxHiliteDrawData = ParseProperty(ParseDrawData); break; case "SLIDERDATA": result.SliderData = ParseProperty(ParseSliderData); break; default: UnexpectedToken(Current); break; } } result.ChildWindows = childWindows.ToArray(); return(result); }
private void AddWindow(WndWindow window) { var windowText = (!string.IsNullOrEmpty(window.Text)) ? _csfFile.Lookup(window.Text) : string.Empty; FrameworkElement contentElement; switch (window.WindowType) { case WndWindowType.PushButton: var contentPresenterFactory = new FrameworkElementFactory(typeof(ContentPresenter)); contentPresenterFactory.SetValue(FrameworkElement.HorizontalAlignmentProperty, HorizontalAlignment.Center); contentPresenterFactory.SetValue(FrameworkElement.VerticalAlignmentProperty, VerticalAlignment.Center); contentElement = new Button { Content = windowText, Background = Brushes.Transparent, BorderBrush = null, Template = new ControlTemplate(typeof(Button)) { VisualTree = contentPresenterFactory } }; break; case WndWindowType.StaticText: contentElement = new TextBlock { Text = windowText, TextWrapping = TextWrapping.Wrap }; break; case WndWindowType.CheckBox: contentElement = new CheckBox { Content = windowText }; break; case WndWindowType.RadioButton: contentElement = new RadioButton { GroupName = "Group" + window.RadioButtonData.Group, Content = windowText }; break; case WndWindowType.TextEntry: contentElement = new TextBox { Text = windowText, Background = Brushes.Transparent }; break; case WndWindowType.ProgressBar: contentElement = new ProgressBar { Value = 50 }; break; case WndWindowType.ComboBox: contentElement = new ComboBox { Items = { new ComboBoxItem { Content = "Test" } }, Background = Brushes.Transparent }; break; case WndWindowType.HorizontalSlider: contentElement = new Slider { Orientation = Orientation.Horizontal, Minimum = window.SliderData.MinValue, Maximum = window.SliderData.MaxValue }; break; case WndWindowType.VerticalSlider: contentElement = new Slider { Orientation = Orientation.Vertical, Minimum = window.SliderData.MinValue, Maximum = window.SliderData.MaxValue }; break; case WndWindowType.ListBox: contentElement = new ListBox { Items = { new ListBoxItem { Content = "Item 1" }, new ListBoxItem{ Content = "Item 2" } }, Background = Brushes.Transparent }; break; case WndWindowType.GenericWindow: contentElement = null; break; default: throw new ArgumentOutOfRangeException(); } var windowElement = CreateWindowElement(window, contentElement); ContainerView.Children.Add(windowElement); foreach (var childWindow in window.ChildWindows) { AddWindow(childWindow); } }
public WndWindowMessage(WndWindowMessageType messageType, WndWindow element) { MessageType = messageType; Element = element; }