/// <summary>
 /// Load entity templates from an xml file
 /// </summary>
 /// <param name="path">path to xml file</param>
 public void LoadTemplateFromXML(string path)
 {
     XElement tmp = XDocument.Load(path).Element("EntityTemplates");
     IEnumerable<XElement> templates = tmp.Elements("EntityTemplate");
     foreach (XElement e in templates)
     {
         var newTemplate = new EntityTemplate(EntityManager);
         newTemplate.LoadFromXml(e);
         AddTemplate(newTemplate);
     }
 }
        public EntitySpawnSelectButton(EntityTemplate entityTemplate, string templateName,
                                       IResourceManager resourceManager)
        {
            _resourceManager = resourceManager;

            var spriteNameParam = entityTemplate.GetBaseSpriteParamaters().FirstOrDefault();
            string SpriteName = "";
            if (spriteNameParam != null)
            {
                SpriteName = spriteNameParam.GetValue<string>();
            }
            string ObjectName = entityTemplate.Name;

            associatedTemplate = entityTemplate;
            associatedTemplateName = templateName;

            objectSprite = _resourceManager.GetSprite(SpriteName);

            font = _resourceManager.GetFont("CALIBRI");
            name = new TextSprite("Label" + SpriteName, "Name", font);
            name.Color = Color.Black;
            name.Text = ObjectName;
        }
        private void NewButtonClicked(EntitySpawnSelectButton sender, EntityTemplate template, string templateName)
        {
            if (sender.selected)
            {
                sender.selected = false;
                _placementManager.Clear();
                return;
            }

            foreach (
                GuiComponent curr in
                    _entityList.components.Where(curr => curr.GetType() == typeof (EntitySpawnSelectButton)))
                ((EntitySpawnSelectButton) curr).selected = false;

            string overrideMode = "";
            if (_lstOverride.CurrentlySelected != null)
                if (_lstOverride.CurrentlySelected.Text.Text != "None")
                    overrideMode = _lstOverride.CurrentlySelected.Text.Text;

            var newObjInfo = new PlacementInformation
                                 {
                                     PlacementOption = overrideMode.Length > 0 ? overrideMode : template.PlacementMode,
                                     EntityType = templateName,
                                     Range = -1,
                                     IsTile = false
                                 };

            _placementManager.BeginPlacing(newObjInfo);

            sender.selected = true; //This needs to be last.
        }
        private void PreparePlacement(string templateName)
        {
            EntityTemplate template =
                IoCManager.Resolve<IEntityManagerContainer>().EntityManager.EntityTemplateDatabase.GetTemplate(
                    templateName);
            if (template == null) return;

            ComponentParameter spriteParam = template.GetBaseSpriteParamaters().FirstOrDefault();
            //Will break if states not ordered correctly.
            //if (spriteParam == null) return;

            var spriteName = spriteParam == null?"":spriteParam.GetValue<string>();
            Sprite sprite = ResourceManager.GetSprite(spriteName);

            CurrentBaseSprite = sprite;
            CurrentBaseSpriteKey = spriteName;
            CurrentTemplate = template;

            IsActive = true;
        }
 public void Clear()
 {
     CurrentBaseSprite = null;
     CurrentTemplate = null;
     CurrentPermission = null;
     CurrentMode = null;
     if (PlacementCanceled != null && IsActive && !Eraser) PlacementCanceled(this, null);
     IsActive = false;
     Eraser = false;
 }
Beispiel #6
0
 /// <summary>
 /// Add a template directly to the database -- used for creating a template in code instead of xml
 /// </summary>
 /// <param name="template">the template to add</param>
 public void AddTemplate(EntityTemplate template)
 {
     m_templates.Add(template.Name, template);
 }
 /// <summary>
 /// Add a template directly to the database -- used for creating a template in code instead of xml
 /// </summary>
 /// <param name="template">the template to add</param>
 public void AddTemplate(EntityTemplate template)
 {
     m_templates.Add(template.Name, template);
 }