diff --git a/Launcher2/LauncherMain.cs b/Launcher2/LauncherMain.cs index 595dbadc4..3c943314b 100644 --- a/Launcher2/LauncherMain.cs +++ b/Launcher2/LauncherMain.cs @@ -243,7 +243,7 @@ namespace Launcher2 return true; } - private bool ToggleFullScreen(object obj) + private bool ToggleFullScreen(GUITickBox tickBox) { settings.FullScreenEnabled = !settings.FullScreenEnabled; return true; diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj index a298fc32a..3fadc6abb 100644 --- a/Subsurface/Barotrauma.csproj +++ b/Subsurface/Barotrauma.csproj @@ -103,6 +103,7 @@ + @@ -225,7 +226,6 @@ - diff --git a/Subsurface/Content/Items/Button/button.xml b/Subsurface/Content/Items/Button/button.xml index e89794e0d..2e487675d 100644 --- a/Subsurface/Content/Items/Button/button.xml +++ b/Subsurface/Content/Items/Button/button.xml @@ -15,12 +15,12 @@ - + - diff --git a/Subsurface/Content/Items/Door/doors.xml b/Subsurface/Content/Items/Door/doors.xml index 298acf04d..8c0819d0e 100644 --- a/Subsurface/Content/Items/Door/doors.xml +++ b/Subsurface/Content/Items/Door/doors.xml @@ -19,7 +19,7 @@ - + @@ -48,7 +48,7 @@ - + diff --git a/Subsurface/Content/Items/Electricity/lights.xml b/Subsurface/Content/Items/Electricity/lights.xml index 85da571ab..2a4152f4e 100644 --- a/Subsurface/Content/Items/Electricity/lights.xml +++ b/Subsurface/Content/Items/Electricity/lights.xml @@ -11,7 +11,7 @@ - + diff --git a/Subsurface/Content/Items/Electricity/poweritems.xml b/Subsurface/Content/Items/Electricity/poweritems.xml index 52f63dcc0..8b1ce1590 100644 --- a/Subsurface/Content/Items/Electricity/poweritems.xml +++ b/Subsurface/Content/Items/Electricity/poweritems.xml @@ -17,7 +17,7 @@ - + @@ -45,7 +45,7 @@ - + @@ -69,7 +69,7 @@ - + diff --git a/Subsurface/Content/Items/Electricity/signalitems.xml b/Subsurface/Content/Items/Electricity/signalitems.xml index 9e138f855..a18e6ee2b 100644 --- a/Subsurface/Content/Items/Electricity/signalitems.xml +++ b/Subsurface/Content/Items/Electricity/signalitems.xml @@ -80,13 +80,13 @@ - - + @@ -108,12 +108,12 @@ - - + @@ -135,12 +135,12 @@ - - + @@ -163,11 +163,11 @@ - + - + @@ -188,12 +188,12 @@ - - + @@ -212,12 +212,12 @@ - - + @@ -239,12 +239,12 @@ - - + @@ -264,12 +264,12 @@ - - + diff --git a/Subsurface/Content/Items/Engine/engine.xml b/Subsurface/Content/Items/Engine/engine.xml index a14c67887..c5d53d5df 100644 --- a/Subsurface/Content/Items/Engine/engine.xml +++ b/Subsurface/Content/Items/Engine/engine.xml @@ -13,7 +13,7 @@ - + @@ -38,7 +38,7 @@ - + @@ -60,7 +60,7 @@ - + diff --git a/Subsurface/Content/Items/MiniMap/item.xml b/Subsurface/Content/Items/MiniMap/item.xml index 463c391d3..3a234dd87 100644 --- a/Subsurface/Content/Items/MiniMap/item.xml +++ b/Subsurface/Content/Items/MiniMap/item.xml @@ -10,7 +10,7 @@ - + diff --git a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml index 1fc53de08..a70fabc8c 100644 --- a/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml +++ b/Subsurface/Content/Items/OxygenGenerator/oxygengenerator.xml @@ -17,7 +17,7 @@ - + diff --git a/Subsurface/Content/Items/Pump/pump.xml b/Subsurface/Content/Items/Pump/pump.xml index 8ce2ecfdb..39e8d8c44 100644 --- a/Subsurface/Content/Items/Pump/pump.xml +++ b/Subsurface/Content/Items/Pump/pump.xml @@ -10,7 +10,7 @@ - + diff --git a/Subsurface/Content/Items/Reactor/reactor.xml b/Subsurface/Content/Items/Reactor/reactor.xml index 7ace14c21..a8bcb913a 100644 --- a/Subsurface/Content/Items/Reactor/reactor.xml +++ b/Subsurface/Content/Items/Reactor/reactor.xml @@ -31,7 +31,7 @@ - + diff --git a/Subsurface/Content/Items/Weapons/explosives.xml b/Subsurface/Content/Items/Weapons/explosives.xml index b5f5c269a..03eb44db1 100644 --- a/Subsurface/Content/Items/Weapons/explosives.xml +++ b/Subsurface/Content/Items/Weapons/explosives.xml @@ -27,7 +27,7 @@ - + @@ -35,7 +35,7 @@ - + diff --git a/Subsurface/Content/UI/style.xml b/Subsurface/Content/UI/style.xml index 093d47574..7e6bf5a62 100644 --- a/Subsurface/Content/UI/style.xml +++ b/Subsurface/Content/UI/style.xml @@ -31,7 +31,6 @@ @@ -39,16 +38,23 @@ + + + + diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs index 23968f6ad..3040be6e6 100644 --- a/Subsurface/Source/Characters/Character.cs +++ b/Subsurface/Source/Characters/Character.cs @@ -286,18 +286,24 @@ namespace Barotrauma { keys = new Key[Enum.GetNames(typeof(InputType)).Length]; - keys[(int)InputType.Select] = new Key(false); - keys[(int)InputType.ActionHeld] = new Key(true); - keys[(int)InputType.ActionHit] = new Key(false); - keys[(int)InputType.SecondaryHit] = new Key(false); - keys[(int)InputType.SecondaryHeld] = new Key(true); - keys[(int)InputType.Left] = new Key(true); - keys[(int)InputType.Right] = new Key(true); - keys[(int)InputType.Up] = new Key(true); - keys[(int)InputType.Down] = new Key(true); + for (int i = 0; i < Enum.GetNames(typeof(InputType)).Length; i++) + { + keys[i] = new Key(GameMain.Config.KeyBind((InputType)i)); + } - keys[(int)InputType.Run] = new Key(true); + //keys[(int)InputType.Select] = new Key(GameMain.Config.KeyBind(InputType.Select)); + //keys[(int)InputType.ActionHeld] = new Key(true); + //keys[(int)InputType.ActionHit] = new Key(false); + //keys[(int)InputType.SecondaryHit] = new Key(false); + //keys[(int)InputType.SecondaryHeld] = new Key(true); + + //keys[(int)InputType.Left] = new Key(true); + //keys[(int)InputType.Right] = new Key(true); + //keys[(int)InputType.Up] = new Key(true); + //keys[(int)InputType.Down] = new Key(true); + + //keys[(int)InputType.Run] = new Key(true); selectedItems = new Item[2]; @@ -410,16 +416,22 @@ namespace Barotrauma } } - public bool GetInputState(InputType inputType) + public bool IsKeyHit(InputType inputType) { - return keys[(int)inputType].State; + return keys[(int)inputType].Hit; + } + + public bool IsKeyDown(InputType inputType) + { + return keys[(int)inputType].Held; } public void ClearInputs() { foreach (Key key in keys) { - key.State = false; + key.Hit = false; + key.Held = false; } } @@ -477,10 +489,10 @@ namespace Barotrauma if (isDead || AnimController.StunTimer>0.0f) return; Vector2 targetMovement = Vector2.Zero; - if (GetInputState(InputType.Left)) targetMovement.X -= 1.0f; - if (GetInputState(InputType.Right)) targetMovement.X += 1.0f; - if (GetInputState(InputType.Up)) targetMovement.Y += 1.0f; - if (GetInputState(InputType.Down)) targetMovement.Y -= 1.0f; + if (IsKeyDown(InputType.Left)) targetMovement.X -= 1.0f; + if (IsKeyDown(InputType.Right)) targetMovement.X += 1.0f; + if (IsKeyDown(InputType.Up)) targetMovement.Y += 1.0f; + if (IsKeyDown(InputType.Down)) targetMovement.Y -= 1.0f; //the vertical component is only used for falling through platforms and climbing ladders when not in water, //so the movement can't be normalized or the character would walk slower when pressing down/up @@ -490,7 +502,7 @@ namespace Barotrauma if (length > 0.0f) targetMovement = targetMovement / length; } - if (Math.Sign(targetMovement.X) == Math.Sign(AnimController.Dir) && GetInputState(InputType.Run)) + if (Math.Sign(targetMovement.X) == Math.Sign(AnimController.Dir) && IsKeyDown(InputType.Run)) targetMovement *= 3.0f; targetMovement *= SpeedMultiplier; @@ -519,22 +531,22 @@ namespace Barotrauma { if (selectedItems[i] == null) continue; if (i == 1 && selectedItems[0] == selectedItems[1]) continue; - - if (GetInputState(InputType.ActionHeld)) selectedItems[i].Use(deltaTime, this); - if (GetInputState(InputType.SecondaryHeld) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this); + + if (IsKeyDown(InputType.Use)) selectedItems[i].Use(deltaTime, this); + if (IsKeyDown(InputType.Aim) && selectedItems[i] != null) selectedItems[i].SecondaryUse(deltaTime, this); } if (selectedConstruction != null) { - if (GetInputState(InputType.ActionHeld)) selectedConstruction.Use(deltaTime, this); - if (selectedConstruction != null && GetInputState(InputType.SecondaryHeld)) selectedConstruction.SecondaryUse(deltaTime, this); + if (IsKeyDown(InputType.Use)) selectedConstruction.Use(deltaTime, this); + if (selectedConstruction != null && IsKeyDown(InputType.Aim)) selectedConstruction.SecondaryUse(deltaTime, this); } if (IsNetworkPlayer) { foreach (Key key in keys) { - key.Reset(); + key.ResetHit(); } } } @@ -658,24 +670,30 @@ namespace Barotrauma if (!DisableControls) { - keys[(int)InputType.Left].SetState(PlayerInput.KeyDown(Keys.A)); - keys[(int)InputType.Right].SetState(PlayerInput.KeyDown(Keys.D)); - keys[(int)InputType.Up].SetState(PlayerInput.KeyDown(Keys.W)); - keys[(int)InputType.Down].SetState(PlayerInput.KeyDown(Keys.S)); + for (int i = 0; i < keys.Length; i++ ) + { + keys[i].SetState(); + } - keys[(int)InputType.Select].SetState(PlayerInput.KeyHit(Keys.E)); - keys[(int)InputType.ActionHit].SetState(PlayerInput.LeftButtonClicked()); - keys[(int)InputType.ActionHeld].SetState(PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed); - keys[(int)InputType.SecondaryHit].SetState(PlayerInput.RightButtonClicked()); - keys[(int)InputType.SecondaryHeld].SetState(PlayerInput.GetMouseState.RightButton == ButtonState.Pressed); + // keys[(int)InputType.Left].SetState(GameMain.Config.KeyBind(inpu)); + //keys[(int)InputType.Right].SetState(PlayerInput.KeyDown(Keys.D)); + //keys[(int)InputType.Up].SetState(PlayerInput.KeyDown(Keys.W)); + //keys[(int)InputType.Down].SetState(PlayerInput.KeyDown(Keys.S)); - keys[(int)InputType.Run].SetState(PlayerInput.KeyDown(Keys.LeftShift)); + //keys[(int)InputType.Select].SetState(PlayerInput.KeyHit(Keys.E)); + //keys[(int)InputType.ActionHit].SetState(PlayerInput.LeftButtonClicked()); + //keys[(int)InputType.ActionHeld].SetState(PlayerInput.GetMouseState.LeftButton == ButtonState.Pressed); + //keys[(int)InputType.SecondaryHit].SetState(PlayerInput.RightButtonClicked()); + //keys[(int)InputType.SecondaryHeld].SetState(PlayerInput.GetMouseState.RightButton == ButtonState.Pressed); + + //keys[(int)InputType.Run].SetState(PlayerInput.KeyDown(Keys.LeftShift)); } else { foreach (Key key in keys) { - key.SetState(false); + if (key == null) continue; + key.Reset(); } } @@ -743,7 +761,12 @@ namespace Barotrauma if (closestItem.Pick(this)) { new NetworkEvent(NetworkEventType.PickItem, ID, true, - new int[] { closestItem.ID, GetInputState(InputType.Select) ? 1 : 0, GetInputState(InputType.ActionHit) ? 1 : 0 }); + new int[] + { + closestItem.ID, + IsKeyHit(InputType.Select) ? 1 : 0, + IsKeyHit(InputType.Use) ? 1 : 0 + }); } } } @@ -756,7 +779,7 @@ namespace Barotrauma } } - if (GetInputState(InputType.Select)) + if (IsKeyHit(InputType.Select)) { if (selectedCharacter != null) { @@ -1186,30 +1209,30 @@ namespace Barotrauma return true; case NetworkEventType.EntityUpdate: var hasInputs = - GetInputState(InputType.Left) || - GetInputState(InputType.Right) || - GetInputState(InputType.Up) || - GetInputState(InputType.Down) || - GetInputState(InputType.ActionHeld) || - GetInputState(InputType.SecondaryHeld); + IsKeyDown(InputType.Left) || + IsKeyDown(InputType.Right) || + IsKeyDown(InputType.Up) || + IsKeyDown(InputType.Down) || + IsKeyDown(InputType.Use) || + IsKeyDown(InputType.Aim); message.Write(hasInputs); message.Write((float)NetTime.Now); if (!hasInputs) return true; - message.Write(keys[(int)InputType.ActionHeld].Dequeue); + message.Write(keys[(int)InputType.Use].DequeueHeld); - bool secondaryHeld = keys[(int)InputType.SecondaryHeld].Dequeue; + bool secondaryHeld = keys[(int)InputType.Aim].DequeueHeld; message.Write(secondaryHeld); - message.Write(keys[(int)InputType.Left].Dequeue); - message.Write(keys[(int)InputType.Right].Dequeue); + message.Write(keys[(int)InputType.Left].Held); + message.Write(keys[(int)InputType.Right].Held); - message.Write(keys[(int)InputType.Up].Dequeue); - message.Write(keys[(int)InputType.Down].Dequeue); + message.Write(keys[(int)InputType.Up].Held); + message.Write(keys[(int)InputType.Down].Held); - message.Write(keys[(int)InputType.Run].Dequeue); + message.Write(keys[(int)InputType.Run].Held); if (secondaryHeld) { @@ -1386,18 +1409,18 @@ namespace Barotrauma AnimController.IsStanding = true; - keys[(int)InputType.ActionHeld].State = actionKeyState; - keys[(int)InputType.SecondaryHeld].State = secondaryKeyState; + keys[(int)InputType.Use].Held = actionKeyState; + keys[(int)InputType.Aim].Held = secondaryKeyState; if (sendingTime <= LastNetworkUpdate) return; - keys[(int)InputType.Left].State = leftKeyState; - keys[(int)InputType.Right].State = rightKeyState; + keys[(int)InputType.Left].Held = leftKeyState; + keys[(int)InputType.Right].Held = rightKeyState; - keys[(int)InputType.Up].State = upKeyState; - keys[(int)InputType.Down].State = downKeyState; + keys[(int)InputType.Up].Held = upKeyState; + keys[(int)InputType.Down].Held = downKeyState; - keys[(int)InputType.Run].State = runState; + keys[(int)InputType.Run].Held = runState; float dir = 1.0f; Vector2 pos = Vector2.Zero; diff --git a/Subsurface/Source/Characters/CharacterInfo.cs b/Subsurface/Source/Characters/CharacterInfo.cs index 4ed7af120..affe2a016 100644 --- a/Subsurface/Source/Characters/CharacterInfo.cs +++ b/Subsurface/Source/Characters/CharacterInfo.cs @@ -25,7 +25,7 @@ namespace Barotrauma public int Salary; - public int HeadSpriteId; + private int headSpriteId; private Sprite headSprite; public bool StartItemsGiven; @@ -44,6 +44,23 @@ namespace Barotrauma } } + public int HeadSpriteId + { + get { return headSpriteId; } + set + { + int oldId = headSpriteId; + + headSpriteId = value; + Vector2 spriteRange = headSpriteRange[gender == Gender.Male ? 0 : 1]; + + if (headSpriteId < (int)spriteRange.X) headSpriteId = (int)(spriteRange.Y-1); + if (headSpriteId > (int)spriteRange.Y) headSpriteId = (int)(spriteRange.X); + + if (headSpriteId != oldId) headSprite = null; + } + } + public Gender Gender { get { return gender; } diff --git a/Subsurface/Source/ContentPackage.cs b/Subsurface/Source/ContentPackage.cs index 61283bedd..826a376a7 100644 --- a/Subsurface/Source/ContentPackage.cs +++ b/Subsurface/Source/ContentPackage.cs @@ -173,6 +173,7 @@ namespace Barotrauma } return filePaths; } + public static void LoadAll(string folder) { if (!Directory.Exists(folder)) @@ -189,6 +190,8 @@ namespace Barotrauma string[] files = Directory.GetFiles(folder, "*.xml"); + list.Clear(); + foreach (string filePath in files) { ContentPackage package = new ContentPackage(filePath); diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 69945e1c4..d5d27bb5f 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -141,7 +141,7 @@ namespace Barotrauma public static void ExecuteCommand(string command, GameMain game) { #if !DEBUG - if (GameMain.Client!=null) + if (GameMain.Client != null) { ThrowError("Console commands are disabled in multiplayer mode"); return; @@ -216,7 +216,7 @@ namespace Barotrauma case "control": if (commands.Length < 2) break; commands[1] = commands[1].ToLower(); - Character.Controlled = Character.CharacterList.Find(c => c.Name.ToLower() == commands[1]); + Character.Controlled = Character.CharacterList.Find(c => !c.IsNetworkPlayer && c.Name.ToLower() == commands[1]); break; case "heal": if (Character.Controlled != null) diff --git a/Subsurface/Source/EventInput/EventInput.cs b/Subsurface/Source/EventInput/EventInput.cs index 331c8c5d2..d166c78c9 100644 --- a/Subsurface/Source/EventInput/EventInput.cs +++ b/Subsurface/Source/EventInput/EventInput.cs @@ -169,8 +169,7 @@ namespace EventInput public static void OnCharEntered(char character) { - if (CharEntered != null) - CharEntered(null, new CharacterEventArgs(character, 0)); + if (CharEntered != null) CharEntered(null, new CharacterEventArgs(character, 0)); } static IntPtr HookProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) @@ -186,6 +185,7 @@ namespace EventInput case WM_KEYDOWN: if (KeyDown != null) KeyDown(null, new KeyEventArgs((Keys)wParam)); + break; case WM_KEYUP: diff --git a/Subsurface/Source/GUI/GUIComponent.cs b/Subsurface/Source/GUI/GUIComponent.cs index 299c1404c..618f489ff 100644 --- a/Subsurface/Source/GUI/GUIComponent.cs +++ b/Subsurface/Source/GUI/GUIComponent.cs @@ -143,6 +143,11 @@ namespace Barotrauma set { selectedColor = value; } } + public static KeyboardDispatcher KeyboardDispatcher + { + get { return keyboardDispatcher; } + } + protected GUIComponent(GUIStyle style) { Visible = true; @@ -227,7 +232,7 @@ namespace Barotrauma foreach (Sprite sprite in sprites) { Vector2 startPos = new Vector2(rect.X, rect.Y); - Vector2 size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height); + Vector2 size = new Vector2(Math.Min(sprite.SourceRect.Width,rect.Width), Math.Min(sprite.SourceRect.Height,rect.Height)); if (sprite.size.X == 0.0f) size.X = rect.Width; if (sprite.size.Y == 0.0f) size.Y = rect.Height; diff --git a/Subsurface/Source/GUI/GUIDropDown.cs b/Subsurface/Source/GUI/GUIDropDown.cs index 73c1bcd02..01fd79766 100644 --- a/Subsurface/Source/GUI/GUIDropDown.cs +++ b/Subsurface/Source/GUI/GUIDropDown.cs @@ -9,6 +9,10 @@ namespace Barotrauma { public class GUIDropDown : GUIComponent { + + public delegate bool OnSelectedHandler(GUIComponent selected); + public OnSelectedHandler OnSelected; + private GUIButton button; private GUIListBox listBox; @@ -65,6 +69,8 @@ namespace Barotrauma Dropped = false; + if (OnSelected != null) OnSelected(component); + return true; } diff --git a/Subsurface/Source/GUI/GUIScrollBar.cs b/Subsurface/Source/GUI/GUIScrollBar.cs index 74d086110..57255549c 100644 --- a/Subsurface/Source/GUI/GUIScrollBar.cs +++ b/Subsurface/Source/GUI/GUIScrollBar.cs @@ -90,7 +90,7 @@ namespace Barotrauma parent.AddChild(this); isHorizontal = (rect.Width > rect.Height); - frame = new GUIFrame(new Rectangle(0,0,0,0), Color.White, style, this); + frame = new GUIFrame(new Rectangle(0,0,0,0), Color.Black*0.8f, style, this); //AddChild(frame); //System.Diagnostics.Debug.WriteLine(frame.rect); diff --git a/Subsurface/Source/GUI/GUITextBlock.cs b/Subsurface/Source/GUI/GUITextBlock.cs index ac4f79400..24050692c 100644 --- a/Subsurface/Source/GUI/GUITextBlock.cs +++ b/Subsurface/Source/GUI/GUITextBlock.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using System; namespace Barotrauma { @@ -120,7 +121,7 @@ namespace Barotrauma this.alignment = alignment; this.textAlignment = textAlignment; - + if (parent != null) parent.AddChild(this); @@ -215,8 +216,8 @@ namespace Barotrauma Color currColor = color; if (state == ComponentState.Hover) currColor = hoverColor; if (state == ComponentState.Selected) currColor = selectedColor; - - GUI.DrawRectangle(spriteBatch, rect, currColor*(currColor.A/255.0f), true); + + if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true); base.Draw(spriteBatch); @@ -233,6 +234,9 @@ namespace Barotrauma } DrawChildren(spriteBatch); + + if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false); + } } } diff --git a/Subsurface/Source/GUI/GUITextBox.cs b/Subsurface/Source/GUI/GUITextBox.cs index 9187a8f37..cf31ade77 100644 --- a/Subsurface/Source/GUI/GUITextBox.cs +++ b/Subsurface/Source/GUI/GUITextBox.cs @@ -7,11 +7,11 @@ using Microsoft.Xna.Framework.Input; namespace Barotrauma { - delegate void TextBoxEvent(GUITextBox sender); + delegate void TextBoxEvent(GUITextBox sender, Keys key); class GUITextBox : GUIComponent, IKeyboardSubscriber { - public event TextBoxEvent Clicked; + public event TextBoxEvent OnSelected; bool caretVisible; float caretTimer; @@ -19,11 +19,13 @@ namespace Barotrauma GUITextBlock textBlock; public delegate bool OnEnterHandler(GUITextBox textBox, string text); - public OnEnterHandler OnEnter; + public OnEnterHandler OnEnterPressed; + + public event TextBoxEvent OnKeyHit; public delegate bool OnTextChangedHandler(GUITextBox textBox, string text); public OnTextChangedHandler OnTextChanged; - + public GUITextBlock.TextGetterHandler TextGetter { get { return textBlock.TextGetter; } @@ -68,6 +70,8 @@ namespace Barotrauma } } + public bool CaretEnabled; + public String Text { get @@ -97,6 +101,7 @@ namespace Barotrauma //ensure that text cannot be larger than the box Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1); } + } } } @@ -130,10 +135,13 @@ namespace Barotrauma parent.AddChild(this); textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this); - textBlock.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f); + if (style != null) style.Apply(textBlock, this); + textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f); previousMouse = PlayerInput.GetMouseState; + + CaretEnabled = true; //SetTextPos(); } @@ -141,7 +149,7 @@ namespace Barotrauma { Selected = true; keyboardDispatcher.Subscriber = this; - if (Clicked != null) Clicked(this); + //if (Clicked != null) Clicked(this); } public void Deselect() @@ -158,27 +166,37 @@ namespace Barotrauma if (flashTimer > 0.0f) flashTimer -= deltaTime; if (!Enabled) return; - caretTimer += deltaTime; - caretVisible = ((caretTimer*1000.0f) % 1000) < 500; + if (CaretEnabled) + { + caretTimer += deltaTime; + caretVisible = ((caretTimer*1000.0f) % 1000) < 500; + } if (rect.Contains(PlayerInput.MousePosition)) { - state = ComponentState.Hover; - if (PlayerInput.LeftButtonClicked()) Select(); + state = ComponentState.Hover; + if (PlayerInput.LeftButtonClicked()) + { + Select(); + if (OnSelected != null) OnSelected(this, Keys.None); + } } else { state = ComponentState.None; + } + textBlock.State = state; + if (keyboardDispatcher.Subscriber == this) { Character.DisableControls = true; - if (OnEnter != null && PlayerInput.KeyHit(Keys.Enter)) + if (OnEnterPressed != null && PlayerInput.KeyHit(Keys.Enter)) { string input = Text; Text = ""; - OnEnter(this, input); + OnEnterPressed(this, input); } } @@ -191,6 +209,8 @@ namespace Barotrauma if (!Visible) return; DrawChildren(spriteBatch); + + if (!CaretEnabled) return; Vector2 caretPos = textBlock.CaretPos; @@ -224,14 +244,14 @@ namespace Barotrauma if (Text.Length > 0) Text = Text.Substring(0, Text.Length - 1); break; - case '\r': //return - if (OnEnterPressed != null) - OnEnterPressed(this); - break; - case '\t': //tab - if (OnTabPressed != null) - OnTabPressed(this); - break; + //case '\r': //return + // if (OnEnterPressed != null) + // OnEnterPressed(this); + // break; + //case '\t': //tab + // if (OnTabPressed != null) + // OnTabPressed(this); + // break; } if (OnTextChanged != null) OnTextChanged(this, Text); @@ -239,10 +259,10 @@ namespace Barotrauma public void ReceiveSpecialInput(Keys key) { + if (OnKeyHit != null) OnKeyHit(this, key); } - public event TextBoxEvent OnEnterPressed; - public event TextBoxEvent OnTabPressed; + //public event TextBoxEvent OnTabPressed; public bool Selected { diff --git a/Subsurface/Source/GUI/GUITickBox.cs b/Subsurface/Source/GUI/GUITickBox.cs index f63ffcf10..49c315044 100644 --- a/Subsurface/Source/GUI/GUITickBox.cs +++ b/Subsurface/Source/GUI/GUITickBox.cs @@ -9,7 +9,7 @@ namespace Barotrauma GUIFrame box; GUITextBlock text; - public delegate bool OnSelectedHandler(object obj); + public delegate bool OnSelectedHandler(GUITickBox obj); public OnSelectedHandler OnSelected; private bool selected; diff --git a/Subsurface/Source/GameMain.cs b/Subsurface/Source/GameMain.cs index 119f8c918..73f08e5f7 100644 --- a/Subsurface/Source/GameMain.cs +++ b/Subsurface/Source/GameMain.cs @@ -69,7 +69,7 @@ namespace Barotrauma //private Stopwatch renderTimer; //public static int renderTimeElapsed; - + public Camera Cam { get { return GameScreen.Cam; } diff --git a/Subsurface/Source/GameSettings.cs b/Subsurface/Source/GameSettings.cs index c6f728918..d24c8a73d 100644 --- a/Subsurface/Source/GameSettings.cs +++ b/Subsurface/Source/GameSettings.cs @@ -12,10 +12,15 @@ namespace Barotrauma public class GameSettings { private GUIFrame settingsFrame; + private GUIButton applyButton; private float soundVolume, musicVolume; - private Keys[] keyMapping; + private KeyOrMouse[] keyMapping; + + + private bool unsavedSettings; + public GUIFrame SettingsFrame { @@ -26,6 +31,11 @@ namespace Barotrauma } } + public KeyOrMouse KeyBind(InputType inputType) + { + return keyMapping[(int)inputType]; + } + public int GraphicsWidth { get; set; } public int GraphicsHeight { get; set; } @@ -37,6 +47,19 @@ namespace Barotrauma public bool AutoCheckUpdates { get; set; } public bool WasGameUpdated { get; set; } + public bool UnsavedSettings + { + get + { + return unsavedSettings; + } + private set + { + unsavedSettings = value; + if (applyButton != null) applyButton.Selected = unsavedSettings; + } + } + public float SoundVolume { get { return soundVolume; } @@ -59,6 +82,8 @@ namespace Barotrauma public GameSettings(string filePath) { + ContentPackage.LoadAll(ContentPackage.Folder); + Load(filePath); } @@ -79,7 +104,7 @@ namespace Barotrauma return; } - + XElement graphicsMode = doc.Root.Element("graphicsmode"); GraphicsWidth = ToolBox.GetAttributeInt(graphicsMode, "width", 0); GraphicsHeight = ToolBox.GetAttributeInt(graphicsMode, "height", 0); @@ -100,14 +125,17 @@ namespace Barotrauma SoundVolume = ToolBox.GetAttributeFloat(doc.Root, "soundvolume", 1.0f); MusicVolume = ToolBox.GetAttributeFloat(doc.Root, "musicvolume", 0.3f); - keyMapping = new Keys[Enum.GetNames(typeof(InputType)).Length]; - keyMapping[(int)InputType.Up] = Keys.W; - keyMapping[(int)InputType.Down] = Keys.S; - keyMapping[(int)InputType.Left] = Keys.A; - keyMapping[(int)InputType.Right] = Keys.D; - keyMapping[(int)InputType.Run] = Keys.LeftShift; - keyMapping[(int)InputType.Chat] = Keys.Tab; - keyMapping[(int)InputType.Select] = Keys.E; + keyMapping = new KeyOrMouse[Enum.GetNames(typeof(InputType)).Length]; + keyMapping[(int)InputType.Up] = new KeyOrMouse(Keys.W); + keyMapping[(int)InputType.Down] = new KeyOrMouse(Keys.S); + keyMapping[(int)InputType.Left] = new KeyOrMouse(Keys.A); + keyMapping[(int)InputType.Right] = new KeyOrMouse(Keys.D); + keyMapping[(int)InputType.Run] = new KeyOrMouse(Keys.LeftShift); + keyMapping[(int)InputType.Chat] = new KeyOrMouse(Keys.Tab); + keyMapping[(int)InputType.Select] = new KeyOrMouse(Keys.E); + + keyMapping[(int)InputType.Use] = new KeyOrMouse(0); + keyMapping[(int)InputType.Aim] = new KeyOrMouse(1); foreach (XElement subElement in doc.Root.Elements()) { @@ -124,19 +152,31 @@ namespace Barotrauma { InputType inputType; Keys key; - if (Enum.TryParse(attribute.Name.ToString(), true, out inputType) && - Enum.TryParse(attribute.Value.ToString(), true, out key)) + int mouseButton; + if (Enum.TryParse(attribute.Name.ToString(), true, out inputType)) { - keyMapping[(int)inputType] = key; + if (Enum.TryParse(attribute.Value.ToString(), true, out key)) + { + keyMapping[(int)inputType] = new KeyOrMouse(key); + } + else if (int.TryParse(attribute.Value.ToString(), out mouseButton)) + { + keyMapping[(int)inputType] = new KeyOrMouse(mouseButton); + } + } } break; } - } + } + + UnsavedSettings = false; } public void Save(string filePath) { + UnsavedSettings = false; + XDocument doc = new XDocument(); if (doc.Root == null) @@ -173,12 +213,12 @@ namespace Barotrauma new XAttribute("path", SelectedContentPackage.Path))); } - doc.Save(filePath); } private bool ChangeSoundVolume(float barScroll) { + UnsavedSettings = true; SoundVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f); return true; @@ -186,49 +226,152 @@ namespace Barotrauma private bool ChangeMusicVolume(float barScroll) { + UnsavedSettings = true; MusicVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f); return true; } + private bool ToggleFullScreen(object userData) + { + UnsavedSettings = true; + FullScreenEnabled = !FullScreenEnabled; + return true; + } + + public void ResetSettingsFrame() + { + settingsFrame = null; + } + private void CreateSettingsFrame() { settingsFrame = new GUIFrame(new Rectangle(0, 0, 500, 500), null, Alignment.Center, GUI.Style); - new GUITextBlock(new Rectangle(0, 0, 100, 20), "Sound volume:", GUI.Style, settingsFrame); - GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, 20, 150, 20), GUI.Style,0.1f, settingsFrame); + new GUITextBlock(new Rectangle(0,-30,0,30), "Settings",GUI.Style,Alignment.TopCenter, Alignment.TopCenter, settingsFrame, false, GUI.LargeFont); + + int x=0, y = 10; + + new GUITextBlock(new Rectangle(0, y, 20, 20), "Resolution", GUI.Style, Alignment.TopLeft, Alignment.TopLeft, settingsFrame); + var resolutionDD = new GUIDropDown(new Rectangle(0, y + 20, 180, 20), "", GUI.Style, settingsFrame); + + var supportedModes = new List(); + foreach (DisplayMode mode in GraphicsAdapter.DefaultAdapter.SupportedDisplayModes) + { + if (supportedModes.FirstOrDefault(m => m.Width == mode.Width && m.Height == mode.Height) != null) continue; + + resolutionDD.AddItem(mode.Width + "x" + mode.Height, mode); + supportedModes.Add(mode); + + if (GraphicsWidth == mode.Width && GraphicsHeight == mode.Height) resolutionDD.SelectItem(mode); + } + + if (resolutionDD.SelectedItemData == null) + { + resolutionDD.SelectItem(GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Last()); + } + + y += 50; + + var fullScreenTick = new GUITickBox(new Rectangle(x, y, 20, 20), "Fullscreen", Alignment.TopLeft, settingsFrame); + fullScreenTick.OnSelected = ToggleFullScreen; + fullScreenTick.Selected = FullScreenEnabled; + + y += 50; + + new GUITextBlock(new Rectangle(0, y, 100, 20), "Sound volume:", GUI.Style, settingsFrame); + GUIScrollBar soundScrollBar = new GUIScrollBar(new Rectangle(0, y+20, 150, 20), GUI.Style,0.1f, settingsFrame); soundScrollBar.BarScroll = SoundVolume; soundScrollBar.OnMoved = ChangeSoundVolume; - new GUITextBlock(new Rectangle(0, 40, 100, 20), "Music volume:", GUI.Style, settingsFrame); - GUIScrollBar musicScrollBar = new GUIScrollBar(new Rectangle(0, 60, 150, 20), GUI.Style, 0.1f, settingsFrame); + new GUITextBlock(new Rectangle(0, y+40, 100, 20), "Music volume:", GUI.Style, settingsFrame); + GUIScrollBar musicScrollBar = new GUIScrollBar(new Rectangle(0, y+60, 150, 20), GUI.Style, 0.1f, settingsFrame); musicScrollBar.BarScroll = MusicVolume; musicScrollBar.OnMoved = ChangeMusicVolume; - int x = 250; - int y = 60; + x = 200; + y = 10; - new GUITextBlock(new Rectangle(x, 40, 100, 20), "Controls:", GUI.Style, settingsFrame); + new GUITextBlock(new Rectangle(x, y, 20, 20), "Content package", GUI.Style, Alignment.TopLeft, Alignment.TopLeft, settingsFrame); + var contentPackageDD = new GUIDropDown(new Rectangle(x, y + 20, 200, 20), "", GUI.Style, settingsFrame); + + foreach (ContentPackage contentPackage in ContentPackage.list) + { + contentPackageDD.AddItem(contentPackage.Name, contentPackage); + + if (SelectedContentPackage == contentPackage) contentPackageDD.SelectItem(contentPackage); + } + + y += 50; + new GUITextBlock(new Rectangle(x, y, 100, 20), "Controls:", GUI.Style, settingsFrame); + y += 30; var inputNames = Enum.GetNames(typeof(InputType)); for (int i = 0; i< inputNames.Length; i++) { new GUITextBlock(new Rectangle(x, y, 100, 20), inputNames[i]+": ", GUI.Style, settingsFrame); - var keyBox = new GUITextBox(new Rectangle(x + 100, y, 70, 15), GUI.Style, settingsFrame); + var keyBox = new GUITextBox(new Rectangle(x + 100, y, 120, 15), GUI.Style, settingsFrame); keyBox.Text = keyMapping[i].ToString(); - keyBox.OnTextChanged = MapKey; + keyBox.UserData = i; + keyBox.OnSelected += KeyBoxSelected; + keyBox.SelectedColor = Color.Gold * 0.3f; y += 20; } - var applyButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Apply", GUI.Style, settingsFrame); + applyButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Apply", Alignment.BottomRight, GUI.Style, settingsFrame); applyButton.OnClicked = ApplyClicked; } - private bool MapKey(GUITextBox textBox, string text) + private void KeyBoxSelected(GUITextBox textBox, Keys key) { + textBox.Text = ""; + CoroutineManager.StartCoroutine(WaitForKeyPress(textBox)); + } + + private bool MarkUnappliedChanges(GUIButton button, object obj) + { + UnsavedSettings = true; + return true; } + private bool SelectResolution(GUIComponent selected) + { + DisplayMode mode = selected.UserData as DisplayMode; + if (mode == null) return false; + + GraphicsWidth = mode.Width; + GraphicsHeight = mode.Height; + + UnsavedSettings = true; + + return true; + } + + + + private IEnumerable WaitForKeyPress(GUITextBox keyBox) + { + while (keyBox.Selected && PlayerInput.GetKeyboardState.GetPressedKeys().Length==0) + { + if (Screen.Selected != GameMain.MainMenuScreen) yield return CoroutineStatus.Success; + + yield return CoroutineStatus.Running; + } + + UnsavedSettings = true; + + Keys key = PlayerInput.GetKeyboardState.GetPressedKeys()[0]; + + int keyIndex = (int)keyBox.UserData; + keyMapping[keyIndex] = new KeyOrMouse(key); + + keyBox.Text = key.ToString("G"); + keyBox.Deselect(); + + yield return CoroutineStatus.Success; + } + private bool ApplyClicked(GUIButton button, object userData) { Save("config.xml"); diff --git a/Subsurface/Source/Items/Components/Holdable/Holdable.cs b/Subsurface/Source/Items/Components/Holdable/Holdable.cs index 4d4b10d5b..881487f5e 100644 --- a/Subsurface/Source/Items/Components/Holdable/Holdable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Holdable.cs @@ -193,7 +193,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { if (!attachable || item.body==null) return true; - if (character != null && !character.GetInputState(InputType.SecondaryHeld)) return false; + if (character != null && !character.IsKeyDown(InputType.Aim)) return false; item.Drop(); @@ -238,7 +238,7 @@ namespace Barotrauma.Items.Components //item.sprite.Depth = picker.AnimController.GetLimb(LimbType.RightHand).sprite.Depth + 0.01f; - ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.GetInputState(InputType.SecondaryHeld), holdAngle); + ac.HoldItem(deltaTime, item, handlePos, holdPos, aimPos, picker.IsKeyDown(InputType.Aim), holdAngle); } protected void Flip(Item item) diff --git a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs index 4d902b2f5..56d0b7f97 100644 --- a/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/MeleeWeapon.cs @@ -52,7 +52,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { if (character == null || reloadTimer>0.0f) return false; - if (!character.GetInputState(InputType.SecondaryHeld) || hitting) return false; + if (!character.IsKeyDown(InputType.Aim) || hitting) return false; user = character; @@ -66,7 +66,7 @@ namespace Barotrauma.Items.Components foreach (Limb l in character.AnimController.Limbs) { - item.body.FarseerBody.IgnoreCollisionWith(l.body.FarseerBody); + //item.body.FarseerBody.IgnoreCollisionWith(l.body.FarseerBody); if (character.AnimController.InWater) continue; if (l.type == LimbType.LeftFoot || l.type == LimbType.LeftThigh || l.type == LimbType.LeftLeg) continue; @@ -107,7 +107,7 @@ namespace Barotrauma.Items.Components reloadTimer -= deltaTime; - if (!picker.GetInputState(InputType.SecondaryHeld) && !hitting) hitPos = 0.0f; + if (!picker.IsKeyDown(InputType.Aim) && !hitting) hitPos = 0.0f; ApplyStatusEffects(ActionType.OnActive, deltaTime, picker); @@ -119,7 +119,7 @@ namespace Barotrauma.Items.Components if (!hitting) { - if (picker.GetInputState(InputType.SecondaryHeld)) + if (picker.IsKeyDown(InputType.Aim)) { hitPos = (float)System.Math.Min(hitPos+deltaTime*5.0f, MathHelper.Pi*0.7f); @@ -167,10 +167,10 @@ namespace Barotrauma.Items.Components item.body.CollisionCategories = Physics.CollisionMisc; item.body.CollidesWith = Physics.CollisionWall; - foreach (Limb l in picker.AnimController.Limbs) - { - item.body.FarseerBody.RestoreCollisionWith(l.body.FarseerBody); - } + //foreach (Limb l in picker.AnimController.Limbs) + //{ + // item.body.FarseerBody.RestoreCollisionWith(l.body.FarseerBody); + //} } diff --git a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs index 587b9ba94..fbb0f21ff 100644 --- a/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs +++ b/Subsurface/Source/Items/Components/Holdable/RangedWeapon.cs @@ -53,7 +53,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { if (character == null) return false; - if (!character.GetInputState(InputType.SecondaryHeld) || reload > 0.0f) return false; + if (!character.IsKeyDown(InputType.Aim) || reload > 0.0f) return false; IsActive = true; reload = 1.0f; diff --git a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs index 3568932b6..e7a9c7e5b 100644 --- a/Subsurface/Source/Items/Components/Holdable/RepairTool.cs +++ b/Subsurface/Source/Items/Components/Holdable/RepairTool.cs @@ -102,7 +102,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { if (character == null) return false; - if (!character.GetInputState(InputType.SecondaryHeld)) return false; + if (!character.IsKeyDown(InputType.Aim)) return false; //if (DoesUseFail(character)) return false; @@ -161,7 +161,7 @@ namespace Barotrauma.Items.Components } else if ((targetLimb = (targetBody.UserData as Limb)) != null) { - if (character.GetInputState(InputType.SecondaryHeld)) + if (character.IsKeyDown(InputType.Aim)) { targetLimb.character.Health += limbFixAmount * degreeOfSuccess; //isActive = true; diff --git a/Subsurface/Source/Items/Components/Holdable/Throwable.cs b/Subsurface/Source/Items/Components/Holdable/Throwable.cs index 3f5e17178..814fe1c2b 100644 --- a/Subsurface/Source/Items/Components/Holdable/Throwable.cs +++ b/Subsurface/Source/Items/Components/Holdable/Throwable.cs @@ -28,7 +28,7 @@ namespace Barotrauma.Items.Components public override bool Use(float deltaTime, Character character = null) { if (character == null) return false; - if (!character.GetInputState(InputType.SecondaryHeld) || throwing) return false; + if (!character.IsKeyDown(InputType.Aim) || throwing) return false; //Vector2 diff = Vector2.Normalize(character.CursorPosition - character.AnimController.RefLimb.Position); @@ -75,7 +75,7 @@ namespace Barotrauma.Items.Components if (!item.body.Enabled) return; if (!picker.HasSelectedItem(item)) IsActive = false; - if (!picker.GetInputState(InputType.SecondaryHeld) && !throwing) throwPos = 0.0f; + if (!picker.IsKeyDown(InputType.Aim) && !throwing) throwPos = 0.0f; ApplyStatusEffects(ActionType.OnActive, deltaTime, picker); @@ -85,7 +85,7 @@ namespace Barotrauma.Items.Components if (!throwing) { - if (picker.GetInputState(InputType.SecondaryHeld)) + if (picker.IsKeyDown(InputType.Aim)) { throwPos = (float)System.Math.Min(throwPos+deltaTime*5.0f, MathHelper.Pi*0.7f); diff --git a/Subsurface/Source/Items/Components/Machines/Engine.cs b/Subsurface/Source/Items/Components/Machines/Engine.cs index b940fe3e1..031a53101 100644 --- a/Subsurface/Source/Items/Components/Machines/Engine.cs +++ b/Subsurface/Source/Items/Components/Machines/Engine.cs @@ -63,6 +63,8 @@ namespace Barotrauma.Items.Components currPowerConsumption = Math.Abs(targetForce)/100.0f * powerConsumption; + if (powerConsumption == 0.0f) voltage = 1.0f; + Force = MathHelper.Lerp(force, (voltage < minVoltage) ? 0.0f : targetForce, 0.1f); if (Force != 0.0f) { diff --git a/Subsurface/Source/Items/Components/Projectile.cs b/Subsurface/Source/Items/Components/Projectile.cs index aeb462c97..68057f21e 100644 --- a/Subsurface/Source/Items/Components/Projectile.cs +++ b/Subsurface/Source/Items/Components/Projectile.cs @@ -109,7 +109,7 @@ namespace Barotrauma.Items.Components { item.body.FarseerBody.RestoreCollisionWith(stickTarget); } - catch + catch (Exception e) { #if DEBUG DebugConsole.ThrowError("Failed to restore collision with stickTarget", e); diff --git a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs index 31470ffe3..1fd38a981 100644 --- a/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs +++ b/Subsurface/Source/Items/Components/Signal/ConnectionPanel.cs @@ -38,7 +38,7 @@ namespace Barotrauma.Items.Components if (character != Character.Controlled || character != user) return; if (Screen.Selected != GameMain.EditMapScreen && - character.GetInputState(InputType.Select) && + character.IsKeyHit(InputType.Select) && character.SelectedConstruction==this.item) character.SelectedConstruction = null; Connection.DrawConnections(spriteBatch, this, character); diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index d9696d903..2c1d5fcfb 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -727,7 +727,7 @@ namespace Barotrauma namesBox.Text = relatedItem.JoinedNames; namesBox.UserData = new ObjectProperty(property, relatedItem); - namesBox.OnEnter = EnterProperty; + namesBox.OnEnterPressed = EnterProperty; namesBox.OnTextChanged = PropertyChanged; y += 30; @@ -754,7 +754,7 @@ namespace Barotrauma } propertyBox.UserData = objectProperty; - propertyBox.OnEnter = EnterProperty; + propertyBox.OnEnterPressed = EnterProperty; propertyBox.OnTextChanged = PropertyChanged; y = y + height+10; } @@ -879,8 +879,8 @@ namespace Barotrauma bool pickHit = false, selectHit = false; if (Screen.Selected == GameMain.EditMapScreen) { - pickHit = picker.GetInputState(InputType.Select); - selectHit = picker.GetInputState(InputType.Select); + pickHit = picker.IsKeyHit(InputType.Select); + selectHit = picker.IsKeyHit(InputType.Select); } else { @@ -891,13 +891,13 @@ namespace Barotrauma } else if (forceActionKey) { - if (ic.PickKey == InputType.ActionHit) pickHit = true; - if (ic.SelectKey == InputType.ActionHit) selectHit = true; + if (ic.PickKey == InputType.Use) pickHit = true; + if (ic.SelectKey == InputType.Use) selectHit = true; } else { - pickHit = picker.GetInputState(ic.PickKey); - selectHit = picker.GetInputState(ic.SelectKey); + pickHit = picker.IsKeyHit(ic.PickKey); + selectHit = picker.IsKeyHit(ic.SelectKey); } } @@ -925,7 +925,7 @@ namespace Barotrauma if (picker.SelectedConstruction == this) { - if (picker.GetInputState(InputType.Select)) picker.SelectedConstruction = null; + if (picker.IsKeyHit(InputType.Select)) picker.SelectedConstruction = null; } else if (selected) { diff --git a/Subsurface/Source/Map/WayPoint.cs b/Subsurface/Source/Map/WayPoint.cs index c63a00e2a..6ed255969 100644 --- a/Subsurface/Source/Map/WayPoint.cs +++ b/Subsurface/Source/Map/WayPoint.cs @@ -179,7 +179,7 @@ namespace Barotrauma new GUITextBlock(new Rectangle(0, y, 100, 20), "ID Card tags:", Color.Transparent, Color.Black, Alignment.TopLeft, null, editingHUD); GUITextBox propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), GUI.Style, editingHUD); propertyBox.Text = string.Join(", ", idCardTags); - propertyBox.OnEnter = EnterIDCardTags; + propertyBox.OnEnterPressed = EnterIDCardTags; propertyBox.OnTextChanged = TextBoxChanged; y = y + 30; @@ -187,7 +187,7 @@ namespace Barotrauma propertyBox = new GUITextBox(new Rectangle(100, y, 200, 20), GUI.Style, editingHUD); propertyBox.Text = (assignedJob == null) ? "None" : assignedJob.Name; - propertyBox.OnEnter = EnterAssignedJob; + propertyBox.OnEnterPressed = EnterAssignedJob; propertyBox.OnTextChanged = TextBoxChanged; y = y + 30; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index f44d800a6..a93011746 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -9,10 +9,8 @@ using Barotrauma.Networking.ReliableMessages; namespace Barotrauma.Networking { - class GameServer : NetworkMember + partial class GameServer : NetworkMember { - public bool ShowNetStats; - public List connectedClients = new List(); //for keeping track of disconnected clients in case the reconnect shortly after @@ -24,41 +22,13 @@ namespace Barotrauma.Networking bool started; private NetServer server; - private NetPeerConfiguration config; - - private TimeSpan sparseUpdateInterval = new TimeSpan(0, 0, 0, 3); - private DateTime sparseUpdateTimer; + private NetPeerConfiguration config; - private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40); + private DateTime sparseUpdateTimer; private DateTime refreshMasterTimer; - private BanList banList; - private bool masterServerResponded; - private bool registeredToMaster; - - private string password; - - private bool autoRestart; - - public bool AutoRestart - { - get { return (connectedClients.Count==0) ? false : autoRestart; } - set - { - autoRestart = value; - - AutoRestartTimer = autoRestart ? 20.0f : 0.0f; - } - } - public float AutoRestartTimer; - - public BanList BanList - { - get { return banList; } - } - public GameServer(string name, int port, bool isPublic = false, string password = "", bool attemptUPnP = false, int maxPlayers = 10) { var endRoundButton = new GUIButton(new Rectangle(GameMain.GraphicsWidth - 170, 20, 150, 25), "End round", Alignment.TopLeft, GUI.Style, inGameHUD); @@ -238,6 +208,7 @@ namespace Barotrauma.Networking public override void Update(float deltaTime) { if (ShowNetStats) netStats.Update(deltaTime); + if (settingsFrame != null) settingsFrame.Update(deltaTime); if (!started) return; @@ -1033,6 +1004,8 @@ namespace Barotrauma.Networking public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { base.Draw(spriteBatch); + + if (settingsFrame != null) settingsFrame.Draw(spriteBatch); if (!ShowNetStats) return; @@ -1292,16 +1265,6 @@ namespace Barotrauma.Networking return preferredClient; } - - private byte PlayerCountToByte(int playerCount, int maxPlayers) - { - byte byteVal = (byte)playerCount; - - byteVal |= (byte)((maxPlayers-1) << 4); - - return byteVal; - } - /// /// sends some random data to the clients /// use for debugging purposes diff --git a/Subsurface/Source/Networking/NetworkMember.cs b/Subsurface/Source/Networking/NetworkMember.cs index b16864f04..af75c2428 100644 --- a/Subsurface/Source/Networking/NetworkMember.cs +++ b/Subsurface/Source/Networking/NetworkMember.cs @@ -109,7 +109,7 @@ namespace Barotrauma.Networking new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25), Color.White * 0.5f, Color.Black, Alignment.TopLeft, Alignment.Left, GUI.Style, inGameHUD); chatMsgBox.Font = GUI.SmallFont; - chatMsgBox.OnEnter = EnterChatMessage; + chatMsgBox.OnEnterPressed = EnterChatMessage; crewButton = new GUIButton(new Rectangle(chatBox.Rect.Right-80, chatBox.Rect.Y-30, 80, 20), "Crew", GUI.Style, inGameHUD); crewButton.OnClicked = ToggleCrewFrame; @@ -175,17 +175,6 @@ namespace Barotrauma.Networking return true; } - //protected void UpdateCrewFrame(List connectedClients) - //{ - // List characterList = new List(); - // foreach (Client c in connectedClients) - // { - // if (c.character != null && c.inGame) characterList.Add(c.character); - // } - - // CreateCrewFrame(characterList); - //} - public bool EnterChatMessage(GUITextBox textBox, string message) { if (string.IsNullOrWhiteSpace(message)) return false; @@ -268,6 +257,15 @@ namespace Barotrauma.Networking public virtual void Disconnect() { } + protected byte PlayerCountToByte(int playerCount, int maxPlayers) + { + byte byteVal = (byte)playerCount; + + byteVal |= (byte)((maxPlayers - 1) << 4); + + return byteVal; + } + public static int ByteToPlayerCount(byte byteVal, out int maxPlayers) { maxPlayers = (byteVal >> 4)+1; diff --git a/Subsurface/Source/PlayerInput.cs b/Subsurface/Source/PlayerInput.cs index 48cf8a746..836c3b5c3 100644 --- a/Subsurface/Source/PlayerInput.cs +++ b/Subsurface/Source/PlayerInput.cs @@ -7,62 +7,177 @@ namespace Barotrauma public enum InputType { Select, - ActionHit, ActionHeld, - SecondaryHit, SecondaryHeld, - Left, Right, Up, Down, + Use, + Aim, + Up, Down, Left, Right, Run, Chat } + public class KeyOrMouse + { + Keys keyBinding; + int? mouseButton; + + public KeyOrMouse(Keys keyBinding) + { + this.keyBinding = keyBinding; + } + + public KeyOrMouse(int mouseButton) + { + this.mouseButton = mouseButton; + } + + public bool IsDown() + { + if (mouseButton==null) + { + return PlayerInput.KeyDown(keyBinding); + } + else if (mouseButton == 0) + { + return PlayerInput.LeftButtonDown(); + } + else if (mouseButton == 1) + { + return PlayerInput.RightButtonDown(); + } + + return false; + } + + public bool IsHit() + { + if (mouseButton == null) + { + return PlayerInput.KeyHit(keyBinding); + } + else if (mouseButton == 0) + { + return PlayerInput.LeftButtonClicked(); + } + else if (mouseButton == 1) + { + return PlayerInput.RightButtonClicked(); + } + + return false; + } + + public override string ToString() + { + if (mouseButton==null) + { + return keyBinding.ToString(); + } + else if (mouseButton==0) + { + return "Mouse1"; + } + else if (mouseButton==1) + { + return "Mouse2"; + } + + return "None"; + } + } + class Key { - private bool state, stateQueue; - private bool canBeHeld; + private bool hit, hitQueue; + private bool held, heldQueue; - public bool CanBeHeld - { - get { return canBeHeld; } - } + + KeyOrMouse binding; + + //public bool CanBeHeld + //{ + // get { return canBeHeld; } + //} - public Key(bool canBeHeld) + public Key(KeyOrMouse binding) { - this.canBeHeld = canBeHeld; + this.binding = binding; } - public bool State + public bool Hit { get { - return state; + return hit; } set { - //if (value == false) return; - state = value; - //if (value) stateQueue = value; + hit = value; } } - public void SetState(bool value) + public bool Held + { + get + { + return held; + } + set + { + held = value; + } + } + + public KeyOrMouse State + { + get { return binding; } + } + + public void SetState() { - state = value; - if (value) stateQueue = value; + hit = binding.IsHit(); + if (hit) hitQueue = true; + + held = binding.IsDown(); + if (held) heldQueue = true; } public bool Dequeue { get { - bool value = stateQueue; - stateQueue = false; + bool value = hitQueue; + hitQueue = false; return value; } } - public void Reset() + public bool DequeueHeld + { + get + { + bool value = heldQueue; + heldQueue = false; + return value; + } + } + + + public void Reset() + { + hit = false; + held = false; + } + + public void ResetHit() { - if (!canBeHeld) state = false; + hit = false; //stateQueue = false; } + + + public void ResetHeld() + { + held = false; + //stateQueue = false; + } } public static class PlayerInput diff --git a/Subsurface/Source/Screens/MainMenuScreen.cs b/Subsurface/Source/Screens/MainMenuScreen.cs index e57183348..aa2af5025 100644 --- a/Subsurface/Source/Screens/MainMenuScreen.cs +++ b/Subsurface/Source/Screens/MainMenuScreen.cs @@ -199,6 +199,23 @@ namespace Barotrauma public void SelectTab(Tab tab) { + int oldTab = selectedTab; + + + if (GameMain.Config.UnsavedSettings) + { + var applyBox = new GUIMessageBox("Apply changes?", "Do you want to apply the settings or discard the changes?", + new string[] {"Apply", "Discard"}); + applyBox.Buttons[0].OnClicked += applyBox.Close; + applyBox.Buttons[0].OnClicked += ApplySettings; + applyBox.Buttons[0].UserData = tab; + applyBox.Buttons[1].OnClicked += applyBox.Close; + applyBox.Buttons[1].OnClicked += DiscardSettings; + applyBox.Buttons[1].UserData = tab; + + return; + } + selectedTab = (int)tab; switch (selectedTab) @@ -207,11 +224,29 @@ namespace Barotrauma UpdateLoadScreen(); break; case (int)Tab.Settings: + GameMain.Config.ResetSettingsFrame(); menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame; break; } } + private bool ApplySettings(GUIButton button, object obj) + { + GameMain.Config.Save("config.xml"); + selectedTab = (int)obj; + + return true; + } + + private bool DiscardSettings(GUIButton button, object obj) + { + GameMain.Config.Load("config.xml"); + selectedTab = (int)obj; + + return true; + } + + private bool TutorialButtonClicked(GUIButton button, object obj) { TutorialMode.StartTutorial(); diff --git a/Subsurface/Source/Screens/NetLobbyScreen.cs b/Subsurface/Source/Screens/NetLobbyScreen.cs index 203bc46d2..aa7ac5d7a 100644 --- a/Subsurface/Source/Screens/NetLobbyScreen.cs +++ b/Subsurface/Source/Screens/NetLobbyScreen.cs @@ -119,7 +119,7 @@ namespace Barotrauma //server info panel ------------------------------------------------------------ infoFrame = new GUIFrame(new Rectangle(0, 0, (int)(panelRect.Width * 0.7f), (int)(panelRect.Height * 0.6f)), GUI.Style, menu); - //infoFrame.Padding = GUI.style.smallPadding; + infoFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f); ; //chatbox ---------------------------------------------------------------------- GUIFrame chatFrame = new GUIFrame( @@ -127,11 +127,12 @@ namespace Barotrauma (int)(panelRect.Width * 0.7f), (int)(panelRect.Height * 0.4f - 20)), GUI.Style, menu); + chatFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 40.0f); chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, GUI.Style, chatFrame); textBox = new GUITextBox(new Rectangle(0, 25, 0, 25), Alignment.Bottom, GUI.Style, chatFrame); textBox.Font = GUI.SmallFont; - textBox.OnEnter = EnterChatMessage; + textBox.OnEnterPressed = EnterChatMessage; //player info panel ------------------------------------------------------------ @@ -148,6 +149,8 @@ namespace Barotrauma (int)(panelRect.Width * 0.3f - 20), (int)(panelRect.Height * 0.4f - 20)), GUI.Style, menu); + playerListFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 40.0f); + playerList = new GUIListBox(new Rectangle(0,0,0,0), null, GUI.Style, playerListFrame); playerList.OnSelected = SelectPlayer; @@ -278,10 +281,14 @@ namespace Barotrauma if (IsServer && GameMain.Server != null) { - GUIButton startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame); + GUIButton startButton = new GUIButton(new Rectangle(0, 0, 80, 30), "Start", Alignment.BottomRight, GUI.Style, infoFrame); startButton.OnClicked = GameMain.Server.StartGameClicked; startButton.UserData = "startButton"; + GUIButton settingsButton = new GUIButton(new Rectangle(-100, 0, 80, 30), "Settings", Alignment.BottomRight, GUI.Style, infoFrame); + settingsButton.OnClicked = GameMain.Server.ToggleSettingsFrame; + settingsButton.UserData = "settingsButton"; + var banListButton = new GUIButton(new Rectangle(0, 30, 100, 20), "Banned IPs", Alignment.BottomRight, GUI.Style, playerList.Parent); banListButton.OnClicked = GameMain.Server.BanList.ToggleBanFrame; banListButton.UserData = "banListButton"; @@ -299,6 +306,10 @@ namespace Barotrauma playYourself.OnSelected = TogglePlayYourself; playYourself.UserData = "playyourself"; } + + if (GameMain.Server.RandomizeSeed) seedBox.Text = ToolBox.RandomSeed(8); + if (GameMain.Server.SubSelectionMode == SelectionMode.Random) subList.Select(Rand.Range(0,subList.CountChildren)); + if (GameMain.Server.ModeSelectionMode == SelectionMode.Random) modeList.Select(Rand.Range(0, modeList.CountChildren)); } else { @@ -322,12 +333,18 @@ namespace Barotrauma playYourself.UserData = "playyourself"; } - new GUITextBlock(new Rectangle(60, 30, 200, 30), "Name: ", GUI.Style, myPlayerFrame); + new GUITextBlock(new Rectangle(100, 30, 200, 30), "Name: ", GUI.Style, myPlayerFrame); - GUITextBox playerName = new GUITextBox(new Rectangle(60, 55, 0, 20), - Alignment.TopLeft, GUI.Style, myPlayerFrame); + GUITextBox playerName = new GUITextBox(new Rectangle(100, 55, 0, 20), Alignment.TopLeft, GUI.Style, myPlayerFrame); playerName.Text = characterInfo.Name; - playerName.OnEnter += ChangeCharacterName; + playerName.OnEnterPressed += ChangeCharacterName; + + GUIButton toggleHead = new GUIButton(new Rectangle(00, 50, 20, 20), "<", GUI.Style, myPlayerFrame); + toggleHead.UserData = -1; + toggleHead.OnClicked = ToggleHead; + toggleHead = new GUIButton(new Rectangle(40, 50, 20, 20), ">", GUI.Style, myPlayerFrame); + toggleHead.UserData = 1; + toggleHead.OnClicked = ToggleHead; new GUITextBlock(new Rectangle(0, 100, 200, 30), "Gender: ", GUI.Style, myPlayerFrame); @@ -374,9 +391,8 @@ namespace Barotrauma } } - private bool TogglePlayYourself(object obj) + private bool TogglePlayYourself(GUITickBox tickBox) { - GUITickBox tickBox = obj as GUITickBox; if (tickBox.Selected) { GameMain.Server.CharacterInfo = new CharacterInfo(Character.HumanConfigFile, GameMain.Server.Name); @@ -398,16 +414,13 @@ namespace Barotrauma return false; } - private bool ToggleAutoRestart(object obj) + private bool ToggleAutoRestart(GUITickBox tickBox) { if (GameMain.Server == null) return false; - GUITickBox tickBox = obj as GUITickBox; - if (tickBox==null) return false; - GameMain.Server.AutoRestart = tickBox.Selected; - GameMain.Server.UpdateNetLobby(obj); + GameMain.Server.UpdateNetLobby(tickBox); return true; } @@ -622,10 +635,23 @@ namespace Barotrauma GUIComponent existing = myPlayerFrame.FindChild("playerhead"); if (existing != null) myPlayerFrame.RemoveChild(existing); - GUIImage image = new GUIImage(new Rectangle(0, 40, 30, 30), characterInfo.HeadSprite, Alignment.TopLeft, myPlayerFrame); + GUIImage image = new GUIImage(new Rectangle(20, 40, 30, 30), characterInfo.HeadSprite, Alignment.TopLeft, myPlayerFrame); image.UserData = "playerhead"; } + private bool ToggleHead(GUIButton button, object userData) + { + int dir = (int)userData; + + if (GameMain.NetworkMember.CharacterInfo == null) return true; + + GameMain.NetworkMember.CharacterInfo.HeadSpriteId += dir; + + UpdatePreviewPlayer(GameMain.NetworkMember.CharacterInfo); + + return true; + } + private bool SwitchGender(GUIButton button, object obj) { Gender gender = (Gender)obj; diff --git a/Subsurface/Source/Screens/NetLobbySettings.cs b/Subsurface/Source/Screens/NetLobbySettings.cs new file mode 100644 index 000000000..85b954910 --- /dev/null +++ b/Subsurface/Source/Screens/NetLobbySettings.cs @@ -0,0 +1,144 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Barotrauma.Networking +{ + enum SelectionMode + { + Manual = 0, Random = 1, Vote = 2 + } + + partial class GameServer : NetworkMember + { + public bool ShowNetStats; + + private TimeSpan refreshMasterInterval = new TimeSpan(0, 0, 40); + private TimeSpan sparseUpdateInterval = new TimeSpan(0, 0, 0, 3); + + private SelectionMode subSelectionMode, modeSelectionMode; + + private bool randomizeSeed; + + private bool registeredToMaster; + + private BanList banList; + + private string password; + + private GUIFrame settingsFrame; + + public float AutoRestartTimer; + + private bool autoRestart; + + public bool AutoRestart + { + get { return (connectedClients.Count == 0) ? false : autoRestart; } + set + { + autoRestart = value; + + AutoRestartTimer = autoRestart ? 20.0f : 0.0f; + } + } + + public SelectionMode SubSelectionMode + { + get { return subSelectionMode; } + } + + public SelectionMode ModeSelectionMode + { + get { return modeSelectionMode; } + } + + public bool RandomizeSeed + { + get { return randomizeSeed; } + } + + public BanList BanList + { + get { return banList; } + } + + private void CreateSettingsFrame() + { + settingsFrame = new GUIFrame(new Rectangle(0,0,GameMain.GraphicsWidth,GameMain.GraphicsHeight), Color.Black*0.5f); + + GUIFrame innerFrame = new GUIFrame(new Rectangle(0,0,400,400), null, Alignment.Center, GUI.Style, settingsFrame); + + var randomizeLevelBox = new GUITickBox(new Rectangle(0, 0, 20, 20), "Randomize level seed", Alignment.Left, innerFrame); + randomizeLevelBox.OnSelected = ToggleRandomizeSeed; + + new GUITextBlock(new Rectangle(0, 35, 100, 20), "Submarine selection:", GUI.Style, innerFrame); + var selectionFrame = new GUIFrame(new Rectangle(0, 60, 300, 20), null, innerFrame); + for (int i = 0; i<3; i++) + { + var selectionTick = new GUITickBox(new Rectangle(i * 100, 00, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame); + selectionTick.Selected = i == (int)subSelectionMode; + selectionTick.OnSelected = SwitchSubSelection; + selectionTick.UserData = (SelectionMode)i; + } + + new GUITextBlock(new Rectangle(0, 85, 100, 20), "Mode selection:", GUI.Style, innerFrame); + selectionFrame = new GUIFrame(new Rectangle(0, 110, 300, 20), null, innerFrame); + for (int i = 0; i<3; i++) + { + var selectionTick = new GUITickBox(new Rectangle(i*100, 0, 20, 20), ((SelectionMode)i).ToString(), Alignment.Left, selectionFrame); + selectionTick.Selected = i == (int)modeSelectionMode; + selectionTick.OnSelected = SwitchModeSelection; + selectionTick.UserData = (SelectionMode)i; + } + } + + private bool SwitchSubSelection(GUITickBox tickBox) + { + subSelectionMode = (SelectionMode)tickBox.UserData; + + foreach (GUIComponent otherTickBox in tickBox.Parent.children) + { + if (otherTickBox == tickBox) continue; + ((GUITickBox)otherTickBox).Selected = false; + } + + return true; + } + + private bool SwitchModeSelection(GUITickBox tickBox) + { + modeSelectionMode = (SelectionMode)tickBox.UserData; + + foreach (GUIComponent otherTickBox in tickBox.Parent.children) + { + if (otherTickBox == tickBox) continue; + ((GUITickBox)otherTickBox).Selected = false; + } + + return true; + } + + private bool ToggleRandomizeSeed(GUITickBox tickBox) + { + randomizeSeed = tickBox.Selected; + return true; + } + + public bool ToggleSettingsFrame(GUIButton button, object obj) + { + if (settingsFrame==null) + { + CreateSettingsFrame(); + } + else + { + settingsFrame = null; + } + + return true; + } + } +} diff --git a/Subsurface/Source/Screens/SettingsScreen.cs b/Subsurface/Source/Screens/SettingsScreen.cs deleted file mode 100644 index f905e8e17..000000000 --- a/Subsurface/Source/Screens/SettingsScreen.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Barotrauma -{ - class SettingsScreen : Screen - { - } -} diff --git a/Subsurface/Source/Utils/TextureLoader.cs b/Subsurface/Source/Utils/TextureLoader.cs index 79b0f17a7..1081ccad5 100644 --- a/Subsurface/Source/Utils/TextureLoader.cs +++ b/Subsurface/Source/Utils/TextureLoader.cs @@ -46,18 +46,13 @@ namespace Barotrauma { try { -#if WINDOWS - using (Stream fileStream = File.OpenRead(path)) - return FromStream(fileStream, preMultiplyAlpha); -#endif -#if LINUX + using (Stream fileStream = File.OpenRead(path)) { var texture = Texture2D.FromStream(_graphicsDevice, fileStream); texture = PreMultiplyAlpha(texture); return texture; } -#endif } catch (Exception e) @@ -68,36 +63,6 @@ namespace Barotrauma } -#if WINDOWS - private static Texture2D FromStream(Stream stream, bool preMultiplyAlpha = true) - { - Texture2D texture; - - if (_needsBmp) - { - // Load image using GDI because Texture2D.FromStream doesn't support BMP - using (Image image = Image.FromStream(stream)) - { - // Now create a MemoryStream which will be passed to Texture2D after converting to PNG internally - using (MemoryStream ms = new MemoryStream()) - { - image.Save(ms, ImageFormat.Png); - ms.Seek(0, SeekOrigin.Begin); - texture = Texture2D.FromStream(_graphicsDevice, ms); - } - } - } - else - { - texture = Texture2D.FromStream(_graphicsDevice, stream); - } - - if (preMultiplyAlpha) texture = PreMultiplyAlpha(texture); - - return texture; - } -#endif - private static Texture2D PreMultiplyAlpha(Texture2D texture) { // Setup a render target to hold our final texture which will have premulitplied alpha values diff --git a/Subsurface_Solution.v12.suo b/Subsurface_Solution.v12.suo index 7b9744537..5dd7e7f11 100644 Binary files a/Subsurface_Solution.v12.suo and b/Subsurface_Solution.v12.suo differ