void CreateGUI() { var cache = ResourceCache; UI ui = UI; UIElement root = ui.Root; // Load the style sheet from xml root.SetDefaultStyle(cache.GetXmlFile("UI/DefaultStyle.xml")); for (int i = 0; i < 10; i++) { Button b = new Button(); root.AddChild(b); // Reference a style from the style sheet loaded earlier: b.SetStyle("Button", null); b.SetSize(300, 100); b.Position = new IntVector2(50 * i, 50 * i); b.SubscribeToDragMove(HandleDragMove); b.SubscribeToDragBegin(HandleDragBegin); b.SubscribeToDragCancel(HandleDragCancel); b.SubscribeToDragEnd(HandleDragEnd); { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.HorizontalAlignment = HorizontalAlignment.Center; t.VerticalAlignment = VerticalAlignment.Center; t.Name = ("Text"); } { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.Name=("Event Touch"); t.HorizontalAlignment=HorizontalAlignment.Center; t.VerticalAlignment=VerticalAlignment.Bottom; } { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.Name=("Num Touch"); t.HorizontalAlignment=HorizontalAlignment.Center; t.VerticalAlignment=VerticalAlignment.Top; } } for (int i = 0; i< 10; i++) { var t = new Text(); root.AddChild(t); t.SetStyle("Text", null); t.Name=("Touch "+ i); t.Visible = false; } }
void CreateDraggableFish() { var cache = ResourceCache; var graphics = Graphics; // Create a draggable Fish button draggableFish = new Button(); draggableFish.Texture = cache.GetTexture2D("Textures/UrhoDecal.dds"); // Set texture draggableFish.BlendMode = BlendMode.Add; draggableFish.SetSize(128, 128); draggableFish.SetPosition((graphics.Width - draggableFish.Width) / 2, 200); draggableFish.Name = "Fish"; uiRoot.AddChild(draggableFish); // Add a tooltip to Fish button ToolTip toolTip = new ToolTip(); draggableFish.AddChild(toolTip); toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width / 2); // slightly offset from close button BorderImage textHolder = new BorderImage(); toolTip.AddChild(textHolder); textHolder.SetStyle("ToolTipBorderImage", null); var toolTipText = new Text(); textHolder.AddChild(toolTipText); toolTipText.SetStyle("ToolTipText", null); toolTipText.Value = "Please drag me!"; // Subscribe draggableFish to Drag Events (in order to make it draggable) draggableFish.SubscribeToDragBegin(HandleDragBegin); draggableFish.SubscribeToDragMove(HandleDragMove); draggableFish.SubscribeToDragEnd(HandleDragEnd); }
void Reload() { // clear UI.Root UI.Root.RemoveAllChildren(); const int count = 8; for (int i = 0; i < count; i++) { for (int j = 0; j < count; j++) { var w = Graphics.Width / count; var h = Graphics.Height / count; var button = new Button(); UI.Root.AddChild(button); button.SetStyle("Button"); button.SetSize(w, h); button.Position = new IntVector2(w * i, h * j); var label = new Text(); button.AddChild(label); label.SetStyle("Text"); label.HorizontalAlignment = HorizontalAlignment.Center; label.VerticalAlignment = VerticalAlignment.Center; label.Value = $"{i};{j}"; //button.Pressed += Button_Pressed; button.Pressed += args => label.Value += "!"; } } }
public NameTextPair(MHUrhoApp game, string name, bool isDirectory) { Name = name; Text = new Text { Value = name, Visible = true }; Text.SetStyle(isDirectory ? "DirectoryEntry" : "FileEntry", game.PackageManager.GetXmlFile("UI/FileBrowserStyle.xml", true)); IsDirectory = isDirectory; }
public static Text GetText(string text, string style = "") { var txt = new Text(); if (string.IsNullOrEmpty(style)) { txt.SetStyleAuto(); } else { txt.SetStyle(style); } txt.Value = text; txt.MinHeight = 20; txt.MinWidth = 100; return(txt); }
Button CreateButton(UnitType unitType) { var button = ui.SelectionBar.CreateButton(); button.SetStyle("SelectedUnitButton"); button.Texture = input.Level.Package.UnitIconTexture; button.ImageRect = unitType.IconRectangle; button.HoverOffset = new IntVector2(unitType.IconRectangle.Width(), 0); button.PressedOffset = new IntVector2(unitType.IconRectangle.Width() * 2, 0); Text text = button.CreateText("Count"); text.SetStyle("SelectedUnitText"); text.Value = "1"; return(button); }
public static void Initialize(Urho.Application app, List <DebugAction> handlers) { app.UI.Root.SetDefaultStyle(CoreAssets.UIs.DefaultStyle); buttons = new List <Button>(handlers.Count); for (int j = 0; j < handlers.Count + 1; j++) { var w = app.Graphics.Width / (handlers.Count + 1); var h = app.Graphics.Height / 25; var button = new Button(); app.UI.Root.AddChild(button); button.SetStyle("Button"); button.SetSize(w, h); button.Position = new IntVector2(w * j, 0); button.Visible = false; var label = new Text(); button.AddChild(label); label.SetStyle("Text"); label.SetFontSize((int)(label.FontSize / 1f)); label.HorizontalAlignment = HorizontalAlignment.Center; label.VerticalAlignment = VerticalAlignment.Center; int index = j; if (j == handlers.Count) { label.Value = "debug menu"; button.Visible = true; button.Pressed += args => buttons.ForEach(b => b.Visible = !b.Visible); } else { label.Value = handlers[j].Name; button.Pressed += args => handlers[index].Action(); buttons.Add(button); } } }
void CreateGUI() { var cache = ResourceCache; UI ui = UI; UIElement root = ui.Root; // Load the style sheet from xml root.SetDefaultStyle(cache.GetXmlFile("UI/DefaultStyle.xml")); for (int i = 0; i < 10; i++) { Button b = new Button(); root.AddChild(b); // Reference a style from the style sheet loaded earlier: b.SetStyle("Button", null); b.SetSize(300, 100); b.Position = new IntVector2(50 * i, 50 * i); b.SubscribeToDragMove(HandleDragMove); b.SubscribeToDragBegin(HandleDragBegin); b.SubscribeToDragCancel(HandleDragCancel); b.SubscribeToDragEnd(HandleDragEnd); { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.HorizontalAlignment = HorizontalAlignment.Center; t.VerticalAlignment = VerticalAlignment.Center; t.Name = ("Text"); } { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.Name = ("Event Touch"); t.HorizontalAlignment = HorizontalAlignment.Center; t.VerticalAlignment = VerticalAlignment.Bottom; } { var t = new Text(); b.AddChild(t); t.SetStyle("Text", null); t.Name = ("Num Touch"); t.HorizontalAlignment = HorizontalAlignment.Center; t.VerticalAlignment = VerticalAlignment.Top; } } for (int i = 0; i < 10; i++) { var t = new Text(); root.AddChild(t); t.SetStyle("Text", null); t.Name = ("Touch " + i); t.Visible = false; } }
void CreateDraggableFish() { var cache = ResourceCache; var graphics = Graphics; // Create a draggable Fish button draggableFish = new Button(); draggableFish.Texture = cache.GetTexture2D("Textures/UrhoDecal.dds"); // Set texture draggableFish.BlendMode = BlendMode.Add; draggableFish.SetSize(128, 128); draggableFish.SetPosition((graphics.Width - draggableFish.Width)/2, 200); draggableFish.Name = "Fish"; uiRoot.AddChild(draggableFish); // Add a tooltip to Fish button ToolTip toolTip = new ToolTip(); draggableFish.AddChild(toolTip); toolTip.Position = new IntVector2(draggableFish.Width + 5, draggableFish.Width/2); // slightly offset from close button BorderImage textHolder = new BorderImage(); toolTip.AddChild(textHolder); textHolder.SetStyle("ToolTipBorderImage", null); var toolTipText = new Text(); textHolder.AddChild(toolTipText); toolTipText.SetStyle("ToolTipText", null); toolTipText.Value = "Please drag me!"; // Subscribe draggableFish to Drag Events (in order to make it draggable) draggableFish.SubscribeToDragBegin(HandleDragBegin); draggableFish.SubscribeToDragMove(HandleDragMove); draggableFish.SubscribeToDragEnd(HandleDragEnd); }