Scratch that. NOW they're working properly.

This commit is contained in:
Simon Holmberg
2012-10-24 01:27:20 +02:00
parent b9f49712db
commit 7d42fb1bf0
7 changed files with 41 additions and 13 deletions
+6 -8
View File
@@ -38,9 +38,8 @@ namespace DepthsBelow
public Rectangle ScreenToWorld(Rectangle screenRectangle) public Rectangle ScreenToWorld(Rectangle screenRectangle)
{ {
var pos = ScreenToWorld(new Vector2(screenRectangle.X, screenRectangle.Y)); var pos = ScreenToWorld(new Vector2(screenRectangle.X, screenRectangle.Y));
screenRectangle.X = (int)pos.X; var size = ScreenToWorld(new Vector2(screenRectangle.X + screenRectangle.Width, screenRectangle.Y + screenRectangle.Height)) - pos;
screenRectangle.Y = (int)pos.Y; return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
return screenRectangle;
} }
public Vector2 WorldToScreen(Vector2 worldPos) public Vector2 WorldToScreen(Vector2 worldPos)
@@ -48,12 +47,11 @@ namespace DepthsBelow
return Vector2.Transform(worldPos, Transform); return Vector2.Transform(worldPos, Transform);
} }
public Rectangle WorldToScreen(Rectangle screenRectangle) public Rectangle WorldToScreen(Rectangle worldRectangle)
{ {
var pos = WorldToScreen(new Vector2(screenRectangle.X, screenRectangle.Y)); var pos = WorldToScreen(new Vector2(worldRectangle.X, worldRectangle.Y));
screenRectangle.X = (int)pos.X; var size = WorldToScreen(new Vector2(worldRectangle.X + worldRectangle.Width, worldRectangle.Y + worldRectangle.Height)) - pos;
screenRectangle.Y = (int)pos.Y; return new Rectangle((int)pos.X, (int)pos.Y, (int)size.X, (int)size.Y);
return screenRectangle;
} }
public void Update(GameTime gameTime) public void Update(GameTime gameTime)
+9
View File
@@ -210,6 +210,15 @@ namespace DepthsBelow
} }
} }
#if DEBUG
var debugTexture = new Texture2D(GraphicsDevice, 1, 1);
debugTexture.SetData(new Color[] { Color.White });
foreach (var collisionComponent in EntityManager.GetComponents<Component.Collision>())
{
spriteBatch.Draw(debugTexture, collisionComponent.Rectangle, Color.Red * 0.5f);
}
#endif
// Draw mouse input visuals // Draw mouse input visuals
MouseInput.Draw(spriteBatch); MouseInput.Draw(spriteBatch);
+9 -1
View File
@@ -383,7 +383,15 @@ namespace DepthsBelow.GUI
if (Visible) if (Visible)
{ {
if (Texture != null) if (Texture != null)
spriteBatch.Draw(Texture, AbsoluteRectangle, Color); spriteBatch.Draw(Texture,
AbsoluteRectangle,
null,
Color,
0,
Vector2.Zero,
((Width < 0) ? SpriteEffects.FlipHorizontally : 0)
| ((Height < 0) ? SpriteEffects.FlipVertically : 0),
0);
/*foreach (var child in Children) /*foreach (var child in Children)
child.Draw(spriteBatch);*/ child.Draw(spriteBatch);*/
+6 -1
View File
@@ -153,8 +153,13 @@ namespace DepthsBelow
var selectFrame = (GUI.Frame)frame["selectionFrame"]; var selectFrame = (GUI.Frame)frame["selectionFrame"];
if (selectFrame.Visible) if (selectFrame.Visible)
{ {
Console.WriteLine("Before: " + selectFrame.AbsoluteRectangle.X + ", " + selectFrame.AbsoluteRectangle.Y + ", " + selectFrame.AbsoluteRectangle.Width + ", " + selectFrame.AbsoluteRectangle.Height);
var intersectionRectangle = core.Camera.ScreenToWorld(selectFrame.AbsoluteRectangle); var intersectionRectangle = core.Camera.ScreenToWorld(selectFrame.AbsoluteRectangle);
Console.WriteLine("After: " + intersectionRectangle.X + ", " + intersectionRectangle.Y + ", " + intersectionRectangle.Width + ", " + intersectionRectangle.Height);
// Select all units in the rectangle // Select all units in the rectangle
foreach (var soldier in core.Squad) foreach (var soldier in core.Squad)
{ {
@@ -192,7 +197,7 @@ namespace DepthsBelow
var button = new GUI.Button(UIParent); var button = new GUI.Button(UIParent);
button.SetTexture("images/Enter"); button.SetTexture("images/Enter");
button.X = 100; button.X = 200;
button.Y = 100; button.Y = 100;
button.Width = 55; button.Width = 55;
button.Height = 40; button.Height = 40;
+4 -3
View File
@@ -41,8 +41,9 @@ namespace DepthsBelow
selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1); selectionTexture = new Texture2D(core.GraphicsDevice, 1, 1);
selectionTexture.SetData(new Color[] { Color.White }); selectionTexture.SetData(new Color[] { Color.White });
gridTexture = new Texture2D(core.GraphicsDevice, 1, 1); //gridTexture = new Texture2D(core.GraphicsDevice, 1, 1);
gridTexture.SetData(new Color[] { Color.White }); //gridTexture.SetData(new Color[] { Color.White });
gridTexture = GameServices.GetService<ContentManager>().Load<Texture2D>("images/selection");
} }
public void OnPress(MouseState ms, GameTime gameTime) public void OnPress(MouseState ms, GameTime gameTime)
@@ -317,7 +318,7 @@ namespace DepthsBelow
public void Draw(SpriteBatch spriteBatch) public void Draw(SpriteBatch spriteBatch)
{ {
spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f); spriteBatch.Draw(selectionTexture, selectionRectangle, Color.Red * 0.5f);
spriteBatch.Draw(gridTexture, gridRectangle, Color.Yellow * 0.3f); spriteBatch.Draw(gridTexture, gridRectangle, Color.White * 0.7f);
if (checkingDirection == true) if (checkingDirection == true)
{ {
@@ -224,6 +224,13 @@
<Processor>TextureProcessor</Processor> <Processor>TextureProcessor</Processor>
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="images\selection.png">
<Name>selection</Name>
<Importer>TextureImporter</Importer>
<Processor>TextureProcessor</Processor>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB