public static GUILayoutSettings Load(XElement element) { var layout = new GUILayoutSettings(); var relativeSize = XMLExtensions.GetAttributeVector2(element, "relativesize", Vector2.Zero); var absoluteSize = XMLExtensions.GetAttributePoint(element, "absolutesize", new Point(-1000, -1000)); var relativeOffset = XMLExtensions.GetAttributeVector2(element, "relativeoffset", Vector2.Zero); var absoluteOffset = XMLExtensions.GetAttributePoint(element, "absoluteoffset", new Point(-1000, -1000)); if (relativeSize.Length() > 0) { layout.RelativeSize = relativeSize; } if (absoluteSize.X > 0 && absoluteSize.Y > 0) { layout.AbsoluteSize = absoluteSize; } if (relativeOffset.Length() > 0) { layout.RelativeOffset = relativeOffset; } if (absoluteOffset.X > -1000 && absoluteOffset.Y > -1000) { layout.AbsoluteOffset = absoluteOffset; } if (Enum.TryParse(XMLExtensions.GetAttributeString(element, "anchor", ""), out Anchor a)) { layout.Anchor = a; } if (Enum.TryParse(XMLExtensions.GetAttributeString(element, "pivot", ""), out Pivot p)) { layout.Pivot = p; } return(layout); }
protected void ReloadGuiFrame() { if (GuiFrame != null) { ReleaseGuiFrame(); } Color?color = null; if (GuiFrameSource.Attribute("color") != null) { color = GuiFrameSource.GetAttributeColor("color", Color.White); } string style = GuiFrameSource.Attribute("style") == null ? null : GuiFrameSource.GetAttributeString("style", ""); GuiFrame = new GUIFrame(RectTransform.Load(GuiFrameSource, GUI.Canvas.ItemComponentHolder, Anchor.Center), style, color); DefaultLayout = GUILayoutSettings.Load(GuiFrameSource); if (GuiFrame != null) { GuiFrame.RectTransform.ParentChanged += OnGUIParentChanged; } GameMain.Instance.ResolutionChanged += OnResolutionChanged; }
private bool LoadElemProjSpecific(XElement subElement) { switch (subElement.Name.ToString().ToLowerInvariant()) { case "guiframe": if (subElement.Attribute("rect") != null) { DebugConsole.ThrowError("Error in item config \"" + item.ConfigFile + "\" - GUIFrame defined as rect, use RectTransform instead."); break; } Color?color = null; if (subElement.Attribute("color") != null) { color = subElement.GetAttributeColor("color", Color.White); } string style = subElement.Attribute("style") == null ? null : subElement.GetAttributeString("style", ""); GuiFrame = new GUIFrame(RectTransform.Load(subElement, GUI.Canvas), style, color); DefaultLayout = GUILayoutSettings.Load(subElement); break; case "alternativelayout": AlternativeLayout = GUILayoutSettings.Load(subElement); break; case "itemsound": case "sound": string filePath = subElement.GetAttributeString("file", ""); if (filePath == "") { filePath = subElement.GetAttributeString("sound", ""); } if (filePath == "") { DebugConsole.ThrowError("Error when instantiating item \"" + item.Name + "\" - sound with no file path set"); break; } if (!filePath.Contains("/") && !filePath.Contains("\\") && !filePath.Contains(Path.DirectorySeparatorChar)) { filePath = Path.Combine(Path.GetDirectoryName(item.Prefab.ConfigFile), filePath); } ActionType type; try { type = (ActionType)Enum.Parse(typeof(ActionType), subElement.GetAttributeString("type", ""), true); } catch (Exception e) { DebugConsole.ThrowError("Invalid sound type in " + subElement + "!", e); break; } RoundSound sound = Submarine.LoadRoundSound(subElement); if (sound == null) { break; } ItemSound itemSound = new ItemSound(sound, type, subElement.GetAttributeBool("loop", false)) { VolumeProperty = subElement.GetAttributeString("volumeproperty", "").ToLowerInvariant() }; if (soundSelectionModes == null) { soundSelectionModes = new Dictionary <ActionType, SoundSelectionMode>(); } if (!soundSelectionModes.ContainsKey(type) || soundSelectionModes[type] == SoundSelectionMode.Random) { SoundSelectionMode selectionMode = SoundSelectionMode.Random; Enum.TryParse(subElement.GetAttributeString("selectionmode", "Random"), out selectionMode); soundSelectionModes[type] = selectionMode; } List <ItemSound> soundList = null; if (!sounds.TryGetValue(itemSound.Type, out soundList)) { soundList = new List <ItemSound>(); sounds.Add(itemSound.Type, soundList); } soundList.Add(itemSound); break; default: return(false); //unknown element } return(true); //element processed }