public static void AddHUDButton(Menu menu, string img_off, string img_on, string label, IButtonReference buttonRef) { var hudButtons = FindVisualChildren <HUDButton>(Api.Client.UI.LayoutRoot); if (hudButtons?.Count() > 0) { if (hudButtons.Last().Parent is StackPanel stackPanel) { var newHUDButton = new HUDButton(); ImageBrush normalBrush = new ImageBrush(); BindingOperations.SetBinding(normalBrush, ImageBrush.ImageSourceProperty, new Binding() { Source = img_off }); newHUDButton.BrushNormal = normalBrush; ImageBrush highlightedBrush = new ImageBrush(); BindingOperations.SetBinding(highlightedBrush, ImageBrush.ImageSourceProperty, new Binding() { Source = img_on }); newHUDButton.BrushHighlighted = highlightedBrush; var labelWithButton = new LabelWithButton() { Content = label }; labelWithButton.Button = buttonRef; newHUDButton.SetBinding(ToolTipServiceExtend.ToolTipProperty, new Binding() { Source = labelWithButton }); newHUDButton.SetBinding(HUDButton.CommandProperty, new Binding("CommandToggle")); newHUDButton.SetBinding(HUDButton.IsSelectedProperty, new Binding("IsSelected")); newHUDButton.DataContext = menu; stackPanel.Children.Add(newHUDButton); } else { Api.Logger.Error("CNEI: HUD buttons parent is not StackPanel."); } } else { Api.Logger.Error("CNEI: HUD buttons not found."); } }
// Use this for initialization void Start() { parent = GetComponentInParent <HUDButton>(); }
public override void OnInitialize() { base.OnInitialize(); string txt = "?"; switch (_mode) { case HighscoreCategory.GlobalPoints: txt = L10N.T(L10NImpl.STR_HSP_GLOBALRANKING); break; case HighscoreCategory.WorldPoints: txt = L10N.TF(L10NImpl.STR_HSP_RANKINGFOR, L10N.T(Levels.WORLD_NAMES[_focus.ID])); break; case HighscoreCategory.MultiplayerPoints: txt = L10N.T(L10NImpl.STR_HSP_MULTIPLAYERRANKING); break; case HighscoreCategory.CustomLevelStars: txt = L10N.T(L10NImpl.STR_HSP_STARRANKING); break; case HighscoreCategory.CustomLevelPoints: txt = L10N.T(L10NImpl.STR_HSP_SCCMRANKING); break; default: SAMLog.Error("HP::EnumSwitch_OI", "_mode: " + _mode); break; } AddElement(new HUDLabel(1) { TextAlignment = (txt.Length > 24) ? HUDAlignment.CENTERLEFT : HUDAlignment.CENTER, Alignment = HUDAlignment.TOPCENTER, RelativePosition = new FPoint(0, 0), Size = new FSize(TAB_WIDTH, TEXT_HEIGHT_REAL), Font = Textures.HUDFontBold, FontSize = 64, Text = txt, TextColor = FlatColors.Clouds, }); AddElement(_btnPrev = new HUDImageButton(1) { Alignment = HUDAlignment.TOPLEFT, RelativePosition = FPoint.Zero, Size = new FSize(72, 72), Image = GetModeIcon(NextCategory(_mode, false)), ImageColor = GetModeColor(NextCategory(_mode, false)), ImagePadding = 8, ImageAlignment = HUDImageAlignmentAlgorithm.CENTER, ImageScale = HUDImageScaleAlgorithm.UNDERSCALE, BackgroundNormal = HUDBackgroundDefinition.CreateRounded(FlatColors.ButtonHUD, 16, true, false, false, false), BackgroundPressed = HUDBackgroundDefinition.CreateRounded(FlatColors.ButtonPressedHUD, 16, true, false, false, false), Click = (s, e) => SwitchMode(false), IsVisible = false, }); AddElement(_btnNext = new HUDImageButton(1) { Alignment = HUDAlignment.TOPRIGHT, RelativePosition = FPoint.Zero, Size = new FSize(72, 72), Image = GetModeIcon(NextCategory(_mode, true)), ImageColor = GetModeColor(NextCategory(_mode, true)), ImagePadding = 8, ImageAlignment = HUDImageAlignmentAlgorithm.CENTER, ImageScale = HUDImageScaleAlgorithm.UNDERSCALE, BackgroundNormal = HUDBackgroundDefinition.CreateRounded(FlatColors.ButtonHUD, 16, false, true, false, false), BackgroundPressed = HUDBackgroundDefinition.CreateRounded(FlatColors.ButtonPressedHUD, 16, false, true, false, false), Click = (s, e) => SwitchMode(true), IsVisible = false, }); _loader = new HUDImage { RelativePosition = new FPoint(0, TEXT_HEIGHT / 2f), Alignment = HUDAlignment.CENTER, Size = new FSize(2 * GDConstants.TILE_WIDTH, 2 * GDConstants.TILE_WIDTH), Color = FlatColors.Clouds, Image = Textures.CannonCogBig, RotationSpeed = 0.1f, IsVisible = true, }; AddElement(_loader); _table = new HUDScrollTable { RelativePosition = new FPoint(0, TEXT_HEIGHT / 2f), Alignment = HUDAlignment.CENTER, Size = new FSize(TAB_WIDTH, TAB_HEIGHT), Background = FlatColors.BackgroundHUD2, Foreground = FlatColors.TextHUD, LineColor = Color.Black, HeaderBackground = FlatColors.Asbestos, HeaderForeground = Color.Black, ScrollThumbColor = FlatColors.Silver, ScrollWidth = 16, ScrollHeight = 64, LineWidth = 2 * HUD.PixelWidth, FontSize = 32, IsVisible = false, }; _table.FixHeightToMultipleOfRowHeight(); AddElement(_table); switch (_mode) { case HighscoreCategory.GlobalPoints: _table.AddColumn("", 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_NAME), null); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_POINTS), 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_TIME), 175); break; case HighscoreCategory.WorldPoints: _table.AddColumn("", 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_NAME), null); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_POINTS), 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_TIME), 175); break; case HighscoreCategory.MultiplayerPoints: _table.AddColumn("", 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_NAME), null); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_POINTS), 100); break; case HighscoreCategory.CustomLevelStars: _table.AddColumn("", 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_NAME), null); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_STARS), 100); break; case HighscoreCategory.CustomLevelPoints: _table.AddColumn("", 100); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_NAME), null); _table.AddColumn(L10N.T(L10NImpl.STR_TAB_POINTS), 100); break; default: SAMLog.Error("HP::EnumSwitch_OI2", "_mode: " + _mode); break; } LoadHighscore().EnsureNoError(); }
public void Initialize(Cockpit cockpit) { cockpit.Name = "modelCockpit"; // Configure how the cockpit moves //cockpit.PositionMode = Cockpit.MovementMode.TrackPosition; // [RMS] use orientation mode to make cockpit follow view orientation. // (however default widgets below are off-screen!) cockpit.PositionMode = Cockpit.MovementMode.TrackOrientation; BoxContainer screenContainer = new BoxContainer(new Cockpit2DContainerProvider(cockpit)); PinnedBoxes2DLayoutSolver screenLayout = new PinnedBoxes2DLayoutSolver(screenContainer); PinnedBoxesLayout layout = new PinnedBoxesLayout(cockpit, screenLayout) { StandardDepth = 2.0f }; cockpit.AddLayout(layout, "2D", true); Func <string, float, HUDLabel> MakeButtonF = (label, buttonW) => { HUDLabel button = new HUDLabel() { Shape = CotangentUI.MakeMenuButtonRect(buttonW, CotangentUI.MenuButtonHeight), TextHeight = CotangentUI.MenuButtonTextHeight, AlignmentHorz = HorizontalAlignment.Center, BackgroundColor = CotangentUI.ButtonBGColor, TextColor = CotangentUI.ButtonTextColor, Text = label, EnableBorder = true, BorderWidth = CotangentUI.StandardButtonBorderWidth, BorderColor = CotangentUI.ButtonTextColor }; button.Create(); button.Name = label; button.Enabled = true; return(button); }; Vector2f progressOffsetY = 4 * CotangentUI.PixelScale * Vector2f.AxisY; HUDRadialProgress slicerProgress = new HUDRadialProgress() { Radius = 18 * CotangentUI.PixelScale }; slicerProgress.Create(); slicerProgress.Name = "slicer_progress"; int MAX_PROGRESS = 1000; slicerProgress.MaxProgress = MAX_PROGRESS; CC.SlicingProgressEvent += (status) => { if (status.bFailed) { double t = 0.5 * (double)status.curProgress / (double)status.maxProgress; slicerProgress.Progress = (int)(t * MAX_PROGRESS); slicerProgress.CompletedColor = Colorf.VideoRed; } else { double t = 0.5 * (double)status.curProgress / (double)status.maxProgress; slicerProgress.Progress = (int)(t * MAX_PROGRESS); slicerProgress.CompletedColor = Colorf.BlueMetal; } }; CC.ToolpathProgressEvent += (status) => { if (status.bFailed) { double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress; slicerProgress.Progress = (int)(t * MAX_PROGRESS); slicerProgress.CompletedColor = Colorf.VideoRed; } else { double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress; if (status.curProgress == 0 && status.maxProgress == 1) { t = 0; } slicerProgress.Progress = (int)(t * MAX_PROGRESS); slicerProgress.CompletedColor = (status.curProgress == status.maxProgress) ? Colorf.LightGreen : Colorf.BlueMetal; } }; layout.Add(slicerProgress, new LayoutOptions() { Flags = LayoutFlags.None, PinSourcePoint2D = LayoutUtil.BoxPointF(slicerProgress, BoxPosition.CenterBottom), PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY) }); HUDButton progressClick = new HUDButton() { Shape = new HUDShape(HUDShapeType.Disc, slicerProgress.Radius) }; fMaterial normalMaterial = MaterialUtil.CreateFlatMaterialF(Colorf.White, 0); fMaterial pauseMaterial = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_pause"); fMaterial pausedMaterial = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_play"); if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing) { progressClick.Create(normalMaterial, null, pauseMaterial); } else { progressClick.Create(pausedMaterial, null, null); } progressClick.Name = "progress_click"; layout.Add(progressClick, new LayoutOptions() { Flags = LayoutFlags.None, DepthShift = -0.1f, PinSourcePoint2D = LayoutUtil.BoxPointF(progressClick, BoxPosition.CenterBottom), PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY) }); progressClick.OnClicked += (o, e) => { if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing) { CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.SliceOnDemand; progressClick.StandardMaterial = pausedMaterial; progressClick.HoverMaterial = null; } else { CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.ImmediateSlicing; progressClick.StandardMaterial = normalMaterial; progressClick.HoverMaterial = pauseMaterial; } if (CC.Toolpather.ToolpathsValid == false) { // not sure why we have to invalidate slicing here, but if we don't toolpath // computation will not stop when we pause... CC.Slicer.InvalidateSlicing(); //CC.InvalidateToolPaths(); } }; CotangentUI.PrintViewHUDItems = new List <HUDStandardItem>() { slicerProgress, progressClick }; screenLayout.RecomputeLayout(); // Configure interaction behaviors // - below we add behaviors for mouse, gamepad, and spatial devices (oculus touch, etc) // - keep in mind that Tool objects will register their own behaviors when active // setup key handlers (need to move to behavior...) cockpit.AddKeyHandler(new CotangentKeyHandler(cockpit.Context)); // these behaviors let us interact with UIElements (ie left-click/trigger, or either triggers for Touch) cockpit.InputBehaviors.Add(new Mouse2DCockpitUIBehavior(cockpit.Context) { Priority = 0 }); cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context) { Priority = 1 }); // selection / multi-selection behaviors // Note: this custom behavior implements some selection redirects that we use in various parts of Archform cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context) { Priority = 10 }); // left click-drag to tumble, and left click-release to de-select cockpit.InputBehaviors.Add(new MouseClickDragSuperBehavior() { Priority = 100, DragBehavior = new MouseViewRotateBehavior(cockpit.Context) { Priority = 100, RotateSpeed = 3.0f }, ClickBehavior = new MouseDeselectBehavior(cockpit.Context) { Priority = 999 } }); // also right-click-drag to tumble cockpit.InputBehaviors.Add(new MouseViewRotateBehavior(cockpit.Context) { Priority = 100, RotateSpeed = 3.0f, ActivateF = MouseBehaviors.RightButtonPressedF, ContinueF = MouseBehaviors.RightButtonDownF }); // middle-click-drag to pan cockpit.InputBehaviors.Add(new MouseViewPanBehavior(cockpit.Context) { Priority = 100, PanSpeed = 0.01f, Adaptive = true, ActivateF = MouseBehaviors.MiddleButtonPressedF, ContinueF = MouseBehaviors.MiddleButtonDownF }); cockpit.OverrideBehaviors.Add(new MouseWheelZoomBehavior(cockpit) { Priority = 100, ZoomScale = 0.2f, Adaptive = true }); // touch input cockpit.InputBehaviors.Add(new TouchUIBehavior(cockpit.Context) { Priority = 1 }); cockpit.InputBehaviors.Add(new Touch2DCockpitUIBehavior(cockpit.Context) { Priority = 0 }); cockpit.InputBehaviors.Add(new TouchViewManipBehavior(cockpit.Context) { Priority = 999, TouchZoomSpeed = 0.1f, TouchPanSpeed = 0.03f }); }