private void BuildTileList(string searchStr = null)
        {
            int maxWidth = 0;
            int yOffset  = 5;

            _tileList.components.Clear();
            _tileList.ResetScrollbars();

            Type            type  = typeof(Tile);
            List <Assembly> asses = AppDomain.CurrentDomain.GetAssemblies().ToList();
            List <Type>     types =
                asses.SelectMany(t => t.GetTypes()).Where(p => type.IsAssignableFrom(p) && !p.IsAbstract).ToList();

            IEnumerable <string> rawNames = from a in types
                                            select a.Name;

            if (types.Count > 255)
            {
                throw new ArgumentOutOfRangeException("types.Count", "Can not load more than 255 types of tiles.");
            }


            List <string> typeNames = (searchStr == null)
                                         ? rawNames.ToList()
                                         : rawNames.Where(x => x.ToLower().Contains(searchStr.ToLower())).ToList();

            if (searchStr != null)
            {
                _clearLabel.BackgroundColor = Color.LightGray;
            }

            foreach (string entry in typeNames)
            {
                var tileLabel = new Label(entry, "CALIBRI", _resourceManager);
                _tileList.components.Add(tileLabel);
                tileLabel.Position       = new Point(5, yOffset);
                tileLabel.DrawBackground = true;
                tileLabel.DrawBorder     = true;
                tileLabel.Update(0);
                yOffset           += 5 + tileLabel.ClientArea.Height;
                tileLabel.Clicked += TileLabelClicked;
                if (tileLabel.ClientArea.Width > maxWidth)
                {
                    maxWidth = tileLabel.ClientArea.Width;
                }
            }

            foreach (GuiComponent curr in _tileList.components.Where(curr => curr.GetType() == typeof(Label)))
            {
                ((Label)curr).FixedWidth = maxWidth;
            }
        }
Exemple #2
0
        private void BuildEntityList(string searchStr = null)
        {
            int maxWidth = 0;
            int yOffset  = 5;

            _entityList.components.Clear();
            _entityList.ResetScrollbars();

            List <KeyValuePair <string, EntityTemplate> > templates = (searchStr == null)
                                                                       ? IoCManager.Resolve <IEntityManagerContainer>()
                                                                      .EntityManager.EntityTemplateDatabase.
                                                                      Templates.ToList()
                                                                       : IoCManager.Resolve <IEntityManagerContainer>()
                                                                      .EntityManager.EntityTemplateDatabase.
                                                                      Templates.Where(
                x =>
                x.Value.Name.ToLower().Contains(
                    searchStr.ToLower())).ToList();


            if (searchStr != null)
            {
                _clearLabel.BackgroundColor = Color.LightGray;
            }

            foreach (
                EntitySpawnSelectButton newButton in
                templates.Select(entry => new EntitySpawnSelectButton(entry.Value, entry.Key, _resourceManager)))
            {
                _entityList.components.Add(newButton);
                newButton.Position = new Point(5, yOffset);
                newButton.Update(0);
                yOffset           += 5 + newButton.ClientArea.Height;
                newButton.Clicked += NewButtonClicked;

                if (newButton.ClientArea.Width > maxWidth)
                {
                    maxWidth = newButton.ClientArea.Width;
                }
            }

            foreach (
                GuiComponent curr in
                _entityList.components.Where(curr => curr.GetType() == typeof(EntitySpawnSelectButton)))
            {
                ((EntitySpawnSelectButton)curr).fixed_width = maxWidth;
            }
        }