/// <summary>Create buttons and add them to the given panel UIBuilder.</summary> /// <param name="window">The parent window.</param> /// <param name="parentComponent">The parent panel component to host the buttons.</param> /// <param name="builder">UI builder to use.</param> /// <param name="buttonDefs">The button definitions array.</param> /// <param name="minRowLength">Shortest horizontal row length allowed before breaking new row.</param> /// <returns>A list of created buttons.</returns> private AddButtonsResult AddButtonsFromButtonDefinitions( MainMenuWindow window, UIComponent parentComponent, UBuilder builder, MenuButtonDef[] buttonDefs, int minRowLength) { AddButtonsResult result; result.Buttons = new List <BaseMenuButton>(); // Count the button objects and set their layout result.Layout = new MainMenuLayout(); result.Layout.CountEnabledButtons(buttonDefs); int placedInARow = 0; foreach (MenuButtonDef buttonDef in buttonDefs) { if (!buttonDef.IsEnabledFunc()) { // Skip buttons which are not enabled continue; } // Create and populate the panel with buttons var button = parentComponent.AddUIComponent(buttonDef.ButtonType) as BaseMenuButton; // Count buttons in a row and break the line bool doRowBreak = result.Layout.IsRowBreak(placedInARow, minRowLength); button.ResizeFunction( resizeFn: (UResizer r) => { r.Stack(doRowBreak ? UStackMode.NewRowBelow : UStackMode.ToTheRight); r.Width(UValue.FixedSize(40f)); r.Height(UValue.FixedSize(40f)); }); if (doRowBreak) { placedInARow = 0; result.Layout.Rows++; } else { placedInARow++; } // Also ask each button what sprites they need button.SetupButtonSkin(builder.AtlasBuilder); // Take button classname, split by ".", and the last word becomes the button name string buttonName = buttonDef.ButtonType.ToString().Split('.').Last(); button.name = $"TMPE_MainMenuButton_{buttonName}"; window.ButtonsDict.Add(buttonDef.Mode, button); result.Buttons.Add(button); } return(result); }
private UILabel SetupControls_TopRow(UiBuilder <MainMenuWindow> builder, U.AtlasBuilder atlasBuilder) { UILabel versionLabel; using (var versionLabelB = builder.Label <U.ULabel>(TrafficManagerMod.ModName)) { versionLabelB.ResizeFunction(r => r.Stack(UStackMode.Below)); this.VersionLabel = versionLabel = versionLabelB.Control; } using (var btnBuilder = builder.Button <U.UButton>()) { UButton control = btnBuilder.Control; this.toggleOsdButton_ = control; control.atlas = this.allButtonsAtlas_; control.name = "TMPE_MainMenu_HelpButton"; // Texture for Help will be included in the `allButtonsAtlas_` ButtonSkin skin = new ButtonSkin { BackgroundPrefix = "RoundButton", Prefix = "Help", BackgroundHovered = true, BackgroundActive = true, ForegroundActive = true, }; skin.UpdateAtlasBuilder( atlasBuilder, spriteSize: new IntVector2(50)); control.Skin = skin; control.UpdateButtonImage(); // This has to be done later when form setup is done: // helpB.Control.atlas = allButtonsAtlas_; btnBuilder.ResizeFunction( resizeFn: r => { r.Control.isVisible = true; // not sure why its hidden on create? TODO r.Stack(mode: UStackMode.ToTheRight, spacing: UConst.UIPADDING * 3f, stackRef: versionLabel); r.Width(UValue.FixedSize(18f)); // assume Version label is 18pt high r.Height(UValue.FixedSize(18f)); }); control.uCanActivate = c => true; control.uTooltip = Translation.Menu.Get("Tooltip:Toggle onscreen display panel"); control.uIsActive = c => GlobalConfig.Instance.Main.KeybindsPanelVisible; control.uOnClick += (component, eventParam) => { ModUI.Instance.MainMenu.OnToggleOsdButtonClicked(component as U.UButton); }; } return(versionLabel); }
/// <summary>Create buttons and add them to the given panel UIBuilder.</summary> /// <param name="builder">UI builder to use.</param> /// <param name="atlasKeysSet">Atlas keys to update for button images.</param> /// <param name="buttonDefs">Button defs collection to create from it.</param> /// <param name="minRowLength">Longest the row can be without breaking.</param> /// <returns>A list of created buttons.</returns> private AddButtonsResult AddButtonsFromButtonDefinitions(UiBuilder <UPanel> builder, U.AtlasBuilder atlasBuilder, MenuButtonDef[] buttonDefs, int minRowLength) { AddButtonsResult result; result.Buttons = new List <BaseMenuButton>(); // Count the button objects and set their layout result.Layout = new MainMenuLayout(); result.Layout.CountEnabledButtons(buttonDefs); int placedInARow = 0; foreach (MenuButtonDef buttonDef in buttonDefs) { if (!buttonDef.IsEnabledFunc()) { // Skip buttons which are not enabled continue; } // Create and populate the panel with buttons var buttonBuilder = builder.Button <BaseMenuButton>(buttonDef.ButtonType); // Count buttons in a row and break the line bool doRowBreak = result.Layout.IsRowBreak(placedInARow, minRowLength); buttonBuilder.ResizeFunction(r => { r.Stack(doRowBreak ? UStackMode.NewRowBelow : UStackMode.ToTheRight); r.Width(UValue.FixedSize(40f)); r.Height(UValue.FixedSize(40f)); }); if (doRowBreak) { placedInARow = 0; result.Layout.Rows++; } else { placedInARow++; } // Also ask each button what sprites they need buttonBuilder.Control.SetupButtonSkin(atlasBuilder); string buttonName = buttonDef.ButtonType.ToString().Split('.').Last(); buttonBuilder.Control.name = $"TMPE_MainMenuButton_{buttonName}"; ButtonsDict.Add(buttonDef.Mode, buttonBuilder.Control); result.Buttons.Add(buttonBuilder.Control); } return(result); }
private UILabel SetupControls_TopRow(UiBuilder <MainMenuWindow> builder, HashSet <string> atlasKeySet) { UILabel versionLabel; using (var versionLabelB = builder.Label <U.Label.ULabel>(TrafficManagerMod.ModName)) { versionLabelB.ResizeFunction(r => r.Stack(UStackMode.Below)); this.VersionLabel = versionLabel = versionLabelB.Control; } using (var helpB = builder.Button <U.Button.UButton>()) { this.helpButton_ = helpB.Control; helpB.Control.atlas = this.allButtonsAtlas_; helpB.Control.name = "TMPE_MainMenu_HelpButton"; // Texture for Help will be included in the `allButtonsAtlas_` ButtonSkin skin = new ButtonSkin { BackgroundPrefix = "RoundButton", Prefix = "Help", BackgroundHovered = true, BackgroundActive = true, ForegroundActive = true, }; atlasKeySet.AddRange(skin.CreateAtlasKeyset()); helpB.Control.Skin = skin; helpB.Control.UpdateButtonImage(); // This has to be done later when form setup is done: // helpB.Control.atlas = allButtonsAtlas_; helpB.ResizeFunction( resizeFn: r => { r.Control.isVisible = true; // not sure why its hidden on create? TODO r.Stack(mode: UStackMode.ToTheRight, spacing: UConst.UIPADDING * 3f, stackRef: versionLabel); r.Width(UValue.FixedSize(18f)); // assume Version label is 18pt high r.Height(UValue.FixedSize(18f)); }); helpB.Control.uCanActivate = c => true; helpB.Control.uIsActive = c => GlobalConfig.Instance.Main.KeybindsPanelVisible; helpB.Control.uOnClick += (component, eventParam) => { ModUI.Instance.MainMenu.OnHelpButtonClicked(component as U.Button.UButton); }; } return(versionLabel); }
static void ApplyQuality(UValue uValue) { if (Targets.ContainsKey(uValue.target)) { if (Members.ContainsKey(uValue.member)) { var qTarget = Targets[uValue.target]; var targetMember = Members[uValue.target + "." + uValue.member]; if (targetMember is FieldInfo) { ((FieldInfo)targetMember).SetValue(qTarget, uValue.value); } else if (targetMember is PropertyInfo) { ((PropertyInfo)targetMember).SetValue(qTarget, uValue.value, null); } } } }
/// <summary> /// Apply one options /// </summary> /// <param name="optionValue"></param> static void ApplyOptions(UValue optionValue) { if (Targets.ContainsKey(optionValue.target)) { var targetObject = Targets[optionValue.target]; if (Members.ContainsKey(optionValue.target + "." + optionValue.member)) { var targetMember = Members[optionValue.target + "." + optionValue.member]; if (targetMember is FieldInfo) { ((FieldInfo)targetMember).SetValue(targetObject, optionValue.value); } else if (targetMember is PropertyInfo) { ((PropertyInfo)targetMember).SetValue(targetObject, optionValue.value, null); } /*else * { * try * { * /*if (evt.IsPrevios && evt.parameters.Length > evt.parameters.Length - 1)//???? >0 ??? * evt.parameters[evt.parameters.Length - 1] = previosResult;*/ /*((MethodInfo)targetMember).Invoke(targetObject, optionValue.parameters); * } * catch (Exception e) * { * ULog.Log("OptionsManager:ApplyOptions error on "+optionValue.member+" \n" + e.Message, ULogType.Error); * } * }*/ } else { ULog.Log("ApplyOptions -2 " + optionValue.member + " : " + Members.Count); } } }
/// <summary> /// Create button triples for number of lanes. /// Buttons are linked to lanes later by LaneArrowTool class. /// </summary> /// <param name="builder">The UI Builder.</param> /// <param name="numLanes">How many lane groups.</param> public void SetupControls(UiBuilder <LaneArrowToolWindow> builder, int numLanes) { Buttons = new List <LaneArrowButton>(); using (var buttonRowBuilder = builder.ChildPanel <U.Panel.UPanel>( setupFn: p => { p.name = "TMPE_ButtonRow"; })) { buttonRowBuilder.ResizeFunction( r => { r.Stack(mode: UStackMode.Below, spacing: UConst.UIPADDING); r.FitToChildren(); }); // ----------------------------------- // Create a row of button groups // [ Lane 1 ] [ Lane 2 ] [ Lane 3 ] ... // [ [←] [↑] [→] ] [... ] [ ... ] // ----------------------------------- for (var i = 0; i < numLanes; i++) { string buttonName = $"TMPE_LaneArrow_ButtonGroup{i + 1}"; using (var buttonGroupBuilder = buttonRowBuilder.ChildPanel <U.Panel.UPanel>( setupFn: p => { p.name = buttonName; p.atlas = TextureUtil.FindAtlas("Ingame"); p.backgroundSprite = "GenericPanel"; })) { int i1 = i; // copy of the loop variable, for the resizeFunction below buttonGroupBuilder.SetPadding(UConst.UIPADDING); buttonGroupBuilder.ResizeFunction( r => { // attach below "Lane #" label, // else: attach to the right of the previous button group r.Stack( mode: i1 == 0 ? UStackMode.Below : UStackMode.ToTheRight, spacing: UConst.UIPADDING); r.FitToChildren(); }); // Create a label with "Lane #" title string labelText = Translation.LaneRouting.Get("Format.Label:Lane") + " " + (i + 1); using (var laneLabel = buttonGroupBuilder.Label <U.Label.ULabel>(labelText)) { // The label will be repositioned to the top of the parent laneLabel.ResizeFunction(r => { r.Stack(UStackMode.Below); }); } // Create and populate the panel with buttons // 3 buttons are created [←] [↑] [→], // The click event is assigned outside in LaneArrowTool.cs foreach (string prefix in new[] { "LaneArrowLeft", "LaneArrowForward", "LaneArrowRight", }) { using (UiBuilder <LaneArrowButton> buttonBuilder = buttonGroupBuilder.Button <LaneArrowButton>()) { buttonBuilder.Control.atlas = GetAtlas(); buttonBuilder.Control.Skin = CreateDefaultButtonSkin(); buttonBuilder.Control.Skin.Prefix = prefix; Buttons.Add(buttonBuilder.Control); buttonBuilder.ResizeFunction( r => { // First button in the group will be stacking vertical // under the "Lane #" label, while 2nd and 3rd will be // stacking horizontal r.Stack( mode: prefix == "LaneArrowLeft" ? UStackMode.Below : UStackMode.ToTheRight, spacing: UConst.UIPADDING); r.Width(UValue.FixedSize(40f)); r.Height(UValue.FixedSize(40f)); }); } } // for each button } // end button group panel } // end button loop, for each lane } // end button row }
string DebugDisplay() => HEX_PRE + UValue.ToString(HEX_FM6);
public override UInt64 ReadUInt64() { byte[] bs = base.ReadBytes(8); UValue u = new UValue(); u.Write(bs); return (UInt64)u.l; }
public override UInt16 ReadUInt16() { byte[] bs = base.ReadBytes(2); UValue u = new UValue(); u.Write(bs); return (UInt16)u.s; }
public override UInt32 ReadUInt32() { byte[] bs = base.ReadBytes(4); UValue u = new UValue(); u.Write(bs); return (UInt16)u.i; }
public override float ReadSingle() { byte[] bs = base.ReadBytes(4); UValue u = new UValue(); u.Write(bs); return u.f; }
public override long ReadInt64() { byte[] bs = base.ReadBytes(8); UValue u = new UValue(); u.Write(bs); return u.l; }
public override int ReadInt32() { byte[] bs = base.ReadBytes(4); UValue u = new UValue(); u.Write(bs); return u.i; }
public override short ReadInt16() { byte[] bs = base.ReadBytes(2); UValue u = new UValue(); u.Write(bs); return u.s; }
public override double ReadDouble() { byte[] bs = base.ReadBytes(8); UValue u = new UValue(); u.Write(bs); return u.d; }