public object FindCels(params object[] args) { var thing = Evaluate(args[0]); var cel = thing as Cel; if (cel != null) { return(cel); } var str = thing.ToString(); var cels = Cels.Where(o => o.ID == str).Cast <object>().ToList(); if (cels.Count == 1) { return(cels[0]); } return(cels); }
private object CelsOrPart(object args) { args = Evaluate(args); if (args is Part) { return((Part)args); } if (args is Cel) { return((Cel)args); } if (args is List <object> ) { return((List <object>)args); } var id = Evaluate <string>(args); if (id.Contains('/')) { var objID = id.Remove(id.IndexOf('/')); var celID = id.Substring(id.IndexOf('/') + 1); var obj = Parts.FirstOrDefault(o => o.ID == objID); if (obj == null) { return(null); } if (celID.Contains('?') || celID.Contains('*')) { return(obj.Cels.Where(o => o.ID.SplatMatch(celID)).Cast <object>().ToList()); } return(obj.Cels.Where(o => o.ID == celID).Cast <object>().ToList()); } else if (id.Contains('?') || id.Contains('*')) { return(Cels.Where(o => o.ID.SplatMatch(id)).Cast <object>().ToList()); } var cels = Cels.Where(o => o.ID == id).Cast <object>().ToList(); if (cels.Count == 0) { return(Parts.FirstOrDefault(o => o.ID == id)); } return(cels); }
protected override void UpdateSpritesCache() { Sprites.Clear(); SpritesLeft.Clear(); for (var i = 0; i < Cels.arraySize; i++) { var frameProp = Cels.GetArrayElementAtIndex(i); var sprite = frameProp.FindPropertyRelative("sprite").objectReferenceValue as Sprite; if (sprite != null) { Sprites.Add(sprite); } var spriteLeft = frameProp.FindPropertyRelative("spriteLeft").objectReferenceValue as Sprite; if (spriteLeft != null) { SpritesLeft.Add(spriteLeft); } } }
public void DrawToBitmap() { if (palette != null) { var colorMap = new ColorMap[palette.Width]; for (var i = 0; i < palette.Width; i++) { var sourceColor = palette.GetPixel(i, 0); var targetColor = palette.GetPixel(i, Palette); colorMap[i] = new ColorMap() { OldColor = sourceColor, NewColor = targetColor }; } attrs.SetRemapTable(colorMap); } if (gfx == null) { gfx = Graphics.FromImage(Bitmap); gfx.InterpolationMode = InterpolationMode.NearestNeighbor; } if (Background is Color) { gfx.Clear((Color)Background); } else if (Background is Brush) { gfx.FillRectangle((Brush)Background, 0, 0, ScreenWidth, ScreenHeight); } else if (Background is Bitmap) { gfx.DrawImage((Bitmap)Background, 0, 0, ScreenWidth, ScreenHeight); } else { gfx.Clear(Color.CornflowerBlue); } foreach (var cel in Cels.Reverse <Cel>()) { var part = cel.Part; if (!cel.OnSet) { continue; } if (!cel.Visible) { continue; } if (cel.Opacity == 0) { continue; } matrix[3][3] = cel.Opacity / 256.0f; if (Viewer.XRay) { matrix[3][3] *= 0.5f; } attrs.SetColorMatrix(new ColorMatrix(matrix)); try { gfx.DrawImage(cel.Image, new Rectangle(cel.Part.Position.X + cel.Offset.X, cel.Part.Position.Y + cel.Offset.Y, cel.Image.Width, cel.Image.Height), 0, 0, cel.Image.Width, cel.Image.Height, GraphicsUnit.Pixel, attrs); } catch (Exception) { } } }
public Cel ParseCelForm(List <object> celItem) { Bitmap image = null; var file = ""; var id = ""; var partof = ""; var alpha = 255; var positions = new List <object>() { 0, 0 }; var offset = new List <object>() { 0, 0 }; var on = defaultOn; //"0123456789"; var fix = 0; var newPos = false; var newFix = false; var mapped = true; var ghosted = false; var labelText = ""; var labelWidth = 0; var labelFont = new Font("Tahoma", 8); var labelColor = Color.Black; var labelCenter = false; var celType = ""; for (var i = 0; i < celItem.Count; i++) { var form = celItem[i] as Symbol; switch (form) { case null: break; case "file": { i++; file = celItem[i] as string; if (id == "") { id = file; } if (partof == "") { partof = id; } celType = "pic"; } break; case "label": { celType = "label"; } break; case "button": { i++; file = celItem[i] as string; celType = "button"; } break; case "id": { i++; if (partof == id) { partof = ""; } id = celItem[i] as string; if (partof == "") { partof = id; } } break; case "partof": { i++; partof = celItem[i] as string; } break; case "alpha": { i++; alpha = (int)celItem[i]; } break; case "pos": { i++; positions = celItem[i] as List <object>; newPos = true; } break; case "offset": { i++; offset = celItem[i] as List <object>; } break; case "fix": { i++; fix = (int)celItem[i]; newFix = true; } break; case "locked": { fix = MaxFix; newFix = true; } break; case "on": { i++; on = celItem[i] as string; } break; case "unmapped": { mapped = false; } break; case "ghost": { ghosted = true; } break; case "group": break; case "text": { i++; labelText = celItem[i] as string; } break; case "width": { i++; labelWidth = (int)celItem[i]; } break; case "color": { i++; var bgi = celItem[i] as List <object>; if (bgi.Count == 3 && bgi[0] is int && bgi[1] is int && bgi[2] is int) { labelColor = Color.FromArgb((int)bgi[0], (int)bgi[1], (int)bgi[2]); } } break; case "font": { i++; var f = labelFont.Name; var p = labelFont.Size; var s = FontStyle.Regular; if (celItem[i] is string) { f = celItem[i] as string; } else if (celItem[i] is List <object> ) { var bgi = celItem[i] as List <object>; f = bgi[0] as string; if (bgi.Count > 1) { p = (int)bgi[1]; } if (bgi.Count > 2) { for (var j = 2; j < bgi.Count; j++) { if (bgi[j] is Symbol && (Symbol)bgi[j] == "bold") { s |= FontStyle.Bold; } if (bgi[j] is Symbol && (Symbol)bgi[j] == "italic") { s |= FontStyle.Italic; } if (bgi[j] is Symbol && (Symbol)bgi[j] == "center") { labelCenter = true; } } } } labelFont = new Font(f, p, s); } break; } } //try to preload the image if (celType == "pic" || celType == "button") { try { image = Tools.GrabClonedBitmap(file + ".png", Mix); } catch (System.IO.FileNotFoundException ex) { DarkUI.Forms.DarkMessageBox.ShowWarning(ex.Message, Application.ProductName); return(null); } } //find the partof object var part = Parts.FirstOrDefault(o => o.ID == partof); if (part == null) { part = new Part(this) { ID = partof, Cels = new List <Cel>(), }; Parts.Add(part); } if (newPos) { if (positions[0] is int) { //pos (12 34) --> pos ((12 34)) positions = new List <object>() { positions }; } while (positions.Count < 10) { positions.Add(positions[0]); } for (var i = 0; i < 10; i++) { if (positions[i] is Symbol && positions[i].ToString() == "*") { if (i == 0) { positions[i] = new List <object>() { 0, 0 } } ; else { positions[i] = positions[0]; } } var pos = positions[i] as List <object>; part.Positions[i] = new Point((int)pos[0], (int)pos[1]); if (pos.Count > 2 && pos[2].ToString() == ">") { pos.RemoveAt(2); for (var j = i + 1; j < 10; j++) { positions[j] = positions[i]; } } } for (var i = 0; i < 10; i++) { part.InitialPositions[i] = part.Positions[i]; } } if (newFix) { part.Fix = part.InitialFix = fix; } var c = new Cel(this) { Image = image, ImageFilename = file + ".png", Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; if (celType == "label") { c = new TextCel(this) { Width = labelWidth, Color = labelColor, Font = labelFont, Centered = labelCenter, Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; ((TextCel)c).Text = labelText; ((TextCel)c).Draw(); } if (celType == "button") { c = new ButtonCel(this, c) { Visible = mapped, ID = id, Opacity = alpha, Ghost = ghosted, }; ((ButtonCel)c).Draw(); } foreach (var s in on) { if (!char.IsDigit(s)) { continue; } var i = (int)(s - '0'); c.OnSets[i] = true; } c.Offset = new Point((int)offset[0], (int)offset[1]); c.Part = part; part.Cels.Add(c); part.UpdateBounds(); Cels.Add(c); return(c); }