GUIStyle improvements & some simple UI graphics, networking bugfixes, separate Random class, some StyleCop cleanup
This commit is contained in:
@@ -33,7 +33,7 @@ namespace Subsurface
|
||||
|
||||
guiFrame = new GUIFrame(new Rectangle(0, 50, 150, 450), Color.Transparent);
|
||||
|
||||
listBox = new GUIListBox(new Rectangle(0, 0, 150, 0), Color.Transparent, guiFrame);
|
||||
listBox = new GUIListBox(new Rectangle(0, 0, 150, 0), Color.Transparent, null, guiFrame);
|
||||
listBox.ScrollBarEnabled = false;
|
||||
listBox.OnSelected = SelectCharacter;
|
||||
|
||||
@@ -72,29 +72,28 @@ namespace Subsurface
|
||||
public void AddCharacter(Character character)
|
||||
{
|
||||
characters.Add(character);
|
||||
if (!characterInfos.Contains(character.info))
|
||||
if (!characterInfos.Contains(character.Info))
|
||||
{
|
||||
characterInfos.Add(character.info);
|
||||
characterInfos.Add(character.Info);
|
||||
}
|
||||
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, listBox);
|
||||
GUIFrame frame = new GUIFrame(new Rectangle(0, 0, 0, 40), Color.Transparent, null, listBox);
|
||||
frame.UserData = character;
|
||||
frame.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f);
|
||||
frame.HoverColor = Color.LightGray * 0.5f;
|
||||
frame.SelectedColor = Color.Gold * 0.5f;
|
||||
|
||||
string name = character.info.name.Replace(' ', '\n');
|
||||
string name = character.Info.Name.Replace(' ', '\n');
|
||||
|
||||
GUITextBlock textBlock = new GUITextBlock(
|
||||
new Rectangle(40, 0, 0, 25),
|
||||
name,
|
||||
Color.Transparent, Color.White,
|
||||
Alignment.Left,
|
||||
Alignment.Left,
|
||||
frame);
|
||||
Alignment.Left, Alignment.Left,
|
||||
null, frame);
|
||||
textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f);
|
||||
|
||||
new GUIImage(new Rectangle(-10, -10, 0, 0), character.animController.limbs[0].sprite, Alignment.Left, frame);
|
||||
new GUIImage(new Rectangle(-10, -10, 0, 0), character.AnimController.limbs[0].sprite, Alignment.Left, frame);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
@@ -123,7 +122,7 @@ namespace Subsurface
|
||||
WayPoint randomWayPoint = WayPoint.GetRandom(WayPoint.SpawnType.Human);
|
||||
Vector2 position = (randomWayPoint == null) ? Vector2.Zero : randomWayPoint.SimPosition;
|
||||
|
||||
Character character = new Character(ci.file, position, ci);
|
||||
Character character = new Character(ci.File, position, ci);
|
||||
Character.Controlled = character;
|
||||
AddCharacter(character);
|
||||
}
|
||||
@@ -137,7 +136,7 @@ namespace Subsurface
|
||||
{
|
||||
if (!c.IsDead) continue;
|
||||
|
||||
CharacterInfo deadInfo = characterInfos.Find(x => c.info == x);
|
||||
CharacterInfo deadInfo = characterInfos.Find(x => c.Info == x);
|
||||
if (deadInfo != null) characterInfos.Remove(deadInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,20 +57,20 @@ namespace Subsurface
|
||||
|
||||
guiRoot = new GUIFrame(new Rectangle(0,0,Game1.GraphicsWidth,Game1.GraphicsWidth), Color.Transparent);
|
||||
|
||||
map = new Map(Game1.random.Next(), 500);
|
||||
map = new Map(Rand.Int(), 500);
|
||||
|
||||
int width = 350, height = 100;
|
||||
if (Game1.Client!=null || Game1.Server!=null)
|
||||
if (Game1.NetworkMember!=null)
|
||||
{
|
||||
chatBox = new GUIListBox(new Rectangle(
|
||||
Game1.GraphicsWidth - (int)GUI.style.smallPadding.X - width,
|
||||
Game1.GraphicsHeight - (int)GUI.style.smallPadding.W*2 - 25 - height,
|
||||
Game1.GraphicsWidth - 20 - width,
|
||||
Game1.GraphicsHeight - 40 - 25 - height,
|
||||
width, height),
|
||||
Color.White * 0.5f, guiRoot);
|
||||
Color.White * 0.5f, GUI.style, guiRoot);
|
||||
|
||||
textBox = new GUITextBox(
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + (int)GUI.style.smallPadding.W, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, guiRoot);
|
||||
new Rectangle(chatBox.Rect.X, chatBox.Rect.Y + chatBox.Rect.Height + 20, chatBox.Rect.Width, 25),
|
||||
Color.White * 0.5f, Color.Black, Alignment.Bottom, Alignment.Left, GUI.style, guiRoot);
|
||||
textBox.OnEnter = EnterChatMessage;
|
||||
}
|
||||
|
||||
@@ -91,8 +91,8 @@ namespace Subsurface
|
||||
|
||||
}
|
||||
|
||||
public GameSession(Submarine selectedMap, string savePath, string filePath)
|
||||
: this(selectedMap)
|
||||
public GameSession(Submarine selectedSub, string savePath, string filePath)
|
||||
: this(selectedSub)
|
||||
{
|
||||
XDocument doc = ToolBox.TryLoadXml(filePath);
|
||||
if (doc == null) return;
|
||||
@@ -111,27 +111,26 @@ namespace Subsurface
|
||||
this.savePath = savePath;
|
||||
}
|
||||
|
||||
public void StartShift(TimeSpan duration, Level level)
|
||||
public void StartShift(TimeSpan duration, string levelSeed, int scriptedEventCount = 1)
|
||||
{
|
||||
submarine.Load();
|
||||
|
||||
level.Generate(submarine==null ? 100.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height));
|
||||
|
||||
this.level = level;
|
||||
|
||||
StartShift(duration, 1);
|
||||
}
|
||||
|
||||
public void StartShift(TimeSpan duration, int scriptedEventCount = 1)
|
||||
public void StartShift(TimeSpan duration, Level level, int scriptedEventCount = 1)
|
||||
{
|
||||
//if (crewManager.characterInfos.Count == 0) return;
|
||||
|
||||
|
||||
|
||||
this.level = level;
|
||||
|
||||
if (Submarine.Loaded!=submarine) submarine.Load();
|
||||
|
||||
if (gameMode!=null) gameMode.Start(duration);
|
||||
|
||||
if (level!=null)
|
||||
if (level != null)
|
||||
{
|
||||
level.Generate(submarine == null ? 100.0f : Math.Max(Submarine.Borders.Width, Submarine.Borders.Height));
|
||||
submarine.SetPosition(level.StartPosition);
|
||||
}
|
||||
|
||||
@@ -177,13 +176,9 @@ namespace Subsurface
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(message)) return false;
|
||||
|
||||
if (Game1.Server!=null)
|
||||
else if (Game1.NetworkMember != null)
|
||||
{
|
||||
Game1.Server.SendChatMessage(message);
|
||||
}
|
||||
else if (Game1.Client!=null)
|
||||
{
|
||||
Game1.Client.SendChatMessage(Game1.Client.Name + ": " + message);
|
||||
Game1.NetworkMember.SendChatMessage(Game1.NetworkMember.Name + ": " + message);
|
||||
}
|
||||
|
||||
textBox.Deselect();
|
||||
@@ -195,9 +190,9 @@ namespace Subsurface
|
||||
{
|
||||
GUITextBlock msg = new GUITextBlock(new Rectangle(0, 0, 0, 20), text,
|
||||
((chatBox.CountChildren % 2) == 0) ? Color.Transparent : Color.Black * 0.1f, color,
|
||||
Alignment.Left, null, true);
|
||||
Alignment.Left, null, null, true);
|
||||
|
||||
msg.Padding = new Vector4(GUI.style.smallPadding.X, 0, 0, 0);
|
||||
msg.Padding = new Vector4(20.0f, 0, 0, 0);
|
||||
chatBox.AddChild(msg);
|
||||
|
||||
while (chatBox.CountChildren > 20)
|
||||
@@ -244,7 +239,7 @@ namespace Subsurface
|
||||
//crewManager.Draw(spriteBatch);
|
||||
taskManager.Draw(spriteBatch);
|
||||
|
||||
gameMode.Draw(spriteBatch);
|
||||
if (gameMode!=null) gameMode.Draw(spriteBatch);
|
||||
|
||||
//chatBox.Draw(spriteBatch);
|
||||
//textBox.Draw(spriteBatch);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Subsurface
|
||||
crewManager = new CrewManager();
|
||||
hireManager = new HireManager();
|
||||
|
||||
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Color.White, Alignment.Left | Alignment.Top);
|
||||
endShiftButton = new GUIButton(new Rectangle(Game1.GraphicsWidth - 240, 20, 100, 25), "End shift", Alignment.Left | Alignment.Top, GUI.style);
|
||||
endShiftButton.OnClicked = EndShift;
|
||||
|
||||
hireManager.GenerateCharacters("Content/Characters/Human/human.xml", 10);
|
||||
@@ -61,12 +61,12 @@ namespace Subsurface
|
||||
|
||||
public bool TryHireCharacter(CharacterInfo characterInfo)
|
||||
{
|
||||
if (crewManager.Money < characterInfo.salary) return false;
|
||||
if (crewManager.Money < characterInfo.Salary) return false;
|
||||
|
||||
hireManager.availableCharacters.Remove(characterInfo);
|
||||
crewManager.characterInfos.Add(characterInfo);
|
||||
|
||||
crewManager.Money -= characterInfo.salary;
|
||||
crewManager.Money -= characterInfo.Salary;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -137,7 +137,7 @@ namespace Subsurface
|
||||
sb.Append("Casualties: \n");
|
||||
foreach (Character c in casualties)
|
||||
{
|
||||
sb.Append(" - " + c.info.name + "\n");
|
||||
sb.Append(" - " + c.Info.Name + "\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -151,9 +151,9 @@ namespace Subsurface
|
||||
}
|
||||
|
||||
crewManager.EndShift();
|
||||
for (int i = Character.characterList.Count-1; i>=0; i--)
|
||||
for (int i = Character.CharacterList.Count-1; i>=0; i--)
|
||||
{
|
||||
Character.characterList.RemoveAt(i);
|
||||
Character.CharacterList.RemoveAt(i);
|
||||
}
|
||||
|
||||
Game1.GameSession.EndShift("");
|
||||
|
||||
@@ -31,9 +31,9 @@ namespace Subsurface
|
||||
|
||||
if (DateTime.Now >= endTime)
|
||||
{
|
||||
string endMessage = traitor.character.info.name + " was a traitor! ";
|
||||
endMessage += (traitor.character.info.gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.info.name + ". The task was unsuccesful.";
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "His" : "Her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". The task was unsuccesful.";
|
||||
End(endMessage);
|
||||
return;
|
||||
}
|
||||
@@ -44,13 +44,13 @@ namespace Subsurface
|
||||
int clientCount = Game1.Server.connectedClients.Count();
|
||||
if (clientCount < 2) return;
|
||||
|
||||
int traitorIndex = Game1.localRandom.Next(clientCount);
|
||||
int traitorIndex = Rand.Int(clientCount, false);
|
||||
traitor = Game1.Server.connectedClients[traitorIndex];
|
||||
|
||||
int targetIndex = 0;
|
||||
while (targetIndex==traitorIndex)
|
||||
while (targetIndex == traitorIndex)
|
||||
{
|
||||
targetIndex = Game1.localRandom.Next(clientCount);
|
||||
targetIndex = Rand.Int(clientCount, false);
|
||||
}
|
||||
target = Game1.Server.connectedClients[targetIndex];
|
||||
|
||||
@@ -61,9 +61,9 @@ namespace Subsurface
|
||||
{
|
||||
if (target.character.IsDead)
|
||||
{
|
||||
string endMessage = traitor.character.info.name + " was a traitor! ";
|
||||
endMessage += (traitor.character.info.gender == Gender.Male) ? "his" : "her";
|
||||
endMessage += " task was to assassinate " + target.character.info.name + ". The task was succesful.";
|
||||
string endMessage = traitor.character.Info.Name + " was a traitor! ";
|
||||
endMessage += (traitor.character.Info.Gender == Gender.Male) ? "his" : "her";
|
||||
endMessage += " task was to assassinate " + target.character.Info.Name + ". The task was succesful.";
|
||||
End(endMessage);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user