/// <summary> /// Reads the content to the dialog. /// </summary> /// <param name="reader">The reader to read from.</param> public void FromBytes(BinaryReader reader) { Code = reader.ReadString(); Alignment = (EnumDialogArea)reader.ReadInt32(); PosX = reader.ReadSingle(); PosY = reader.ReadSingle(); Rows = new DialogRow[reader.ReadInt32()]; for (int i = 0; i < Rows.Length; i++) { Rows[i] = new DialogRow(); Rows[i].FromBytes(reader); } SizeMultiplier = reader.ReadSingle(); }
/// <summary> /// Composes the dialogue with specifications dictated by JSON. /// </summary> public void ComposeDialog() { double factor = settings.SizeMultiplier; ElementBounds dlgBounds = ElementStdBounds.AutosizedMainDialog .WithAlignment(settings.Alignment) .WithFixedPadding(10) .WithScale(factor) .WithFixedPosition(settings.PosX, settings.PosY) ; GuiComposer composer = capi.Gui .CreateCompo("cmdDlg" + settings.Code, dlgBounds) .AddDialogBG(ElementStdBounds.DialogBackground().WithScale(factor).WithFixedPadding(settings.Padding), false) .BeginChildElements() ; double y = 0; int elemKey = 1; for (int i = 0; i < settings.Rows.Length; i++) { DialogRow row = settings.Rows[i]; y += row.TopPadding; double maxheight = 0; double x = 0; for (int j = 0; j < row.Elements.Length; j++) { DialogElement elem = row.Elements[j]; maxheight = Math.Max(elem.Height, maxheight); x += elem.PaddingLeft; ComposeElement(composer, settings, elem, elemKey, x, y); elemKey++; x += elem.Width + 20; } y += maxheight + row.BottomPadding; } Composers["cmdDlg" + settings.Code] = composer.EndChildElements().Compose(); }
/// <summary> /// Reloads the values in the GUI. /// </summary> public void ReloadValues() { GuiComposer composer = Composers["cmdDlg" + settings.Code]; int elemKey = 1; for (int i = 0; i < settings.Rows.Length; i++) { DialogRow row = settings.Rows[i]; for (int j = 0; j < row.Elements.Length; j++) { DialogElement elem = row.Elements[j]; string currentValue = settings.OnGet?.Invoke(elem.Code); switch (elem.Type) { case EnumDialogElementType.Slider: { string key = "slider-" + elemKey; int curVal = 0; int.TryParse(currentValue, out curVal); composer.GetSlider(key).SetValues(curVal, elem.MinValue, elem.MaxValue, elem.Step); break; } case EnumDialogElementType.Switch: { string key = "switch-" + elemKey; composer.GetSwitch(key).SetValue(currentValue == "1"); } break; case EnumDialogElementType.Input: { string key = "input-" + elemKey; CairoFont font = CairoFont.WhiteSmallText(); composer.GetTextInput(key).SetValue(currentValue); break; } case EnumDialogElementType.NumberInput: { string key = "numberinput-" + elemKey; composer.GetNumberInput(key).SetValue(currentValue); break; } case EnumDialogElementType.Button: break; case EnumDialogElementType.Text: break; case EnumDialogElementType.Select: case EnumDialogElementType.DynamicSelect: { string[] values = elem.Values; if (elem.Type == EnumDialogElementType.DynamicSelect) { string[] compos = currentValue.Split(new string[] { "\n" }, StringSplitOptions.None); values = compos[0].Split(new string[] { "||" }, StringSplitOptions.None); string[] names = compos[1].Split(new string[] { "||" }, StringSplitOptions.None); currentValue = compos[2]; string key = "dropdown-" + elemKey; composer.GetDropDown(key).SetList(values, names); } int selectedIndex = Array.FindIndex(values, w => w.Equals(currentValue)); if (elem.Mode == EnumDialogElementMode.DropDown) { string key = "dropdown-" + elemKey; composer.GetDropDown(key).SetSelectedIndex(selectedIndex); } else { if (elem.Icons != null && elem.Icons.Length > 0) { string key = "togglebuttons-" + elemKey; if (currentValue != null && currentValue.Length > 0) { composer.ToggleButtonsSetValue(key, selectedIndex); } } } } break; } elemKey++; } } }