diff --git a/OpenRA.Game/Widgets/TextFieldWidget.cs b/OpenRA.Game/Widgets/TextFieldWidget.cs index fc19af21e9..3c572103a2 100644 --- a/OpenRA.Game/Widgets/TextFieldWidget.cs +++ b/OpenRA.Game/Widgets/TextFieldWidget.cs @@ -11,6 +11,7 @@ using System; using System.Drawing; using OpenRA.Traits; +using OpenRA.Graphics; namespace OpenRA.Widgets { @@ -24,9 +25,7 @@ namespace OpenRA.Widgets } public int MaxLength = 0; - public bool Bold = false; public int VisualHeight = 1; - public string Background = "dialog3"; public int LeftMargin = 5; public int RightMargin = 5; @@ -34,6 +33,13 @@ namespace OpenRA.Widgets public Func OnTabKey = () => false; public Action OnLoseFocus = () => { }; public int CursorPosition { get; protected set; } + + public Func IsDisabled = () => false; + public Color TextColor = Color.White; + public Color DisabledColor = Color.Gray; + public string Font = "Regular"; + + [Obsolete] public bool Bold = false; public TextFieldWidget() : base() {} protected TextFieldWidget(TextFieldWidget widget) @@ -42,6 +48,9 @@ namespace OpenRA.Widgets Text = widget.Text; MaxLength = widget.MaxLength; Bold = widget.Bold; + Font = widget.Font; + TextColor = widget.TextColor; + DisabledColor = widget.DisabledColor; VisualHeight = widget.VisualHeight; } @@ -55,6 +64,9 @@ namespace OpenRA.Widgets // TODO: TextFieldWidgets don't support delegate methods for mouse input public override bool HandleMouseInput(MouseInput mi) { + if (IsDisabled()) + return false; + if (mi.Event == MouseInputEvent.Move) return false; @@ -74,8 +86,10 @@ namespace OpenRA.Widgets public int ClosestCursorPosition(int x) { - var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"]; + if (Font == "Regular" && Bold) + Font = "Bold"; + var font = Game.Renderer.Fonts[Font]; var textSize = font.Measure(Text); var start = RenderOrigin.X + LeftMargin; @@ -97,6 +111,9 @@ namespace OpenRA.Widgets public override bool HandleKeyPressInner(KeyInput e) { + if (IsDisabled()) + return false; + if (e.Event == KeyInputEvent.Up) return false; // Only take input if we are focused @@ -183,13 +200,22 @@ namespace OpenRA.Widgets public virtual void DrawWithString(string text) { - var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"]; + if (Font == "Regular" && Bold) + Font = "Bold"; + + var font = Game.Renderer.Fonts[Font]; var pos = RenderOrigin; var textSize = font.Measure(text); var cursorPosition = font.Measure(text.Substring(0,CursorPosition)); - WidgetUtils.DrawPanel(Background, + var disabled = IsDisabled(); + var state = disabled ? "textfield-disabled" : + Focused ? "textfield-focused" : + RenderBounds.Contains(Viewport.LastMousePos) ? "textfield-hover" : + "textfield"; + + WidgetUtils.DrawPanel(state, new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height)); // Inset text by the margin and center vertically @@ -204,9 +230,10 @@ namespace OpenRA.Widgets Game.Renderer.EnableScissor(pos.X + LeftMargin, pos.Y, Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom); } - - font.DrawText(text, textPos, Color.White); + var color = disabled ? DisabledColor : TextColor; + font.DrawText(text, textPos, color); + if (showCursor && Focused) font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White); diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index 9103f7189e..0e8f8e7fe3 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -121,79 +121,6 @@ namespace OpenRA.Mods.Cnc.Widgets public override Widget Clone() { return new CncScrollPanelWidget(this); } } - - public class CncTextFieldWidget : TextFieldWidget - { - public CncTextFieldWidget() - : base() { } - protected CncTextFieldWidget(CncTextFieldWidget widget) - : base(widget) { } - - public Func IsDisabled = () => false; - public Color TextColor = Color.White; - public Color DisabledColor = Color.Gray; - - public override bool HandleMouseInput(MouseInput mi) - { - if (IsDisabled()) - return false; - return base.HandleMouseInput(mi); - } - - public override bool HandleKeyPressInner(KeyInput e) - { - if (IsDisabled()) - return false; - return base.HandleKeyPressInner(e); - } - - public override void DrawWithString(string text) - { - if (text == null) text = ""; - - var font = (Bold) ? Game.Renderer.Fonts["Bold"] : Game.Renderer.Fonts["Regular"]; - var pos = RenderOrigin; - - if (CursorPosition > text.Length) - CursorPosition = text.Length; - - var textSize = font.Measure(text); - var cursorPosition = font.Measure(text.Substring(0,CursorPosition)); - - var disabled = IsDisabled(); - var state = disabled ? "button-disabled" : - Focused ? "button-pressed" : - RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" : - "button"; - - WidgetUtils.DrawPanel(state, - new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height)); - - // Inset text by the margin and center vertically - var textPos = pos + new int2(LeftMargin, (Bounds.Height - textSize.Y) / 2 - VisualHeight); - - // Right align when editing and scissor when the text overflows - if (textSize.X > Bounds.Width - LeftMargin - RightMargin) - { - if (Focused) - textPos += new int2(Bounds.Width - LeftMargin - RightMargin - textSize.X, 0); - - Game.Renderer.EnableScissor(pos.X + LeftMargin, pos.Y, Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom); - } - - var color = disabled ? DisabledColor : TextColor; - - font.DrawText(text, textPos, color); - - if (showCursor && Focused) - font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), color); - - if (textSize.X > Bounds.Width - LeftMargin - RightMargin) - Game.Renderer.DisableScissor(); - } - - public override Widget Clone() { return new CncTextFieldWidget(this); } - } public class CncSliderWidget : SliderWidget { diff --git a/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs index 4a24ebf966..7e3fa2fa5f 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncServerCreationLogic.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.Widgets panel.GetWidget("LISTEN_PORT").Text = settings.Server.ListenPort.ToString(); advertiseOnline = Game.Settings.Server.AdvertiseOnline; - var externalPort = panel.GetWidget("EXTERNAL_PORT"); + var externalPort = panel.GetWidget("EXTERNAL_PORT"); externalPort.Text = settings.Server.ExternalPort.ToString(); externalPort.IsDisabled = () => !advertiseOnline; @@ -67,8 +67,8 @@ namespace OpenRA.Mods.Cnc.Widgets advertiseCheckbox.OnClick = () => advertiseOnline ^= true; // Disable these until we have some logic behind them - panel.GetWidget("SERVER_DESC").IsDisabled = () => true; - panel.GetWidget("SERVER_PASSWORD").IsDisabled = () => true; + panel.GetWidget("SERVER_DESC").IsDisabled = () => true; + panel.GetWidget("SERVER_PASSWORD").IsDisabled = () => true; } void CreateAndJoin() diff --git a/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs index 87b7d289cc..107d41b221 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncSettingsLogic.cs @@ -90,10 +90,10 @@ namespace OpenRA.Mods.Cnc.Widgets windowModeDropdown.GetText = () => windowMode == WindowMode.Windowed ? "Windowed" : windowMode == WindowMode.Fullscreen ? "Fullscreen" : "Pseudo-Fullscreen"; generalPane.GetWidget("WINDOW_RESOLUTION").IsVisible = () => windowMode == WindowMode.Windowed; - var windowWidth = generalPane.GetWidget("WINDOW_WIDTH"); + var windowWidth = generalPane.GetWidget("WINDOW_WIDTH"); windowWidth.Text = Game.Settings.Graphics.WindowedSize.X.ToString(); - var windowHeight = generalPane.GetWidget("WINDOW_HEIGHT"); + var windowHeight = generalPane.GetWidget("WINDOW_HEIGHT"); windowHeight.Text = Game.Settings.Graphics.WindowedSize.Y.ToString(); // Audio diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index 2dfb37c32b..aea19ff095 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -48,6 +48,54 @@ button-pressed: chrome.png corner-bl: 64,254,2,2 corner-br: 126,254,2,2 +# A copy of button +textfield: chrome.png + background: 2,194,60,60 + border-r: 62,194,2,60 + border-l: 0,194,2,60 + border-b: 2,254,60,2 + border-t: 2,192,60,2 + corner-tl: 0,192,2,2 + corner-tr: 62,192,2,2 + corner-bl: 0,254,2,2 + corner-br: 62,254,2,2 + +# A copy of button-hover +textfield-hover: chrome.png + background: 2,130,60,60 + border-r: 62,132,2,60 + border-l: 0,130,2,60 + border-b: 2,190,60,2 + border-t: 2,128,60,2 + corner-tl: 0,128,2,2 + corner-tr: 62,128,2,2 + corner-bl: 0,190,2,2 + corner-br: 62,190,2,2 + +# A copy of button-disabled +textfield-disabled: chrome.png + background: 66,130,60,60 + border-r: 126,130,2,60 + border-l: 64,130,2,60 + border-b: 66,190,60,2 + border-t: 66,128,60,2 + corner-tl: 64,128,2,2 + corner-tr: 126,128,2,2 + corner-bl: 64,190,2,2 + corner-br: 126,190,2,2 + +# A copy of button-pressed +textfield-focused: chrome.png + background: 66,194,60,60 + border-r: 126,194,2,60 + border-l: 64,194,2,60 + border-b: 66,254,60,2 + border-t: 66,192,60,2 + corner-tl: 64,192,2,2 + corner-tr: 126,192,2,2 + corner-bl: 64,254,2,2 + corner-br: 126,254,2,2 + # A copy of button progressbar-bg: chrome.png background: 2,194,60,60 diff --git a/mods/cnc/chrome/createserver.yaml b/mods/cnc/chrome/createserver.yaml index 5abdb57e9a..263b0309ca 100644 --- a/mods/cnc/chrome/createserver.yaml +++ b/mods/cnc/chrome/createserver.yaml @@ -49,7 +49,7 @@ Container@CREATESERVER_PANEL: Height:25 Align:Right Text:Server Name: - CncTextField@SERVER_NAME: + TextField@SERVER_NAME: Id:SERVER_NAME X:110 Y:15 @@ -64,7 +64,7 @@ Container@CREATESERVER_PANEL: Height:25 Align:Right Text:Description: - CncTextField@SERVER_DESC: + TextField@SERVER_DESC: Id:SERVER_DESC X:110 Y:50 @@ -78,7 +78,7 @@ Container@CREATESERVER_PANEL: Height:25 Align:Right Text:Password: - CncTextField@SERVER_PASSWORD: + TextField@SERVER_PASSWORD: Id:SERVER_PASSWORD X:110 Y:85 @@ -92,7 +92,7 @@ Container@CREATESERVER_PANEL: Height:25 Align: Right Text:Port: - CncTextField@LISTEN_PORT: + TextField@LISTEN_PORT: Id:LISTEN_PORT X:110 Y:120 @@ -121,7 +121,7 @@ Container@CREATESERVER_PANEL: Height:25 Align:Right Text:External Port: - CncTextField@EXTERNAL_PORT: + TextField@EXTERNAL_PORT: Id:EXTERNAL_PORT X:110 Y:220 diff --git a/mods/cnc/chrome/directconnect.yaml b/mods/cnc/chrome/directconnect.yaml index c7993e1560..1a3c6ba28d 100644 --- a/mods/cnc/chrome/directconnect.yaml +++ b/mods/cnc/chrome/directconnect.yaml @@ -25,7 +25,7 @@ Container@DIRECTCONNECT_PANEL: Height:25 Align:Right Text:Address: - CncTextField@SERVER_ADDRESS: + TextField@SERVER_ADDRESS: Id:IP X:150 Y:15 @@ -38,7 +38,7 @@ Container@DIRECTCONNECT_PANEL: Height:25 Align:Right Text:Port: - CncTextField@PORT: + TextField@PORT: Id:PORT X:150 Y:50 diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 6b02c2ad69..6886a12613 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -61,7 +61,7 @@ Container@SERVER_LOBBY: Height:25 Visible:false Children: - CncTextField@NAME: + TextField@NAME: Id:NAME Text:Name Width:150 @@ -338,14 +338,13 @@ Container@SERVER_LOBBY: Height:14 Width:PARENT_RIGHT - 100 - 10 WordWrap:true - CncTextField@CHAT_TEXTFIELD: + TextField@CHAT_TEXTFIELD: Id:CHAT_TEXTFIELD X:15 Y:PARENT_BOTTOM - HEIGHT - 15 Width:PARENT_RIGHT - 30 Height:25 LeftMargin:50 - Background: panel-darkred Children: Label@LABEL_CHATTYPE: Id:LABEL_CHATTYPE diff --git a/mods/cnc/chrome/preferences.yaml b/mods/cnc/chrome/preferences.yaml index 72777773b0..300f316978 100644 --- a/mods/cnc/chrome/preferences.yaml +++ b/mods/cnc/chrome/preferences.yaml @@ -33,7 +33,7 @@ Container@SETTINGS_PANEL: Height:25 Align:Right Text:Name: - CncTextField@NAME_TEXTFIELD: + TextField@NAME_TEXTFIELD: Id:NAME_TEXTFIELD X:65 Y:40 @@ -125,7 +125,7 @@ Container@SETTINGS_PANEL: Height:25 Width:25 Align:Center - CncTextField@SCREEN_WIDTH: + TextField@SCREEN_WIDTH: Id:WINDOW_WIDTH X:600 Y:40 @@ -140,7 +140,7 @@ Container@SETTINGS_PANEL: Height:25 Width:25 Align:Center - CncTextField@SCREEN_HEIGHT: + TextField@SCREEN_HEIGHT: Id:WINDOW_HEIGHT X:670 Y:40 diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index fbdf542214..4163d03b78 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -285,3 +285,51 @@ button-pressed: dialog.png corner-tr: 722,0,1,1 corner-bl: 640,82,1,1 corner-br: 722,82,1,1 + +# A copy of dialog3 +textfield: dialog.png + background: 641,1,126,126 + border-r: 767,1,1,126 + border-l: 640,1,1,126 + border-b: 641,127,126,1 + border-t: 641,0,126,1 + corner-tl: 640,0,1,1 + corner-tr: 722,0,1,1 + corner-bl: 640,82,1,1 + corner-br: 722,82,1,1 + +# A copy of dialog3 +textfield-hover: dialog.png + background: 641,1,126,126 + border-r: 767,1,1,126 + border-l: 640,1,1,126 + border-b: 641,127,126,1 + border-t: 641,0,126,1 + corner-tl: 640,0,1,1 + corner-tr: 722,0,1,1 + corner-bl: 640,82,1,1 + corner-br: 722,82,1,1 + +# A copy of dialog3 +textfield-disabled: dialog.png + background: 641,1,126,126 + border-r: 767,1,1,126 + border-l: 640,1,1,126 + border-b: 641,127,126,1 + border-t: 641,0,126,1 + corner-tl: 640,0,1,1 + corner-tr: 722,0,1,1 + corner-bl: 640,82,1,1 + corner-br: 722,82,1,1 + +# A copy of dialog3 +textfield-focused: dialog.png + background: 641,1,126,126 + border-r: 767,1,1,126 + border-l: 640,1,1,126 + border-b: 641,127,126,1 + border-t: 641,0,126,1 + corner-tl: 640,0,1,1 + corner-tr: 722,0,1,1 + corner-bl: 640,82,1,1 + corner-br: 722,82,1,1