Browse files

Selection rectangle + fixed selections. Fixes #14

  • Loading branch information...
1 parent ac0744e commit a52846ebf0c9ec7e9484bb05fc6616eb6969e71e @liquidmetal committed Apr 26, 2012
View
BIN ChipsChallenge.suo
Binary file not shown.
View
7 Engine/Entities/Entity.cs
@@ -31,6 +31,7 @@ public abstract class Entity
protected string m_strHeightmap;
protected string m_strNormalmap;
protected EntityType m_etType;
+ protected bool m_bSelected;
/// <summary>
/// The position where this floor tile was placed
@@ -41,6 +42,12 @@ public Vector2 Position
set { m_vecPosition = value; }
}
+ public bool Selected
+ {
+ get { return m_bSelected; }
+ set { m_bSelected = value; }
+ }
+
public string Sprite
{
get { return m_strSprite; }
View
40 Engine/Renderer.cs
@@ -418,6 +418,35 @@ public bool RenderWorld(World world)
spriteBatch.End();
}
+ // Render out 'selection rectangles'
+ Texture2D selectionRect = new Texture2D(graphicsDevice, 1, 1);
+ selectionRect.SetData<Color>(new[] { Color.Red });
+
+ spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
+ foreach (Entity ent in lstEntities)
+ {
+ if (!ent.Selected)
+ continue;
+
+ Vector2 upperLeft = Project(new Vector3(ent.Position.X, ent.Position.Y, ent.Type==EntityType.Sprite?ent.Z:0));
+ upperLeft.X -= 2;
+ upperLeft.Y -= 2;
+
+ Vector2 size = new Vector2(14, 14);
+
+ if (ent.Type == EntityType.Sprite)
+ {
+ Texture2D sprite = assetManager.GetTexture(ent.Sprite + "/dif");
+ size = new Vector2(sprite.Width+4, sprite.Height+4);
+ }
+
+ spriteBatch.Draw(selectionRect, new Rectangle((int)upperLeft.X, (int)upperLeft.Y, 1, (int)size.Y), Color.White);
+ spriteBatch.Draw(selectionRect, new Rectangle((int)upperLeft.X, (int)upperLeft.Y, (int)size.X, 1), Color.White);
+ spriteBatch.Draw(selectionRect, new Rectangle((int)(upperLeft.X+size.X), (int)upperLeft.Y, 1, (int)size.Y), Color.White);
+ spriteBatch.Draw(selectionRect, new Rectangle((int)(upperLeft.X), (int)(upperLeft.Y+size.Y), (int)size.X, 1), Color.White);
+ }
+ spriteBatch.End();
+
////////////////////////////////////////////////////////////////////
// finalResult stores the final beauty pass
// That is, a combination of the dif and the lighting outputs
@@ -474,14 +503,15 @@ public Entity GetEntityAtPosition(World world, int x, int y)
foreach (Entity ent in world.GetEntities())
{
Vector2 pos = ent.Position;
- Rectangle rect = new Rectangle((int)pos.X-10, (int)pos.Y-10, 10, 10);;
+ Vector2 pos2D = Project(new Vector3(pos.X, pos.Y, ent.Type==EntityType.Sprite?ent.Z:0));
+
+ Rectangle rect = new Rectangle((int)pos2D.X, (int)pos2D.Y, 10, 10);;
if(ent.Type==EntityType.Sprite)
{
- Texture2D tex = assetManager.GetTexture(ent.Sprite);
- Vector2 pos2D = Project(new Vector3(pos.X, pos.Y, ent.Z));
- Vector3 vec = Unproject(new Vector2(pos2D.X+tex.Width, pos2D.Y+tex.Height));
+ Texture2D tex = assetManager.GetTexture(ent.Sprite+"/dif");
+
- rect = new Rectangle((int)pos.X, (int)pos.Y, (int)(vec.X-pos.X), (int)(vec.Y-pos.Y));
+ rect = new Rectangle((int)pos2D.X, (int)pos2D.Y, (int)(tex.Width), (int)(tex.Height));
}
if (rect.Contains((int)x, (int)y))
View
BIN Engine/bin/x86/Debug/Engine.dll
Binary file not shown.
View
BIN Engine/bin/x86/Debug/Engine.pdb
Binary file not shown.
View
BIN Engine/obj/x86/Debug/Engine.dll
Binary file not shown.
View
BIN Engine/obj/x86/Debug/Engine.pdb
Binary file not shown.
View
21 LevelEditorXna/LevelEditorXna/MainForm.cs
@@ -134,17 +134,32 @@ private void UpdateEntitiesList()
lstEntitiesList.Refresh();
}
+ private void SetSelectedObject(Entity ent)
+ {
+ if (m_selectedEntity != ent && m_selectedEntity!=null)
+ {
+ m_selectedEntity.Selected = false;
+ }
+
+ if(ent!=null)
+ {
+ ent.Selected = true;
+ }
+
+ m_selectedEntity = ent;
+ gridProperties.SelectedObject = m_selectedEntity;
+ }
+
private void formRenderer_MouseDown(object sender, MouseEventArgs e)
{
// Do stuff based on the current state
Vector3 worldPos = formRenderer.CurrentRenderer.Unproject(new Vector2(e.X, e.Y));
m_ptLastMouseClick = new Vector2(worldPos.X, worldPos.Y);
- Entity ent = currentRenderer.GetEntityAtPosition(currentWorld, (int)worldPos.X, (int)worldPos.Y);
+ Entity ent = currentRenderer.GetEntityAtPosition(currentWorld, (int)e.X, (int)e.Y);
- m_selectedEntity = ent;
- gridProperties.SelectedObject = m_selectedEntity;
+ SetSelectedObject(ent);
if (m_selectedEntity == null)
{
View
BIN LevelEditorXna/LevelEditorXna/bin/x86/Debug/Engine.dll
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/bin/x86/Debug/Engine.pdb
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/bin/x86/Debug/LevelEditorXna.exe
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/bin/x86/Debug/LevelEditorXna.pdb
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/obj/x86/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/obj/x86/Debug/LevelEditorXna.exe
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/obj/x86/Debug/LevelEditorXna.pdb
Binary file not shown.
View
BIN LevelEditorXna/LevelEditorXna/obj/x86/Debug/ResolveAssemblyReference.cache
Binary file not shown.

0 comments on commit a52846e

Please sign in to comment.