Пример #1
0
        private MyGuiControlTable.Cell CreateTerminalCell(CubeGridInfo gridInfo, bool isActive)
        {
            MyGuiControlTable.Cell cell = new MyGuiControlTable.Cell();

            Vector2 size = new Vector2(0.1f, m_shipsData.RowHeight * 0.9f);

            MyStringId     tooltip = MySpaceTexts.BroadcastScreen_TerminalButton_ToolTip;
            MyRefuseReason reason  = CanTakeTerminal(gridInfo);

            switch (reason)
            {
            case MyRefuseReason.NoStableConnection:
            case MyRefuseReason.PlayerBroadcastOff:
            case MyRefuseReason.NoOwner:
                isActive = false;
                break;
            }

            cell.Control = new MyGuiControlButton(text: MyTexts.Get(MySpaceTexts.Terminal),
                                                  visualStyle: VRage.Game.MyGuiControlButtonStyleEnum.Rectangular,
                                                  size: size,
                                                  textScale: 0.9f,
                                                  onButtonClick: OnButtonClicked_OpenTerminal
                                                  );
            cell.Control.SetToolTip(tooltip);
            cell.Control.Enabled = isActive;
            m_shipsData.Controls.Add(cell.Control);
            return(cell);
        }
Пример #2
0
        private MyRefuseReason CanTakeRemoteControl(CubeGridInfo gridInfo)
        {
            MyEntity openTerminalEntity;

            MyEntities.TryGetEntityById(gridInfo.EntityId, out openTerminalEntity);
            if (openTerminalEntity != null && openTerminalEntity is MyCubeGrid)
            {
                var grid = openTerminalEntity as MyCubeGrid;

                int remoteControlCount = grid.GetFatBlockCount <MyRemoteControl>();
                if (remoteControlCount == 0)
                {
                    return(MyRefuseReason.NoRemoteControl);
                }
                if (remoteControlCount > 1 && !grid.HasMainRemoteControl())
                {
                    return(MyRefuseReason.NoMainRemoteControl);
                }

                if (grid.HasMainRemoteControl())
                {
                    if (grid.MainRemoteControl.OwnerId != MySession.Static.LocalHumanPlayer.Identity.IdentityId ||
                        (MySession.Static.Factions.GetPlayerFaction(grid.MainRemoteControl.OwnerId) != null &&
                         !MySession.Static.Factions.GetPlayerFaction(grid.MainRemoteControl.OwnerId).IsMember(MySession.Static.LocalHumanPlayer.Identity.IdentityId)))
                    {
                        return(MyRefuseReason.NoOwner);
                    }
                }
                if (remoteControlCount == 1)
                {
                    var fbs = grid.GetFatBlocks <MyRemoteControl>();
                    fbs.MoveNext();
                    if (fbs.Current.OwnerId != MySession.Static.LocalHumanPlayer.Identity.IdentityId ||
                        (MySession.Static.Factions.GetPlayerFaction(fbs.Current.OwnerId) != null &&
                         !MySession.Static.Factions.GetPlayerFaction(fbs.Current.OwnerId).IsMember(MySession.Static.LocalHumanPlayer.Identity.IdentityId)))
                    {
                        return(MyRefuseReason.NoOwner);
                    }
                }
            }
            return(MyRefuseReason.NoProblem);
        }
Пример #3
0
        private MyRefuseReason CanTakeTerminal(CubeGridInfo gridInfo)
        {
            MyEntity openTerminalEntity;

            MyEntities.TryGetEntityById(gridInfo.EntityId, out openTerminalEntity);
            if (openTerminalEntity != null && openTerminalEntity is MyCubeGrid)
            {
                var grid = openTerminalEntity as MyCubeGrid;

                m_tempSendingToGrid.Clear();
                m_tempReceivingFromGrid.Clear();
                GridBroadcastersFromPlayer(grid, m_tempSendingToGrid);
                PlayerBroadcastersFromGrid(grid, m_tempReceivingFromGrid);

                if (m_tempReceivingFromGrid.Count > 0 && m_tempSendingToGrid.Count > 0)
                {
                    bool ownership = false;
                    foreach (var item in m_tempReceivingFromGrid)
                    {
                        var cubeBlock = item.Entity as MyCubeBlock;
                        if (cubeBlock == null)
                        {
                            continue;
                        }

                        if (cubeBlock.OwnerId == MySession.Static.LocalHumanPlayer.Identity.IdentityId)
                        {
                            ownership = true;
                        }
                        var blockFaction = MySession.Static.Factions.GetPlayerFaction(cubeBlock.OwnerId);
                        if (blockFaction != null && blockFaction.IsMember(MySession.Static.LocalHumanPlayer.Identity.IdentityId))
                        {
                            ownership = true;
                        }
                    }
                    foreach (var item in m_tempSendingToGrid)
                    {
                        var cubeBlock = item.Entity as MyCubeBlock;
                        if (cubeBlock == null)
                        {
                            continue;
                        }

                        if (cubeBlock.OwnerId == MySession.Static.LocalHumanPlayer.Identity.IdentityId)
                        {
                            ownership = true;
                        }
                        var blockFaction = MySession.Static.Factions.GetPlayerFaction(cubeBlock.OwnerId);
                        if (blockFaction != null && blockFaction.IsMember(MySession.Static.LocalHumanPlayer.Identity.IdentityId))
                        {
                            ownership = true;
                        }
                    }
                    if (!ownership)
                    {
                        return(MyRefuseReason.NoOwner);
                    }
                }

                if (gridInfo.Status == MyCubeGridConnectionStatus.OutOfReceivingRange && (MySession.Static.ControlledEntity.Entity is MyCharacter) && !(MySession.Static.ControlledEntity.Entity as MyCharacter).RadioBroadcaster.Enabled)
                {
                    return(MyRefuseReason.PlayerBroadcastOff);
                }

                if (gridInfo.Status == MyCubeGridConnectionStatus.OutOfBroadcastingRange || gridInfo.Status == MyCubeGridConnectionStatus.OutOfReceivingRange)
                {
                    return(MyRefuseReason.NoStableConnection);
                }
            }

            return(MyRefuseReason.NoProblem);
        }
Пример #4
0
        private MyGuiControlTable.Cell CreateStatusIcons(CubeGridInfo gridInfo, bool isActive)
        {
            MyGuiControlTable.Cell cell = new MyGuiControlTable.Cell();
            float iconSize = m_shipsData.RowHeight * 0.7f;

            bool antIsActive, keyIsActive, remIsActive;

            antIsActive = keyIsActive = remIsActive = isActive;
            MyStringId antTooltip, remTooltip;

            antTooltip = remTooltip = MyStringId.NullOrEmpty;
            StringBuilder keyTooltip = new StringBuilder();

            MyGuiControlParent gr = new MyGuiControlParent();

            MyRefuseReason reasonT  = CanTakeTerminal(gridInfo);
            MyRefuseReason reasonRC = CanTakeRemoteControl(gridInfo);

            //Antenna icon
            switch (reasonT)
            {
            case MyRefuseReason.PlayerBroadcastOff:
                antIsActive = false;
                antTooltip  = MySpaceTexts.BroadcastScreen_TerminalButton_PlayerBroadcastOffToolTip;
                break;

            case MyRefuseReason.NoStableConnection:
                antIsActive = false;
                antTooltip  = MySpaceTexts.BroadcastScreen_TerminalButton_NoStableConnectionToolTip;
                break;

            case MyRefuseReason.NoOwner:
            case MyRefuseReason.NoProblem:
                antTooltip = MySpaceTexts.BroadcastScreen_TerminalButton_StableConnectionToolTip;
                break;
            }
            MyGuiControlImage antenna = new MyGuiControlImage(
                position: new Vector2(-2 * iconSize, 0),
                size: new Vector2(iconSize, iconSize),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                backgroundTexture: (antIsActive ? MyGuiConstants.BS_ANTENNA_ON : MyGuiConstants.BS_ANTENNA_OFF)
                );

            antenna.SetToolTip(antTooltip);
            gr.Controls.Add(antenna);

            //Remote Control icon
            switch (reasonRC)
            {
            case MyRefuseReason.NoRemoteControl:
                remTooltip  = MySpaceTexts.BroadcastScreen_TakeControlButton_NoRemoteToolTip;
                remIsActive = false;
                break;

            case MyRefuseReason.NoMainRemoteControl:
                remTooltip  = MySpaceTexts.BroadcastScreen_TakeControlButton_NoMainRemoteControl;
                remIsActive = false;
                break;

            case MyRefuseReason.NoOwner:
            case MyRefuseReason.NoProblem:
                remTooltip = MySpaceTexts.BroadcastScreen_TakeControlButton_RemoteToolTip;
                break;
            }
            MyGuiControlImage remote = new MyGuiControlImage(
                position: new Vector2(-1 * iconSize, 0),
                size: new Vector2(iconSize, iconSize),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                backgroundTexture: (remIsActive ? MyGuiConstants.BS_REMOTE_ON : MyGuiConstants.BS_REMOTE_OFF)
                );

            remote.SetToolTip(remTooltip);
            gr.Controls.Add(remote);

            //Key icon
            if ((reasonT == MyRefuseReason.NoStableConnection || reasonT == MyRefuseReason.PlayerBroadcastOff) && reasonRC == MyRefuseReason.NoRemoteControl)
            {
                keyTooltip.Append(MyTexts.Get(MySpaceTexts.BroadcastScreen_UnavailableControlButton));
                keyIsActive = false;
            }
            if (keyIsActive && (reasonT == MyRefuseReason.NoOwner || reasonRC == MyRefuseReason.NoOwner || reasonT == MyRefuseReason.NoStableConnection || reasonT == MyRefuseReason.PlayerBroadcastOff))
            {
                keyIsActive = false;
                keyTooltip.Append(MyTexts.Get(MySpaceTexts.BroadcastScreen_NoOwnership));
            }
            if (reasonT == MyRefuseReason.NoOwner)
            {
                keyTooltip.AppendLine();
                keyTooltip.Append(MyTexts.Get(MySpaceTexts.DisplayName_Block_Antenna));
            }
            if (reasonRC == MyRefuseReason.NoOwner)
            {
                keyTooltip.AppendLine();
                keyTooltip.Append(MyTexts.Get(MySpaceTexts.DisplayName_Block_RemoteControl));
            }
            if (keyIsActive)
            {
                keyTooltip.Append(MyTexts.Get(MySpaceTexts.BroadcastScreen_Ownership));
            }
            MyGuiControlImage key = new MyGuiControlImage(
                size: new Vector2(iconSize, iconSize),
                originAlign: MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER,
                backgroundTexture: (keyIsActive ? MyGuiConstants.BS_KEY_ON : MyGuiConstants.BS_KEY_OFF)
                );

            key.SetToolTip(keyTooltip.ToString());
            gr.Controls.Add(key);


            cell.Control = gr;
            m_shipsData.Controls.Add(gr);
            return(cell);
        }