void ShowContextMenu(GameMap.MapCell cell) { ContextMenu menu = (ContextMenu)Resources["MapContextMenu"]; if (menu.IsOpen) { return; } rightClickCell = cell; menu.DataContext = cell; bool hasMarkers = map.CellHasMarkers(cell); menu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; menu.IsOpen = true; MenuItem mi; if (CellOnBoard(cell)) { mi = (MenuItem)menu.FindLogicalNode("ToggleFogItem"); mi.DataContext = cell; mi.Visibility = !playerMode ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("DeleteMarkerItem"); mi.Visibility = (hasMarkers && !playerMode) ? Visibility.Visible : Visibility.Collapsed; mi.DataContext = cell; mi = (MenuItem)menu.FindLogicalNode("NameBoxItem"); mi.Visibility = (hasMarkers && !playerMode) ? Visibility.Visible : Visibility.Collapsed; if (hasMarkers) { mi.DataContext = map.GetMarkers(cell)[0]; } } else { menu.SetElementsVisibility(new string[] { "ToggleFogItem", "DeleteMarkerItem", "NameBoxItem" }, Visibility.Collapsed); } mi = (MenuItem)menu.FindLogicalNode("ShowControlsItem"); mi.Visibility = controlsHidden ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("HideControlsItem"); mi.Visibility = controlsHidden ? Visibility.Collapsed : Visibility.Visible; mi = (MenuItem)menu.FindLogicalNode("ExitFullScreenItem"); mi.Visibility = fullscreen ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("EnterFullScreenItem"); mi.Visibility = fullscreen ? Visibility.Collapsed : Visibility.Visible; }
private void MapGridCanvas_MouseRightButtonUp(object sender, MouseButtonEventArgs e) { if (rightClickDown) { rightClickDown = false; GameMap.MapCell cell = PointToCell(rightClickPosition); rightClickCell = cell; if (CellOnBoard(cell)) { bool hasMarkers = map.CellHasMarkers(cell); ContextMenu menu = (ContextMenu)Resources["MapContextMenu"]; menu.DataContext = cell; menu.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint; menu.IsOpen = true; MenuItem mi; mi = (MenuItem)menu.FindLogicalNode("ToggleFogItem"); mi.DataContext = cell; mi.Visibility = !playerMode ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("DeleteMarkerItem"); mi.Visibility = (hasMarkers && !playerMode) ? Visibility.Visible : Visibility.Collapsed; mi.DataContext = cell; mi = (MenuItem)menu.FindLogicalNode("NameBoxItem"); mi.Visibility = (hasMarkers && !playerMode) ? Visibility.Visible : Visibility.Collapsed; if (hasMarkers) { mi.DataContext = map.GetMarkers(cell)[0]; } mi = (MenuItem)menu.FindLogicalNode("ShowControlsItem"); mi.Visibility = controlsHidden ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("HideControlsItem"); mi.Visibility = controlsHidden ? Visibility.Collapsed : Visibility.Visible; mi = (MenuItem)menu.FindLogicalNode("ExitFullScreenItem"); mi.Visibility = fullscreen ? Visibility.Visible : Visibility.Collapsed; mi = (MenuItem)menu.FindLogicalNode("EnterFullScreenItem"); mi.Visibility = fullscreen ? Visibility.Collapsed : Visibility.Visible; } } }