public MyControllableSphere() { ControllerInfo.ControlAcquired += OnControlAcquired; ControllerInfo.ControlReleased += OnControlReleased; m_toolbar = new MyToolbar(ToolbarType); }
public override void OnRemovedFromToolbar(MyToolbar toolbar) { if (m_block != null) { UnregisterEvents(); } base.OnRemovedFromToolbar(toolbar); }
private void Toolbar_CurrentPageChanged(MyToolbar toolbar, MyToolbar.PageChangeArgs args) { m_contextMenu.Deactivate(); HighlightCurrentPageLabel(); for (int i = 0; i < MyToolbarComponent.CurrentToolbar.SlotCount; ++i) { SetGridItemAt(i, toolbar.GetSlotItem(i)); } }
private void Toolbar_ItemUpdated(MyToolbar toolbar, MyToolbar.IndexArgs args, MyToolbarItem.ChangeInfo changes) { // Quicker method if only icon changed if (changes == MyToolbarItem.ChangeInfo.Icon) { UpdateItemIcon(toolbar, args); } else { UpdateItemAtIndex(toolbar, args.ItemIndex); } }
private void Toolbar_ItemEnabledChanged(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (args.SlotNumber.HasValue) { var idx = args.SlotNumber.Value; m_toolbarItemsGrid.GetItemAt(idx).Enabled = toolbar.IsEnabled(toolbar.SlotToIndex(idx)); } else { for (int i = 0; i < m_toolbarItemsGrid.ColumnsCount; ++i) { m_toolbarItemsGrid.GetItemAt(i).Enabled = toolbar.IsEnabled(toolbar.SlotToIndex(i)); } } }
public override void OnRemoving() { MyToolbarComponent.CurrentToolbarChanged -= ToolbarComponent_CurrentToolbarChanged; if (m_shownToolbar != null) { m_shownToolbar.ItemChanged -= Toolbar_ItemChanged; m_shownToolbar.ItemUpdated -= Toolbar_ItemUpdated; m_shownToolbar.SelectedSlotChanged -= Toolbar_SelectedSlotChanged; m_shownToolbar.SlotActivated -= Toolbar_SlotActivated; m_shownToolbar.ItemEnabledChanged -= Toolbar_ItemEnabledChanged; m_shownToolbar.CurrentPageChanged -= Toolbar_CurrentPageChanged; m_shownToolbar = null; } base.OnRemoving(); }
private void UpdateItemAtIndex(MyToolbar toolbar, int index) { Debug.Assert(toolbar == m_shownToolbar); int slot = toolbar.IndexToSlot(index); if (!toolbar.IsValidIndex(index) || !toolbar.IsValidSlot(slot)) { return; } SetGridItemAt(slot, toolbar[index], clear: true); if (toolbar.SelectedSlot == slot) { RefreshSelectedItem(toolbar); } }
private void UpdateItemIcon(MyToolbar toolbar, MyToolbar.IndexArgs args) { if (toolbar.IsValidIndex(args.ItemIndex)) { var slot = toolbar.IndexToSlot(args.ItemIndex); if (slot != -1) { m_toolbarItemsGrid.GetItemAt(slot).Icons = toolbar.GetItemIcons(args.ItemIndex); } } else { for (int i = 0; i < m_toolbarItemsGrid.ColumnsCount; ++i) { m_toolbarItemsGrid.GetItemAt(i).Icons = toolbar.GetItemIcons(toolbar.SlotToIndex(i)); } } }
private void RefreshSelectedItem(MyToolbar toolbar) { m_toolbarItemsGrid.SelectedIndex = toolbar.SelectedSlot; var item = toolbar.SelectedItem; if (item != null) { m_selectedItemLabel.Text = item.DisplayName.ToString(); Debug.Assert(MyCubeBuilder.Static != null, "Cube builder should be loaded here"); m_colorVariantPanel.Visible = (item is MyToolbarItemCubeBlock) && MyFakes.ENABLE_BLOCK_COLORING; } else { m_colorVariantPanel.Visible = false; m_selectedItemLabel.Text = String.Empty; } }
private void RefreshSelectedItem(MyToolbar toolbar) { m_toolbarItemsGrid.SelectedIndex = toolbar.SelectedSlot; var item = toolbar.SelectedItem; if (item != null) { m_selectedItemLabel.Text = item.DisplayName.ToString(); Debug.Assert(MyCubeBuilder.Static != null, "Cube builder should be loaded here"); m_colorVariantPanel.Visible = (item is MyToolbarItemCubeBlock) && MyFakes.ENABLE_BLOCK_COLORING; //set grid size image visible when some block is selected m_gridSize.Visible = (item is MyToolbarItemCubeBlock); if (m_gridSize.Visible) { if (MyCubeBuilder.Static.CubeBuilderState.HasComplementBlock()) { MyStringId keyId = MyStringId.GetOrCompute("SLOT" + (toolbar.SelectedSlot + 1).ToString()); MyControl control = MyInput.Static.GetGameControl(keyId); StringBuilder sb = new StringBuilder(); m_gridSizeLabel.Text = sb.AppendFormat(MyTexts.GetString(MySpaceTexts.CubeBuilder_CubeSizeModeChange), (control != null ? "\"" + control.ToString() + "\"" : "?"), "\n").ToString(); } else { m_gridSizeLabel.Text = ""; } } } else { m_colorVariantPanel.Visible = false; m_selectedItemLabel.Text = String.Empty; m_gridSize.Visible = false; } }
public virtual void OnAddedToToolbar(MyToolbar toolbar) { }
private void CurrentToolbar_SlotActivated(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.GetItemAtIndex(toolbar.SlotToIndex(args.SlotNumber.Value)) is MyToolbarItemAreaMarker)) AreaMarkerDefinition = null; }
void Toolbar_ItemChanged(MyToolbar toolbar, MyToolbar.IndexArgs index) { var item = toolbar.GetItemAtIndex(index.ItemIndex); if (item != null) { var def = item as MyToolbarItemDefinition; if (def != null) { var defId = def.Definition.Id; if (defId != null) { if (defId.TypeId != typeof(MyObjectBuilder_PhysicalGunObject)) MyToolBarCollection.RequestChangeSlotItem(MySession.Static.LocalHumanPlayer.Id, index.ItemIndex, defId); else MyToolBarCollection.RequestChangeSlotItem(MySession.Static.LocalHumanPlayer.Id, index.ItemIndex, item.GetObjectBuilder()); } } } else if (MySandboxGame.IsGameReady) { MyToolBarCollection.RequestClearSlot(MySession.Static.LocalHumanPlayer.Id, index.ItemIndex); } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( BlockDefinition.ResourceSinkGroup, BlockDefinition.RequiredPowerInput, this.CalculateRequiredPowerInput); ResourceSink = sinkComp; base.Init(objectBuilder, cubeGrid); m_items = new List<ToolbarItem>(2); for (int i = 0; i < 2; i++) { m_items.Add(new ToolbarItem() { EntityID = 0 }); } Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1); Toolbar.DrawNumbers = false; var builder = (MyObjectBuilder_SensorBlock)objectBuilder; m_fieldMin.Value = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One); m_fieldMax.Value = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange)); PlayProximitySound = builder.PlaySound; DetectPlayers = builder.DetectPlayers; DetectFloatingObjects = builder.DetectFloatingObjects; DetectSmallShips = builder.DetectSmallShips; DetectLargeShips = builder.DetectLargeShips; DetectStations = builder.DetectStations; DetectAsteroids = builder.DetectAsteroids; DetectOwner = builder.DetectOwner; DetectFriendly = builder.DetectFriendly; DetectNeutral = builder.DetectNeutral; DetectEnemy = builder.DetectEnemy; m_active.Value = builder.IsActive; Toolbar.Init(builder.Toolbar, this); for (int i = 0; i < 2; i++) { var item = Toolbar.GetItemAtIndex(i); if (item == null) continue; m_items.RemoveAt(i); m_items.Insert(i, ToolbarItem.FromItem(item)); } Toolbar.ItemChanged += Toolbar_ItemChanged; NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged; ResourceSink.RequiredInputChanged += Receiver_RequiredInputChanged; ResourceSink.Update(); m_fieldShape = GetHkShape(); OnClose += delegate(MyEntity self) { m_fieldShape.RemoveReference(); }; m_gizmoColor = MySandboxGame.IsDirectX11 ? new Vector4(0.35f, 0, 0, 0.5f) : new Vector4(0.1f, 0, 0, 0.1f); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( BlockDefinition.ResourceSinkGroup, m_powerNeeded, this.CalculateRequiredPowerInput); ResourceSink = sinkComp; base.Init(objectBuilder, cubeGrid); NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME; var remoteOb = (MyObjectBuilder_RemoteControl)objectBuilder; m_savedPreviousControlledEntityId = remoteOb.PreviousControlledEntityId; sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged; sinkComp.RequiredInputChanged += Receiver_RequiredInputChanged; sinkComp.Update(); m_autoPilotEnabled.Value = remoteOb.AutoPilotEnabled; m_dockingModeEnabled.Value = remoteOb.DockingModeEnabled; m_currentFlightMode.Value = (FlightMode)remoteOb.FlightMode; m_currentDirection.Value = (Base6Directions.Direction)remoteOb.Direction; m_autopilotSpeedLimit.Value = remoteOb.AutopilotSpeedLimit; m_bindedCamera.Value = remoteOb.BindedCamera; m_waypointThresholdDistance.Value = remoteOb.WaypointThresholdDistance; m_currentAutopilotSpeedLimit = m_autopilotSpeedLimit; m_stuckDetection = new MyStuckDetection(0.03f, 0.01f, this.CubeGrid.PositionComp.WorldAABB); if (remoteOb.Coords == null || remoteOb.Coords.Count == 0) { if (remoteOb.Waypoints == null) { m_waypoints = new List<MyAutopilotWaypoint>(); CurrentWaypoint = null; } else { m_waypoints = new List<MyAutopilotWaypoint>(remoteOb.Waypoints.Count); for (int i = 0; i < remoteOb.Waypoints.Count; i++) { m_waypoints.Add(new MyAutopilotWaypoint(remoteOb.Waypoints[i], this)); } } } else { m_waypoints = new List<MyAutopilotWaypoint>(remoteOb.Coords.Count); for (int i = 0; i < remoteOb.Coords.Count; i++) { m_waypoints.Add(new MyAutopilotWaypoint(remoteOb.Coords[i], remoteOb.Names[i], this)); } if (remoteOb.AutoPilotToolbar != null && m_currentFlightMode == FlightMode.OneWay) { m_waypoints[m_waypoints.Count - 1].SetActions(remoteOb.AutoPilotToolbar.Slots); } } if (remoteOb.CurrentWaypointIndex == -1 || remoteOb.CurrentWaypointIndex >= m_waypoints.Count) { CurrentWaypoint = null; } else { CurrentWaypoint = m_waypoints[remoteOb.CurrentWaypointIndex]; } UpdatePlanetWaypointInfo(); m_actionToolbar = new MyToolbar(MyToolbarType.ButtonPanel, pageCount: 1); m_actionToolbar.DrawNumbers = false; m_actionToolbar.Init(null, this); m_selectedGpsLocations = new List<IMyGps>(); m_selectedWaypoints = new List<MyAutopilotWaypoint>(); UpdateText(); AddDebugRenderComponent(new MyDebugRenderComponentRemoteControl(this)); m_useCollisionAvoidance.Value = remoteOb.CollisionAvoidance; for (int i = 0; i < TERRAIN_HEIGHT_DETECTION_SAMPLES; i++) { m_terrainHeightDetection[i] = 0.0f; } }
private void CurrentToolbar_Unselected(MyToolbar toolbar) { BotToSpawn = null; CommandDefinition = null; }
private void Toolbar_SelectedSlotChanged(MyToolbar toolbar, MyToolbar.SlotArgs args) { Debug.Assert(toolbar == m_shownToolbar); RefreshSelectedItem(toolbar); }
private void Toolbar_ItemChanged(MyToolbar toolbar, MyToolbar.IndexArgs args) { UpdateItemAtIndex(toolbar, args.ItemIndex); }
private void CreateDefaultToolbar(PlayerId playerId) { if (ContainsToolbar(playerId)) return; var toolbar = new MyToolbar(MyToolbarType.Character); toolbar.Init(MySession.Static.Scenario.DefaultToolbar, null, true); AddPlayerToolbar(playerId, toolbar); }
private void CurrentToolbar_SelectedSlotChanged(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.SelectedItem is MyToolbarItemBot)) BotToSpawn = null; if (!(toolbar.SelectedItem is MyToolbarItemAiCommand)) CommandDefinition = null; }
public MyToolbarComponent() { m_universalCharacterToolbar = new MyToolbar(MyToolbarType.Character); m_currentToolbar = m_universalCharacterToolbar; AutoUpdate = true; }
private static void SetupPlayer(ref Args args) { var identity = Sync.Players.CreateNewIdentity(Sync.Clients.LocalClient.DisplayName); var player = Sync.Players.CreateNewPlayer(identity, Sync.Clients.LocalClient, Sync.MyName); var playerStarts = args.Scenario.PossiblePlayerStarts; if (playerStarts == null || playerStarts.Length == 0) { Sync.Players.RespawnComponent.SetupCharacterDefault(player, args); } else { var randomStart = playerStarts[MyUtils.GetRandomInt(playerStarts.Length)]; randomStart.SetupCharacter(args); } // Setup toolbar if (args.Scenario.DefaultToolbar != null) { // TODO: JakubD fix this MyToolbar toolbar = new MyToolbar(MyToolbarType.Character); toolbar.Init(args.Scenario.DefaultToolbar, player.Character, true); MySession.Static.Toolbars.RemovePlayerToolbar(player.Id); MySession.Static.Toolbars.AddPlayerToolbar(player.Id, toolbar); MyToolbarComponent.InitToolbar(MyToolbarType.Character, args.Scenario.DefaultToolbar); MyToolbarComponent.InitCharacterToolbar(args.Scenario.DefaultToolbar); } }
public void ShowToolbar(MyToolbar toolbar) { if (m_shownToolbar != null) { m_shownToolbar.ItemChanged -= Toolbar_ItemChanged; m_shownToolbar.ItemUpdated -= Toolbar_ItemUpdated; m_shownToolbar.SelectedSlotChanged -= Toolbar_SelectedSlotChanged; m_shownToolbar.SlotActivated -= Toolbar_SlotActivated; m_shownToolbar.ItemEnabledChanged -= Toolbar_ItemEnabledChanged; m_shownToolbar.CurrentPageChanged -= Toolbar_CurrentPageChanged; foreach (var label in m_pageLabelList) { Elements.Remove(label); } m_pageLabelList.Clear(); } m_shownToolbar = toolbar; if (m_shownToolbar == null) // Toolbar can be null in the passenger seat { m_toolbarItemsGrid.Enabled = false; m_toolbarItemsGrid.Visible = false; } else { var slotCount = toolbar.SlotCount; m_toolbarItemsGrid.ColumnsCount = slotCount + (toolbar.ShowHolsterSlot ? 1 : 0); for (int i = 0; i < slotCount; ++i) { SetGridItemAt(i, toolbar.GetSlotItem(i), clear: true); } m_selectedItemLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM; m_colorVariantPanel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_BOTTOM; m_colorVariantPanel.Visible = MyFakes.ENABLE_BLOCK_COLORING; // character != null; if (toolbar.ShowHolsterSlot) { SetGridItemAt(slotCount, new MyToolbarItemEmpty(), new string[] { @"Textures\GUI\Icons\HideWeapon.dds" }, null, MyTexts.GetString(MyCommonTexts.HideWeapon)); } if (toolbar.PageCount > 1) { for (int i = 0; i < toolbar.PageCount; ++i) { m_textCache.Clear(); m_textCache.AppendInt32(i + 1); MyGuiControlLabel pageLabel = new MyGuiControlLabel(text: MyToolbarComponent.GetSlotControlText(i).ToString() ?? m_textCache.ToString()); pageLabel.BackgroundTexture = MyGuiConstants.TEXTURE_TOOLBAR_TAB; pageLabel.TextScale = 0.7f; pageLabel.Size = m_toolbarItemsGrid.ItemSize * new Vector2(0.5f, 0.35f); pageLabel.OriginAlign = MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER; m_pageLabelList.Add(pageLabel); Elements.Add(pageLabel); } } RepositionControls(); HighlightCurrentPageLabel(); RefreshSelectedItem(toolbar); m_shownToolbar.ItemChanged -= Toolbar_ItemChanged; m_shownToolbar.ItemChanged += Toolbar_ItemChanged; m_shownToolbar.ItemUpdated -= Toolbar_ItemUpdated; m_shownToolbar.ItemUpdated += Toolbar_ItemUpdated; m_shownToolbar.SelectedSlotChanged -= Toolbar_SelectedSlotChanged; m_shownToolbar.SelectedSlotChanged += Toolbar_SelectedSlotChanged; m_shownToolbar.SlotActivated -= Toolbar_SlotActivated; m_shownToolbar.SlotActivated += Toolbar_SlotActivated; m_shownToolbar.ItemEnabledChanged -= Toolbar_ItemEnabledChanged; m_shownToolbar.ItemEnabledChanged += Toolbar_ItemEnabledChanged; m_shownToolbar.CurrentPageChanged -= Toolbar_CurrentPageChanged; m_shownToolbar.CurrentPageChanged += Toolbar_CurrentPageChanged; MaxSize = MinSize = new Vector2(m_toolbarItemsGrid.Size.X, m_toolbarItemsGrid.Size.Y + m_selectedItemLabel.Size.Y + m_colorVariantPanel.Size.Y); m_toolbarItemsGrid.Enabled = true; m_toolbarItemsGrid.Visible = true; } }
public void LoadToolbars(MyObjectBuilder_Checkpoint checkpoint) { if (checkpoint.AllPlayersData != null) { foreach (var item in checkpoint.AllPlayersData.Dictionary) { var playerId = new PlayerId(item.Key.ClientId, item.Key.SerialId); var toolbar = new MyToolbar(MyToolbarType.Character); toolbar.Init(item.Value.Toolbar, null, true); AddPlayerToolbar(playerId, toolbar); } } }
private void Toolbar_ItemChanged(MyToolbar self, MyToolbar.IndexArgs index) { if (m_syncing) { return; } MyMultiplayer.RaiseEvent(this,x => x.SendToolbarItemChanged,ToolbarItem.FromItem(self.GetItemAtIndex(index.ItemIndex)), index.ItemIndex); }
private void Toolbar_SlotActivated(MyToolbar toolbar, MyToolbar.SlotArgs args) { Debug.Assert(toolbar == m_shownToolbar); m_toolbarItemsGrid.blinkSlot(args.SlotNumber); }
private void CurrentToolbar_SlotActivated(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.GetItemAtIndex(toolbar.SlotToIndex(args.SlotNumber.Value)) is MyToolbarItemBot)) BotToSpawn = null; if (!(toolbar.GetItemAtIndex(toolbar.SlotToIndex(args.SlotNumber.Value)) is MyToolbarItemAiCommand)) CommandDefinition = null; }
public bool AddPlayerToolbar(PlayerId pid, MyToolbar toolbar) { if (pid == null || toolbar == null) return false; MyToolbar result; var success = m_playerToolbars.TryGetValue(pid, out result); if (!success) { m_playerToolbars.Add(pid, toolbar); return true; } else { return false; } }
public override void OnRemovedFromToolbar(MyToolbar toolbar) { if (m_block != null) UnregisterEvents(); base.OnRemovedFromToolbar(toolbar); }
public virtual void OnRemovedFromToolbar(MyToolbar toolbar) { }
public void SetToToolbar(MyToolbar toolbar, int index) { var item = m_cachedItem; if (item != null) toolbar.SetItemAtIndex(index, item); }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); var builder = (MyObjectBuilder_AirVent)objectBuilder; InitializeConveyorEndpoint(); NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; SourceComp.Init(BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo { ResourceTypeId = m_oxygenGasId, DefinedOutput = BlockDefinition.VentilationCapacityPerSecond, ProductionToCapacityMultiplier = 1 }); SourceComp.OutputChanged += Source_OutputChanged; FillSinkInfo(); var sinkDataList = new List<MyResourceSinkInfo> { new MyResourceSinkInfo {ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower}, }; ResourceSink.Init( BlockDefinition.ResourceSinkGroup, sinkDataList); ResourceSink.IsPoweredChanged += PowerReceiver_IsPoweredChanged; ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged; m_lastOutputUpdateTime = MySession.Static.GameplayFrameCounter; m_lastInputUpdateTime = MySession.Static.GameplayFrameCounter; m_nextGasTransfer = 0f; m_actionToolbar = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1); m_actionToolbar.DrawNumbers = false; m_actionToolbar.Init(null, this); if (builder.OnFullAction != null) m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction); if (builder.OnEmptyAction != null) m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction); UpdateEmissivity(); UdpateTexts(); AddDebugRenderComponent(new Sandbox.Game.Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; IsWorkingChanged += MyAirVent_IsWorkingChanged; m_isDepressurizing.Value = builder.IsDepressurizing; SetDepressurizing(); }
public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid) { SyncFlag = true; var sinkComp = new MyResourceSinkComponent(); sinkComp.Init( BlockDefinition.ResourceSinkGroup, 0.0001f, () => IsFunctional ? 0.0001f : 0); sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged; sinkComp.IsPoweredChanged += ComponentStack_IsFunctionalChanged; ResourceSink = sinkComp; base.Init(builder, cubeGrid); m_emissiveNames = new List<string>(BlockDefinition.ButtonCount); for (int i = 1; i <= BlockDefinition.ButtonCount; i++) //button dummies have 1-based index { m_emissiveNames.Add(string.Format("Emissive{0}", i)); // because of modding } var ob = builder as MyObjectBuilder_ButtonPanel; Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, Math.Min(BlockDefinition.ButtonCount, MyToolbar.DEF_SLOT_COUNT), (BlockDefinition.ButtonCount / MyToolbar.DEF_SLOT_COUNT) + 1); Toolbar.DrawNumbers = false; Toolbar.GetSymbol = (slot) => { var ret = new Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon(); if(Toolbar.SlotToIndex(slot) < BlockDefinition.ButtonCount) { ret.Icon = BlockDefinition.ButtonSymbols[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonSymbols.Length]; var color = BlockDefinition.ButtonColors[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonColors.Length]; color.W = 1; ret.Color = color; } return ret; }; Toolbar.Init(ob.Toolbar, this); Toolbar.ItemChanged += Toolbar_ItemChanged; AnyoneCanUse = ob.AnyoneCanUse; SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; ResourceSink.Update(); if (ob.CustomButtonNames != null) { m_customButtonNames = ob.CustomButtonNames; } NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_FRAME; UseObjectsComponent.GetInteractiveObjects<MyUseObjectPanelButton>(m_buttonsUseObjects); }
void Toolbar_ItemChanged(MyToolbar self, MyToolbar.IndexArgs index) { if (m_selectedWaypoints.Count == 1) { SendToolbarItemChanged(ToolbarItem.FromItem(self.GetItemAtIndex(index.ItemIndex)), index.ItemIndex, m_waypoints.IndexOf(m_selectedWaypoints[0])); } }
void Toolbar_ItemChanged(MyToolbar self, MyToolbar.IndexArgs index) { if(m_syncing) { return; } Debug.Assert(self == Toolbar); var tItem = ToolbarItem.FromItem(self.GetItemAtIndex(index.ItemIndex)); UpdateButtonEmissivity(index.ItemIndex); MyMultiplayer.RaiseEvent(this, x => x.SendToolbarItemChanged, tItem, index.ItemIndex); if (m_shouldSetOtherToolbars) { m_shouldSetOtherToolbars = false; foreach (var toolbar in m_openedToolbars) { if (toolbar != self) { toolbar.SetItemAtIndex(index.ItemIndex, self.GetItemAtIndex(index.ItemIndex)); } } m_shouldSetOtherToolbars = true; } var slot = Toolbar.GetItemAtIndex(index.ItemIndex); if (slot != null) { string name = slot.DisplayName.ToString(); MyMultiplayer.RaiseEvent(this, x => x.SetButtonName, name, index.ItemIndex); } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { SyncFlag = true; base.Init(objectBuilder, cubeGrid); //MyDebug.AssertDebug(objectBuilder.TypeId == typeof(MyObjectBuilder_ShipController)); var def = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId()); m_enableFirstPerson = BlockDefinition.EnableFirstPerson || MySession.Static.Settings.Enable3rdPersonView == false; m_enableShipControl = BlockDefinition.EnableShipControl; m_rechargeSocket = new MyRechargeSocket(); MyObjectBuilder_ShipController shipControllerOb = (MyObjectBuilder_ShipController)objectBuilder; // No need for backward compatibility of selected weapon, we just leave it alone // m_selectedGunType = shipControllerOb.SelectedGunType; m_selectedGunId = shipControllerOb.SelectedGunId; m_controlThrusters = shipControllerOb.ControlThrusters; m_controlWheels = shipControllerOb.ControlWheels; if (shipControllerOb.IsMainCockpit) { IsMainCockpit = true; } Toolbar = new MyToolbar(ToolbarType); Toolbar.Init(shipControllerOb.Toolbar, this); SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged; // TODO: Seems like overkill if (Sync.IsServer && false) { //Because of simulating thrusts NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; } CubeGrid.OnGridSplit += CubeGrid_OnGridSplit; }
private void CurrentToolbar_SelectedSlotChanged(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.SelectedItem is MyToolbarItemVoxelHand)) { if (Enabled) Enabled = false; } }
void Toolbar_ItemChanged(MyToolbar self, MyToolbar.IndexArgs index) { if(m_syncing) { return; } Debug.Assert(self == Toolbar); var tItem = ToolbarItem.FromItem(self.GetItemAtIndex(index.ItemIndex)); var oldItem = m_items[index.ItemIndex]; if ((tItem.EntityID == 0 && oldItem.EntityID == 0 || (tItem.EntityID != 0 && oldItem.EntityID != 0 && tItem.Equals(oldItem)))) return; m_items.RemoveAt(index.ItemIndex); m_items.Insert(index.ItemIndex, tItem); MyMultiplayer.RaiseEvent(this, x => x.SendToolbarItemChanged, tItem, index.ItemIndex); if (m_shouldSetOtherToolbars) { m_shouldSetOtherToolbars = false; foreach (var toolbar in m_openedToolbars) { if (toolbar != self) { toolbar.SetItemAtIndex(index.ItemIndex, self.GetItemAtIndex(index.ItemIndex)); } } m_shouldSetOtherToolbars = true; } }
private void CurrentToolbar_SlotActivated(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.GetItemAtIndex(toolbar.SlotToIndex(args.SlotNumber.Value)) is MyToolbarItemVoxelHand)) { if (Enabled) Enabled = false; } }
private void CurrentToolbar_SelectedSlotChanged(MyToolbar toolbar, MyToolbar.SlotArgs args) { if (!(toolbar.SelectedItem is MyToolbarItemAreaMarker)) AreaMarkerDefinition = null; }
private void CurrentToolbar_Unselected(MyToolbar toolbar) { if (Enabled) Enabled = false; }
private void CurrentToolbar_Unselected(MyToolbar toolbar) { AreaMarkerDefinition = null; }