private static void ChangeOwnershipToNearestPlayer(MyTerminalBlock block) { Wrapper.GameAction(() => { double minDist = 0; MyPlayer nearest = null; foreach (var player in MySession.Static.Players.GetOnlinePlayers()) { var dist = Vector3D.DistanceSquared(player.GetPosition(), block.PositionComp.GetPosition()); if (nearest == null) { nearest = player; minDist = dist; } else if (dist < minDist) { nearest = player; } } if (nearest == null) { return; } MyAPIGateway.Utilities.InvokeOnGameThread(() => block.ChangeBlockOwnerRequest(nearest.Identity.IdentityId, MyOwnershipShareModeEnum.Faction)); }); }
void block_ShowInTerminalChanged(MyTerminalBlock obj) { ClearBlockList(); PopulateBlockList(); //GR: Scroll toolbar to top manually when needed from individual controls m_blockListbox.ScrollToolbarToTop(); }
private void OnSpawnIntoContainer(MyGuiControlButton myGuiControlButton) { if (!IsValidAmount()) { m_errorLabel.Visible = true; return; } MyCharacterDetectorComponent comp; if (MySession.Static.LocalCharacter == null || !MySession.Static.LocalCharacter.Components.TryGet(out comp)) { return; } MyTerminalBlock entity = comp.DetectedEntity as MyTerminalBlock; if (entity == null || !entity.HasInventory) { return; } SerializableDefinitionId itemId = m_physicalItemDefinitions[(int)m_physicalObjectCombobox.GetSelectedKey()].Id; if (Sync.IsServer) { SpawnIntoContainer_Implementation(m_amount, itemId, entity.EntityId, MySession.Static.LocalPlayerId); } else { MyMultiplayer.RaiseStaticEvent(x => SpawnIntoContainer_Implementation, m_amount, itemId, entity.EntityId, MySession.Static.LocalPlayerId); } }
void block_CustomNameChanged(MyTerminalBlock obj) { System.Diagnostics.Debug.Assert(m_blockListbox != null, "block_CustomNameChanged was not unregistered!"); if (m_blockListbox == null) { return; } ProfilerShort.Begin("MyTerminalControlPanel.block_CustomNameChanged"); foreach (var item in m_blockListbox.Items) { if (item.UserData == obj) { UpdateItemAppearance(obj, item); break; } } if (CurrentBlocks.Count > 0 && CurrentBlocks[0] == obj) { m_blockNameLabel.Text = obj.CustomName.ToString(); } ProfilerShort.End(); }
private void UpdateItemAppearance(MyTerminalBlock block, MyGuiControlListbox.Item item) { item.Text.Clear().Append(block.CustomName); if (!block.IsFunctional) { item.ColorMask = Vector4.One; item.Text.AppendStringBuilder(MyTexts.Get(MySpaceTexts.Terminal_BlockIncomplete)); item.FontOverride = MyFontEnum.Red; } else if (!block.HasPlayerAccess(m_controller.Identity.IdentityId)) { item.ColorMask = Vector4.One; item.Text.AppendStringBuilder(MyTexts.Get(MySpaceTexts.Terminal_BlockAccessDenied)); item.FontOverride = MyFontEnum.Red; } else if (block.ShowInTerminal == false) { item.ColorMask = 0.6f * m_colorHelper.GetGridColor(block.CubeGrid).ToVector4(); item.FontOverride = null; } else { item.ColorMask = m_colorHelper.GetGridColor(block.CubeGrid).ToVector4(); item.FontOverride = null; } }
public void UpdateCubeBlock(MyTerminalBlock block) { if (block == null) { return; } if (m_terminalSystem != null) { m_terminalSystem.BlockAdded -= TerminalSystem_BlockAdded; m_terminalSystem.BlockRemoved -= TerminalSystem_BlockRemoved; m_terminalSystem.GroupAdded -= TerminalSystem_GroupAdded; m_terminalSystem.GroupRemoved -= TerminalSystem_GroupRemoved; } var grid = block.CubeGrid; m_terminalSystem = grid.GridSystems.TerminalSystem; m_tmpGroup = new MyBlockGroup(grid); m_terminalSystem.BlockAdded += TerminalSystem_BlockAdded; m_terminalSystem.BlockRemoved += TerminalSystem_BlockRemoved; m_terminalSystem.GroupAdded += TerminalSystem_GroupAdded; m_terminalSystem.GroupRemoved += TerminalSystem_GroupRemoved; SelectBlocks(new MyTerminalBlock[] { block }); }
public void WriteValue(MyTerminalBlock block, StringBuilder appendTo) { if (Writer != null) { Writer((TBlock)block, appendTo); } }
public override bool Init(MyObjectBuilder_ToolbarItem objectBuilder) { Debug.Assert(objectBuilder is MyObjectBuilder_ToolbarItemTerminalBlock, "Wrong definition put to toolbar"); WantsToBeActivated = false; WantsToBeSelected = false; ActivateOnClick = true; m_block = null; var builder = (MyObjectBuilder_ToolbarItemTerminalBlock)objectBuilder; m_blockEntityId = builder.BlockEntityId; if (m_blockEntityId == 0) { m_wasValid = false; return(false); } TryGetBlock(); SetAction(builder.Action); if (builder.Parameters != null && builder.Parameters.Count > 0) { m_parameters.Clear(); foreach (var item in builder.Parameters) { m_parameters.Add(TerminalActionParameter.Deserialize(item.Value, item.TypeCode)); } } return(true); }
void TerminalSystem_BlockRemoved(MyTerminalBlock obj) { var removedAssembler = obj as MyAssembler; if (removedAssembler != null) { removedAssembler.CustomNameChanged -= assembler_CustomNameChanged; int?key = null; foreach (var entry in m_assemblersByKey) { if (entry.Value == removedAssembler) { key = entry.Key; break; } } if (key.HasValue) { m_assemblersByKey.Remove(key.Value); m_comboboxAssemblers.RemoveItem(key.Value); } if (removedAssembler == m_selectedAssembler) { if (m_assemblersByKey.Count > 0) { m_comboboxAssemblers.SelectItemByIndex(0); } else { ShowError(MySpaceTexts.ScreenTerminalError_NoAssemblers, m_controlsParent); } } } }
public void Remove(MyTerminalBlock block) { if (block.MarkedForClose) { return; } Debug.Assert(m_blocks.Contains(block), "Block to remove is not in terminal"); m_blocks.Remove(block); for (int i = 0; i < BlockGroups.Count; i++) { var group = BlockGroups[i]; if (group.Blocks.Contains(block)) { group.Blocks.Remove(block); } if (group.Blocks.Count == 0) { RemoveGroup(group); i--; } } var handler = BlockRemoved; if (handler != null) { handler(block); } }
private void thrust_EnabledChanged(MyTerminalBlock obj) { MarkDirty(); if (!CubeGrid.Physics.RigidBody.IsActive) { CubeGrid.ActivatePhysics(); } }
void block_OwnershipChanged(MyTerminalBlock sender) { if (m_canChangeShareMode) { RecreateOwnershipControls(); UpdateOwnerGui(); } }
private void AddBlock(MyTerminalBlock block) { if (!Blocks.TryGetValue(block.BlockDefinition, out var group)) { group = Blocks[block.BlockDefinition] = new MtObservableSortedDictionary <long, BlockViewModel>(); } group.Add(block.EntityId, new BlockViewModel(block, Tree)); }
private static void AddToClipboard(MyTerminalBlock block) { if (MySession.Static.ElapsedGameTime != m_lastAccess) { Clipboard.Clear(); m_lastAccess = MySession.Static.ElapsedGameTime; } Clipboard.Add(block); }
public void Apply(MyTerminalBlock block) { var b = (TBlock)block; if (Enabled(b)) { m_action(b); } }
public void Apply(MyTerminalBlock block, ListReader <TerminalActionParameter> parameters) { var b = (TBlock)block; if (Enabled(b)) { m_actionWithParameters(b, parameters); } }
private void AddRow(MyTerminalBlock block) { MyGuiControlTable.Row row; MyGuiControlTable.Cell cell; row = new MyGuiControlTable.Row(block); cell = new MyGuiControlTable.Cell(block.CustomName); row.AddCell(cell); m_selectedBlocks.Add(row); }
private void DroneRemoteOwnershipChanged(MyTerminalBlock remote) { long newOwner = remote.OwnerId; if (!Sync.Players.IdentityIsNpc(newOwner)) { UnregisterDrone(remote); } }
public static void SendShowInTerminalRequest(MyTerminalBlock block, bool show) { var msg = new ShowInTerminalMsg(); msg.EntityId = block.EntityId; msg.Show = show; Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); }
private void block_VisibilityChanged(MyTerminalBlock obj) { foreach (var control in m_currentControls) { if (control.GetGuiControl().Visible != control.IsVisible(obj)) { control.GetGuiControl().Visible = control.IsVisible(obj); } } }
private void OnBlockOwnershipChanged(MyTerminalBlock block) { SQLQueryData.WriteToDatabase(new BlockOwnershipDescription() { GridId = block.CubeGrid.EntityId, BlockEntityId = block.EntityId, Owner = block.OwnerId, Timestamp = Tools.DateTime }); }
void TerminalSystem_BlockRemoved(MyTerminalBlock obj) { obj.CustomNameChanged -= block_CustomNameChanged; obj.PropertiesChanged -= block_CustomNameChanged; Debug.Assert(m_blockListbox != null); if (m_blockListbox != null && (obj.ShowInTerminal || m_showAllTerminalBlocks)) { m_blockListbox.Remove((item) => (item.UserData == obj)); } }
private static StringBuilder GetTargetBlockName(MyTerminalBlock block) { ManualMessage instance; if (!Registrar.TryGetValue(block.EntityId, out instance)) { throw new ArgumentException("block id not found in registrar"); } return(instance.m_targetBlockName); }
private static void SetMessage(MyTerminalBlock block, StringBuilder value) { ManualMessage instance; if (!Registrar.TryGetValue(block.EntityId, out instance)) { throw new ArgumentException("block id not found in registrar"); } instance.m_message = value; }
public void Initialize(Vector3 panelOrientation, bool isTwoSided, float panelOffset, MyTerminalBlock solarBlock) { m_initialized = true; m_panelOrientation = panelOrientation; m_isTwoSided = isTwoSided; m_panelOffset = panelOffset; m_solarBlock = solarBlock; //Warning: this will change the NeedsUpdate variable on the entity NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; }
void block_ShowInTerminalChanged(MyTerminalBlock obj) { ClearBlockList(); PopulateBlockList(); //JC: This should never be null at this point but is happening... if (m_blockListbox != null) { //GR: Scroll toolbar to top manually when needed from individual controls m_blockListbox.ScrollToolbarToTop(); } }
private MyGuiControlListbox.Item AddBlockToList(MyTerminalBlock block) { var item = new MyGuiControlListbox.Item(userData: block); UpdateItemAppearance(block, item); block.CustomNameChanged += block_CustomNameChanged; block.PropertiesChanged += block_CustomNameChanged; block.ShowInTerminalChanged += block_ShowInTerminalChanged; m_blockListbox.Add(item); return(item); }
private static void FatBlock_OwnershipChanged(MyTerminalBlock block) { if (block?.CubeGrid?.Physics == null || block.Closed) { //idfk Thread.Sleep(500); if (block?.CubeGrid?.Physics == null || block.Closed) { return; } } Task.Run(() => { if (block.OwnerId != 0) { var owner = MySession.Static.Players.GetPlayerById(new MyPlayer.PlayerId(PlayerMap.Instance.GetSteamIdFromPlayerId(block.OwnerId))); if (owner != null && MySession.Static.Players.IdentityIsNpc(block.OwnerId)) { if (owner.DisplayName != "Space Pirates") { lock (BlockOwners) BlockOwners[block] = block.OwnerId; return; } } } lock ( BlockOwners ) { if (BlockOwners.ContainsKey(block)) { MyAPIGateway.Utilities.InvokeOnGameThread(() => block.ChangeBlockOwnerRequest(BlockOwners[block], MyOwnershipShareModeEnum.Faction)); } else if (PluginSettings.Instance.PlayerBlockEnforcementChangeOwner) { ChangeOwnershipToNearestPlayer(block); if (block.OwnerId == 0 && block.CubeGrid.BigOwners.Count > 0) { MyAPIGateway.Utilities.InvokeOnGameThread(() => block.ChangeBlockOwnerRequest(block.CubeGrid.BigOwners[0], MyOwnershipShareModeEnum.Faction)); } if (block.OwnerId != 0) { BlockOwners[block] = block.OwnerId; } } } }); ProcessEnforcement(); }
public static void SendChangeNameRequest(MyTerminalBlock block, string name) { if (name.CompareTo(block.CustomName.ToString()) != 0) { block.UpdateCustomName(name); var msg = new ChangeNameMsg(); msg.EntityId = block.EntityId; msg.Name = name; // Allocation will be either here or in deserialization...or messages would have to be pooled Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request); } }
void assembler_CustomNameChanged(MyTerminalBlock block) { Debug.Assert(block is MyAssembler && m_assemblersByKey.ContainsValue(block as MyAssembler)); foreach (var entry in m_assemblersByKey) { if (entry.Value == block) { var comboItem = m_comboboxAssemblers.TryGetItemByKey(entry.Key); comboItem.Value.Clear().AppendStringBuilder(block.CustomName); } } }