This commit is contained in:
Regalis
2015-07-31 21:05:55 +03:00
parent 23d847a4ac
commit 85b0cda4ca
181 changed files with 4455 additions and 4073 deletions
@@ -0,0 +1,343 @@
using System;
using System.Linq;
using FarseerPhysics;
using FarseerPhysics.Dynamics.Joints;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
namespace Subsurface
{
class EditCharacterScreen : Screen
{
Camera cam;
GUIComponent GUIpanel;
GUIButton physicsButton;
GUIListBox limbList, jointList;
GUIFrame limbPanel;
Character editingCharacter;
Limb editingLimb;
//RevoluteJoint editingJoint;
List<Texture2D> textures;
List<string> texturePaths;
private bool physicsEnabled;
public Camera Cam
{
get { return cam; }
}
public override void Select()
{
base.Select();
Game1.DebugDraw = true;
cam = new Camera();
GUIpanel = new GUIFrame(new Rectangle(0, 0, 300, Game1.GraphicsHeight), Color.DarkGray * 0.8f);
GUIpanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
physicsButton = new GUIButton(new Rectangle(0, 50, 200, 25), "Physics", Alignment.Left, GUI.style, GUIpanel);
physicsButton.OnClicked += TogglePhysics;
new GUITextBlock(new Rectangle(0, 80, 0, 25), "Limbs:", Color.Transparent, Color.Black, Alignment.Left, null, GUIpanel);
limbList = new GUIListBox(new Rectangle(0, 110, 0, 250), Color.White * 0.7f, GUI.style, GUIpanel);
limbList.OnSelected = SelectLimb;
new GUITextBlock(new Rectangle(0, 360, 0, 25), "Joints:", Color.Transparent, Color.Black, Alignment.Left, null, GUIpanel);
jointList = new GUIListBox(new Rectangle(0, 390, 0, 250), Color.White * 0.7f, GUI.style, GUIpanel);
while (Character.CharacterList.Count > 1)
{
Character.CharacterList.First().Remove();
}
if (Character.CharacterList.Count == 1)
{
if (editingCharacter != Character.CharacterList[0]) UpdateLimbLists(Character.CharacterList[0]);
editingCharacter = Character.CharacterList[0];
Vector2 camPos = editingCharacter.AnimController.limbs[0].body.Position;
camPos = ConvertUnits.ToDisplayUnits(camPos);
camPos.Y = -camPos.Y;
cam.TargetPos = camPos;
if (physicsEnabled)
{
editingCharacter.Control(1.0f, cam);
}
else
{
cam.TargetPos = Vector2.Zero;
}
}
textures = new List<Texture2D>();
texturePaths = new List<string>();
foreach (Limb limb in editingCharacter.AnimController.limbs)
{
if (texturePaths.Contains(limb.sprite.FilePath)) continue;
textures.Add(limb.sprite.Texture);
texturePaths.Add(limb.sprite.FilePath);
}
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
Physics.accumulator += deltaTime;
//cam.Zoom += Math.Sign(PlayerInput.GetMouseState.ScrollWheelValue - PlayerInput.GetOldMouseState.ScrollWheelValue)*0.1f;
cam.MoveCamera((float)deltaTime);
if (physicsEnabled)
{
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
while (Physics.accumulator >= Physics.step)
{
Character.UpdateAnimAll((float)Physics.step * 1000.0f);
Ragdoll.UpdateAll((float)Physics.step);
Game1.World.Step((float)Physics.step);
Physics.accumulator -= Physics.step;
}
Physics.Alpha = Physics.accumulator / Physics.step;
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//cam.UpdateTransform();
graphics.Clear(Color.CornflowerBlue);
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
Submarine.Draw(spriteBatch, true);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
//if (EntityPrefab.Selected != null) EntityPrefab.Selected.UpdatePlacing(spriteBatch, cam);
//Entity.DrawSelecting(spriteBatch, cam);
if (editingCharacter!=null)
editingCharacter.Draw(spriteBatch);
spriteBatch.End();
//-------------------- HUD -----------------------------
spriteBatch.Begin();
GUIpanel.Draw(spriteBatch);
EditLimb(spriteBatch);
int x = 0, y = 0;
for (int i = 0; i < textures.Count; i++ )
{
x = Game1.GraphicsWidth - textures[i].Width;
spriteBatch.Draw(textures[i], new Vector2(x, y), Color.White);
foreach (Limb limb in editingCharacter.AnimController.limbs)
{
if (limb.sprite.FilePath != texturePaths[i]) continue;
Rectangle rect = limb.sprite.SourceRect;
rect.X += x;
rect.Y += y;
GUI.DrawRectangle(spriteBatch, rect, Color.Red);
Vector2 limbBodyPos = new Vector2(
rect.X + limb.sprite.Origin.X,
rect.Y + limb.sprite.Origin.Y);
DrawJoints(spriteBatch, limb, limbBodyPos);
if (limb.BodyShapeTexture == null) continue;
spriteBatch.Draw(limb.BodyShapeTexture, limbBodyPos,
null, Color.White, 0.0f,
new Vector2(limb.BodyShapeTexture.Width, limb.BodyShapeTexture.Height) / 2,
1.0f, SpriteEffects.None, 0.0f);
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitY * 5.0f, limbBodyPos - Vector2.UnitY * 5.0f, Color.White);
GUI.DrawLine(spriteBatch, limbBodyPos + Vector2.UnitX * 5.0f, limbBodyPos - Vector2.UnitX * 5.0f, Color.White);
if (Vector2.Distance(PlayerInput.MousePosition, limbBodyPos)<5.0f && PlayerInput.LeftButtonDown())
{
limb.sprite.Origin += PlayerInput.MouseSpeed;
}
}
y += textures[i].Height;
}
GUI.Draw((float)deltaTime, spriteBatch, cam);
//EntityPrefab.DrawList(spriteBatch, new Vector2(20,50));
//Entity.Edit(spriteBatch, cam);
spriteBatch.End();
}
private void UpdateLimbLists(Character character)
{
limbList.ClearChildren();
foreach (Limb limb in character.AnimController.limbs)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0,0,0,25),
limb.type.ToString(),
Color.Transparent,
Color.Black,
Alignment.Left, null,
limbList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = limb;
}
jointList.ClearChildren();
foreach (RevoluteJoint joint in character.AnimController.limbJoints)
{
Limb limb1 = (Limb)(joint.BodyA.UserData);
Limb limb2 = (Limb)(joint.BodyB.UserData);
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
limb1.type.ToString() + " - " + limb2.type.ToString(),
Color.Transparent,
Color.Black,
Alignment.Left, null,
jointList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = joint;
}
}
private void DrawJoints(SpriteBatch spriteBatch, Limb limb, Vector2 limbBodyPos)
{
foreach (var joint in editingCharacter.AnimController.limbJoints)
{
Vector2 jointPos = Vector2.Zero;
if (joint.BodyA == limb.body.FarseerBody)
{
jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorA);
}
else if (joint.BodyB == limb.body.FarseerBody)
{
jointPos = ConvertUnits.ToDisplayUnits(joint.LocalAnchorB);
}
else
{
continue;
}
jointPos.Y = -jointPos.Y;
jointPos += limbBodyPos;
if (joint.BodyA == limb.body.FarseerBody)
{
float a1 = joint.UpperLimit - MathHelper.PiOver2;
float a2 = joint.LowerLimit - MathHelper.PiOver2;
float a3 =( a1+a2)/2.0f;
GUI.DrawLine(spriteBatch, jointPos, jointPos + new Vector2((float)Math.Cos(a1), -(float)Math.Sin(a1)) * 30.0f, Color.Green);
GUI.DrawLine(spriteBatch, jointPos, jointPos + new Vector2((float)Math.Cos(a2), -(float)Math.Sin(a2)) * 30.0f, Color.DarkGreen);
GUI.DrawLine(spriteBatch, jointPos, jointPos + new Vector2((float)Math.Cos(a3), -(float)Math.Sin(a3)) * 30.0f, Color.LightGray);
}
GUI.DrawRectangle(spriteBatch, jointPos, new Vector2(5.0f, 5.0f), Color.Red, true);
if (Vector2.Distance(PlayerInput.MousePosition, jointPos) < 6.0f)
{
GUI.DrawRectangle(spriteBatch, jointPos - new Vector2(3.0f, 3.0f), new Vector2(11.0f, 11.0f), Color.Red, false);
if (PlayerInput.LeftButtonDown())
{
Vector2 speed = ConvertUnits.ToSimUnits(PlayerInput.MouseSpeed);
speed.Y = -speed.Y;
if (joint.BodyA == limb.body.FarseerBody)
{
joint.LocalAnchorA += speed;
}
else
{
joint.LocalAnchorB += speed;
}
}
}
}
}
private bool SelectLimb(object selection)
{
try
{
editingLimb = (Limb)selection;
limbPanel = new GUIFrame(new Rectangle(300, 0, 500, 100), Color.Gray*0.8f);
limbPanel.Padding = new Vector4(10.0f,10.0f,10.0f,10.0f);
new GUITextBlock(new Rectangle(0, 0, 200, 25), editingLimb.type.ToString(), Color.Transparent, Color.Black, Alignment.Left, null, limbPanel);
//spriteOrigin = new GUITextBlock(new Rectangle(0, 25, 200, 25), "Sprite origin: ", Color.White, Color.Black, Alignment.Left, limbPanel);
}
catch
{
return false;
}
return true;
}
private void EditLimb(SpriteBatch spriteBatch)
{
if (editingLimb == null) return;
limbPanel.Draw(spriteBatch);
}
private bool TogglePhysics(GUIButton button, object selection)
{
physicsEnabled = !physicsEnabled;
physicsButton.Text = (physicsEnabled) ? "Disable physics" : "Enable physics";
return false;
}
}
}
+302
View File
@@ -0,0 +1,302 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Subsurface
{
class EditMapScreen : Screen
{
Camera cam;
GUIComponent GUIpanel;
GUIComponent[] GUItabs;
int selectedTab;
//a character used for picking up and manipulating items
Character dummyCharacter;
bool characterMode;
public Camera Cam
{
get { return cam; }
}
public EditMapScreen()
{
cam = new Camera();
cam.Translate(new Vector2(-10.0f, 50.0f));
selectedTab = -1;
GUIpanel = new GUIFrame(new Rectangle(0,0, 120, Game1.GraphicsHeight), Color.DarkGray*0.8f);
GUIpanel.Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
//GUIListBox constructionList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUIpanel);
//constructionList.OnSelected = MapEntityPrefab.SelectPrefab;
//constructionList.CheckSelected = MapEntityPrefab.GetSelected;
GUIButton button = new GUIButton(new Rectangle(0, 50, 100, 20), "Items", Alignment.Left, GUI.style, GUIpanel);
button.UserData = 0;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 80, 100, 20), "Structures", Alignment.Left, GUI.style, GUIpanel);
button.UserData = 1;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 140, 100, 20), "Character mode", Alignment.Left, GUI.style, GUIpanel);
button.OnClicked = ToggleCharacterMode;
GUItabs = new GUIComponent[2];
int width = 400, height = 400;
GUItabs[0] = new GUIFrame(new Rectangle(Game1.GraphicsWidth/2-width/2, Game1.GraphicsHeight/2-height/2, width, height), Color.DarkGray*0.8f);
GUItabs[0].Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
GUIListBox itemList = new GUIListBox(new Rectangle(0, 0, 0, 0), Color.White * 0.7f, GUI.style, GUItabs[0]);
itemList.OnSelected = SelectPrefab;
itemList.CheckSelected = MapEntityPrefab.GetSelected;
GUItabs[1] = new GUIFrame(new Rectangle(Game1.GraphicsWidth / 2 - width / 2, Game1.GraphicsHeight / 2 - height / 2, width, height), Color.DarkGray * 0.8f);
GUItabs[1].Padding = new Vector4(10.0f, 10.0f, 10.0f, 10.0f);
GUIListBox structureList = new GUIListBox(new Rectangle(0, 0, 0, 300), Color.White * 0.7f, GUI.style, GUItabs[1]);
structureList.OnSelected = SelectPrefab;
structureList.CheckSelected = MapEntityPrefab.GetSelected;
foreach (MapEntityPrefab ep in MapEntityPrefab.list)
{
GUIListBox parent = ((ep as ItemPrefab) == null) ? structureList : itemList;
Color color = ((parent.CountChildren % 2) == 0) ? Color.White : Color.LightGray;
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, null, parent);
frame.UserData = ep;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.Color = color;
frame.HoverColor = Color.Gold * 0.2f;
frame.SelectedColor = Color.Gold * 0.5f;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
ep.Name,
Color.Transparent, Color.Black,
Alignment.Left, Alignment.Left,
null, frame);
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
if (ep.sprite != null)
{
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.Left, frame);
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
}
}
}
public override void Select()
{
base.Select();
GUIComponent.MouseOn = null;
characterMode = false;
//CreateDummyCharacter();
}
public override void Deselect()
{
base.Deselect();
GUIComponent.MouseOn = null;
if (dummyCharacter != null)
{
dummyCharacter.Remove();
dummyCharacter = null;
Game1.World.ProcessChanges();
}
}
private void CreateDummyCharacter()
{
if (dummyCharacter != null) dummyCharacter.Remove();
dummyCharacter = new Character(Character.HumanConfigFile, Vector2.Zero);
Character.Controlled = dummyCharacter;
Game1.World.ProcessChanges();
}
private bool SelectTab(GUIButton button, object obj)
{
selectedTab = (int)obj;
return true;
}
private bool ToggleCharacterMode(GUIButton button, object obj)
{
characterMode = !characterMode;
button.Color = (characterMode) ? Color.Gold : Color.White;
if (characterMode)
{
CreateDummyCharacter();
}
else if (dummyCharacter != null)
{
dummyCharacter.Remove();
dummyCharacter = null;
}
foreach (MapEntity me in MapEntity.mapEntityList)
{
me.IsHighlighted = false;
me.IsSelected = false;
}
return true;
}
private bool SelectPrefab(object obj)
{
MapEntityPrefab.SelectPrefab(obj);
selectedTab = -1;
GUIComponent.MouseOn = null;
return true;
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
//Vector2 mousePosition = new Vector2(PlayerInput.GetMouseState.X, PlayerInput.GetMouseState.Y);
//mousePosition = cam.ScreenToWorld(mousePosition);
//if (!Character.characterList.Contains(dummyCharacter))
//{
// CreateDummyCharacter();
//}
cam.MoveCamera((float)deltaTime);
cam.Zoom = MathHelper.Clamp(cam.Zoom + PlayerInput.ScrollWheelSpeed/1000.0f,0.1f, 2.0f);
if (characterMode)
{
foreach (MapEntity me in MapEntity.mapEntityList)
{
me.IsHighlighted = false;
}
if (dummyCharacter.SelectedConstruction==null)
{
Vector2 mouseSimPos = FarseerPhysics.ConvertUnits.ToSimUnits(cam.ScreenToWorld(PlayerInput.MousePosition));
foreach (Limb limb in dummyCharacter.AnimController.limbs)
{
limb.body.SetTransform(mouseSimPos, 0.0f);
}
}
dummyCharacter.ControlLocalPlayer(cam, false);
dummyCharacter.Control((float)deltaTime, cam);
}
else
{
MapEntity.UpdateSelecting(cam);
}
GUIpanel.Update((float)deltaTime);
if (selectedTab > -1)
{
GUItabs[selectedTab].Update((float)deltaTime);
if (PlayerInput.RightButtonClicked()) selectedTab = -1;
}
}
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//cam.UpdateTransform();
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
graphics.Clear(new Color(0.051f, 0.149f, 0.271f, 1.0f));
Submarine.Draw(spriteBatch, true);
if (!characterMode)
{
if (MapEntityPrefab.Selected != null) MapEntityPrefab.Selected.UpdatePlacing(spriteBatch, cam);
MapEntity.DrawSelecting(spriteBatch, cam);
}
spriteBatch.End();
//-------------------- HUD -----------------------------
spriteBatch.Begin();
GUIpanel.Draw(spriteBatch);
if (selectedTab > -1) GUItabs[selectedTab].Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch, cam);
//EntityPrefab.DrawList(spriteBatch, new Vector2(20,50));
if (characterMode)
{
if (dummyCharacter != null)
{
foreach (Item item in dummyCharacter.SelectedItems)
{
if (item == null) continue;
item.SetTransform(dummyCharacter.SimPosition, 0.0f);
item.Update(cam, (float)deltaTime);
}
if (dummyCharacter.SelectedConstruction != null)
{
if (dummyCharacter.SelectedConstruction == dummyCharacter.ClosestItem)
{
dummyCharacter.SelectedConstruction.DrawHUD(spriteBatch, dummyCharacter);
}
else
{
dummyCharacter.SelectedConstruction = null;
}
}
}
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed)
{
//if (Inventory.draggingItem!=null)
//{
// Inventory.draggingItem.see
//}
Inventory.draggingItem = null;
}
}
else
{
MapEntity.Edit(spriteBatch, cam);
}
spriteBatch.End();
}
}
}
+283
View File
@@ -0,0 +1,283 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Subsurface.Lights;
namespace Subsurface
{
class GameScreen : Screen
{
Camera cam;
readonly RenderTarget2D renderTarget;
readonly RenderTarget2D renderTargetWater;
readonly RenderTarget2D renderTargetAir;
readonly Sprite background, backgroundTop;
public Camera Cam
{
get { return cam; }
}
public GameScreen(GraphicsDevice graphics)
{
cam = new Camera();
cam.Translate(new Vector2(-10.0f, 50.0f));
renderTarget = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight);
renderTargetWater = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight);
renderTargetAir = new RenderTarget2D(graphics, Game1.GraphicsWidth, Game1.GraphicsHeight);
background = new Sprite("Content/Map/background.png", Vector2.Zero);
backgroundTop = new Sprite("Content/Map/background2.png", Vector2.Zero);
}
public override void Select()
{
base.Select();
foreach (MapEntity entity in MapEntity.mapEntityList)
entity.IsHighlighted = false;
}
/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
public override void Update(double deltaTime)
{
//the accumulator code is based on this article:
//http://gafferongames.com/game-physics/fix-your-timestep/
Physics.accumulator += deltaTime;
AmbientSoundManager.Update();
//if (Game1.GameSession != null && Game1.GameSession.Level != null)
//{
// Vector2 targetMovement = Vector2.Zero;
// if (PlayerInput.KeyDown(Keys.I)) targetMovement.Y += 1.0f;
// if (PlayerInput.KeyDown(Keys.K)) targetMovement.Y -= 1.0f;
// if (PlayerInput.KeyDown(Keys.J)) targetMovement.X -= 1.0f;
// if (PlayerInput.KeyDown(Keys.L)) targetMovement.X += 1.0f;
// Game1.GameSession.Submarine.ApplyForce(targetMovement * 100000.0f);
//}
if (Game1.GameSession!=null) Game1.GameSession.Update((float)deltaTime);
//EventManager.Update(gameTime);
Character.UpdateAll(cam, (float)deltaTime);
Game1.ParticleManager.Update((float)deltaTime);
StatusEffect.UpdateAll((float)deltaTime);
cam.MoveCamera((float)deltaTime);
Physics.accumulator = Math.Min(Physics.accumulator, Physics.step * 4);
while (Physics.accumulator >= Physics.step)
{
foreach (PhysicsBody pb in PhysicsBody.list)
{
pb.SetPrevTransform(pb.Position, pb.Rotation);
}
MapEntity.UpdateAll(cam, (float)Physics.step);
Character.UpdateAnimAll((float)Physics.step);
Ragdoll.UpdateAll((float)Physics.step);
if (Game1.GameSession != null && Game1.GameSession.Level != null) Game1.GameSession.Submarine.Update((float)Physics.step);
Game1.World.Step((float)Physics.step);
Level.AfterWorldStep();
Physics.accumulator -= Physics.step;
}
Physics.Alpha = Physics.accumulator / Physics.step;
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//if (!Physics.updated) return;
DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
if (Game1.GameSession != null) Game1.GameSession.Draw(spriteBatch);
if (Character.Controlled != null && Character.Controlled.SelectedConstruction != null)
{
if (Character.Controlled.SelectedConstruction == Character.Controlled.ClosestItem)
{
Character.Controlled.SelectedConstruction.DrawHUD(spriteBatch, Character.Controlled);
}
else
{
Character.Controlled.SelectedConstruction = null;
}
}
GUI.Draw((float)deltaTime, spriteBatch, cam);
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) Inventory.draggingItem = null;
spriteBatch.End();
}
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
Game1.LightManager.DrawLightmap(graphics, spriteBatch, cam);
//----------------------------------------------------------------------------------------
//1. draw the background, characters and the parts of the submarine that are behind them
//----------------------------------------------------------------------------------------
graphics.SetRenderTarget(renderTarget);
graphics.Clear(new Color(11, 18, 26, 255));
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap);
Vector2 backgroundPos = cam.Position;
if (Level.Loaded != null) backgroundPos -= Level.Loaded.Position;
backgroundPos.Y = -backgroundPos.Y;
backgroundPos /= 20.0f;
if (backgroundPos.Y < 1024)
{
if (backgroundPos.Y > -1024)
{
background.SourceRect = new Rectangle((int)backgroundPos.X, (int)Math.Max(backgroundPos.Y, 0), 1024, 1024);
background.DrawTiled(spriteBatch,
(backgroundPos.Y < 0) ? new Vector2(0.0f, -backgroundPos.Y) : Vector2.Zero,
new Vector2(Game1.GraphicsWidth, 1024 - backgroundPos.Y),
Vector2.Zero, Color.White);
}
if (backgroundPos.Y < 0)
{
backgroundTop.SourceRect = new Rectangle((int)backgroundPos.X, (int)backgroundPos.Y, 1024, (int)Math.Min(-backgroundPos.Y, 1024));
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(-backgroundPos.Y, Game1.GraphicsHeight)),
Vector2.Zero, Color.White);
}
}
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
Submarine.DrawBack(spriteBatch);
foreach (Character c in Character.CharacterList) c.Draw(spriteBatch);
spriteBatch.End();
//----------------------------------------------------------------------------------------
//draw the rendertarget and particles that are only supposed to be drawn in water into renderTargetWater
graphics.SetRenderTarget(renderTargetWater);
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, Game1.GraphicsWidth, Game1.GraphicsHeight), Color.White);
spriteBatch.End();
BlendState blend = new BlendState();
blend.AlphaSourceBlend = Blend.One;
blend.AlphaDestinationBlend = Blend.InverseSourceAlpha;
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend,
null, DepthStencilState.DepthRead, null, null,
cam.Transform);
Game1.ParticleManager.Draw(spriteBatch, true);
spriteBatch.End();
//----------------------------------------------------------------------------------------
//draw the rendertarget and particles that are only supposed to be drawn in air into renderTargetAir
graphics.SetRenderTarget(renderTargetAir);
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend);
spriteBatch.Draw(renderTarget, new Rectangle(0, 0, Game1.GraphicsWidth, Game1.GraphicsHeight), Color.White);
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate,
BlendState.AlphaBlend,
null, DepthStencilState.DepthRead, null, null,
cam.Transform);
Game1.ParticleManager.Draw(spriteBatch, false);
spriteBatch.End();
graphics.SetRenderTarget(null);
//----------------------------------------------------------------------------------------
//2. pass the renderTarget to the water shader to do the water effect
//----------------------------------------------------------------------------------------
Hull.renderer.RenderBack(graphics, renderTargetWater, Cam.ShaderTransform);
Array.Clear(Hull.renderer.vertices, 0, Hull.renderer.vertices.Length);
Hull.renderer.positionInBuffer = 0;
foreach (Hull hull in Hull.hullList)
{
hull.Render(graphics, cam);
}
Hull.renderer.Render(graphics, cam, renderTargetAir, Cam.ShaderTransform);
if (Game1.GameSession != null && Game1.GameSession.Level != null)
{
Game1.GameSession.Level.Render(graphics, cam);
Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
}
if (Game1.LightManager.LightingEnabled)
{
//multiply scene with lightmap
spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.Multiplicative);
spriteBatch.Draw(Game1.LightManager.LightMap, Vector2.Zero, Color.White);
spriteBatch.End();
}
//----------------------------------------------------------------------------------------
//3. draw the sections of the map that are on top of the water
//----------------------------------------------------------------------------------------
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend, SamplerState.LinearWrap,
null, null, null,
cam.Transform);
Submarine.DrawFront(spriteBatch);
foreach (Character c in Character.CharacterList) c.DrawFront(spriteBatch);
if (Game1.GameSession != null && Game1.GameSession.Level != null)
{
Game1.GameSession.Level.Draw(spriteBatch);
//Game1.GameSession.Level.SetObserverPosition(cam.WorldViewCenter);
}
spriteBatch.End();
Game1.LightManager.DrawLOS(graphics, cam, LightManager.ViewPos);
}
}
}
+443
View File
@@ -0,0 +1,443 @@
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Factories;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Subsurface
{
class LobbyScreen : Screen
{
enum PanelTab { Crew = 0, Map = 1, CurrentLocation = 2, Store = 3 }
GUIFrame leftPanel;
GUIFrame[] rightPanel;
GUIButton startButton;
int selectedRightPanel;
GUIListBox characterList;
GUIListBox hireList;
GUIListBox selectedItemList, itemList;
SinglePlayerMode gameMode;
GUIFrame previewFrame;
GUIButton buyButton;
Level selectedLevel;
float mapZoom = 3.0f;
private string CostTextGetter()
{
return "Cost: "+selectedItemCost.ToString();
}
private int selectedItemCost
{
get
{
int cost = 0;
foreach (GUIComponent child in selectedItemList.children)
{
MapEntityPrefab ep = child.UserData as MapEntityPrefab;
if (ep == null) continue;
cost += ep.Price;
}
return cost;
}
}
public LobbyScreen()
{
Rectangle panelRect = new Rectangle(
40, 40,
180,
Game1.GraphicsHeight - 80);
leftPanel = new GUIFrame(panelRect, GUI.style);
//leftPanel.Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25),
"asdfdasfasdf", Color.Transparent, Color.White, Alignment.Left, GUI.style, leftPanel);
GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 30, 200, 25),
"", Color.Transparent, Color.White, Alignment.Left, GUI.style, leftPanel);
moneyText.TextGetter = GetMoney;
GUIButton button = new GUIButton(new Rectangle(0, 70, 100, 30), "Map", null, Alignment.Left, GUI.style, leftPanel);
button.UserData = PanelTab.Map;
button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 110, 100, 30), "Crew", null, Alignment.Left, GUI.style, leftPanel);
button.UserData = PanelTab.Crew;
button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 150, 100, 30), "Hire", null, Alignment.Left, GUI.style, leftPanel);
button.UserData = PanelTab.CurrentLocation;
button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 190, 100, 30), "Store", null, Alignment.Left, GUI.style, leftPanel);
button.UserData = PanelTab.Store;
button.OnClicked = SelectRightPanel;
//---------------------------------------------------------------
//---------------------------------------------------------------
panelRect = new Rectangle(
panelRect.X + panelRect.Width + 40,
40,
Game1.GraphicsWidth - panelRect.Width - 120,
Game1.GraphicsHeight - 80);
rightPanel = new GUIFrame[4];
rightPanel[(int)PanelTab.Crew] = new GUIFrame(panelRect, GUI.style);
//rightPanel[(int)PanelTab.Crew].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, GUI.style, rightPanel[(int)PanelTab.Crew]);
characterList = new GUIListBox(new Rectangle(0, 30, 300, 0), GUI.style, rightPanel[(int)PanelTab.Crew]);
characterList.OnSelected = SelectCharacter;
//---------------------------------------
rightPanel[(int)PanelTab.Map] = new GUIFrame(panelRect, GUI.style);
//rightPanel[(int)PanelTab.Map].Padding = GUI.style.smallPadding;
startButton = new GUIButton(new Rectangle(0, 0, 100, 30), "Start",
Alignment.BottomRight, GUI.style, rightPanel[(int)PanelTab.Map]);
startButton.OnClicked = StartShift;
startButton.Enabled = false;
//---------------------------------------
rightPanel[(int)PanelTab.CurrentLocation] = new GUIFrame(panelRect, GUI.style);
//---------------------------------------
rightPanel[(int)PanelTab.Store] = new GUIFrame(panelRect, GUI.style);
selectedItemList = new GUIListBox(new Rectangle(0, 0, 300, 400), Color.White * 0.7f, GUI.style, rightPanel[(int)PanelTab.Store]);
selectedItemList.OnSelected = DeselectItem;
var costText = new GUITextBlock(new Rectangle(0, 0, 200, 25), "Cost: ", GUI.style, Alignment.BottomLeft, Alignment.TopLeft, rightPanel[(int)PanelTab.Store]);
costText.TextGetter = CostTextGetter;
buyButton = new GUIButton(new Rectangle(150, 0, 100, 25), "Buy", Alignment.Bottom, GUI.style, rightPanel[(int)PanelTab.Store]);
buyButton.OnClicked = BuyItems;
itemList = new GUIListBox(new Rectangle(0, 0, 300, 400), Color.White * 0.7f, Alignment.TopRight, GUI.style, rightPanel[(int)PanelTab.Store]);
itemList.OnSelected = SelectItem;
foreach (MapEntityPrefab ep in MapEntityPrefab.list)
{
if (ep.Price == 0) continue;
CreateItemFrame(ep, itemList);
}
}
public override void Select()
{
base.Select();
gameMode = Game1.GameSession.gameMode as SinglePlayerMode;
selectedRightPanel = (int)PanelTab.Crew;
//Map.Unload();
UpdateCharacterLists();
}
private void UpdateLocationTab(Location location)
{
rightPanel[(int)PanelTab.CurrentLocation] = new GUIFrame(rightPanel[(int)PanelTab.CurrentLocation].Rect, GUI.style);
rightPanel[(int)PanelTab.CurrentLocation].UserData = location;
//rightPanel[(int)PanelTab.Hire].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25),
"Location: "+location.Name, GUI.style, rightPanel[(int)PanelTab.CurrentLocation]);
new GUITextBlock(new Rectangle(0, 20, 200, 25),
"("+location.Type.Name+")", GUI.style, rightPanel[(int)PanelTab.CurrentLocation]);
if (location.HireManager != null)
{
hireList = new GUIListBox(new Rectangle(0, 60, 300, 0), GUI.style, Alignment.Left, rightPanel[(int)PanelTab.CurrentLocation]);
hireList.OnSelected = SelectCharacter;
hireList.ClearChildren();
foreach (CharacterInfo c in location.HireManager.availableCharacters)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.Name + " (" + c.Job.Name + ")", GUI.style, hireList);
textBlock.UserData = c;
textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.Salary.ToString(),
null, null,
Alignment.TopRight, GUI.style, textBlock);
}
}
}
public override void Deselect()
{
SelectLocation(null,null);
base.Deselect();
}
public void SelectLocation(Location location, LocationConnection connection)
{
GUIComponent locationPanel = rightPanel[(int)PanelTab.Map].GetChild("selectedlocation");
if (locationPanel != null) rightPanel[(int)PanelTab.Map].RemoveChild(locationPanel);
locationPanel = new GUIFrame(new Rectangle(0, 0, 200, 190), Color.Transparent, Alignment.TopRight, null, rightPanel[(int)PanelTab.Map]);
locationPanel.UserData = "selectedlocation";
if (location == null) return;
new GUITextBlock(new Rectangle(0,0,0,0), location.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel);
if (Game1.GameSession.Map.SelectedConnection != null && Game1.GameSession.Map.SelectedConnection.Quest != null)
{
var quest = Game1.GameSession.Map.SelectedConnection.Quest;
new GUITextBlock(new Rectangle(0, 40, 0, 20), "Quest: "+quest.Name, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel);
new GUITextBlock(new Rectangle(0, 60, 0, 20), "Reward: " + quest.Reward, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel);
new GUITextBlock(new Rectangle(0, 80, 0, 0), quest.Description, Color.Transparent, Color.White, Alignment.TopLeft, null, locationPanel, true);
}
startButton.Enabled = true;
selectedLevel = connection.Level;
}
private void UpdateCharacterLists()
{
characterList.ClearChildren();
foreach (CharacterInfo c in gameMode.crewManager.characterInfos)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.Name + " (" + c.Job.Name + ")", GUI.style,
Alignment.Left,
Alignment.Left,
characterList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = c;
}
}
private void CreateItemFrame(MapEntityPrefab ep, GUIListBox listBox)
{
Color color = ((listBox.CountChildren % 2) == 0) ? Color.Transparent : Color.White * 0.1f;
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 50), Color.Transparent, null, listBox);
frame.UserData = ep;
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
frame.Color = color;
frame.HoverColor = Color.Gold * 0.2f;
frame.SelectedColor = Color.Gold * 0.5f;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(40, 0, 0, 25),
ep.Name,
Color.Transparent, Color.White,
Alignment.Left, Alignment.Left,
null, frame);
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
ep.Price.ToString(),
null, null,
Alignment.TopRight, GUI.style, textBlock);
if (ep.sprite != null)
{
GUIImage img = new GUIImage(new Rectangle(0, 0, 40, 40), ep.sprite, Alignment.Left, frame);
img.Scale = Math.Min(Math.Min(40.0f / img.SourceRect.Width, 40.0f / img.SourceRect.Height), 1.0f);
}
}
private bool SelectItem(object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
CreateItemFrame(prefab, selectedItemList);
buyButton.Enabled = gameMode.crewManager.Money >= selectedItemCost;
return false;
}
private bool DeselectItem(object obj)
{
MapEntityPrefab prefab = obj as MapEntityPrefab;
if (prefab == null) return false;
selectedItemList.RemoveChild(selectedItemList.children.Find(c => c.UserData == obj));
return false;
}
private bool BuyItems(GUIButton button, object obj)
{
int cost = selectedItemCost;
if (gameMode.crewManager.Money < cost) return false;
gameMode.crewManager.Money -= cost;
for (int i = selectedItemList.children.Count-1; i>=0; i--)
{
GUIComponent child = selectedItemList.children[i];
MapEntityPrefab ep = child.UserData as MapEntityPrefab;
if (ep == null) continue;
gameMode.CargoManager.AddItem(ep);
selectedItemList.RemoveChild(child);
}
return false;
}
public override void Update(double deltaTime)
{
base.Update(deltaTime);
leftPanel.Update((float)deltaTime);
rightPanel[selectedRightPanel].Update((float)deltaTime);
mapZoom += PlayerInput.ScrollWheelSpeed / 1000.0f;
mapZoom = MathHelper.Clamp(mapZoom, 1.0f, 4.0f);
//shiftPanel.Update((float)deltaTime);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
if (characterList.CountChildren != gameMode.crewManager.characterInfos.Count)
{
UpdateCharacterLists();
}
graphics.Clear(Color.CornflowerBlue);
Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
leftPanel.Draw(spriteBatch);
rightPanel[selectedRightPanel].Draw(spriteBatch);
if (selectedRightPanel == (int)PanelTab.Map)
{
Game1.GameSession.Map.Draw(spriteBatch, new Rectangle(
rightPanel[selectedRightPanel].Rect.X + 20,
rightPanel[selectedRightPanel].Rect.Y + 20,
rightPanel[selectedRightPanel].Rect.Width - 280,
rightPanel[selectedRightPanel].Rect.Height - 40), mapZoom);
}
if (rightPanel[(int)selectedRightPanel].UserData as Location != Game1.GameSession.Map.CurrentLocation)
{
UpdateLocationTab(Game1.GameSession.Map.CurrentLocation);
}
GUI.Draw((float)deltaTime, spriteBatch, null);
spriteBatch.End();
}
public bool SelectRightPanel(GUIButton button, object selection)
{
try { selectedRightPanel = (int)selection; }
catch { return false; }
return true;
}
private string GetMoney()
{
return "Money: " + ((Game1.GameSession == null) ? "" : gameMode.crewManager.Money.ToString());
}
private bool SelectCharacter(object selection)
{
CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
if (Character.Controlled != null && characterInfo == Character.Controlled.Info) return false;
if (previewFrame == null || previewFrame.UserData != characterInfo)
{
previewFrame = new GUIFrame(new Rectangle(350, 60, 300, 300),
new Color(0.0f, 0.0f, 0.0f, 0.8f),
Alignment.Top, GUI.style, rightPanel[selectedRightPanel]);
previewFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
previewFrame.UserData = characterInfo;
characterInfo.CreateInfoFrame(previewFrame);
}
if (selectedRightPanel == (int)PanelTab.CurrentLocation)
{
GUIButton hireButton = new GUIButton(new Rectangle(0,0, 100, 20), "Hire", Alignment.BottomCenter, GUI.style, previewFrame);
hireButton.UserData = characterInfo;
hireButton.OnClicked = HireCharacter;
}
return false;
}
private bool HireCharacter(GUIButton button, object selection)
{
CharacterInfo characterInfo = selection as CharacterInfo;
if (characterInfo == null) return false;
if (gameMode.TryHireCharacter(Game1.GameSession.Map.CurrentLocation.HireManager, characterInfo))
{
UpdateLocationTab(Game1.GameSession.Map.CurrentLocation);
}
return false;
}
private bool StartShift(GUIButton button, object selection)
{
Game1.GameSession.StartShift(TimeSpan.Zero, selectedLevel);
Game1.GameScreen.Select();
return true;
}
public bool QuitToMainMenu(GUIButton button, object selection)
{
Game1.MainMenuScreen.Select();
return true;
}
}
}
+432
View File
@@ -0,0 +1,432 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
using System.IO;
using System.Xml.Linq;
namespace Subsurface
{
class MainMenuScreen : Screen
{
public enum Tabs { Main = 0, NewGame = 1, LoadGame = 2, JoinServer = 3, HostServer = 4 }
private GUIFrame[] menuTabs;
private GUIListBox mapList;
private GUIListBox saveList;
private GUITextBox saveNameBox, seedBox;
private GUITextBox clientNameBox, ipBox;
private GUITextBox serverNameBox, portBox;
private Game1 game;
int selectedTab;
public MainMenuScreen(Game1 game)
{
menuTabs = new GUIFrame[Enum.GetValues(typeof(Tabs)).Length];
Rectangle panelRect = new Rectangle(
Game1.GraphicsWidth / 2 - 250,
Game1.GraphicsHeight/ 2 - 250,
500, 500);
menuTabs[(int)Tabs.Main] = new GUIFrame(panelRect, GUI.style);
//menuTabs[(int)Tabs.Main].Padding = GUI.style.smallPadding;
GUIButton button = new GUIButton(new Rectangle(0, 0, 0, 30), "New Game", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
button.UserData = (int)Tabs.NewGame;
button.OnClicked = SelectTab;
//button.Enabled = false;
button = new GUIButton(new Rectangle(0, 60, 0, 30), "Load Game", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
button.UserData = (int)Tabs.LoadGame;
button.OnClicked = SelectTab;
//button.Enabled = false;
button = new GUIButton(new Rectangle(0, 120, 0, 30), "Join Server", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
button.UserData = (int)Tabs.JoinServer;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 180, 0, 30), "Host Server", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
button.UserData = (int)Tabs.HostServer;
button.OnClicked = SelectTab;
//button.Enabled = false;
button = new GUIButton(new Rectangle(0, 240, 0, 30), "Quit", Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.Main]);
button.OnClicked = QuitClicked;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.NewGame] = new GUIFrame(panelRect, GUI.style);
//menuTabs[(int)Tabs.NewGame].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, -20, 0, 30), "New Game", null, null, Alignment.CenterX, GUI.style, menuTabs[(int)Tabs.NewGame]);
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected submarine:", null, null, Alignment.Left, GUI.style, menuTabs[(int)Tabs.NewGame]);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 360), GUI.style, menuTabs[(int)Tabs.NewGame]);
foreach (Submarine sub in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
sub.Name,
GUI.style,
Alignment.Left, Alignment.Left, mapList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = sub;
}
if (Submarine.SavedSubmarines.Count > 0) mapList.Select(Submarine.SavedSubmarines[0]);
new GUITextBlock(new Rectangle((int)(mapList.Rect.Width + 20), 30, 100, 20),
"Save name: ", GUI.style, Alignment.Left, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
saveNameBox = new GUITextBox(new Rectangle((int)(mapList.Rect.Width + 20), 60, 180, 20),
Alignment.TopLeft, GUI.style, menuTabs[(int)Tabs.NewGame]);
saveNameBox.Text = SaveUtil.CreateSavePath();
new GUITextBlock(new Rectangle((int)(mapList.Rect.Width + 20), 90, 100, 20),
"Map Seed: ", GUI.style, Alignment.Left, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
seedBox = new GUITextBox(new Rectangle((int)(mapList.Rect.Width + 20), 120, 180, 20),
Alignment.TopLeft, GUI.style, menuTabs[(int)Tabs.NewGame]);
seedBox.Text = ToolBox.RandomSeed(8);
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.BottomRight, GUI.style, menuTabs[(int)Tabs.NewGame]);
button.OnClicked = StartGame;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.LoadGame] = new GUIFrame(panelRect, GUI.style);
//menuTabs[(int)Tabs.LoadGame].Padding = GUI.style.smallPadding;
//new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.LoadGame]);
////if (!Directory.Exists(SaveUtil.SaveFolder))
////{
//// DebugConsole.ThrowError("Save folder ''"+SaveUtil.SaveFolder+" not found! Attempting to create a new folder");
//// try
//// {
//// Directory.CreateDirectory(SaveUtil.SaveFolder);
//// }
//// catch (Exception e)
//// {
//// DebugConsole.ThrowError("Failed to create the folder ''"+SaveUtil.SaveFolder+"''!", e);
//// }
////}
//string[] saveFiles = SaveUtil.GetSaveFiles();//Directory.GetFiles(SaveUtil.SaveFolder, "*.save");
////new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
//saveList = new GUIListBox(new Rectangle(0, 60, 200, 360), Color.White, GUI.style, menuTabs[(int)Tabs.LoadGame]);
//foreach (string saveFile in saveFiles)
//{
// GUITextBlock textBlock = new GUITextBlock(
// new Rectangle(0, 0, 0, 25),
// saveFile,
// GUI.style,
// Alignment.Left,
// Alignment.Left,
// saveList);
// textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
// textBlock.UserData = saveFile;
//}
//button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start",Alignment.Right | Alignment.Bottom, GUI.style, menuTabs[(int)Tabs.LoadGame]);
//button.OnClicked = LoadGame;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.JoinServer] = new GUIFrame(panelRect, GUI.style);
//menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Join Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
clientNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.JoinServer]);
GUIButton joinButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Join", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.JoinServer]);
joinButton.OnClicked = JoinServer;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.HostServer] = new GUIFrame(panelRect, GUI.style);
//menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Host Server", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Name:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
serverNameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.HostServer]);
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server port:", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.HostServer]);
portBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, null, menuTabs[(int)Tabs.HostServer]);
portBox.Text = NetworkMember.DefaultPort.ToString();
portBox.ToolTip = "Server port";
GUIButton hostButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.BottomCenter, GUI.style, menuTabs[(int)Tabs.HostServer]);
hostButton.OnClicked = HostServerClicked;
//----------------------------------------------------------------------
for (int i = 1; i < 5; i++ )
{
button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menuTabs[i]);
button.OnClicked = PreviousTab;
}
this.game = game;
}
public bool SelectTab(GUIButton button, object obj)
{
selectedTab = (int)obj;
if (selectedTab == (int)Tabs.LoadGame) UpdateLoadScreen();
this.Select();
return true;
}
private bool HostServerClicked(GUIButton button, object obj)
{
string name = serverNameBox.Text;
if (string.IsNullOrEmpty(name)) name = "Server";
int port;
if (!int.TryParse(portBox.Text, out port))
{
DebugConsole.ThrowError("ERROR: " + portBox.Text + " is not a valid port. Using the default port " + NetworkMember.DefaultPort);
port = NetworkMember.DefaultPort;
}
Game1.NetworkMember = new GameServer(name, port);
Game1.NetLobbyScreen.IsServer = true;
Game1.NetLobbyScreen.Select();
return true;
}
private bool QuitClicked(GUIButton button, object obj)
{
game.Exit();
return true;
}
private void UpdateLoadScreen()
{
menuTabs[(int)Tabs.LoadGame].ClearChildren();
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Load Game", GUI.style, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.LoadGame]);
string[] saveFiles = SaveUtil.GetSaveFiles();
saveList = new GUIListBox(new Rectangle(0, 60, 200, 360), Color.White, GUI.style, menuTabs[(int)Tabs.LoadGame]);
saveList.OnSelected = SelectSaveFile;
foreach (string saveFile in saveFiles)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
saveFile,
GUI.style,
Alignment.Left,
Alignment.Left,
saveList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = saveFile;
}
var button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", Alignment.Right | Alignment.Bottom, GUI.style, menuTabs[(int)Tabs.LoadGame]);
button.OnClicked = LoadGame;
button = new GUIButton(new Rectangle(-20, -20, 100, 30), "Back", Alignment.TopLeft, GUI.style, menuTabs[(int)Tabs.LoadGame]);
button.OnClicked = PreviousTab;
}
private bool SelectSaveFile(object obj)
{
string fileName = (string)obj;
XDocument doc = SaveUtil.LoadGameSessionDoc(fileName);
if (doc==null)
{
DebugConsole.ThrowError("Error loading save file ''"+fileName+"''. The file may be corrupted.");
return false;
}
RemoveSaveFrame();
string saveTime = ToolBox.GetAttributeString(doc.Root, "savetime", "unknown");
XElement modeElement = null;
foreach (XElement element in doc.Root.Elements())
{
if (element.Name.ToString().ToLower() != "gamemode") continue;
modeElement = element;
break;
}
string mapseed = ToolBox.GetAttributeString(modeElement, "mapseed", "unknown");
GUIFrame saveFileFrame = new GUIFrame(new Rectangle((int)(saveList.Rect.Width + 20), 60, 200, 200), Color.Black*0.4f, GUI.style, menuTabs[(int)Tabs.LoadGame]);
saveFileFrame.UserData = "savefileframe";
saveFileFrame.Padding = new Vector4(20.0f, 20.0f, 20.0f, 20.0f);
new GUITextBlock(new Rectangle(0,0,0,20), fileName, GUI.style, saveFileFrame);
new GUITextBlock(new Rectangle(0, 30, 0, 20), "Last saved: ", GUI.style, saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 45, 0, 20), saveTime, GUI.style, saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(0, 65, 0, 20), "Map seed: ", GUI.style, saveFileFrame).Font = GUI.SmallFont;
new GUITextBlock(new Rectangle(15, 80, 0, 20), mapseed, GUI.style, saveFileFrame).Font = GUI.SmallFont;
var deleteSaveButton = new GUIButton(new Rectangle(0, 0, 100, 20), "Delete", Alignment.BottomCenter, GUI.style, saveFileFrame);
deleteSaveButton.UserData = fileName;
deleteSaveButton.OnClicked = DeleteSave;
return true;
}
private bool DeleteSave(GUIButton button, object obj)
{
string saveFile = obj as string;
if (obj == null) return false;
SaveUtil.DeleteSave(saveFile);
UpdateLoadScreen();
return true;
}
private void RemoveSaveFrame()
{
GUIComponent prevFrame = null;
foreach (GUIComponent child in menuTabs[(int)Tabs.LoadGame].children)
{
if (child.UserData as string != "savefileframe") continue;
prevFrame = child;
break;
}
menuTabs[(int)Tabs.LoadGame].RemoveChild(prevFrame);
}
public override void Update(double deltaTime)
{
menuTabs[selectedTab].Update((float)deltaTime);
Game1.TitleScreen.Position.Y = MathHelper.Lerp(Game1.TitleScreen.Position.Y, -870.0f, 0.1f);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
graphics.Clear(Color.CornflowerBlue);
Game1.TitleScreen.Draw(spriteBatch, graphics, -1.0f, (float)deltaTime);
//Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
menuTabs[selectedTab].Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch, null);
spriteBatch.DrawString(GUI.Font, "Subsurface v"+Game1.Version, new Vector2(10, Game1.GraphicsHeight-20), Color.White);
spriteBatch.End();
}
private bool StartGame(GUIButton button, object obj)
{
if (string.IsNullOrEmpty(saveNameBox.Text)) return false;
string[] existingSaveFiles = SaveUtil.GetSaveFiles();
if (Array.Find(existingSaveFiles, s => s == saveNameBox.Text)!=null)
{
new GUIMessageBox("Save name already in use", "Please choose another name for the save file");
return false;
}
Submarine selectedSub = mapList.SelectedData as Submarine;
if (selectedSub == null) return false;
Game1.GameSession = new GameSession(selectedSub, saveNameBox.Text, GameModePreset.list.Find(gm => gm.Name == "Single Player"));
(Game1.GameSession.gameMode as SinglePlayerMode).GenerateMap(seedBox.Text);
Game1.LobbyScreen.Select();
new GUIMessageBox("Welcome to Subsurface!", "Please note that the single player mode is very unfinished at the moment; "+
"for example, the NPCs don't have an AI yet and there are only a couple of different quests to complete. The multiplayer "+
"mode should be much more enjoyable to play at the moment, so my recommendation is to try out and get a hang of the game mechanics "+
"in the single player mode and then move on to multiplayer. Have fun!\n - Regalis, the main dev of Subsurface", 400, 350);
return true;
}
private bool PreviousTab(GUIButton button, object obj)
{
selectedTab = (int)Tabs.Main;
return true;
}
private bool LoadGame(GUIButton button, object obj)
{
string saveFile = saveList.SelectedData as string;
if (string.IsNullOrWhiteSpace(saveFile)) return false;
try
{
SaveUtil.LoadGame(saveFile);
}
catch (Exception e)
{
DebugConsole.ThrowError("Loading map ''"+saveFile+"'' failed", e);
return false;
}
Game1.LobbyScreen.Select();
return true;
}
private bool JoinServer(GUIButton button, object obj)
{
if (string.IsNullOrEmpty(clientNameBox.Text)) return false;
if (string.IsNullOrEmpty(ipBox.Text)) return false;
Game1.NetworkMember = new GameClient(clientNameBox.Text);
Game1.Client.ConnectToServer(ipBox.Text);
return true;
//{
// Game1.NetLobbyScreen.Select();
// return true;
//}
//else
//{
// Game1.NetworkMember = null;
// return false;
//}
}
}
}
+691
View File
@@ -0,0 +1,691 @@
using System;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
using FarseerPhysics;
using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics;
using System.IO;
using System.Collections.Generic;
namespace Subsurface
{
class NetLobbyScreen : Screen
{
private GUIFrame menu;
private GUIFrame infoFrame;
private GUIListBox playerList;
private GUIListBox subList, modeList, chatBox;
private GUIListBox jobList;
private GUITextBox textBox, seedBox;
GUIFrame previewPlayer;
private GUIScrollBar durationBar;
private GUIFrame playerFrame;
private float camAngle;
public bool IsServer;
public string ServerName, ServerMessage;
private GUITextBox serverMessage;
public Submarine SelectedMap
{
get { return subList.SelectedData as Submarine; }
}
public GameModePreset SelectedMode
{
get { return modeList.SelectedData as GameModePreset; }
}
//for guitextblock delegate
public string GetServerName()
{
return ServerName;
}
public string GetServerMessage()
{
return ServerMessage;
}
public TimeSpan GameDuration
{
get
{
int minutes = (int)(durationBar.BarScroll* 60.0f);
return new TimeSpan(0, minutes, 0);
}
}
public List<JobPrefab> JobPreferences
{
get
{
List<JobPrefab> jobPreferences = new List<JobPrefab>();
foreach (GUIComponent child in jobList.children)
{
JobPrefab jobPrefab = child.UserData as JobPrefab;
if (jobPrefab == null) continue;
jobPreferences.Add(jobPrefab);
}
return jobPreferences;
}
}
private string levelSeed;
public string LevelSeed
{
get
{
return levelSeed;
}
private set
{
levelSeed = value;
seedBox.Text = levelSeed;
}
}
public string DurationText()
{
return "Game duration: " + GameDuration + " min";
}
public NetLobbyScreen()
{
int width = Math.Min(Game1.GraphicsWidth - 80, 1500);
int height = Math.Min(Game1.GraphicsHeight - 80, 800);
Rectangle panelRect = new Rectangle(0,0,width,height);
menu = new GUIFrame(panelRect, Color.Transparent, Alignment.Center);
//menu.Padding = GUI.style.smallPadding;
//server info panel ------------------------------------------------------------
infoFrame = new GUIFrame(new Rectangle(0, 0, (int)(panelRect.Width * 0.6f), (int)(panelRect.Height * 0.6f)), GUI.style, menu);
//infoFrame.Padding = GUI.style.smallPadding;
//chatbox ----------------------------------------------------------------------
GUIFrame chatFrame = new GUIFrame(
new Rectangle(0, (int)(panelRect.Height * 0.6f + 20),
(int)(panelRect.Width * 0.6f),
(int)(panelRect.Height * 0.4f - 20)),
GUI.style, menu);
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;
//player info panel ------------------------------------------------------------
playerFrame = new GUIFrame(
new Rectangle((int)(panelRect.Width * 0.6f + 20), 0,
(int)(panelRect.Width * 0.4f - 20), (int)(panelRect.Height * 0.6f)),
GUI.style, menu);
//player list ------------------------------------------------------------------
GUIFrame playerListFrame = new GUIFrame(
new Rectangle((int)(panelRect.Width * 0.6f + 20), (int)(panelRect.Height * 0.6f + 20),
(int)(panelRect.Width * 0.4f - 20), (int)(panelRect.Height * 0.4f - 20)),
GUI.style, menu);
playerList = new GUIListBox(new Rectangle(0,0,0,0), null, GUI.style, playerListFrame);
//submarine list ------------------------------------------------------------------
int columnWidth = infoFrame.Rect.Width / 3 - 30;
int columnX = 0;
new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 30), "Selected submarine:", GUI.style, infoFrame);
subList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, 200), Color.White, GUI.style, infoFrame);
subList.OnSelected = SelectMap;
if (Submarine.SavedSubmarines.Count > 0)
{
foreach (Submarine sub in Submarine.SavedSubmarines)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
sub.Name, GUI.style,
Alignment.Left, Alignment.Left,
subList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = sub;
}
}
else
{
DebugConsole.ThrowError("No saved submarines found!");
return;
}
columnX += columnWidth + 20;
//gamemode ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 120, 0, 30), "Selected game mode: ", GUI.style, infoFrame);
modeList = new GUIListBox(new Rectangle(columnX, 150, columnWidth, 200), GUI.style, infoFrame);
foreach (GameModePreset mode in GameModePreset.list)
{
if (mode.IsSinglePlayer) continue;
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
mode.Name, GUI.style,
Alignment.Left, Alignment.Left,
modeList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = mode;
}
columnX += columnWidth + 20;
//duration ------------------------------------------------------------------
GUITextBlock durationText = new GUITextBlock(new Rectangle(columnX, 120, columnWidth, 20),
"Game duration: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame);
durationText.TextGetter = DurationText;
durationBar = new GUIScrollBar(new Rectangle(columnX, 150, columnWidth, 20),
GUI.style, 0.1f, infoFrame);
durationBar.BarSize = 0.1f;
//seed ------------------------------------------------------------------
new GUITextBlock(new Rectangle(columnX, 190, columnWidth, 20),
"Level Seed: ", GUI.style, Alignment.Left, Alignment.TopLeft, infoFrame);
seedBox = new GUITextBox(new Rectangle(columnX, 220, columnWidth, 20),
Alignment.TopLeft, GUI.style, infoFrame);
seedBox.OnTextChanged = SelectSeed;
LevelSeed = ToolBox.RandomSeed(8);
//server info ------------------------------------------------------------------
var serverName = new GUITextBox(new Rectangle(0, 0, 200, 20), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame);
serverName.TextGetter = GetServerName;
serverName.Enabled = Game1.Server != null;
serverName.OnTextChanged = ChangeServerName;
serverMessage = new GUITextBox(new Rectangle(0, 30, 360, 70), null, null, Alignment.TopLeft, Alignment.TopLeft, GUI.style, infoFrame);
serverMessage.Wrap = true;
serverMessage.TextGetter = GetServerMessage;
serverMessage.OnTextChanged = UpdateServerMessage;
}
public override void Deselect()
{
textBox.Deselect();
}
public override void Select()
{
Game1.LightManager.LosEnabled = false;
//infoFrame.ClearChildren();
textBox.Select();
Character.Controlled = null;
Game1.GameScreen.Cam.TargetPos = Vector2.Zero;
subList.Enabled = Game1.Server != null;
modeList.Enabled = Game1.Server != null;
durationBar.Enabled = Game1.Server != null;
seedBox.Enabled = Game1.Server != null;
serverMessage.Enabled = Game1.Server != null;
ServerName = (Game1.Server==null) ? "Server" : Game1.Server.Name;
infoFrame.RemoveChild(infoFrame.children.Find(c => c.UserData as string == "startButton"));
if (IsServer && Game1.Server != null)
{
GUIButton startButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Start", Alignment.TopRight, GUI.style, infoFrame);
startButton.OnClicked = Game1.Server.StartGame;
startButton.UserData = "startButton";
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
modeList.OnSelected = Game1.Server.UpdateNetLobby;
durationBar.OnMoved = Game1.Server.UpdateNetLobby;
if (subList.CountChildren > 0) subList.Select(0);
if (GameModePreset.list.Count > 0) modeList.Select(0);
}
else
{
int x = playerFrame.Rect.Width / 2;
playerFrame.ClearChildren();
new GUITextBlock(new Rectangle(x, 0, 200, 30), "Name: ", GUI.style, playerFrame);
GUITextBox playerName = new GUITextBox(new Rectangle(x, 30, 0, 20),
Alignment.TopLeft, GUI.style, playerFrame);
playerName.Text = Game1.Client.CharacterInfo.Name;
playerName.OnEnter += ChangeCharacterName;
new GUITextBlock(new Rectangle(x, 70, 200, 30), "Gender: ", GUI.style, playerFrame);
GUIButton maleButton = new GUIButton(new Rectangle(x, 100, 70, 20), "Male",
Alignment.TopLeft, GUI.style,playerFrame);
maleButton.UserData = Gender.Male;
maleButton.OnClicked += SwitchGender;
GUIButton femaleButton = new GUIButton(new Rectangle(x+90, 100, 70, 20), "Female",
Alignment.TopLeft, GUI.style, playerFrame);
femaleButton.UserData = Gender.Female;
femaleButton.OnClicked += SwitchGender;
new GUITextBlock(new Rectangle(x, 150, 200, 30), "Job preferences:", GUI.style, playerFrame);
jobList = new GUIListBox(new Rectangle(x, 180, 150, 0), GUI.style, playerFrame);
foreach (JobPrefab job in JobPrefab.List)
{
GUITextBlock jobText = new GUITextBlock(new Rectangle(0,0,0,20), job.Name, GUI.style, jobList);
jobText.UserData = job;
GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 45, 0, 20, 20), "u", GUI.style, jobText);
upButton.UserData = -1;
upButton.OnClicked += ChangeJobPreference;
GUIButton downButton = new GUIButton(new Rectangle(jobText.Rect.Width - 20, 0, 20, 20), "d", GUI.style, jobText);
downButton.UserData = 1;
downButton.OnClicked += ChangeJobPreference;
}
UpdateJobPreferences(jobList);
UpdatePreviewPlayer(Game1.Client.CharacterInfo);
}
base.Select();
}
private bool SelectMap(object obj)
{
if (Game1.Server != null) Game1.Server.UpdateNetLobby(obj);
Submarine sub = (Submarine)obj;
//submarine already loaded
if (Submarine.Loaded != null && sub.FilePath == Submarine.Loaded.FilePath) return true;
sub.Load();
return true;
}
public bool ChangeServerName(GUITextBox textBox, string text)
{
if (Game1.Server == null) return false;
ServerName = text;
Game1.Server.UpdateNetLobby(null);
return true;
}
public bool UpdateServerMessage(GUITextBox textBox, string text)
{
if (Game1.Server == null) return false;
ServerMessage = text;
Game1.Server.UpdateNetLobby(null);
return true;
}
public void AddPlayer(Client client)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")"),
GUI.style, Alignment.Left, Alignment.Left,
playerList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = client;
}
public void RemovePlayer(Client client)
{
if (client == null) return;
playerList.RemoveChild(playerList.GetChild(client));
}
public void ClearPlayers()
{
for (int i = 1; i<playerList.CountChildren; i++)
{
playerList.RemoveChild(playerList.children[i]);
}
}
public override void Update(double deltaTime)
{
base.Update(deltaTime);
Vector2 pos = new Vector2(
Submarine.Borders.X + Submarine.Borders.Width / 2,
Submarine.Borders.Y - Submarine.Borders.Height / 2);
camAngle += (float)deltaTime / 10.0f;
Vector2 offset = (new Vector2(
(float)Math.Cos(camAngle) * (Submarine.Borders.Width / 2.0f),
(float)Math.Sin(camAngle) * (Submarine.Borders.Height / 2.0f)));
pos += offset * 0.8f;
Game1.GameScreen.Cam.TargetPos = pos;
Game1.GameScreen.Cam.MoveCamera((float)deltaTime);
menu.Update((float)deltaTime);
//durationBar.BarScroll = Math.Max(durationBar.BarScroll, 1.0f / 60.0f);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
graphics.Clear(Color.CornflowerBlue);
Game1.GameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
menu.Draw(spriteBatch);
if (previewPlayer!=null) previewPlayer.Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch, null);
spriteBatch.End();
}
public void NewChatMessage(string message, Color color)
{
float prevSize = chatBox.BarSize;
float oldScroll = chatBox.BarScroll;
while (chatBox.CountChildren>20)
{
chatBox.RemoveChild(chatBox.children[1]);
}
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20),
message,
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color,
Alignment.Left, GUI.style, null, true);
msg.Font = GUI.SmallFont;
msg.Padding = new Vector4(20, 0, 0, 0);
chatBox.AddChild(msg);
if ((prevSize == 1.0f && chatBox.BarScroll == 0.0f) || (prevSize < 1.0f && chatBox.BarScroll == 1.0f)) chatBox.BarScroll = 1.0f;
}
public bool StartGame(object obj)
{
Game1.Server.StartGame(null, obj);
return true;
}
public bool EnterChatMessage(GUITextBox textBox, string message)
{
if (String.IsNullOrEmpty(message)) return false;
Game1.NetworkMember.SendChatMessage(Game1.NetworkMember.Name + ": " + message);
return true;
}
private void UpdatePreviewPlayer(CharacterInfo characterInfo)
{
previewPlayer = new GUIFrame(
new Rectangle(playerFrame.Rect.X + 20, playerFrame.Rect.Y + 20, 230, 300),
new Color(0.0f, 0.0f, 0.0f, 0.8f), GUI.style);
previewPlayer.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
characterInfo.CreateInfoFrame(previewPlayer);
previewPlayer.UserData = characterInfo;
}
private bool SwitchGender(GUIButton button, object obj)
{
try
{
Gender gender = (Gender)obj;
Game1.Client.CharacterInfo.Gender = gender;
Game1.Client.SendCharacterData();
//CreatePreviewCharacter();
}
catch {}
UpdatePreviewPlayer(Game1.Client.CharacterInfo);
return true;
}
private bool SelectSeed(GUITextBox textBox, string seed)
{
if (!string.IsNullOrWhiteSpace(seed))
{
LevelSeed = seed;
}
//textBox.Text = LevelSeed;
//textBox.Selected = false;
if (Game1.Server != null) Game1.Server.UpdateNetLobby(null);
return true;
}
private bool ChangeCharacterName(GUITextBox textBox, string newName)
{
if (string.IsNullOrEmpty(newName)) return false;
Game1.Client.CharacterInfo.Name = newName;
Game1.Client.Name = newName;
Game1.Client.SendCharacterData();
textBox.Text = newName;
textBox.Selected = false;
return true;
}
private bool ChangeJobPreference(GUIButton button, object obj)
{
GUIComponent jobText = button.Parent;
GUIListBox jobList = jobText.Parent as GUIListBox;
int index = jobList.children.IndexOf(jobText);
int newIndex = index + (int)obj;
if (newIndex < 0 || newIndex > jobList.children.Count - 1) return false;
GUIComponent temp = jobList.children[newIndex];
jobList.children[newIndex] = jobText;
jobList.children[index] = temp;
UpdateJobPreferences(jobList);
return true;
}
private void UpdateJobPreferences(GUIListBox listBox)
{
listBox.Deselect();
for (int i = 1; i < listBox.children.Count; i++)
{
float a = (float)(i - 1) / 3.0f;
a = Math.Min(a, 3);
Color color = new Color(1.0f - a, (1.0f - a) * 0.6f, 0.0f, 0.3f);
listBox.children[i].Color = color;
}
Game1.Client.SendCharacterData();
}
public bool TrySelectMap(string mapName, string md5Hash)
{
Submarine map = Submarine.SavedSubmarines.Find(m => m.Name == mapName);
if (map == null)
{
DebugConsole.ThrowError("The map ''" + mapName + "'' has been selected by the server.");
DebugConsole.ThrowError("Matching map not found in your map folder.");
return false;
}
else
{
if (map.Hash.Hash != md5Hash)
{
DebugConsole.ThrowError("Your version of the map file ''" + map.Name + "'' doesn't match the server's version!");
DebugConsole.ThrowError("Your file: " + map.Name + "(MD5 hash : " + map.Hash.Hash + ")");
DebugConsole.ThrowError("Server's file: " + mapName + "(MD5 hash : " + md5Hash + ")");
return false;
}
else
{
subList.Select(map);
//map.Load();
return true;
}
}
}
public void WriteData(NetOutgoingMessage msg)
{
Submarine selectedMap = subList.SelectedData as Submarine;
if (selectedMap==null)
{
msg.Write(" ");
msg.Write(" ");
}
else
{
msg.Write(Path.GetFileName(selectedMap.Name));
msg.Write(selectedMap.Hash.Hash);
}
msg.Write(ServerName);
msg.Write(ServerMessage);
msg.Write(modeList.SelectedIndex-1);
msg.Write(durationBar.BarScroll);
msg.Write(LevelSeed);
msg.Write(playerList.CountChildren - 1);
for (int i = 1; i < playerList.CountChildren; i++)
{
Client client = playerList.children[i].UserData as Client;
msg.Write(client.ID);
msg.Write(client.assignedJob==null ? "" : client.assignedJob.Name);
}
}
public void ReadData(NetIncomingMessage msg)
{
string mapName="", md5Hash="";
int modeIndex = 0;
float durationScroll = 0.0f;
string levelSeed = "";
try
{
mapName = msg.ReadString();
md5Hash = msg.ReadString();
ServerName = msg.ReadString();
ServerMessage = msg.ReadString();
modeIndex = msg.ReadInt32();
durationScroll = msg.ReadFloat();
levelSeed = msg.ReadString();
}
catch
{
return;
}
TrySelectMap(mapName, md5Hash);
modeList.Select(modeIndex);
durationBar.BarScroll = durationScroll;
LevelSeed = levelSeed;
try
{
int playerCount = msg.ReadInt32();
for (int i = 0; i < playerCount; i++)
{
int clientID = msg.ReadInt32();
string jobName = msg.ReadString();
Client client = null;
GUITextBlock textBlock = null;
foreach (GUIComponent child in playerList.children)
{
Client tempClient = child.UserData as Client;
if (tempClient == null || tempClient.ID != clientID) continue;
client = tempClient;
textBlock = child as GUITextBlock;
break;
}
if (client == null) continue;
client.assignedJob = JobPrefab.List.Find(jp => jp.Name == jobName);
textBlock.Text = client.name + ((client.assignedJob==null) ? "" : " (" + client.assignedJob.Name + ")");
if (client.assignedJob==null || jobName != client.assignedJob.Name)
{
if (clientID == Game1.Client.ID)
{
Game1.Client.CharacterInfo.Job = new Job(client.assignedJob);
Game1.Client.CharacterInfo.Name = client.name;
UpdatePreviewPlayer(Game1.Client.CharacterInfo);
}
}
}
}
catch
{
return;
}
}
}
}
+33
View File
@@ -0,0 +1,33 @@
using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class Screen
{
private static Screen selected;
public static Screen Selected
{
get { return selected; }
}
public virtual void Deselect()
{
}
public virtual void Select()
{
if (selected != null && selected!=this) selected.Deselect();
selected = this;
}
public virtual void Update(double deltaTime)
{
}
public virtual void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
}
}
}
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Subsurface
{
class SettingsScreen : Screen
{
}
}