/// <summary>Create sprite from name of badguy's class</summary> private Sprite CrateSprite(string classname) { Type type = this.GetType().Assembly.GetType(classname, false, true); //case-insensitive search if (type == null) { LogManager.Log(LogLevel.Warning, "No type found for " + classname); return(null); } SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { LogManager.Log(LogLevel.Warning, "No objectAttribute found for " + classname); return(null); } Sprite result = null; // Might be a sprite try{ result = SpriteManager.Create(objectAttribute.IconSprite); } catch { } if (result != null) // Try to find a nice action. { try { result.Action = objectAttribute.ObjectListAction; } catch { try { result.Action = "left"; } catch { try { result.Action = "normal"; } catch { try { result.Action = "default"; } catch { LogManager.Log(LogLevel.DebugWarning, "BadguyChooserWidget: No action selected for " + objectAttribute.IconSprite); } } } } } else // Not a sprite so it has to be an Image. { try{ result = SpriteManager.CreateFromImage(objectAttribute.IconSprite); } catch (Exception) { result = null; } } if (result == null) { LogManager.Log(LogLevel.Warning, "No editor image found for " + classname); return(null); } return(result); }
public void CustomLispWrite(Writer Writer) { if (SortObjectTags) { var attributes = new List <Tuple <Type, SupertuxObjectAttribute> >(); foreach (Type type in GetType().Assembly.GetTypes()) { var attr = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (attr != null) { attributes.Add(Tuple.Create(type, attr)); } } attributes.Sort((lhs, rhs) => lhs.Item2.Name.CompareTo(rhs.Item2.Name)); foreach (var attr in attributes) { LispSerializer serializer = new LispSerializer(attr.Item1); foreach (var obj in GetObjects(attr.Item1)) { serializer.Write(Writer, attr.Item2.Name, obj); } } } else { foreach (object obj in GetObjects()) { Type type = obj.GetType(); SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute) Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } string name = objectAttribute.Name; LispSerializer serializer = new LispSerializer(type); serializer.Write(Writer, name, obj); } } }
public void CustomLispRead(Properties Props) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } LispSerializer serializer = new LispSerializer(type); foreach (List list in Props.GetList(objectAttribute.Name)) { IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); } } }
public void CustomLispWrite(Writer Writer) { Type[] types = this.GetType().Assembly.GetTypes(); Array.Sort(types, CompareTypeNames); foreach (Type type in types) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute) Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } string name = objectAttribute.Name; LispSerializer serializer = new LispSerializer(type); foreach (object Object in GetObjects(type)) { serializer.Write(Writer, name, Object); } } }
/// <summary>Create object list</summary> /// <remarks>Loading Images need Gl context so this has to be called from DrawGl</remarks> private void LoadObjectImages() { if (objectsLoaded) { return; } // Reinitialize gameObjectTypes.Clear(); gameObjectSprites.Clear(); // The null object (arrow) gameObjectTypes.Add(null); gameObjectSprites.Add(CreateSprite("images/engine/editor/arrow.png", null)); foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } if (objectAttribute.Target == SupertuxObjectAttribute.Usage.None) { continue; } // We load all objects if no level is loaded to avoid crash // when accessing the level object (as that is null // when no level is loaded). if (this.level != null) { if ((objectAttribute.Target == SupertuxObjectAttribute.Usage.WorldmapOnly) && (!level.isWorldmap)) { continue; } else if ((objectAttribute.Target == SupertuxObjectAttribute.Usage.LevelOnly) && (level.isWorldmap)) { continue; } } Sprite icon = CreateSprite(objectAttribute.IconSprite, objectAttribute.ObjectListAction); if (icon == null) //no sprite, no image, no can do. { LogManager.Log(LogLevel.Warning, "ObjectListWidget: Can't create an icon for " + objectAttribute.Name + " from " + objectAttribute.IconSprite); } else { gameObjectTypes.Add(type); gameObjectSprites.Add(icon); } } objectsLoaded = true; updateScrollbar(); }
public void CustomLispRead(Properties Props) { if (SortObjectTags) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } LispSerializer serializer = new LispSerializer(type); foreach (List list in Props.GetList(objectAttribute.Name)) { try { IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); } catch (System.NullReferenceException) { if (type == typeof(MusicObject) || type == typeof(AmbientLightObject)) { // ignore errors here due to the given fields being // turned from properties to objects } else { Console.WriteLine("Unexpected error while parsing object: {0} {1}", type, list); throw; } } } } } else { // FIXME: this is all just a hack to make the // editor not reorder the elements on load, // could be done nicer. foreach (List list in Props.GetList()) { foreach (Type type in this.GetType().Assembly.GetTypes()) { SupertuxObjectAttribute objectAttribute = (SupertuxObjectAttribute)Attribute.GetCustomAttribute(type, typeof(SupertuxObjectAttribute)); if (objectAttribute == null) { continue; } if (objectAttribute.Name == (list[0] as Symbol).Name) { LispSerializer serializer = new LispSerializer(type); IGameObject Object = (IGameObject)serializer.Read(list); GameObjects.Add(Object); break; } } } } }