protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { if (sheet != null) { if (operation == Operation.None) { SpriteDefinition sprite = GetSpriteFromMousePoint(e.X, e.Y); if (sprite != null) { PointPosition position = GetMousePosition(sprite.Rectangle, e.X, e.Y); this.Cursor = GetMouseCursor(position); } else { this.Cursor = Cursors.Default; } } else { if (e.Button == MouseButtons.Left) { DoOperation(e.X, e.Y); } } } base.OnMouseMove(e); }
public void RefreshSpriteImage(SpriteDefinition sprite) { Bitmap bitmap = GetImageFromTexture(sprite.Rectangle, SelectedSheet.Texture); this.imageList1.Images.RemoveByKey(sprite.Name); this.imageList1.Images.Add(sprite.Name, bitmap); }
public void AddSprite(SpriteDefinition sprite) { if (!this.sheet.Contains(sprite)) { this.sheet.Add(sprite); } this.Refresh(); }
private void _CurrentLevel_SpriteAdded(object sender, TEventArgs <Sprite> e) { SpriteDefinition sp = ProjectController.SpriteManager.GetMapDefinition(e.Data.InGameID); Rectangle r = new Rectangle(e.Data.X * 16 + sp.MaxLeftX, e.Data.Y * 16 + sp.MaxTopY, sp.MaxRightX - sp.MaxLeftX, sp.MaxBottomY - sp.MaxTopY); FullSpriteRender(r); Redraw(); }
/// <summary> /// Create a new <see cref="RelativeTexture"/>. /// </summary> /// /// <exception cref="ArgumentNullException" /> public RelativeTexture(IPositionedElement parent, SpriteDefinition spriteDef) : base(parent) { SpriteDefinition = spriteDef; LayerDepth = 0F; Size = Point.Zero; SpriteEffects = SpriteEffects.None; Visible = true; }
/// <summary> /// Create a new <see cref="Scrollbar"/>. /// </summary> /// /// <exception cref="Exception" /> public Scrollbar(IPositionedElement parent) : base(parent) { // Before the scrollbar items can be created, the required resources need to be created. Texture2D scrollbarSheet; if (UIContentManager.TryGetInstance(out UIContentManager manager)) { scrollbarSheet = manager.GetTexture("UI\\Scrollbar"); } else { throw new Exception("Could not retrieve scrollbar spritesheet."); } // Sprite definitions are created for the different sprites used by scrollbar items. Rectangle upButtonRect = new Rectangle(0, 0, 15, 15); SpriteDefinition upButtonDef = new SpriteDefinition(scrollbarSheet, upButtonRect); Rectangle downButtonRect = new Rectangle(15, 0, 15, 15); SpriteDefinition downButtonDef = new SpriteDefinition(scrollbarSheet, downButtonRect); Rectangle handleRect = new Rectangle(0, 15, 15, 20); SpriteDefinition handleDef = new SpriteDefinition(scrollbarSheet, handleRect); Rectangle backgroundRect = new Rectangle(15, 15, 15, 35); SpriteDefinition backgroundDef = new SpriteDefinition(scrollbarSheet, backgroundRect); // Finally, the items themselves can be created. _upButton = new Button(this, upButtonDef) { RelativePosition = Point.Zero, Size = new Point(15, 15), Focused = true, Visible = true }; _downButton = new Button(this, downButtonDef) { AnchorPosition = AnchorPosition.BottomLeft, RelativePosition = new Point(0, -15), Size = new Point(15, 15), Focused = true, Visible = true }; _handle = new RelativeTexture(this, handleDef) { Size = new Point(15, 20) }; _background = new RelativeTexture(this, backgroundDef) { RelativePosition = new Point(0, 15) }; _downButton.Hold += _downButton_Hold; _upButton.Hold += _upButton_Hold; ScrollPosition = 0F; }
public void RemoveSprite(SpriteDefinition sprite) { this.sheet.Remove(sprite); if (sprite == this.SelectedSprite) { this.SelectedSprite = null; } this.Refresh(); }
public void Render(string name, SpriteDefinition definition) { _definition = definition; _converted0 = new List <byte[]>(); _converted1 = new List <byte[]>(); _attached = string.Compare(definition.SpriteNumber, "attached", StringComparison.CurrentCultureIgnoreCase) == 0; ConvertSprite(name); }
private void FullSpriteRender() { Graphics g = Graphics.FromImage(SpriteBuffer); g.Clear(QuickColorLookup[0, 0]); g.Dispose(); if (_CurrentPalette == null) { return; } BitmapData data = SpriteBuffer.LockBits(new Rectangle(0, 0, SpriteBuffer.Width, 48), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); foreach (var s in SpriteList) { SpriteDefinition def = IsViewingMapSprites ? ProjectController.SpriteManager.GetMapDefinition(s.InGameID) : ProjectController.SpriteManager.GetDefinition(s.InGameID); foreach (var sp in def.Sprites) { if (sp.Table < 0) { continue; } if (sp.Property != null && !sp.Property.Contains(s.Property)) { continue; } if (!sp.HorizontalFlip && !sp.VerticalFlip) { RenderSprite(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), s.X * 16 + sp.X, s.Y * 16 + sp.Y, sp.Palette, data); RenderSprite(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), s.X * 16 + sp.X, (s.Y * 16 + sp.Y) + 8, sp.Palette, data); } else if (sp.HorizontalFlip && !sp.VerticalFlip) { RenderSpriteHorizontalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), s.X * 16 + sp.X, s.Y * 16 + sp.Y, sp.Palette, data); RenderSpriteHorizontalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), s.X * 16 + sp.X, (s.Y * 16 + sp.Y) + 8, sp.Palette, data); } else if (!sp.HorizontalFlip && sp.VerticalFlip) { RenderSpriteVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), s.X * 16 + sp.X, s.Y * 16 + sp.Y, sp.Palette, data); RenderSpriteVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), s.X * 16 + sp.X, (s.Y * 16 + sp.Y) + 8, sp.Palette, data); } else { RenderSpriteHorizontalVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), s.X * 16 + sp.X, s.Y * 16 + sp.Y, sp.Palette, data); RenderSpriteHorizontalVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), s.X * 16 + sp.X, (s.Y * 16 + sp.Y) + 8, sp.Palette, data); } } } SpriteBuffer.UnlockBits(data); }
/// <summary> /// Creates a single sprite definition from an image resource. /// </summary> /// <returns>The sprite definition.</returns> /// <param name="id">ID (including the mod's namespace) for the new sprite definition.</param> /// <param name="sprite_path">Relative resource path to the image.</param> public SpriteDefinition CreateSpriteDefinition(ID id, string sprite_path) { CheckMode(); id = GetFullID(id, true); var tex = Texture2DLoader.LoadTexture2D(GetFullResourcePath(sprite_path)); var mat = new Material(ShaderCache.Acquire(SpriteDefinition.DEFAULT_SHADER)); mat.mainTexture = tex; var sprite_def = SpriteDefinition.Construct(mat, id); return(sprite_def); }
public void SetVisuals(Animator animator, SpriteRenderer renderer) { animator.runtimeAnimatorController = SpriteDefinition.GetDefinition(_visuals); if (animator.runtimeAnimatorController == null) { animator.runtimeAnimatorController = _defaultVisuals; } renderer.material = PatternDefinition.GetDefinition(_patterns); if (renderer.material == null) { renderer.material = _defaultPattern; } }
public void AddNewSprite() { SpriteDefinition sprite = new SpriteDefinition(); sprite.X = 50; sprite.Y = 50; sprite.Width = 50; sprite.Height = 50; AddSprite(sprite); SpriteAdded(this, new SpriteEventArgs(sprite)); this.SelectedSprite = sprite; }
public void AddSprite(SpriteDefinition sprite) { if (!this.SelectedSheet.Contains(sprite)) { this.SelectedSheet.Add(sprite); } if (!this.imageList1.Images.ContainsKey(sprite.Name)) { Bitmap bitmap = GetImageFromTexture(sprite.Rectangle, SelectedSheet.Texture); this.imageList1.Images.Add(sprite.Name, bitmap); this.listView1.Items.Add(sprite.Name, sprite.Name, sprite.Name); } }
private GameObject GetObject(string objectTypeName, IFactoryManager manager, SpriteDefinition spriteDef, XElement xmlNode) { GameObject obj = null; switch (objectTypeName) { case "Sprite": case "AnimatedSprite": obj = LoadSprite(spriteDef, xmlNode); break; } return(obj); }
public static SpriteDefinition Read(BinaryReader br) { var result = new SpriteDefinition(); result.Position = br.ReadVector2(); result.Size = br.ReadVector2(); result.Origin = br.ReadVector2(); result.Border = br.ReadVector4(); result.TileX = br.ReadBoolean(); result.TileY = br.ReadBoolean(); result.Hollow = br.ReadBoolean(); result.Color = br.ReadString(); return(result); }
public Sprite LoadSprite(SpriteDefinition spriteDef, XElement xmlNode) { float x = 0; float y = 0; int zorder = 0; float rotation = 0; float alpha = 255; Color tint = Color.White; foreach (XElement element in xmlNode.Elements()) { switch (element.Name.LocalName) { case "Position": x = XmlConvert.ToSingle(element.Attribute("X").Value); y = XmlConvert.ToSingle(element.Attribute("Y").Value); break; case "ZOrder": zorder = XmlConvert.ToInt32(element.Value); break; case "Tint": tint = LoadTint(element); break; case "Alpha": alpha = XmlConvert.ToSingle(element.Value); break; case "Rotation": rotation = XmlConvert.ToSingle(element.Value); break; } } Sprite sprite = new Sprite(spriteDef); sprite.Position = new Vector2(x, y); sprite.ZOrder = zorder; sprite.Tint = tint; sprite.Alpha = alpha; sprite.Rotation = rotation; return(sprite); }
public void RemoveSprite(SpriteDefinition sprite) { if (sprite != null) { if (SelectedSheet.Contains(sprite)) { SpriteEventArgs e = new SpriteEventArgs(sprite); this.imageList1.Images.RemoveByKey(sprite.Name); this.listView1.Items.RemoveByKey(sprite.Name); SelectedSheet.Remove(sprite); if (sprite == SelectedSprite) { SelectedSprite = null; } SpriteRemoved(this, e); } } }
//Automatic layout private Image generateAutomaticLayout(Dictionary <string, SpriteDefinition> atlas) { var sortedByArea = from m in CreateModules() orderby m.Width *m.Height descending select m; List <Module> moduleList = sortedByArea.ToList <Module>(); Placement placement = Algorithm.Greedy(moduleList); //Creating an empty result image. uint minWidth = (uint)(placement.Width - layoutProp.distanceBetweenImages + 2 * layoutProp.marginWidth); uint minHeight = (uint)(placement.Height - layoutProp.distanceBetweenImages + 2 * layoutProp.marginWidth); if (layoutProp.powerOfTwo) { minWidth = FindNextPowerOfTwo(minWidth); minHeight = FindNextPowerOfTwo(minHeight); minWidth = minHeight = Math.Max(minWidth, minHeight); } Image resultSprite = new Bitmap((int)minWidth, (int)minHeight, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(resultSprite); //Drawing images into the result image in the original order and writing atlas data. foreach (Module m in placement.Modules) { m.Draw(graphics, layoutProp.marginWidth); Rectangle rectangle = new Rectangle(m.X + layoutProp.marginWidth, m.Y + layoutProp.marginWidth, m.Width - layoutProp.distanceBetweenImages, m.Height - layoutProp.distanceBetweenImages); SpriteDefinition def; if (metadata.ContainsKey(m.Name)) { def = metadata[m.Name].ToObject <SpriteDefinition>(); } else { def = new SpriteDefinition(); } def.Position = new Vector2(rectangle.X, rectangle.Y); def.Size = new Vector2(rectangle.Width, rectangle.Height); atlas.Add(spriteNames[m.Name], def); } return(resultSprite); }
protected override void OnMouseDown(MouseEventArgs e) { if (sheet != null) { SpriteDefinition sprite = GetSpriteFromMousePoint(e.X, e.Y); if (sprite != null) { PointPosition position = GetMousePosition(sprite.Rectangle, e.X, e.Y); if (position != PointPosition.Outside) { this.SelectedSprite = sprite; BeginOperation(e.X, e.Y); } } } base.OnMouseDown(e); }
/// <summary> /// Gets a rectangle that can bound the item visually and be used for click detection. /// </summary> public Rectangle GetCollisionRect() { switch (item.ItemType) { case ItemTypeIndex.Elevator: return(new Rectangle(112, 128, 32, 8)); case ItemTypeIndex.MotherBrain: return(new Rectangle(92, 24, 45, 40)); case ItemTypeIndex.Zebetite: var zebIndex = item.SpriteSlot; if (zebIndex == 1 || zebIndex == 3) { return(new Rectangle(24, 96, 8, 32)); } else { return(new Rectangle(152, 96, 8, 32)); } case ItemTypeIndex.Turret: var pos = ((IItemScreenPosition)item).ScreenPosition; return(new Rectangle(pos.X * 16, pos.Y * 16, 16, 16)); } // Try using generic sprite measurement if a special rect isn't provided. int x, y, p; SpriteDefinition sprite = GetSprite(out x, out y, out p); if (item.ItemType == ItemTypeIndex.Door) { return(new Rectangle(x * 8, y * 8, sprite.Width * 8 - 8, sprite.Height * 8)); } if (sprite != null) { return(new Rectangle(x * 8, y * 8, sprite.Width * 8, sprite.Height * 8)); } // Return no rect. return(Rectangle.Empty); }
public GameObject GetObject(string objectTypeName, IFactoryManager manager, Module.Module module, XElement xmlNode) { GameObject obj = null; SpriteDefinition spriteDef = null; string tag = string.Empty; string name = string.Empty; Guid id = Guid.Empty; foreach (XAttribute attribNode in xmlNode.Attributes()) { switch (attribNode.Name.LocalName) { case "Id": try { id = Guid.Parse(attribNode.Value); } catch (Exception) { } break; case "Name": name = attribNode.Value; break; case "Tag": tag = attribNode.Value; break; case "Ref": spriteDef = SpriteDefinition.LoadFromModule(module, attribNode.Value); break; } } obj = GetObject(objectTypeName, manager, spriteDef, xmlNode); obj.Id = id; obj.Name = name; obj.Tag = tag; return(obj); }
public Player() { SpriteDefinition spriteDef = new SpriteDefinition("PlayerBase", string.Empty, 1, 4, 64, 96); spriteDef.AnimationList.Add("Idle", new Animation("Idle", 0, 0, 0, false)); _PlayerSprite = new CompoundSprite(OrionEngine.Instance.GraphicsDM.GraphicsDevice); _BaseBodySprite = new AnimatedSprite(spriteDef); _BaseBodySprite.Animate("Idle"); _BaseBodySprite.ZOrder = 3; _PlayerSprite.AddSprite(_BaseBodySprite); _ArmBackSprite = new Sprite("ArmBack"); _ArmBackSprite.Origin = new Vector2(68, 56); _ArmBackSprite.Position = new Vector2(-2, 2); _PlayerSprite.AddSprite(_ArmBackSprite); _ArmFrontSprite = new Sprite("ArmFront"); _ArmFrontSprite.Origin = new Vector2(68, 56); _ArmFrontSprite.Position = new Vector2(0, 2); _ArmFrontSprite.ZOrder = 5; _PlayerSprite.AddSprite(_ArmFrontSprite); _GunSprite = new Sprite("Gun"); _GunSprite.Origin = new Vector2(44, 32); _GunSprite.Position = new Vector2(-10, 10); _GunSprite.ZOrder = 4; _PlayerSprite.AddSprite(_GunSprite); Attach(_PlayerSprite); CircleCollider collider = OrionEngine.Instance.GetComponent <PhysicsComponent>().CreateCircleCollider(Vector2.Zero, 48, 1, ColliderType.Dynamic); collider.Restitution = 0.01f; collider.Friction = 2.0f; collider.UseRotation = false; Attach(collider); }
void Initialize(Stream stream, Shader shader = null) { ThreadContext.Current.EnsureGLContext(); if (shader == null) { shader = new SpriteShader(); } int filterMode = 0; var defs = new Dictionary <string, SpriteDefinition>(); var tr = new TarReader(stream); while (tr.MoveNext(false)) { switch (tr.FileInfo.FileName) { case "atlas.bin": using (var atlasStream = new MemoryStream()) { tr.Read(atlasStream); atlasStream.Position = 0; using (var br = new BinaryReader(atlasStream)) { filterMode = br.ReadInt32(); for (var count = br.ReadInt32(); count > 0; --count) { var key = br.ReadString(); var value = SpriteDefinition.Read(br); defs.Add(key, value); } } } break; case "sheet.png": using (var sheetStream = new MemoryStream((int)tr.FileInfo.SizeInBytes)) { tr.Read(sheetStream); sheetStream.Position = 0; var tex = new Texture(sheetStream, new TextureSettings { MagFilter = filterMode > 0 ? TextureFilter.Linear : TextureFilter.Nearest, MinFilter = filterMode == 1 ? TextureFilter.Linear : filterMode == 2 ? TextureFilter.Trilinear : TextureFilter.Nearest, }); _material = new SpriteMaterial(shader, tex); } break; default: throw new ContentException("Unrecognized atlas file " + tr.FileInfo.FileName); } } if (defs == null) { throw new ContentException("Missing atlas file."); } if (_material == null) { throw new ContentException("Missing image file."); } _sprites = new Dictionary <string, Sprite>(); _vbuffer = new VertexBuffer(VertexFormat.PositionColorUV); _ibuffer = new IndexBuffer(); var vstride = _vbuffer.Format.Stride * 4; int vOffset = 0, iOffset = 0, vcount = 0; var vertices = new float[vstride * defs.Count]; var indices = new int[6 * defs.Count]; var tsz = new Vector2(_material.Texture.Size.Width, _material.Texture.Size.Height); foreach (var kvp in defs) { var def = kvp.Value; var pos = def.Position; var sz = def.Size; var orig = def.Origin; var color = ParseColor(def.Color); orig.X *= sz.X; orig.Y *= sz.Y; if (def.Border != Vector4.Zero) { _sprites.Add(kvp.Key, new SlicedSprite(_material, pos, sz, orig, color, def.Border, def.TileX, def.TileY, def.Hollow)); continue; } var uv = new Vector4( pos.X / tsz.X, ((pos.Y + sz.Y)) / tsz.Y, (pos.X + sz.X) / tsz.X, (pos.Y) / tsz.Y ); Array.Copy(new[] { -orig.X, -orig.Y, 0f, color.X, color.Y, color.Z, color.W, uv.X, uv.Y, sz.X - orig.X, -orig.Y, 0f, color.X, color.Y, color.Z, color.W, uv.Z, uv.Y, sz.X - orig.X, sz.Y - orig.Y, 0f, color.X, color.Y, color.Z, color.W, uv.Z, uv.W, -orig.X, sz.Y - orig.Y, 0f, color.X, color.Y, color.Z, color.W, uv.X, uv.W }, 0, vertices, vOffset, vstride); Array.Copy(new[] { vcount + 0, vcount + 1, vcount + 2, vcount + 2, vcount + 3, vcount + 0 }, 0, indices, iOffset, 6); var sprite = new Sprite(_material, sz, _vbuffer, _ibuffer, iOffset, 6); _sprites.Add(kvp.Key, sprite); vOffset += vstride; iOffset += 6; vcount += 4; } _vbuffer.Data = vertices; _vbuffer.Commit(); _ibuffer.Data = indices; _ibuffer.Commit(); }
//Automatic layout private Image generateAutomaticLayout(Dictionary<string, SpriteDefinition> atlas) { var sortedByArea = from m in CreateModules() orderby m.Width * m.Height descending select m; List<Module> moduleList = sortedByArea.ToList<Module>(); Placement placement = Algorithm.Greedy(moduleList); //Creating an empty result image. uint minWidth = (uint)(placement.Width - layoutProp.distanceBetweenImages + 2 * layoutProp.marginWidth); uint minHeight = (uint)(placement.Height - layoutProp.distanceBetweenImages + 2 * layoutProp.marginWidth); if (layoutProp.powerOfTwo) { minWidth = FindNextPowerOfTwo(minWidth); minHeight = FindNextPowerOfTwo(minHeight); minWidth = minHeight = Math.Max(minWidth, minHeight); } Image resultSprite = new Bitmap((int)minWidth, (int)minHeight, PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(resultSprite); //Drawing images into the result image in the original order and writing atlas data. foreach (Module m in placement.Modules) { m.Draw(graphics, layoutProp.marginWidth); Rectangle rectangle = new Rectangle(m.X + layoutProp.marginWidth, m.Y + layoutProp.marginWidth, m.Width - layoutProp.distanceBetweenImages, m.Height - layoutProp.distanceBetweenImages); SpriteDefinition def; if (metadata.ContainsKey(m.Name)) def = metadata[m.Name].ToObject<SpriteDefinition>(); else def = new SpriteDefinition(); def.Position = new Vector2(rectangle.X, rectangle.Y); def.Size = new Vector2(rectangle.Width, rectangle.Height); atlas.Add(spriteNames[m.Name], def); } return resultSprite; }
public SpriteEventArgs(SpriteDefinition sprite) { Sprite = sprite; }
public void ExternalURLDidChange(string json) { SpriteDefinition definition = SpriteDefinition.OfJson(json); ObservableURLOfKey(definition.FullKey).SetValue(definition.URL); }
public void RemoveSpriteFromSheet(SpriteDefinition sprite) { this.spritesSheetViewer1.RemoveSprite(sprite); this.propertyGrid1.SelectedObject = null; this.spritesSheetList1.RemoveSprite(sprite); }
public GameUI(Game game) : base(game) { orbis = (Orbis)game; logger = Logger.GetInstance(); logExporter = new LogExporter(); play = new SpriteDefinition(_contentManager.GetTexture("UI/Button_Play"), new Rectangle(0, 0, 96, 64)); pause = new SpriteDefinition(_contentManager.GetTexture("UI/Button_Pause"), new Rectangle(0, 0, 96, 64)); AddChild(playButton = new Button(this, play) { AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(-(RIGHT_UI_WIDTH - 96) / 2 - 96, -10), Size = new Point(96, 64), LayerDepth = 0, Focused = true }); AddChild(nextButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Next"), new Rectangle(0, 0, 70, 64))) { AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(-(RIGHT_UI_WIDTH - playButton.Size.X) / 2, -10), Size = new Point(70, 64), LayerDepth = 0, Focused = true }); AddChild(exportButton = new Button(this, new SpriteDefinition(_contentManager.GetTexture("UI/Button_Export"), new Rectangle(0, 0, 70, 64))) { AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(-(RIGHT_UI_WIDTH - playButton.Size.X) / 2 - playButton.Size.X - 70, -10), Size = new Point(70, 64), LayerDepth = 0, Focused = true }); playButton.Click += PlayButton_Click; nextButton.Click += NextButton_Click; exportButton.Click += ExportButton_Click; // Progress bar AddChild(progressBar = new ProgressBar(this) { AnchorPosition = AnchorPosition.BottomLeft, RelativePosition = new Point(20, -70), Size = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH - 40, 50), LayerDepth = 0 }); // Background for progressbar AddChild(backgroundProgressBar = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1))) { Size = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH, BOTTOM_UI_HEIGHT), AnchorPosition = AnchorPosition.BottomLeft, RelativePosition = new Point(0, -BOTTOM_UI_HEIGHT), LayerDepth = 1 }); // Background for UI AddChild(background = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1))) { Size = new Point(RIGHT_UI_WIDTH, _game.Window.ClientBounds.Height), AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(-RIGHT_UI_WIDTH, 0), LayerDepth = 1 }); // Background for UI AddChild(cellInfoBackground = new RelativeTexture(this, new SpriteDefinition(_contentManager.GetColorTexture(UI_COLOR), new Rectangle(0, 0, 1, 1))) { Size = new Point(RIGHT_UI_WIDTH, 300), AnchorPosition = AnchorPosition.BottomRight, RelativePosition = new Point(-RIGHT_UI_WIDTH * 2 - 10, -BOTTOM_UI_HEIGHT - 310), LayerDepth = 0.0000001f, Visible = false }); AddChild(text = new RelativeText(this, _contentManager.GetFont("DebugFont")) { Text = "", AnchorPosition = AnchorPosition.BottomRight, RelativePosition = new Point(-RIGHT_UI_WIDTH * 2, -BOTTOM_UI_HEIGHT - 300), LayerDepth = 0, Visible = false }); // Scene panel var sceneSize = new Point(_game.Window.ClientBounds.Width - RIGHT_UI_WIDTH, _game.Window.ClientBounds.Height - BOTTOM_UI_HEIGHT); AddChild(scene = new RelativeTexture(this, new SpriteDefinition( new RenderTarget2D(orbis.GraphicsDevice, sceneSize.X, sceneSize.Y), new Rectangle(0, 0, sceneSize.X, sceneSize.Y))) { Size = sceneSize, AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(0, 0), LayerDepth = 0.5f }); // Scene panel itself is invisible, we just use it for size and texture storage scene.Visible = false; AddChild(civPanel = new CivPanel(this, orbis.Scene.Civilizations) { AnchorPosition = AnchorPosition.TopRight, RelativePosition = new Point(-RIGHT_UI_WIDTH, 64), Size = new Point(RIGHT_UI_WIDTH, game.Window.ClientBounds.Height - 64), LayerDepth = 0.99F }); screenResized = true; }
public void AddNewSprite(SpriteDefinition sprite) { this.spritesSheetViewer1.AddSprite(sprite); this.spritesSheetList1.AddSprite(sprite); }
private void FullSpriteRender(Rectangle rect) { if (rect.X < 0) { rect.X = 0; } if (rect.Y < 0) { rect.Y = 0; } if (rect.X > SpriteBuffer.Width) { rect.X = SpriteBuffer.Width; } if (rect.Y > SpriteBuffer.Height) { rect.Y = SpriteBuffer.Height; } if ((rect.X + rect.Width) > SpriteBuffer.Width) { rect.Width = SpriteBuffer.Width - rect.X; } if ((rect.Y + rect.Height) > SpriteBuffer.Height) { rect.Height = SpriteBuffer.Height - rect.Y; } if (_CurrentPalette == null) { return; } BitmapData data = SpriteBuffer.LockBits(rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); ClearAreaWithTransparentcolor(rect.Width, rect.Height, data); int definiteX, definiteY; foreach (var s in CurrentWorld.SpriteData) { SpriteDefinition def = ProjectController.SpriteManager.GetMapDefinition(s.InGameID); if (def == null) { continue; } foreach (var sp in def.Sprites) { if (sp.Table < 0) { continue; } definiteX = s.X * 16 + sp.X; definiteY = s.Y * 16 + sp.Y; if ((definiteX + 8) < rect.X || definiteX - 8 > rect.X + rect.Width) { continue; } if ((definiteY + 16) < rect.Y || definiteY - 16 > rect.Y + rect.Height) { continue; } definiteX = definiteX - rect.X; definiteY = definiteY - rect.Y; if (!sp.HorizontalFlip && !sp.VerticalFlip) { RenderSprite(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), definiteX, definiteY, sp.Palette, data); RenderSprite(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), definiteX, (definiteY) + 8, sp.Palette, data); } else if (sp.HorizontalFlip && !sp.VerticalFlip) { RenderSpriteHorizontalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), definiteX, definiteY, sp.Palette, data); RenderSpriteHorizontalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), definiteX, (definiteY) + 8, sp.Palette, data); } else if (!sp.HorizontalFlip && sp.VerticalFlip) { RenderSpriteVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), definiteX, definiteY, sp.Palette, data); RenderSpriteVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), definiteX, (definiteY) + 8, sp.Palette, data); } else { RenderSpriteHorizontalVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value + 1), definiteX, definiteY, sp.Palette, data); RenderSpriteHorizontalVerticalFlip(ProjectController.GraphicsManager.QuickTileGrab(sp.Table, sp.Value), definiteX, (definiteY) + 8, sp.Palette, data); } } } SpriteBuffer.UnlockBits(data); }
public SpriteListItem(SpriteDefinition sprite, int palIndex, Point location) { this.sprite = sprite; this.palette = palIndex; this.location = location; }