private MyGuiControlButton MakeButtonCategory(Vector2 position, MySteamWorkshop.Category category) { var idWithoutSpaces = category.Id.Replace(" ", ""); var button = MakeButtonTiny(position, 0f, category.LocalizableName, new MyGuiHighlightTexture { Normal = string.Format(@"Textures\GUI\Icons\buttons\{0}.dds", idWithoutSpaces), Highlight = string.Format(@"Textures\GUI\Icons\buttons\{0}Highlight.dds", idWithoutSpaces), SizePx = new Vector2(64f, 64f), }, OnCategoryButtonClick); button.UserData = category.Id; button.HighlightType = MyGuiControlHighlightType.FORCED; m_categoryButtonList.Add(button); return(button); }
void ProcessTags() { // TODO: This code could be better. // Get the list of existing tags, if there are any var existingTags = GetTags(); var length = m_tags.Length; // Order or tag processing matters // 1) Copy mod type into tags var modtype = m_type.ToString(); // 2) Verify the modtype matches what was listed in the workshop // TODO If type doesn't match, process as workshop type if (existingTags != null && existingTags.Length > 0) { MyDebug.AssertDebug(existingTags.Contains(modtype), string.Format("Mod type '{0}' does not match workshop '{1}'", modtype, existingTags[0])); } // 3a) check if user passed in the 'development' tag // If so, remove it, and mark the mod as 'dev' so it doesn't get flagged later if (m_tags.Contains(MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG)) { m_tags = (from tag in m_tags where tag != MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG select tag).ToArray(); m_isDev = true; } // 3b If tags contain mod type, remove it if (m_tags.Contains(modtype)) { m_tags = (from tag in m_tags where tag != modtype select tag).ToArray(); } // 4) if (m_tags.Length == 1 && m_tags[0] == null && existingTags != null && existingTags.Length > 0) { // 4a) If user passed no tags, use existing ones Array.Resize(ref m_tags, existingTags.Length); Array.Copy(existingTags, m_tags, existingTags.Length); } else { // 4b) Verify passed in tags are valid for this mod type MySteamWorkshop.Category[] validTags = new MySteamWorkshop.Category[0]; switch (m_type) { case WorkshopType.Mod: validTags = MySteamWorkshop.ModCategories; break; case WorkshopType.Blueprint: validTags = MySteamWorkshop.BlueprintCategories; break; case WorkshopType.Scenario: validTags = MySteamWorkshop.ScenarioCategories; break; case WorkshopType.World: validTags = MySteamWorkshop.WorldCategories; break; case WorkshopType.IngameScript: //tags = new MySteamWorkshop.Category[0]; // There are none currently break; default: MyDebug.FailRelease("Invalid category."); break; } // This query gets all the items in 'm_tags' that do *not* exist in 'validTags' // This is for detecting invalid tags passed in var invalidItems = from utag in m_tags where !( from tag in validTags select tag.Id ).Contains(utag) select utag; if (invalidItems.Count() > 0) { MySandboxGame.Log.WriteLineAndConsole(string.Format("{0} invalid tags: {1}", (m_force ? "Forced" : "Removing"), string.Join(", ", invalidItems))); if (!m_force) { m_tags = (from tag in m_tags where !invalidItems.Contains(tag) select tag).ToArray(); } } // Now prepend the 'Type' tag string[] newTags = new string[m_tags.Length + 1]; newTags[0] = m_type.ToString(); Array.Copy(m_tags, 0, newTags, 1, m_tags.Length); m_tags = newTags; } // 5) Set or clear development tag if (m_isDev) { // If user selected dev, add dev tag if (!m_tags.Contains(MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG)) { Array.Resize(ref m_tags, m_tags.Length + 1); m_tags[m_tags.Length - 1] = MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG; } } else { // If not, remove tag if (m_tags.Contains(MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG)) { m_tags = (from tag in m_tags where tag != MySteamWorkshop.WORKSHOP_DEVELOPMENT_TAG select tag).ToArray(); } } // 6) Strip empty values m_tags = m_tags.Where(x => !string.IsNullOrEmpty(x)).ToArray(); // Done MySandboxGame.Log.WriteLineAndConsole(string.Format("Publishing with tags: {0}", string.Join(", ", m_tags))); }