GUIStyle improvements & some simple UI graphics, networking bugfixes, separate Random class, some StyleCop cleanup

This commit is contained in:
Regalis
2015-07-02 22:24:50 +03:00
parent b493ed2b39
commit d836a99515
119 changed files with 8842 additions and 1277 deletions
@@ -80,7 +80,7 @@ namespace Subsurface.Items.Components
if (character != null)
{
character.SelectedConstruction = null;
character.animController.anim = AnimController.Animation.None;
character.AnimController.Anim = AnimController.Animation.None;
character = null;
}
isActive = false;
@@ -89,33 +89,33 @@ namespace Subsurface.Items.Components
ApplyStatusEffects(ActionType.OnActive, deltaTime, character);
if (userPos != 0.0f && character.animController.anim != AnimController.Animation.UsingConstruction)
if (userPos != 0.0f && character.AnimController.Anim != AnimController.Animation.UsingConstruction)
{
Limb torso = character.animController.GetLimb(LimbType.Torso);
Limb torso = character.AnimController.GetLimb(LimbType.Torso);
float torsoX = ConvertUnits.ToDisplayUnits(torso.SimPosition.X);
if (Math.Abs(torsoX - item.Rect.X + userPos) > 10.0f)
{
character.animController.anim = AnimController.Animation.None;
character.AnimController.Anim = AnimController.Animation.None;
character.animController.TargetMovement =
character.AnimController.TargetMovement =
new Vector2(
Math.Min(Math.Max(item.Rect.X + userPos - torsoX, -1.0f), 1.0f),
0.0f);
character.animController.targetDir = (Math.Sign(torsoX - item.Rect.X + userPos) == 1) ? Direction.Right : Direction.Left;
character.AnimController.TargetDir = (Math.Sign(torsoX - item.Rect.X + userPos) == 1) ? Direction.Right : Direction.Left;
return;
}
}
if (limbPositions.Count == 0) return;
character.animController.anim = AnimController.Animation.UsingConstruction;
character.animController.ResetPullJoints();
if (dir != 0) character.animController.targetDir = dir;
character.AnimController.Anim = AnimController.Animation.UsingConstruction;
character.AnimController.ResetPullJoints();
if (dir != 0) character.AnimController.TargetDir = dir;
foreach (LimbPos lb in limbPositions)
{
Limb limb = character.animController.GetLimb(lb.limbType);
Limb limb = character.AnimController.GetLimb(lb.limbType);
if (limb == null) continue;
FixedMouseJoint fmj = limb.pullJoint;
@@ -167,7 +167,7 @@ namespace Subsurface.Items.Components
{
character = null;
isActive = false;
if (activator != null) activator.animController.anim = AnimController.Animation.None;
if (activator != null) activator.AnimController.Anim = AnimController.Animation.None;
return false;
}
+15 -6
View File
@@ -30,7 +30,7 @@ namespace Subsurface.Items.Components
}
}
[Editable, HasDefaultValue(50000.0f, true)]
[Editable, HasDefaultValue(500.0f, true)]
public float MaxForce
{
get { return maxForce; }
@@ -62,9 +62,17 @@ namespace Subsurface.Items.Components
Force = MathHelper.Lerp(force, (voltage < minVoltage) ? 0.0f : targetForce, 0.1f);
if (Force != 0.0f)
{
Submarine.Loaded.ApplyForce(new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f));
Vector2 currForce = new Vector2((force / 100.0f) * maxForce * (voltage / minVoltage), 0.0f);
Submarine.Loaded.ApplyForce(currForce);
for (int i = 0; i < 5; i++)
{
Game1.particleManager.CreateParticle("bubbles", item.SimPosition,
-currForce/500.0f + new Vector2(Rand.Range(-1.0f, 1.0f), Rand.Range(-0.5f, 0.5f)));
}
}
voltage = 0.0f;
}
@@ -79,7 +87,7 @@ namespace Subsurface.Items.Components
//GUI.DrawRectangle(spriteBatch, new Rectangle(x, y, width, height), Color.Black, true);
spriteBatch.DrawString(GUI.font, "Force: " + (int)targetForce + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
spriteBatch.DrawString(GUI.font, "Force: " + (int)(targetForce) + " %", new Vector2(GuiFrame.Rect.X + 30, GuiFrame.Rect.Y + 30), Color.White);
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 30, 40, 40), "+", true)) targetForce += 1.0f;
if (GUI.DrawButton(spriteBatch, new Rectangle(GuiFrame.Rect.X + 280, GuiFrame.Rect.Y + 80, 40, 40), "-", true)) targetForce -= 1.0f;
@@ -96,12 +104,13 @@ namespace Subsurface.Items.Components
{
base.ReceiveSignal(signal, connection, sender, power);
if (connection.name == "set_force")
if (connection.Name == "set_force")
{
float tempForce;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempForce))
{
Force = tempForce;
targetForce = tempForce;
targetForce = MathHelper.Clamp(targetForce, -100.0f, 100.0f);
}
}
}
@@ -90,12 +90,9 @@ namespace Subsurface.Items.Components
//frame.SelectedColor = Color.Gold * 0.5f;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
fi.TargetItem.Name,
new Rectangle(0, 0, 0, 25), fi.TargetItem.Name,
color, Color.Black,
Alignment.Left,
Alignment.Left,
itemList);
Alignment.Left, Alignment.Left, null, itemList);
textBlock.UserData = fi;
textBlock.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
@@ -114,7 +111,7 @@ namespace Subsurface.Items.Components
int width = 200, height = 150;
selectedItemFrame = new GUIFrame(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, itemList.Rect.Bottom+20, width, height), Color.Black*0.8f);
selectedItemFrame.Padding = GUI.style.smallPadding;
//selectedItemFrame.Padding = GUI.style.smallPadding;
if (targetItem.TargetItem.sprite != null)
{
@@ -134,10 +131,10 @@ namespace Subsurface.Items.Components
text,
Color.Transparent, Color.White,
Alignment.CenterX | Alignment.CenterY,
Alignment.Left,
Alignment.Left, null,
selectedItemFrame);
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, selectedItemFrame);
GUIButton button = new GUIButton(new Rectangle(0,0,100,20), "Create", Color.White, Alignment.CenterX | Alignment.Bottom, GUI.style, selectedItemFrame);
button.OnClicked = StartFabricating;
button.UserData = targetItem;
@@ -67,9 +67,9 @@ namespace Subsurface.Items.Components
GUI.DrawRectangle(spriteBatch, hullRect, Color.White);
}
foreach (Character c in Character.characterList)
foreach (Character c in Character.CharacterList)
{
if (c.animController.CurrentHull!=null) continue;
if (c.AnimController.CurrentHull!=null) continue;
Rectangle characterRect = new Rectangle(
miniMap.X + (int)((c.Position.X - Submarine.Borders.X) * size),
@@ -36,7 +36,7 @@ namespace Subsurface.Items.Components
currPowerConsumption = powerConsumption;
if (item.currentHull == null) return;
if (item.CurrentHull == null) return;
if (voltage < minVoltage)
{
@@ -56,7 +56,7 @@ namespace Subsurface.Items.Components
running = true;
float deltaOxygen = Math.Min(voltage, 1.0f) * 50000.0f;
item.currentHull.Oxygen += deltaOxygen * deltaTime;
item.CurrentHull.Oxygen += deltaOxygen * deltaTime;
UpdateVents(deltaOxygen);
+25 -4
View File
@@ -10,6 +10,8 @@ namespace Subsurface.Items.Components
float flowPercentage;
float maxFlow;
float? targetLevel;
//bool flowIn;
Hull hull1, hull2;
@@ -41,7 +43,18 @@ namespace Subsurface.Items.Components
float powerFactor = (currPowerConsumption==0.0f) ? 1.0f : voltage;
//flowPercentage = maxFlow * powerFactor;
float deltaVolume = (flowPercentage/100.0f) * maxFlow * powerFactor;
float deltaVolume = 0.0f;
if (targetLevel!=null)
{
float hullPercentage = 0.0f;
if (hull1 != null) hullPercentage = (hull1.Volume / hull1.FullVolume)*100.0f;
deltaVolume = ((float)targetLevel - hullPercentage)/100.0f * maxFlow * powerFactor;
}
else
{
deltaVolume = (flowPercentage/100.0f) * maxFlow * powerFactor;
}
hull1.Volume += deltaVolume;
if (hull2 != null) hull2.Volume -= deltaVolume;
@@ -139,15 +152,15 @@ namespace Subsurface.Items.Components
isActive = true;
if (connection.name == "toggle")
if (connection.Name == "toggle")
{
isActive = !isActive;
}
else if (connection.name == "set_active")
else if (connection.Name == "set_active")
{
isActive = (signal != "0");
}
else if (connection.name == "set_speed")
else if (connection.Name == "set_speed")
{
float tempSpeed;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempSpeed))
@@ -155,6 +168,14 @@ namespace Subsurface.Items.Components
flowPercentage = MathHelper.Clamp(tempSpeed, -100.0f, 100.0f);
}
}
else if (connection.Name == "set_targetlevel")
{
float tempTarget;
if (float.TryParse(signal, NumberStyles.Float, CultureInfo.InvariantCulture, out tempTarget))
{
targetLevel = MathHelper.Clamp(tempTarget, 0.0f, 100.0f);
}
}
}
@@ -55,7 +55,7 @@ namespace Subsurface.Items.Components
float scale = 0.01f;
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.position, 5);
List<Vector2[]> edges = Level.Loaded.GetCellEdges(-Level.Loaded.Position, 5);
Vector2 offset = Vector2.Zero; //Level.Loaded.position;
//offset.Y = -offset.Y;
@@ -181,10 +181,10 @@ namespace Subsurface.Items.Components
//the power generated by the reactor is equal to the temperature
currPowerConsumption = -temperature*powerPerTemp;
if (item.currentHull != null)
if (item.CurrentHull != null)
{
//the sound can be heard from 20 000 display units away when everything running at 100%
item.currentHull.SoundRange += (coolingRate + fissionRate) * 100;
item.CurrentHull.SoundRange += (coolingRate + fissionRate) * 100;
}
UpdateGraph(deltaTime);
@@ -68,7 +68,7 @@ namespace Subsurface.Items.Components
public override void ReceiveSignal(string signal, Connection connection, Item sender, float power=0.0f)
{
if (connection.name == "velocity_in")
if (connection.Name == "velocity_in")
{
currVelocity = ToolBox.ParseToVector2(signal, false);
}
+2 -2
View File
@@ -23,9 +23,9 @@ namespace Subsurface.Items.Components
{
base.Update(deltaTime, cam);
if (item.currentHull == null) return;
if (item.CurrentHull == null) return;
item.currentHull.Oxygen += oxygenFlow * deltaTime;
item.CurrentHull.Oxygen += oxygenFlow * deltaTime;
OxygenFlow -= deltaTime * 1000.0f;
}
}