private void SetupMainPanel() { panelMain = new BaseElement { Width = { Percent = 100 }, Height = { Pixels = -28, Percent = 100 }, Y = { Pixels = 28 } }; UIPanel panelLocations = new UIPanel { Width = { Percent = 100 }, Height = { Pixels = -48, Percent = 100 } }; panelMain.Add(panelLocations); gridLocations = new UIGrid <UITeleporterItem> { Width = { Pixels = -28, Percent = 100 }, Height = { Percent = 100 } }; panelLocations.Add(gridLocations); UpdateGrid(); gridLocations.scrollbar.Height = new StyleDimension { Percent = 100 }; gridLocations.scrollbar.X.Percent = 100; panelLocations.Add(gridLocations.scrollbar); UITextButton buttonDialOnce = new UITextButton(Language.GetText("Mods.Teleportation.UI.DialOnce")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, Y = { Percent = 100 } }; buttonDialOnce.OnClick += args => { if (SelectedTeleporter == null) { return; } if (SelectedTeleporter.Destination == Container) { SelectedTeleporter = null; } else { Container.Destination = SelectedTeleporter; Container.DialOnce = true; Net.SendTeleporterDestination(Container); } }; panelMain.Add(buttonDialOnce); UITextButton buttonDial = new UITextButton(Language.GetText("Mods.Teleportation.UI.Dial")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, Y = { Percent = 100 }, X = { Percent = 33 } }; buttonDial.OnClick += args => { if (SelectedTeleporter == null) { return; } if (SelectedTeleporter.Destination == Container) { SelectedTeleporter = null; } else { Container.Destination = SelectedTeleporter; Container.DialOnce = false; Net.SendTeleporterDestination(Container); } }; panelMain.Add(buttonDial); UITextButton buttonInterrupt = new UITextButton(Language.GetText("Mods.Teleportation.UI.Interrupt")) { Width = { Pixels = -4, Percent = 25 }, Height = { Pixels = 40 }, X = { Percent = 50 }, Y = { Percent = 100 } }; buttonInterrupt.OnClick += args => { if (SelectedTeleporter != null) { SelectedTeleporter.Destination = null; } SelectedTeleporter = null; Container.Destination = null; Container.DialOnce = false; Net.SendTeleporterDestination(Container); }; panelMain.Add(buttonInterrupt); UIContainerSlot slotFuel = new UIContainerSlot(() => Container.Handler) { Width = { Pixels = -4, Percent = 25 }, X = { Percent = 100 }, Y = { Percent = 100 }, Padding = new Padding(0, 24, 24, 0), PreviewItem = new Item() }; slotFuel.PreviewItem.SetDefaults(ModContent.ItemType <FuelCell>()); panelMain.Add(slotFuel); }
static void SetColorStyleValue(string cmd, string avAtrName, string value, XElement svgElement, BaseElement avElement, List <string> warnings) { if (value == "none") { avElement.SetAndroidAttributeValue(avAtrName, value); } else if (value.StartsWith("url(")) { if (!value.StartsWith("url(#")) { throw new Exception("Only anchor URLs are supported at this time."); } //var iri = value.Substring("url(#".Length).Trim(')').Trim(); var iri = value.SubstringWithTerminator("url(#".Length, ')').Trim(); if (svgElement.GetRoot() is XElement root) { AndroidVector.BaseGradient gradient = null; if (root.Descendants(Namespace.Svg + "linearGradient").FirstOrDefault(e => e.Attribute("id").Value == iri) is XElement svgLinearGradient) { if (PaintConverter.ConvertLinearGradient(svgLinearGradient, warnings) is LinearGradient avGradient) { gradient = avGradient; } } else if (root.Descendants(Namespace.Svg + "radialGradient").FirstOrDefault(e => e.Attribute("id").Value == iri) is XElement svgRadialGradient) { if (PaintConverter.ConvertRadialGradient(svgRadialGradient, warnings) is RadialGradient avGradient) { gradient = avGradient; } } if (gradient != null) { if (avElement.Element(AndroidVector.Namespace.Aapt + "attr") is XElement aaptAttr && aaptAttr.Attribute("name").Value == "android:" + gradient.Attribute(AndroidVector.Namespace.AndroidVector + "type").Value) { aaptAttr.Remove(); } var aapt = new AaptAttr(cmd + "Color"); avElement.Add(aapt); if (aapt.Elements("gradient").FirstOrDefault(e => e.Attribute(AndroidVector.Namespace.AndroidVector + "type").Value == gradient.Attribute(AndroidVector.Namespace.AndroidVector + "type").Value) is XElement oldGradient) { oldGradient.Remove(); } aapt.Add(gradient); avElement.SetAndroidAttributeValue(avAtrName, null); return; } warnings.AddWarning("Ignoring gradient because no element found to complete link [" + value + "]."); return; } throw new Exception("Could not find document root"); } else { var(hexColor, opacity) = GetHexColorAndFloatOpacity(value, warnings); avElement.SetAndroidAttributeValue(avAtrName, hexColor); if (!float.IsNaN(opacity)) { avElement.SetAndroidAttributeValue(cmd + "Alpha", opacity); } } }
private void SetupSettingsPanel() { panelSettings = new BaseElement { Width = { Percent = 100 }, Height = { Pixels = -28, Percent = 100 }, Y = { Pixels = 28 } }; UIText textWhitelist = new UIText(Language.GetText("Mods.BaseLibrary.UI.Whitelist")) { Y = { Pixels = 8 } }; panelSettings.Add(textWhitelist); buttonsWhitelist = new UIToggleButton[Container is TileEntities.UltimateTeleporter ? 5 : 4]; for (int i = 0; i < buttonsWhitelist.Length; i++) { buttonsWhitelist[i] = new UIToggleButton(Teleportation.whitelist[i], ScaleMode.Zoom) { Size = new Vector2(40), Y = { Pixels = 36 }, X = { Pixels = 48 * i }, Padding = new Padding(6, 6, 6, 6), Toggled = Container.Whitelist[i], HoverText = Language.GetText($"Mods.Teleportation.UI.Whitelist_{i}") }; int pos = i; buttonsWhitelist[i].OnClick += args => { Container.Whitelist[pos] = !Container.Whitelist[pos]; Net.SendTeleporterWhitelist(Container); }; panelSettings.Add(buttonsWhitelist[i]); } UIText textIcon = new UIText(Language.GetText("Mods.BaseLibrary.UI.Icon")) { Y = { Pixels = 84 } }; panelSettings.Add(textIcon); UIIcon buttonIcon = new UIIcon(Container) { Size = new Vector2(40), Y = { Pixels = 112 }, Padding = new Padding(6, 6, 6, 6), HoverText = Language.GetText("Mods.Teleportation.UI.SetIcon").Format(ModContent.ItemType <Pipette>()) }; buttonIcon.OnClick += args => { Pipette pipette = (Pipette)Main.mouseItem.modItem; if (pipette?.icon == null) { return; } Container.Icon = pipette.icon.Clone(); Net.SendTeleporterIcon(Container); Main.PlaySound(SoundID.MenuTick); }; panelSettings.Add(buttonIcon); }