Settings menu with sound and music volume sliders, re-enabled deselecting connectionpanels with E in editmapscreen

This commit is contained in:
Regalis
2015-10-26 19:35:57 +02:00
parent ebe248a7cc
commit 9ed2963cd9
19 changed files with 223 additions and 72 deletions

View File

@@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.3.2")]
[assembly: AssemblyFileVersion("0.2.3.2")]
[assembly: AssemblyVersion("0.2.4.1")]
[assembly: AssemblyFileVersion("0.2.4.1")]

View File

@@ -998,7 +998,7 @@ namespace Barotrauma
// limb.Damage = 100.0f;
}
AmbientSoundManager.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body.FarseerBody);
SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.RefLimb.body.FarseerBody);
for (int i = 0; i < 10; i++)
{

View File

@@ -319,7 +319,7 @@ namespace Barotrauma
if (playSound)
{
AmbientSoundManager.PlayDamageSound(damageSoundType, amount, ConvertUnits.ToDisplayUnits(simPosition));
SoundPlayer.PlayDamageSound(damageSoundType, amount, ConvertUnits.ToDisplayUnits(simPosition));
}
//Bleeding += bleedingAmount;

View File

@@ -368,7 +368,7 @@ namespace Barotrauma
character.Health -= (impact - l.impactTolerance * 0.1f);
strongestImpact = Math.Max(strongestImpact, impact - l.impactTolerance);
AmbientSoundManager.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody);
SoundPlayer.PlayDamageSound(DamageSoundType.LimbBlunt, strongestImpact, l.body.FarseerBody);
if (Character.Controlled == character) GameMain.GameScreen.Cam.Shake = strongestImpact;
}

View File

@@ -17,7 +17,7 @@ namespace Barotrauma
private bool enabled;
public delegate bool OnMovedHandler(object obj);
public delegate bool OnMovedHandler(float barScroll);
public OnMovedHandler OnMoved;
public bool IsHorizontal
@@ -95,6 +95,8 @@ namespace Barotrauma
//System.Diagnostics.Debug.WriteLine(frame.rect);
this.barSize = barSize;
bar = new GUIButton(new Rectangle(0, 0, 0, 0), "", color, style, this);
bar.OnPressed = SelectBar;
@@ -172,7 +174,7 @@ namespace Barotrauma
barScroll = (float)newY / ((float)frame.Rect.Height - (float)bar.Rect.Height);
}
if (moveAmount != 0 && OnMoved != null) OnMoved(moveAmount);
if (moveAmount != 0 && OnMoved != null) OnMoved(barScroll);
bar.Rect = new Rectangle(newX + frame.Rect.X, newY + frame.Rect.Y, bar.Rect.Width, bar.Rect.Height);

View File

@@ -202,7 +202,7 @@ namespace Barotrauma
yield return CoroutineStatus.Running;
Debug.WriteLine("sounds");
CoroutineManager.StartCoroutine(AmbientSoundManager.Init());
CoroutineManager.StartCoroutine(SoundPlayer.Init());
TitleScreen.LoadState = 70.0f;
yield return CoroutineStatus.Running;
@@ -267,7 +267,7 @@ namespace Barotrauma
if (hasLoaded && !titleScreenOpen)
{
AmbientSoundManager.Update();
SoundPlayer.Update();
if (PlayerInput.KeyHit(Keys.Escape)) GUI.TogglePauseMenu();

View File

@@ -1,4 +1,6 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,45 +11,50 @@ namespace Barotrauma
{
public class GameSettings
{
public int GraphicsWidth
private GUIFrame settingsFrame;
private float soundVolume, musicVolume;
private Keys[] keyMapping;
public GUIFrame SettingsFrame
{
get;
set;
}
public int GraphicsHeight
{
get;
set;
get
{
if (settingsFrame == null) CreateSettingsFrame();
return settingsFrame;
}
}
public bool FullScreenEnabled
public int GraphicsWidth { get; set; }
public int GraphicsHeight { get; set; }
public bool FullScreenEnabled { get; set; }
public ContentPackage SelectedContentPackage { get; set; }
public string MasterServerUrl { get; set; }
public bool AutoCheckUpdates { get; set; }
public bool WasGameUpdated { get; set; }
public float SoundVolume
{
get;
set;
get { return soundVolume; }
set
{
soundVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
Sounds.SoundManager.MasterVolume = soundVolume;
}
}
public ContentPackage SelectedContentPackage
public float MusicVolume
{
get;
set;
}
public string MasterServerUrl
{
get;
private set;
}
public bool AutoCheckUpdates
{
get;
set;
}
public bool WasGameUpdated
{
get;
set;
get { return musicVolume; }
set
{
musicVolume = MathHelper.Clamp(value, 0.0f, 1.0f);
SoundPlayer.MusicVolume = musicVolume;
}
}
public GameSettings(string filePath)
@@ -90,6 +97,18 @@ namespace Barotrauma
AutoCheckUpdates = ToolBox.GetAttributeBool(doc.Root, "autocheckupdates", true);
WasGameUpdated = ToolBox.GetAttributeBool(doc.Root, "wasgameupdated", false);
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;
foreach (XElement subElement in doc.Root.Elements())
{
switch (subElement.Name.ToString().ToLower())
@@ -100,6 +119,18 @@ namespace Barotrauma
if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path);
break;
case "keymapping":
foreach (XAttribute attribute in subElement.Attributes())
{
InputType inputType;
Keys key;
if (Enum.TryParse(attribute.Name.ToString(), true, out inputType) &&
Enum.TryParse(attribute.Value.ToString(), true, out key))
{
keyMapping[(int)inputType] = key;
}
}
break;
}
}
}
@@ -115,13 +146,14 @@ namespace Barotrauma
doc.Root.Add(
new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates));
new XAttribute("autocheckupdates", AutoCheckUpdates),
new XAttribute("musicvolume", musicVolume),
new XAttribute("soundvolume", soundVolume));
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("gamupdated", true));
}
doc.Root.Add(new XAttribute("wasgameupdated", true));
}
XElement gMode = doc.Root.Element("graphicsmode");
if (gMode == null)
@@ -144,5 +176,63 @@ namespace Barotrauma
doc.Save(filePath);
}
private bool ChangeSoundVolume(float barScroll)
{
SoundVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f);
return true;
}
private bool ChangeMusicVolume(float barScroll)
{
MusicVolume = MathHelper.Clamp(barScroll, 0.0f, 1.0f);
return true;
}
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);
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);
musicScrollBar.BarScroll = MusicVolume;
musicScrollBar.OnMoved = ChangeMusicVolume;
int x = 250;
int y = 60;
new GUITextBlock(new Rectangle(x, 40, 100, 20), "Controls:", GUI.Style, settingsFrame);
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);
keyBox.Text = keyMapping[i].ToString();
keyBox.OnTextChanged = MapKey;
y += 20;
}
var applyButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Apply", GUI.Style, settingsFrame);
applyButton.OnClicked = ApplyClicked;
}
private bool MapKey(GUITextBox textBox, string text)
{
return true;
}
private bool ApplyClicked(GUIButton button, object userData)
{
Save("config.xml");
return true;
}
}
}

View File

@@ -105,7 +105,17 @@ namespace Barotrauma.Items.Components
{
if (stickTarget != null)
{
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
try
{
item.body.FarseerBody.RestoreCollisionWith(stickTarget);
}
catch
{
#if DEBUG
DebugConsole.ThrowError("Failed to restore collision with stickTarget", e);
#endif
}
stickTarget = null;
}
GameMain.World.RemoveJoint(stickJoint);

View File

@@ -37,7 +37,8 @@ namespace Barotrauma.Items.Components
{
if (character != Character.Controlled || character != user) return;
if (character.GetInputState(InputType.Select) &&
if (Screen.Selected != GameMain.EditMapScreen &&
character.GetInputState(InputType.Select) &&
character.SelectedConstruction==this.item) character.SelectedConstruction = null;
Connection.DrawConnections(spriteBatch, this, character);

View File

@@ -234,7 +234,7 @@ namespace Barotrauma
int index = (int)Math.Floor(flowForce.Length() / 100.0f);
index = Math.Min(index,2);
soundIndex = AmbientSoundManager.flowSounds[index].Loop(soundIndex, soundVolume, Position, 2000.0f);
soundIndex = SoundPlayer.flowSounds[index].Loop(soundIndex, soundVolume, Position, 2000.0f);
flowForce = Vector2.Zero;
lerpedFlowForce = Vector2.Lerp(lerpedFlowForce, flowForce, 0.05f);

View File

@@ -345,7 +345,7 @@ namespace Barotrauma
if (impact < 10.0f) return true;
AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact,
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact,
new Vector2(
sections[section].rect.X + sections[section].rect.Width / 2,
sections[section].rect.Y - sections[section].rect.Height / 2));
@@ -436,7 +436,7 @@ namespace Barotrauma
if (playSound && !SectionHasHole(i))
{
DamageSoundType damageSoundType = (attack.DamageType == DamageType.Blunt) ? DamageSoundType.StructureBlunt : DamageSoundType.StructureSlash;
AmbientSoundManager.PlayDamageSound(damageSoundType, damageAmount, position);
SoundPlayer.PlayDamageSound(damageSoundType, damageAmount, position);
}
AddDamage(i, damageAmount);

View File

@@ -361,7 +361,7 @@ namespace Barotrauma
public void ApplyForce(Vector2 force)
{
subBody.ApplyForce(force);
if (subBody != null) subBody.ApplyForce(force);
}
public void SetPosition(Vector2 position)

View File

@@ -258,7 +258,7 @@ namespace Barotrauma
if (lastContactPoint == null || lastContactCell==null || impact < 3.0f) return;
AmbientSoundManager.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
SoundPlayer.PlayDamageSound(DamageSoundType.StructureBlunt, impact * 10.0f, ConvertUnits.ToDisplayUnits((Vector2)lastContactPoint));
GameMain.GameScreen.Cam.Shake = impact * 2.0f;
Vector2 limbForce = -normal * impact*0.5f;

View File

@@ -10,7 +10,7 @@ namespace Barotrauma
ActionHit, ActionHeld,
SecondaryHit, SecondaryHeld,
Left, Right, Up, Down,
Run
Run, Chat
}
class Key

View File

@@ -8,7 +8,7 @@ namespace Barotrauma
{
class MainMenuScreen : Screen
{
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3 }
public enum Tab { NewGame = 1, LoadGame = 2, HostServer = 3, Settings = 4 }
GUIFrame buttonsTab;
@@ -42,23 +42,27 @@ namespace Barotrauma
GUIButton button = new GUIButton(new Rectangle(0, 0, 0, 30), "Tutorial", Alignment.CenterX, GUI.Style, buttonsTab);
button.OnClicked = TutorialButtonClicked;
button = new GUIButton(new Rectangle(0, 70, 0, 30), "New Game", Alignment.CenterX, GUI.Style, buttonsTab);
button = new GUIButton(new Rectangle(0, 60, 0, 30), "New Game", Alignment.CenterX, GUI.Style, buttonsTab);
button.UserData = Tab.NewGame;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 130, 0, 30), "Load Game", Alignment.CenterX, GUI.Style, buttonsTab);
button = new GUIButton(new Rectangle(0, 100, 0, 30), "Load Game", Alignment.CenterX, GUI.Style, buttonsTab);
button.UserData = Tab.LoadGame;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 200, 0, 30), "Join Server", Alignment.CenterX, GUI.Style, buttonsTab);
button = new GUIButton(new Rectangle(0, 160, 0, 30), "Join Server", Alignment.CenterX, GUI.Style, buttonsTab);
//button.UserData = (int)Tabs.JoinServer;
button.OnClicked = JoinServerClicked;
button = new GUIButton(new Rectangle(0, 260, 0, 30), "Host Server", Alignment.CenterX, GUI.Style, buttonsTab);
button = new GUIButton(new Rectangle(0, 200, 0, 30), "Host Server", Alignment.CenterX, GUI.Style, buttonsTab);
button.UserData = Tab.HostServer;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 330, 0, 30), "Quit", Alignment.CenterX, GUI.Style, buttonsTab);
button = new GUIButton(new Rectangle(0, 260, 0, 30), "Settings", Alignment.CenterX, GUI.Style, buttonsTab);
button.UserData = Tab.Settings;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 320, 0, 30), "Quit", Alignment.CenterX, GUI.Style, buttonsTab);
button.OnClicked = QuitClicked;
//----------------------------------------------------------------------
@@ -197,7 +201,15 @@ namespace Barotrauma
{
selectedTab = (int)tab;
if (selectedTab == (int)Tab.LoadGame) UpdateLoadScreen();
switch (selectedTab)
{
case (int)Tab.LoadGame:
UpdateLoadScreen();
break;
case (int)Tab.Settings:
menuTabs[(int)Tab.Settings] = GameMain.Config.SettingsFrame;
break;
}
}
private bool TutorialButtonClicked(GUIButton button, object obj)

View File

@@ -49,10 +49,12 @@ namespace Barotrauma
}
}
static class AmbientSoundManager
static class SoundPlayer
{
public static Sound[] flowSounds = new Sound[3];
public static float MusicVolume = 1.0f;
private const float MusicLerpSpeed = 0.01f;
private static Sound[] waterAmbiences = new Sound[2];
@@ -63,7 +65,7 @@ namespace Barotrauma
private static BackgroundMusic currentMusic;
private static BackgroundMusic targetMusic;
private static BackgroundMusic[] musicClips;
private static float musicVolume;
private static float currMusicVolume;
private static Sound startDrone;
@@ -251,20 +253,20 @@ namespace Barotrauma
if (targetMusic == null || currentMusic == null || targetMusic.file != currentMusic.file)
{
musicVolume = MathHelper.Lerp(musicVolume, 0.0f, MusicLerpSpeed);
if (currentMusic != null) Sound.StreamVolume(musicVolume);
currMusicVolume = MathHelper.Lerp(currMusicVolume, 0.0f, MusicLerpSpeed);
if (currentMusic != null) Sound.StreamVolume(currMusicVolume);
if (musicVolume < 0.01f)
if (currMusicVolume < 0.01f)
{
Sound.StopStream();
if (targetMusic != null) Sound.StartStream(targetMusic.file, musicVolume);
if (targetMusic != null) Sound.StartStream(targetMusic.file, currMusicVolume);
currentMusic = targetMusic;
}
}
else
{
musicVolume = MathHelper.Lerp(musicVolume, 0.3f, MusicLerpSpeed);
Sound.StreamVolume(musicVolume);
currMusicVolume = MathHelper.Lerp(currMusicVolume, MusicVolume, MusicLerpSpeed);
Sound.StreamVolume(currMusicVolume);
}
}

View File

@@ -29,6 +29,8 @@ namespace Barotrauma.Sounds
public static OggStreamer oggStreamer;
public static OggStream oggStream;
public static float MasterVolume = 1.0f;
public static void Init()
{
AC = new AudioContext();
@@ -250,7 +252,7 @@ namespace Barotrauma.Sounds
public static void Volume(int sourceIndex, float volume)
{
AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume);
AL.Source(alSources[sourceIndex], ALSourcef.Gain, volume * MasterVolume);
ALHelper.Check();
}
@@ -303,8 +305,8 @@ namespace Barotrauma.Sounds
//Resume(sourceIndex);
position/= 1000.0f;
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume);
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSourcef.Gain, baseVolume * MasterVolume);
OpenTK.Audio.OpenAL.AL.Source(alSources[sourceIndex], OpenTK.Audio.OpenAL.ALSource3f.Position, position.X, position.Y, 0.0f);
float lowPassGain = lowPassHfGain / Math.Max(position.Length() * 5.0f, 1.0f);

View File

@@ -1,3 +1,35 @@
---------------------------------------------------------------------------------------------------------
v0.2.4.1
---------------------------------------------------------------------------------------------------------
- fixed rewiring not working in the editor
- fixed a game-crashing projectile bug
---------------------------------------------------------------------------------------------------------
v0.2.4
---------------------------------------------------------------------------------------------------------
Multiplayer:
- fixed invincible NPCs
- the target in traitor mode is properly randomized and the host can be selected as a traitor/target
- the "fix list" when repairing items is synced between clients, so the reactor can actually be fixed now
- more networking optimization
- bans can be removed by using a button under the player list, not just by editing the bannedplayers.xml file
Items:
- wires are removed from connection panels when they're deleted in the editor
- doors can be rewired from either side
- the rewire screen can be deselect by pressing E
- sonar won't work anymore if the power wire is removed
- stun batons can't be double wielded or used for fast underwater movement
Misc:
- some particles floating in the water, which make it easier to see if the sub is moving just by
looking out of a window
- fixed a bug which may have crashed the game if a character spawned on a platform or stairs
---------------------------------------------------------------------------------------------------------
v0.2.3.2
---------------------------------------------------------------------------------------------------------

Binary file not shown.