Beispiel #1
0
    /// <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);
        }

        TuxjuniorObjectAttribute objectAttribute = (TuxjuniorObjectAttribute)Attribute.GetCustomAttribute(type, typeof(TuxjuniorObjectAttribute));

        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);
    }
Beispiel #2
0
    public void CustomLispRead(Properties Props)
    {
        foreach (Type type in this.GetType().Assembly.GetTypes())
        {
            TuxjuniorObjectAttribute objectAttribute
                = (TuxjuniorObjectAttribute)Attribute.GetCustomAttribute(type, typeof(TuxjuniorObjectAttribute));
            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);
            }
        }
    }
Beispiel #3
0
    public void CustomLispWrite(Writer Writer)
    {
        Type[] types = this.GetType().Assembly.GetTypes();
        Array.Sort(types, CompareTypeNames);
        foreach (Type type in types)
        {
            TuxjuniorObjectAttribute objectAttribute = (TuxjuniorObjectAttribute)
                                                       Attribute.GetCustomAttribute(type, typeof(TuxjuniorObjectAttribute));
            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())
        {
            TuxjuniorObjectAttribute objectAttribute
                = (TuxjuniorObjectAttribute)Attribute.GetCustomAttribute(type, typeof(TuxjuniorObjectAttribute));
            if (objectAttribute == null)
            {
                continue;
            }

            if (objectAttribute.Target == TuxjuniorObjectAttribute.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 == TuxjuniorObjectAttribute.Usage.WorldmapOnly) &&
                    (!level.isWorldmap))
                {
                    continue;
                }
                else if ((objectAttribute.Target == TuxjuniorObjectAttribute.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();
    }