Exemplo n.º 1
0
        public override void Deselect()
        {
            base.Deselect();

            GUIComponent.ForceMouseOn(null);

            MapEntityPrefab.Selected = null;

            MapEntity.DeselectAll();

            if (characterMode)
            {
                ToggleCharacterMode();
            }

            if (wiringMode)
            {
                ToggleWiringMode();
            }

            SoundPlayer.OverrideMusicType = null;
            for (int i = 0; i < Sounds.SoundManager.DefaultSourceCount; i++)
            {
                Sounds.SoundManager.Resume(i);
            }

            if (dummyCharacter != null)
            {
                dummyCharacter.Remove();
                dummyCharacter = null;
                GameMain.World.ProcessChanges();
            }
        }
Exemplo n.º 2
0
        public override void Select()
        {
            base.Select();

            GUIComponent.ForceMouseOn(null);
            characterMode = false;

            if (Submarine.MainSub != null)
            {
                cam.Position = Submarine.MainSub.Position + Submarine.MainSub.HiddenSubPosition;
            }
            else
            {
                Submarine.MainSub = new Submarine(Path.Combine(Submarine.SavePath, "Unnamed.sub"), "", false);
                cam.Position      = Submarine.MainSub.Position;
            }

            SoundPlayer.OverrideMusicType = "none";
            for (int i = 0; i < Sounds.SoundManager.DefaultSourceCount; i++)
            {
                Sounds.SoundManager.Pause(i);
            }

            linkedSubBox.ClearChildren();
            foreach (Submarine sub in Submarine.SavedSubmarines)
            {
                linkedSubBox.AddItem(sub.Name, sub);
            }

            cam.UpdateTransform();
        }
Exemplo n.º 3
0
        public static void Update(GameMain game, float deltaTime)
        {
            lock (queuedMessages)
            {
                while (queuedMessages.Count > 0)
                {
                    AddMessage(queuedMessages.Dequeue());
                }
            }

            if (activeQuestionText != null &&
                (listBox.children.Count == 0 || listBox.children[listBox.children.Count - 1] != activeQuestionText))
            {
                listBox.children.Remove(activeQuestionText);
                listBox.children.Add(activeQuestionText);
            }

            if (PlayerInput.KeyHit(Keys.F3))
            {
                isOpen = !isOpen;
                if (isOpen)
                {
                    textBox.Select();
                    AddToGUIUpdateList();
                }
                else
                {
                    GUIComponent.ForceMouseOn(null);
                    textBox.Deselect();
                }
            }

            if (isOpen)
            {
                frame.Update(deltaTime);

                Character.DisableControls = true;

                if (PlayerInput.KeyHit(Keys.Up))
                {
                    textBox.Text = SelectMessage(-1);
                }
                else if (PlayerInput.KeyHit(Keys.Down))
                {
                    textBox.Text = SelectMessage(1);
                }
                else if (PlayerInput.KeyHit(Keys.Tab))
                {
                    textBox.Text = AutoComplete(textBox.Text);
                }

                if (PlayerInput.KeyHit(Keys.Enter))
                {
                    ExecuteCommand(textBox.Text);
                    textBox.Text = "";
                }
            }
        }
Exemplo n.º 4
0
        private bool SelectPrefab(GUIComponent component, object obj)
        {
            AddPreviouslyUsed(obj as MapEntityPrefab);

            MapEntityPrefab.SelectPrefab(obj);
            selectedTab = -1;
            GUIComponent.ForceMouseOn(null);
            return(false);
        }
Exemplo n.º 5
0
        public static void Update(GameMain game, float deltaTime)
        {
            if (PlayerInput.KeyHit(Keys.F3))
            {
                isOpen = !isOpen;
                if (isOpen)
                {
                    textBox.Select();
                    AddToGUIUpdateList();
                }
                else
                {
                    GUIComponent.ForceMouseOn(null);
                    textBox.Deselect();
                }

                //keyboardDispatcher.Subscriber = (isOpen) ? textBox : null;
            }

            if (isOpen)
            {
                frame.Update(deltaTime);

                Character.DisableControls = true;

                if (PlayerInput.KeyHit(Keys.Up))
                {
                    SelectMessage(-1);
                }
                else if (PlayerInput.KeyHit(Keys.Down))
                {
                    SelectMessage(1);
                }

                //textBox.Update(deltaTime);

                if (PlayerInput.KeyDown(Keys.Enter) && textBox.Text != "")
                {
                    ExecuteCommand(textBox.Text, game);
                    textBox.Text = "";

                    //selectedIndex = messages.Count;
                }
            }
        }
Exemplo n.º 6
0
        public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam)
        {
            if (statusIcons == null)
            {
                statusIcons = new Sprite("Content/UI/statusIcons.png", Vector2.Zero);
            }

            if (noiseOverlay == null)
            {
                noiseOverlay = new Sprite("Content/UI/noise.png", Vector2.Zero);
            }

            if (damageOverlay == null)
            {
                damageOverlay = new Sprite("Content/UI/damageOverlay.png", Vector2.Zero);
            }

            if (GUI.DisableHUD)
            {
                return;
            }

            if (character.Inventory != null)
            {
                for (int i = 0; i < character.Inventory.Items.Length - 1; i++)
                {
                    var item = character.Inventory.Items[i];
                    if (item == null || CharacterInventory.limbSlots[i] == InvSlotType.Any)
                    {
                        continue;
                    }

                    foreach (ItemComponent ic in item.components)
                    {
                        if (ic.DrawHudWhenEquipped)
                        {
                            ic.DrawHUD(spriteBatch, character);
                        }
                    }
                }
            }

            DrawStatusIcons(spriteBatch, character);

            if (!character.IsUnconscious && character.Stun <= 0.0f)
            {
                if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
                {
                    character.Inventory.DrawOffset = Vector2.Zero;
                    character.Inventory.DrawOwn(spriteBatch);
                }

                if (character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
                {
                    character.SelectedCharacter.Inventory.DrawOffset = new Vector2(320.0f, 0.0f);
                    character.SelectedCharacter.Inventory.DrawOwn(spriteBatch);

                    if (cprButton == null)
                    {
                        cprButton = new GUIButton(
                            new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(320, -30), new Point(130, 20)), "Perform CPR", "");

                        cprButton.OnClicked = (button, userData) =>
                        {
                            if (Character.Controlled == null || Character.Controlled.SelectedCharacter == null)
                            {
                                return(false);
                            }

                            Character.Controlled.AnimController.Anim = (Character.Controlled.AnimController.Anim == AnimController.Animation.CPR) ?
                                                                       AnimController.Animation.None : AnimController.Animation.CPR;

                            foreach (Limb limb in Character.Controlled.SelectedCharacter.AnimController.Limbs)
                            {
                                limb.pullJoint.Enabled = false;
                            }

                            if (GameMain.Client != null)
                            {
                                GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Repair });
                            }

                            return(true);
                        };
                    }

                    //cprButton.Visible = character.GetSkillLevel("Medical") > 20.0f;

                    if (cprButton.Visible)
                    {
                        cprButton.Draw(spriteBatch);
                    }
                }

                if (character.ClosestCharacter != null && character.ClosestCharacter.CanBeSelected)
                {
                    Vector2 startPos = character.DrawPosition + (character.ClosestCharacter.DrawPosition - character.DrawPosition) * 0.7f;
                    startPos = cam.WorldToScreen(startPos);

                    Vector2 textPos = startPos;
                    textPos -= new Vector2(GUI.Font.MeasureString(character.ClosestCharacter.Info.Name).X / 2, 20);

                    GUI.DrawString(spriteBatch, textPos, character.ClosestCharacter.Info.Name, Color.White, Color.Black, 2);
                }
                else if (character.SelectedCharacter == null && character.ClosestItem != null && character.SelectedConstruction == null)
                {
                    var hudTexts = character.ClosestItem.GetHUDTexts(character);

                    Vector2 startPos = new Vector2((int)(GameMain.GraphicsWidth / 2.0f), GameMain.GraphicsHeight);
                    startPos.Y -= 50 + hudTexts.Count * 25;

                    Vector2 textPos = startPos;
                    textPos -= new Vector2((int)GUI.Font.MeasureString(character.ClosestItem.Name).X / 2, 20);

                    GUI.DrawString(spriteBatch, textPos, character.ClosestItem.Name, Color.White, Color.Black * 0.7f, 2);

                    textPos.Y += 30.0f;
                    foreach (ColoredText coloredText in hudTexts)
                    {
                        textPos.X = (int)(startPos.X - GUI.SmallFont.MeasureString(coloredText.Text).X / 2);

                        GUI.DrawString(spriteBatch, textPos, coloredText.Text, coloredText.Color, Color.Black * 0.7f, 2, GUI.SmallFont);

                        textPos.Y += 25;
                    }
                }

                foreach (HUDProgressBar progressBar in character.HUDProgressBars.Values)
                {
                    progressBar.Draw(spriteBatch, cam);
                }
            }

            if (Screen.Selected == GameMain.EditMapScreen)
            {
                return;
            }

            if (character.IsUnconscious || (character.Oxygen < 80.0f && !character.IsDead))
            {
                Vector2 offset = Rand.Vector(noiseOverlay.size.X);
                offset.X = Math.Abs(offset.X);
                offset.Y = Math.Abs(offset.Y);

                float alpha = character.IsUnconscious ? 1.0f : Math.Min((80.0f - character.Oxygen) / 50.0f, 0.8f);

                noiseOverlay.DrawTiled(spriteBatch, Vector2.Zero - offset, new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight) + offset,
                                       Vector2.Zero,
                                       Color.White * alpha);
            }
            else
            {
                if (suicideButton != null)
                {
                    suicideButton.Visible = false;
                }
            }

            if (damageOverlayTimer > 0.0f)
            {
                damageOverlay.Draw(spriteBatch, Vector2.Zero, Color.White * damageOverlayTimer, Vector2.Zero, 0.0f,
                                   new Vector2(GameMain.GraphicsWidth / damageOverlay.size.X, GameMain.GraphicsHeight / damageOverlay.size.Y));
            }

            if (character.IsUnconscious && !character.IsDead)
            {
                if (suicideButton == null)
                {
                    suicideButton = new GUIButton(
                        new Rectangle(new Point(GameMain.GraphicsWidth / 2 - 60, 20), new Point(120, 20)), "Give in", "");


                    suicideButton.ToolTip = GameMain.NetworkMember == null ?
                                            "The character can no longer be revived if you give in." :
                                            "Let go of your character and enter spectator mode (other players will no longer be able to revive you)";

                    suicideButton.OnClicked = (button, userData) =>
                    {
                        GUIComponent.ForceMouseOn(null);
                        if (Character.Controlled != null)
                        {
                            if (GameMain.Client != null)
                            {
                                GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Status });
                            }
                            else
                            {
                                Character.Controlled.Kill(Character.Controlled.CauseOfDeath);
                                Character.Controlled = null;
                            }
                        }
                        return(true);
                    };
                }

                suicideButton.Visible = true;
                suicideButton.Draw(spriteBatch);
            }
        }
Exemplo n.º 7
0
        public static void Draw(SpriteBatch spriteBatch, Character character, Camera cam)
        {
            if (statusIcons == null)
            {
                statusIcons = new Sprite("Content/UI/statusIcons.png", Vector2.Zero);
            }

            if (noiseOverlay == null)
            {
                noiseOverlay = new Sprite("Content/UI/noise.png", Vector2.Zero);
            }

            if (damageOverlay == null)
            {
                damageOverlay = new Sprite("Content/UI/damageOverlay.png", Vector2.Zero);
            }

            if (GUI.DisableHUD)
            {
                return;
            }

            if (character.Inventory != null)
            {
                for (int i = 0; i < character.Inventory.Items.Length - 1; i++)
                {
                    var item = character.Inventory.Items[i];
                    if (item == null || CharacterInventory.limbSlots[i] == InvSlotType.Any)
                    {
                        continue;
                    }

                    foreach (ItemComponent ic in item.components)
                    {
                        if (ic.DrawHudWhenEquipped)
                        {
                            ic.DrawHUD(spriteBatch, character);
                        }
                    }
                }
            }

            DrawStatusIcons(spriteBatch, character);

            if (!character.IsUnconscious && character.Stun <= 0.0f)
            {
                if (character.IsHumanoid && character.SelectedCharacter != null && character.SelectedCharacter.Inventory != null)
                {
                    if (cprButton == null)
                    {
                        cprButton = new GUIButton(
                            new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(320, -30), new Point(130, 20)), "Perform CPR", "");

                        cprButton.OnClicked = (button, userData) =>
                        {
                            if (Character.Controlled == null || Character.Controlled.SelectedCharacter == null)
                            {
                                return(false);
                            }

                            Character.Controlled.AnimController.Anim = (Character.Controlled.AnimController.Anim == AnimController.Animation.CPR) ?
                                                                       AnimController.Animation.None : AnimController.Animation.CPR;

                            Character.Controlled.SelectedCharacter.AnimController.ResetPullJoints();

                            if (GameMain.Client != null)
                            {
                                GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Repair });
                            }

                            return(true);
                        };
                    }

                    if (grabHoldButton == null)
                    {
                        grabHoldButton = new GUIButton(
                            new Rectangle(character.SelectedCharacter.Inventory.SlotPositions[0].ToPoint() + new Point(320, -60), new Point(130, 20)),
                            TextManager.Get("Grabbing") + ": " + TextManager.Get(character.AnimController.GrabLimb == LimbType.None ? "Hands" : character.AnimController.GrabLimb.ToString()), "");

                        grabHoldButton.OnClicked = (button, userData) =>
                        {
                            if (Character.Controlled == null || Character.Controlled.SelectedCharacter == null)
                            {
                                return(false);
                            }

                            Character.Controlled.AnimController.GrabLimb = Character.Controlled.AnimController.GrabLimb == LimbType.None ? LimbType.Torso : LimbType.None;

                            Character.Controlled.SelectedCharacter.AnimController.ResetPullJoints();

                            if (GameMain.Client != null)
                            {
                                GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Control });
                            }

                            grabHoldButton.Text = TextManager.Get("Grabbing") + ": " + TextManager.Get(character.AnimController.GrabLimb == LimbType.None ? "Hands" : character.AnimController.GrabLimb.ToString());
                            return(true);
                        };
                    }

                    if (cprButton.Visible)
                    {
                        cprButton.Draw(spriteBatch);
                    }
                    if (grabHoldButton.Visible)
                    {
                        grabHoldButton.Draw(spriteBatch);
                    }

                    character.SelectedCharacter.Inventory.DrawOffset = new Vector2(320.0f, 0.0f);
                    character.SelectedCharacter.Inventory.DrawOwn(spriteBatch);
                }

                if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
                {
                    character.Inventory.DrawOffset = Vector2.Zero;
                    character.Inventory.DrawOwn(spriteBatch);
                }
                if (character.Inventory != null && !character.LockHands && character.Stun >= -0.1f)
                {
                    Inventory.DrawDragging(spriteBatch);
                }

                if (character.FocusedCharacter != null && character.FocusedCharacter.CanBeSelected)
                {
                    Vector2 startPos = character.DrawPosition + (character.FocusedCharacter.DrawPosition - character.DrawPosition) * 0.7f;
                    startPos = cam.WorldToScreen(startPos);

                    string focusName = character.FocusedCharacter.SpeciesName;
                    if (character.FocusedCharacter.Info != null)
                    {
                        focusName = character.FocusedCharacter.Info.DisplayName;
                    }
                    Vector2 textPos = startPos;
                    textPos -= new Vector2(GUI.Font.MeasureString(focusName).X / 2, 20);

                    GUI.DrawString(spriteBatch, textPos, focusName, Color.White, Color.Black, 2);
                }
                else if (character.SelectedCharacter == null && character.FocusedItem != null && character.SelectedConstruction == null)
                {
                    var hudTexts = character.FocusedItem.GetHUDTexts(character);

                    Vector2 startPos = new Vector2((int)(GameMain.GraphicsWidth / 2.0f), GameMain.GraphicsHeight);
                    startPos.Y -= 50 + hudTexts.Count * 25;

                    Vector2 textPos = startPos;
                    textPos -= new Vector2((int)GUI.Font.MeasureString(character.FocusedItem.Name).X / 2, 20);

                    GUI.DrawString(spriteBatch, textPos, character.FocusedItem.Name, Color.White, Color.Black * 0.7f, 2);

                    textPos.Y += 30.0f;
                    foreach (ColoredText coloredText in hudTexts)
                    {
                        textPos.X = (int)(startPos.X - GUI.SmallFont.MeasureString(coloredText.Text).X / 2);

                        GUI.DrawString(spriteBatch, textPos, coloredText.Text, coloredText.Color, Color.Black * 0.7f, 2, GUI.SmallFont);

                        textPos.Y += 25;
                    }
                }

                foreach (HUDProgressBar progressBar in character.HUDProgressBars.Values)
                {
                    progressBar.Draw(spriteBatch, cam);
                }
            }

            if (Screen.Selected == GameMain.SubEditorScreen)
            {
                return;
            }

            if (character.IsUnconscious || (character.Oxygen < 80.0f && !character.IsDead))
            {
                Vector2 offset = Rand.Vector(noiseOverlay.size.X);
                offset.X = Math.Abs(offset.X);
                offset.Y = Math.Abs(offset.Y);

                float alpha = character.IsUnconscious ? 1.0f : Math.Min((80.0f - character.Oxygen) / 50.0f, 0.8f);

                noiseOverlay.DrawTiled(spriteBatch, Vector2.Zero - offset, new Vector2(GameMain.GraphicsWidth, GameMain.GraphicsHeight) + offset,
                                       color: Color.White * alpha);
            }
            else
            {
                if (suicideButton != null)
                {
                    suicideButton.Visible = false;
                }
            }

            if (damageOverlayTimer > 0.0f)
            {
                damageOverlay.Draw(spriteBatch, Vector2.Zero, Color.White * damageOverlayTimer, Vector2.Zero, 0.0f,
                                   new Vector2(GameMain.GraphicsWidth / damageOverlay.size.X, GameMain.GraphicsHeight / damageOverlay.size.Y));
            }

            if (character.IsUnconscious && !character.IsDead)
            {
                if (suicideButton == null)
                {
                    suicideButton = new GUIButton(
                        new Rectangle(new Point(GameMain.GraphicsWidth / 2 - 60, 20), new Point(120, 20)), TextManager.Get("GiveInButton"), "");


                    suicideButton.ToolTip = TextManager.Get(GameMain.NetworkMember == null ? "GiveInHelpSingleplayer" : "GiveInHelpMultiplayer");

                    suicideButton.OnClicked = (button, userData) =>
                    {
                        GUIComponent.ForceMouseOn(null);
                        if (Character.Controlled != null)
                        {
                            if (GameMain.Client != null)
                            {
                                GameMain.Client.CreateEntityEvent(Character.Controlled, new object[] { NetEntityEvent.Type.Status });
                            }
                            else
                            {
                                Character.Controlled.Kill(Character.Controlled.CauseOfDeath);
                                Character.Controlled = null;
                            }
                        }
                        return(true);
                    };
                }

                suicideButton.Visible = true;
                suicideButton.Draw(spriteBatch);
            }
        }