First commit

This commit is contained in:
Regalis
2015-05-25 01:04:03 +03:00
commit fadb89ae9e
320 changed files with 32186 additions and 0 deletions
+334
View File
@@ -0,0 +1,334 @@
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 EditCharacterScreen()
{
}
public override void Select()
{
base.Select();
Ragdoll.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", Color.White, GUIpanel);
physicsButton.OnClicked += TogglePhysics;
new GUITextBlock(new Rectangle(0, 80, 0, 25), "Limbs:", Color.Transparent, Color.Black, Alignment.Left, GUIpanel);
limbList = new GUIListBox(new Rectangle(0, 110, 0, 250), Color.White * 0.7f, GUIpanel);
limbList.OnSelected = SelectLimb;
new GUITextBlock(new Rectangle(0, 360, 0, 25), "Joints:", Color.Transparent, Color.Black, Alignment.Left, GUIpanel);
jointList = new GUIListBox(new Rectangle(0, 390, 0, 250), Color.White * 0.7f, 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(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);
Map.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);
//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,
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,
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 = limbBodyPos + ConvertUnits.ToDisplayUnits(joint.LocalAnchorA);
}
else if (joint.BodyB == limb.body.FarseerBody)
{
jointPos = limbBodyPos + ConvertUnits.ToDisplayUnits(joint.LocalAnchorB);
}
else
{
continue;
}
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())
{
if (joint.BodyA == limb.body.FarseerBody)
{
joint.LocalAnchorA += ConvertUnits.ToSimUnits(PlayerInput.MouseSpeed);
}
else
{
joint.LocalAnchorB += ConvertUnits.ToSimUnits(PlayerInput.MouseSpeed);
}
}
}
}
}
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, 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;
}
}
}
+291
View File
@@ -0,0 +1,291 @@
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", GUI.style, Alignment.Left, GUIpanel);
button.UserData = 0;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 80, 100, 20), "Structures", GUI.style, Alignment.Left, GUIpanel);
button.UserData = 1;
button.OnClicked = SelectTab;
button = new GUIButton(new Rectangle(0, 140, 100, 20), "Character mode", GUI.style, Alignment.Left, 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, 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, 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, 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,
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("Content/Characters/Human/human.xml", 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(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));
Map.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);
//EntityPrefab.DrawList(spriteBatch, new Vector2(20,50));
if (characterMode)
{
if (dummyCharacter != null && dummyCharacter.SelectedConstruction != null)
{
if (Character.Controlled.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();
}
}
}
+255
View File
@@ -0,0 +1,255 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Subsurface.Lights;
using FarseerPhysics;
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();
if (Game1.gameSession == null) Game1.gameSession = new GameSession("",false, TimeSpan.Zero);
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();
Game1.gameSession.Update((float)deltaTime);
//EventManager.Update(gameTime);
Character.UpdateAll(cam, (float)deltaTime);
Game1.particleManager.Update((float)deltaTime);
StatusEffect.UpdateAll((float)deltaTime);
//Physics.updated = false;
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);
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>
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//if (!Physics.updated) return;
DrawMap(graphics, spriteBatch);
//----------------------------------------------------------------------------------------
//2. draw the HUD on top of everything
//----------------------------------------------------------------------------------------
spriteBatch.Begin();
if (Game1.gameSession != null) Game1.gameSession.Draw(spriteBatch);
//EventManager.DrawInfo(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);
if (PlayerInput.GetMouseState.LeftButton != ButtonState.Pressed) Inventory.draggingItem = null;
spriteBatch.End();
}
public void DrawMap(GraphicsDevice graphics, SpriteBatch spriteBatch)
{
//----------------------------------------------------------------------------------------
//1. draw the characters and the parts of the map that are behind them
//----------------------------------------------------------------------------------------
//cam.UpdateTransform();
//----------------------------------------------------------------------------------------
//draw the map and characters to a rendertarget
graphics.SetRenderTarget(renderTarget);
graphics.Clear(new Color(11, 18, 26, 255));
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearWrap);
int x = (int)(cam.Position.X / 20.0f);
int y = (int)((-cam.Position.Y+5000) / 20.0f);
if (y<1024)
{
if (y>-1024)
{
background.SourceRect = new Rectangle(x, Math.Max(y,0), 1024, 1024);
background.DrawTiled(spriteBatch, (y<0) ? new Vector2(0.0f, -y) : Vector2.Zero, new Vector2(Game1.GraphicsWidth, 1024 - y),
Vector2.Zero, Color.White);
}
if (y<0)
{
backgroundTop.SourceRect = new Rectangle(x, y, 1024, 1024);
backgroundTop.DrawTiled(spriteBatch, Vector2.Zero, new Vector2(Game1.GraphicsWidth, Math.Min(1024 - y, Game1.GraphicsHeight)),
Vector2.Zero, Color.White);
}
}
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
Map.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);
//----------------------------------------------------------------------------------------
//3. draw the sections of the map that are on top of the water
//----------------------------------------------------------------------------------------
spriteBatch.Begin(SpriteSortMode.BackToFront,
BlendState.AlphaBlend,
null, null, null, null,
cam.Transform);
Map.DrawFront(spriteBatch);
spriteBatch.End();
LightManager.DrawFow(graphics,cam);
}
}
}
+227
View File
@@ -0,0 +1,227 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Subsurface
{
class LobbyScreen : Screen
{
GUIFrame leftPanel;
GUIFrame[] rightPanel;
GUIFrame shiftPanel;
int selectedRightPanel;
GUIListBox characterList;
GUIListBox hireList;
public LobbyScreen()
{
Rectangle panelRect = new Rectangle(
(int)GUI.style.largePadding.X,
(int)GUI.style.largePadding.Y,
(int)(Game1.GraphicsWidth * 0.3f) - (int)(GUI.style.largePadding.X * 1.5f),
Game1.GraphicsHeight - (int)(GUI.style.largePadding.Y * 2));
leftPanel = new GUIFrame(panelRect, GUI.style.backGroundColor);
leftPanel.Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25),
"asdfdasfasdf", Color.Transparent, Color.White, Alignment.Left, leftPanel);
GUITextBlock moneyText = new GUITextBlock(new Rectangle(0, 30, 200, 25),
"", Color.Transparent, Color.White, Alignment.Left, leftPanel);
moneyText.TextGetter = GetMoney;
GUIButton button = new GUIButton(new Rectangle(0, 60, 100, 30), "Crew", GUI.style, Alignment.CenterX, leftPanel);
button.UserData = 0;
button.OnClicked = SelectRightPanel;
button = new GUIButton(new Rectangle(0, 100, 100, 30), "Hire", GUI.style, Alignment.CenterX, leftPanel);
button.UserData = 1;
button.OnClicked = SelectRightPanel;
//--------------------------------------
panelRect = new Rectangle(
panelRect.X + panelRect.Width + (int)(GUI.style.largePadding.X),
panelRect.Y,
Game1.GraphicsWidth - panelRect.Width - (int)(GUI.style.largePadding.X * 3.0f),
(int)(Game1.GraphicsHeight * 0.3f) - (int)(GUI.style.largePadding.Y * 1.5f));
shiftPanel = new GUIFrame(panelRect, GUI.style.backGroundColor);
shiftPanel.Padding = GUI.style.smallPadding;
GUITextBlock dayText = new GUITextBlock(new Rectangle(0, 0, 200, 25),
"", Color.Transparent, Color.White, Alignment.Left, shiftPanel);
dayText.TextGetter = GetDay;
GUIProgressBar progressBar = new GUIProgressBar(new Rectangle(0, 30, 200, 20), Color.Green, 0.0f, shiftPanel);
progressBar.ProgressGetter = GetWeekProgress;
button = new GUIButton(new Rectangle(0,0,100,30), "Start", GUI.style,
(Alignment.Right | Alignment.Bottom), shiftPanel);
button.OnClicked = StartShift;
//---------------------------------------------------------------
//---------------------------------------------------------------
rightPanel = new GUIFrame[2];
panelRect = new Rectangle(
panelRect.X,
panelRect.Y + panelRect.Height + (int)(GUI.style.largePadding.Y),
panelRect.Width,
(int)(Game1.GraphicsHeight * 0.7f) - (int)(GUI.style.largePadding.Y * 1.5f));
rightPanel[0] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[0].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 200, 25), "Crew:", Color.Transparent, Color.White, Alignment.Left, rightPanel[0]);
characterList = new GUIListBox(new Rectangle(0, 30, 300, 400), Color.White, rightPanel[0]);
//---------------------------------------
rightPanel[1] = new GUIFrame(panelRect, GUI.style.backGroundColor);
rightPanel[1].Padding = GUI.style.smallPadding;
hireList = new GUIListBox(new Rectangle(0, 30, 300, 400), Color.White, Alignment.Left, rightPanel[1]);
hireList.OnSelected = HireCharacter;
}
public override void Select()
{
base.Select();
Map.Clear();
UpdateCharacterLists();
}
private void UpdateCharacterLists()
{
characterList.ClearChildren();
foreach (CharacterInfo c in Game1.gameSession.crewManager.characterInfos)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.name, GUI.style,
Alignment.Left,
Alignment.Left,
characterList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
}
hireList.ClearChildren();
foreach (CharacterInfo c in Game1.gameSession.hireManager.availableCharacters)
{
GUIFrame frame = new GUIFrame(
new Rectangle(0, 0, 0, 25),
Color.White,
Alignment.Left,
GUI.style,
hireList);
frame.UserData = c;
frame.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f);
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.name,
Color.Transparent, Color.Black,
Alignment.Left,
frame);
textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
c.salary.ToString(),
Color.Transparent, Color.Black,
Alignment.Right,
frame);
}
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
if (characterList.CountChildren != Game1.gameSession.crewManager.characterInfos.Count
|| hireList.CountChildren != Game1.gameSession.hireManager.availableCharacters.Count)
{
UpdateCharacterLists();
}
graphics.Clear(Color.CornflowerBlue);
Game1.gameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
//ConstructionPrefab.list[5].sprite.Draw(spriteBatch, Vector2.Zero, new Vector2(10.0f, 1.0f), Color.White);
leftPanel.Draw(spriteBatch);
shiftPanel.Draw(spriteBatch);
rightPanel[selectedRightPanel].Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch);
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) ? "" : Game1.gameSession.crewManager.Money.ToString());
}
private string GetDay()
{
return "Day #" + ((Game1.gameSession == null) ? "" : Game1.gameSession.Day.ToString());
}
private float GetWeekProgress()
{
if (Game1.gameSession == null) return 0.0f;
return (float)((Game1.gameSession.Day - 1) % 7) / 7.0f;
}
private bool HireCharacter(object selection)
{
CharacterInfo characterInfo;
try { characterInfo = (CharacterInfo)selection; }
catch { return false; }
if (characterInfo == null) return false;
Game1.gameSession.TryHireCharacter(characterInfo);
return false;
}
private bool StartShift(GUIButton button, object selection)
{
Map.Load("", Game1.gameSession.SaveFile);
Game1.gameSession.StartShift();
//EventManager.StartShift();
Game1.gameScreen.Select();
return true;
}
}
}
+177
View File
@@ -0,0 +1,177 @@
using System;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
namespace Subsurface
{
class MainMenuScreen : Screen
{
enum Tabs { Main = 0, NewGame = 1, JoinServer = 2}
GUIFrame[] menuTabs;
GUIListBox mapList;
GUITextBox nameBox;
GUITextBox ipBox;
Game1 game;
int selectedTab;
public MainMenuScreen(Game1 game)
{
menuTabs = new GUIFrame[3];
Rectangle panelRect = new Rectangle(
Game1.GraphicsWidth / 2 - 250,
Game1.GraphicsHeight/ 2 - 250,
500, 500);
menuTabs[(int)Tabs.Main] = new GUIFrame(panelRect, GUI.style.backGroundColor);
menuTabs[(int)Tabs.Main].Padding = GUI.style.smallPadding;
GUIButton button = new GUIButton(new Rectangle(0, 0, 0, 30), "New Game", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]);
button.OnClicked = NewGameClicked;
//button.Enabled = false;
button = new GUIButton(new Rectangle(0, 60, 0, 30), "Join Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]);
button.OnClicked = JoinServerClicked;
button = new GUIButton(new Rectangle(0, 120, 0, 30), "Host Server", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]);
button.OnClicked = HostServerClicked;
//button.Enabled = false;
button = new GUIButton(new Rectangle(0, 180, 0, 30), "Quit", GUI.style, Alignment.CenterX, menuTabs[(int)Tabs.Main]);
button.OnClicked = QuitClicked;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.NewGame] = new GUIFrame(panelRect, GUI.style.backGroundColor);
menuTabs[(int)Tabs.NewGame].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 0, 30), "New Game", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.NewGame]);
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, menuTabs[(int)Tabs.NewGame]);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 400), Color.White, menuTabs[1]);
string[] mapFilePaths = Map.GetMapFilePaths();
if (mapFilePaths!=null)
{
foreach (string s in mapFilePaths)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
Path.GetFileNameWithoutExtension(s),
GUI.style,
Alignment.Left,
Alignment.Left,
mapList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = s;
}
if (mapFilePaths.Length > 0) mapList.Select(mapFilePaths[0]);
}
button = new GUIButton(new Rectangle(0, 0, 100, 30), "Start", GUI.style, Alignment.Right | Alignment.Bottom, menuTabs[(int)Tabs.NewGame]);
button.OnClicked = StartGame;
//----------------------------------------------------------------------
menuTabs[(int)Tabs.JoinServer] = new GUIFrame(panelRect, GUI.style.backGroundColor);
menuTabs[(int)Tabs.JoinServer].Padding = GUI.style.smallPadding;
new GUITextBlock(new Rectangle(0, 0, 0, 30), "Join Server", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Name:", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
nameBox = new GUITextBox(new Rectangle(0, 60, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
new GUITextBlock(new Rectangle(0, 100, 0, 30), "Server IP:", Color.Transparent, Color.Black, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
ipBox = new GUITextBox(new Rectangle(0, 130, 200, 30), Color.White, Color.Black, Alignment.CenterX, Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
GUIButton joinButton = new GUIButton(new Rectangle(0, 0, 200, 30), "Join", Color.White, Alignment.Bottom | Alignment.CenterX, menuTabs[(int)Tabs.JoinServer]);
joinButton.OnClicked = JoinServer;
this.game = game;
}
private bool NewGameClicked(GUIButton button, object obj)
{
selectedTab = (int)Tabs.NewGame;
return true;
}
private bool JoinServerClicked(GUIButton button, object obj)
{
selectedTab = (int)Tabs.JoinServer;
return true;
}
private bool HostServerClicked(GUIButton button, object obj)
{
Game1.netLobbyScreen.isServer = true;
Game1.netLobbyScreen.Select();
return true;
}
private bool QuitClicked(GUIButton button, object obj)
{
game.Exit();
return true;
}
public override void Update(double deltaTime)
{
menuTabs[selectedTab].Update((float)deltaTime);
}
public override void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
graphics.Clear(Color.CornflowerBlue);
Game1.gameScreen.DrawMap(graphics, spriteBatch);
spriteBatch.Begin();
menuTabs[selectedTab].Draw(spriteBatch);
GUI.Draw((float)deltaTime, spriteBatch);
spriteBatch.End();
}
private bool StartGame(GUIButton button, object obj)
{
if (mapList.SelectedData == null) return false;
Game1.gameSession = new GameSession(mapList.SelectedData.ToString(), true, TimeSpan.Zero);
Game1.lobbyScreen.Select();
return true;
}
private bool JoinServer(GUIButton button, object obj)
{
if (string.IsNullOrEmpty(nameBox.Text)) return false;
if (string.IsNullOrEmpty(ipBox.Text)) return false;
Game1.client = new GameClient(nameBox.Text);
if (Game1.client.ConnectToServer(ipBox.Text))
{
Game1.netLobbyScreen.Select();
return true;
}
else
{
Game1.client = null;
return false;
}
}
}
}
+462
View File
@@ -0,0 +1,462 @@
using System;
using System.Collections.Generic;
using System.IO;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Subsurface.Networking;
using FarseerPhysics;
using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics;
namespace Subsurface
{
class NetLobbyScreen : Screen
{
GUIFrame menu;
GUIFrame infoFrame;
GUIListBox playerList;
GUIListBox mapList, modeList, chatBox;
GUITextBox textBox;
GUIScrollBar durationBar;
GUIFrame playerFrame;
float camAngle;
public bool isServer;
public string SelectedMap
{
get { return mapList.SelectedData.ToString(); }
}
public GameMode SelectedMode
{
get { return modeList.SelectedData as GameMode; }
}
public TimeSpan GameDuration
{
get
{
int minutes = (int)(durationBar.BarScroll* 60.0f);
return new TimeSpan(0, minutes, 0);
}
}
public string DurationText()
{
return "Game duration: "+GameDuration+" min";
}
public NetLobbyScreen()
{
Rectangle panelRect = new Rectangle(
(int)GUI.style.largePadding.X,
(int)GUI.style.largePadding.Y,
(int)(Game1.GraphicsWidth - GUI.style.largePadding.X * 2.0f),
(int)(Game1.GraphicsHeight - GUI.style.largePadding.Y * 2.0f));
menu = new GUIFrame(panelRect, Color.Transparent);
//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.backGroundColor, menu);
infoFrame.Padding = GUI.style.smallPadding;
//chatbox ----------------------------------------------------------------------
GUIFrame chatFrame = new GUIFrame(
new Rectangle(0, (int)(panelRect.Height * 0.6f + GUI.style.smallPadding.W),
(int)(panelRect.Width * 0.6f),
(int)(panelRect.Height * 0.4f - GUI.style.smallPadding.W)),
GUI.style.backGroundColor, menu);
chatFrame.Padding = GUI.style.smallPadding;
chatBox = new GUIListBox(new Rectangle(0,0,0,chatFrame.Rect.Height-80), Color.White, chatFrame);
textBox = new GUITextBox(new Rectangle(0, 0, 0, 25), Color.White, Color.Black, Alignment.Bottom, Alignment.Left, chatFrame);
textBox.OnEnter = EnterChatMessage;
//player info panel ------------------------------------------------------------
playerFrame = new GUIFrame(
new Rectangle((int)(panelRect.Width * 0.6f + GUI.style.smallPadding.Z), 0,
(int)(panelRect.Width * 0.4f - GUI.style.smallPadding.Z), (int)(panelRect.Height * 0.6f)),
GUI.style.backGroundColor, menu);
playerFrame.Padding = GUI.style.smallPadding;
//player list ------------------------------------------------------------------
GUIFrame playerListFrame = new GUIFrame(
new Rectangle((int)(panelRect.Width * 0.6f + GUI.style.smallPadding.Z), (int)(panelRect.Height * 0.6f + GUI.style.smallPadding.W),
(int)(panelRect.Width * 0.4f - GUI.style.smallPadding.Z), (int)(panelRect.Height * 0.4f - GUI.style.smallPadding.W)),
GUI.style.backGroundColor, menu);
playerListFrame.Padding = GUI.style.smallPadding;
playerList = new GUIListBox(new Rectangle(0,0,0,0), Color.White, playerListFrame);
}
public override void Deselect()
{
textBox.Deselect();
}
public override void Select()
{
infoFrame.ClearChildren();
if (isServer && Game1.server == null) Game1.server = new GameServer();
textBox.Select();
int oldMapIndex = 0;
if (mapList != null && mapList.SelectedData != null) oldMapIndex = mapList.SelectedIndex;
new GUITextBlock(new Rectangle(0, 30, 0, 30), "Selected map:", Color.Transparent, Color.Black, Alignment.Left, infoFrame);
mapList = new GUIListBox(new Rectangle(0, 60, 200, 200), Color.White, infoFrame);
mapList.OnSelected = SelectMap;
mapList.Enabled = (Game1.server!=null);
string[] mapFilePaths = Map.GetMapFilePaths();
if (mapFilePaths != null)
{
foreach (string s in mapFilePaths)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
Path.GetFileNameWithoutExtension(s),
GUI.style,
Alignment.Left,
Alignment.Left,
mapList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = s;
}
}
else
{
DebugConsole.ThrowError("No saved maps found!");
return;
}
new GUITextBlock(new Rectangle(220, 30, 0, 30), "Selected game mode: ", Color.Transparent, Color.Black, Alignment.Left, infoFrame);
modeList = new GUIListBox(new Rectangle(220, 60, 200, 200), Color.White, infoFrame);
modeList.Enabled = (Game1.server != null);
//modeList.OnSelected = new GUIListBox.OnSelectedHandler(SelectEvent);
foreach (GameMode mode in GameMode.list)
{
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;
}
GUITextBlock durationText = new GUITextBlock(new Rectangle((int)(modeList.Rect.X + modeList.Rect.Width + GUI.style.smallPadding.X), modeList.Rect.Y, 100, 20),
"Game duration: ", Color.Transparent, Color.Black, Alignment.Left, infoFrame);
durationText.TextGetter = DurationText;
durationBar = new GUIScrollBar(new Rectangle((int)(modeList.Rect.X + modeList.Rect.Width + GUI.style.smallPadding.X), modeList.Rect.Y + 30, 100, 20),
Color.Gold, 0.1f, Alignment.Left, infoFrame);
durationBar.BarSize = 0.1f;
durationBar.Enabled = (Game1.server != null);
if (isServer && Game1.server!=null)
{
GUIButton startButton = new GUIButton(new Rectangle(0,0,200,30), "Start", Color.White, Alignment.Right | Alignment.Bottom, infoFrame);
startButton.OnClicked = Game1.server.StartGame;
//mapList.OnSelected = new GUIListBox.OnSelectedHandler(Game1.server.UpdateNetLobby);
modeList.OnSelected = Game1.server.UpdateNetLobby;
durationBar.OnMoved = Game1.server.UpdateNetLobby;
if (mapFilePaths.Length > 0) mapList.Select(mapFilePaths[oldMapIndex]);
if (GameMode.list.Count > 0) modeList.Select(GameMode.list[0]);
}
else
{
int x = playerFrame.Rect.Width / 2;
GUITextBox playerName = new GUITextBox(new Rectangle(x, 0, 0, 20), Color.White, Color.Black,
Alignment.Left | Alignment.Top, Alignment.Left, playerFrame);
playerName.Text = Game1.client.CharacterInfo.name;
playerName.OnEnter += ChangeCharacterName;
new GUITextBlock(new Rectangle(x,40,200, 30), "Gender: ", Color.Transparent, Color.Black,
Alignment.Left | Alignment.Top, Alignment.Left, playerFrame);
GUIButton maleButton = new GUIButton(new Rectangle(x+70,50,70,20), "Male", GUI.style,
Alignment.Left | Alignment.Top, playerFrame);
maleButton.UserData = Gender.Male;
maleButton.OnClicked += SwitchGender;
GUIButton femaleButton = new GUIButton(new Rectangle(x+150, 50, 70, 20), "Female", GUI.style,
Alignment.Left | Alignment.Top, playerFrame);
femaleButton.UserData = Gender.Female;
femaleButton.OnClicked += SwitchGender;
new GUITextBlock(new Rectangle(0, 200, 200,30), "Job preferences:", Color.Transparent, Color.Black, Alignment.Left, playerFrame);
GUIListBox jobList = new GUIListBox(new Rectangle(0,230,200,250), Color.White, playerFrame);
foreach (Job job in Job.jobList)
{
GUITextBlock jobText = new GUITextBlock(new Rectangle(0,0,0,20), job.Name, Color.Transparent, Color.Black, Alignment.Left, jobList);
GUIButton upButton = new GUIButton(new Rectangle(jobText.Rect.Width - 40, 0, 20, 20), "u", Color.White, jobText);
upButton.UserData = -1;
upButton.OnClicked += ChangeJobPreference;
GUIButton downButton = new GUIButton(new Rectangle(jobText.Rect.Width - 20, 0, 20, 20), "d", Color.White, jobText);
downButton.UserData = 1;
downButton.OnClicked += ChangeJobPreference;
}
UpdateJobPreferences(jobList);
}
base.Select();
}
private bool SelectMap(object obj)
{
if (Game1.server != null) Game1.server.UpdateNetLobby(obj);
if ((string)obj == Map.FilePath) return true;
Map.Load((string)obj);
return true;
}
public void AddPlayer(string name)
{
GUITextBlock textBlock = new GUITextBlock(
new Rectangle(0, 0, 0, 25),
name,
GUI.style,
Alignment.Left,
Alignment.Left,
playerList);
textBlock.Padding = new Vector4(10.0f, 0.0f, 0.0f, 0.0f);
textBlock.UserData = name;
}
public void RemovePlayer(string name)
{
playerList.RemoveChild(playerList.GetChild(name));
}
public override void Update(double deltaTime)
{
base.Update(deltaTime);
Game1.gameScreen.Cam.MoveCamera((float)deltaTime);
Vector2 pos = new Vector2(
Map.Borders.X + Map.Borders.Width / 2,
Map.Borders.Y - Map.Borders.Height / 2);
camAngle += (float)deltaTime / 10.0f;
Vector2 offset = (new Vector2(
(float)Math.Cos(camAngle) * (Map.Borders.Width / 2.0f),
(float)Math.Sin(camAngle) * (Map.Borders.Height / 2.0f)));
pos += offset * 0.8f;
Game1.gameScreen.Cam.TargetPos = pos;
menu.Update((float)deltaTime);
if (Game1.client != null && Game1.client.Character != null)
{
}
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);
GUI.Draw((float)deltaTime, spriteBatch);
spriteBatch.End();
if (Game1.client != null)
{
if (Game1.client.Character != null)
{
Vector2 position = new Vector2(playerFrame.Rect.X + playerFrame.Rect.Width * 0.25f, playerFrame.Rect.Y + 100.0f);
Matrix transform = Matrix.CreateTranslation(new Vector3(ConvertUnits.ToDisplayUnits(-Game1.client.Character.SimPosition)+position, 0.0f));
spriteBatch.Begin(SpriteSortMode.BackToFront, null,null,null,null,null,transform);
Game1.client.Character.Draw(spriteBatch);
spriteBatch.End();
}
else
{
CreatePreviewCharacter();
}
}
}
public void NewChatMessage(string message, Color color)
{
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20),
message,
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black*0.1f, color,
Alignment.Left, null, true);
msg.Padding = new Vector4(GUI.style.smallPadding.X, 0, 0, 0);
chatBox.AddChild(msg);
}
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;
if (isServer)
{
Game1.server.SendChatMessage("Server: " + message);
}
else
{
Game1.client.SendChatMessage(Game1.client.Name + ": " + message);
}
return true;
}
private void CreatePreviewCharacter()
{
if (Game1.client.Character != null) Game1.client.Character.Remove();
Vector2 pos = new Vector2(1000.0f, 1000.0f);
Character character = new Character(Game1.client.CharacterInfo, pos);
Game1.client.Character = character;
character.animController.isStanding = true;
//TODO: only create if hasn't been created yet
//{
Body platform = BodyFactory.CreateRectangle(Game1.world, 3.0f, 1.0f, 5.0f);
platform.SetTransform(new Vector2(pos.X, pos.Y + 1.5f), 0.0f);
platform.IsStatic = true;
pos = ConvertUnits.ToDisplayUnits(pos);
new Hull(new Rectangle((int)pos.X - 100, (int)-pos.Y + 100, 200, 200));
//}
Physics.Alpha = 1.0f;
for (int i = 0; i < 500; i++)
{
character.animController.Update((float)Physics.step);
character.animController.UpdateAnim((float)Physics.step);
Game1.world.Step((float)Physics.step);
}
}
private bool SwitchGender(GUIButton button, object obj)
{
try
{
Gender gender = (Gender)obj;
Game1.client.CharacterInfo.gender = gender;
Game1.client.SendCharacterData();
CreatePreviewCharacter();
}
catch
{
return false;
}
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;
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 = 0; i<listBox.children.Count; i++)
{
float a = (float)i/listBox.children.Count;
Color color = new Color(a, 1.0f - a, 0.5f, 1.0f);
listBox.children[i].Color = color;
}
}
public void WriteData(NetOutgoingMessage msg)
{
msg.Write(mapList.SelectedIndex);
msg.Write(modeList.SelectedIndex);
msg.Write(durationBar.BarScroll);
}
public void ReadData(NetIncomingMessage msg)
{
mapList.Select(msg.ReadInt32());
modeList.Select(msg.ReadInt32());
durationBar.BarScroll = msg.ReadFloat();
}
}
}
+34
View File
@@ -0,0 +1,34 @@
using Microsoft.Xna.Framework;
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.Deselect();
selected = this;
}
public virtual void Update(double deltaTime)
{
}
public virtual void Draw(double deltaTime, GraphicsDevice graphics, SpriteBatch spriteBatch)
{
}
}
}