mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-06-09 10:06:34 +02:00
Implements SFML.Window.Event.TextEvent. (#48)
Fixes TextBoxes, and fixes the console being unable to be opened.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace SS14.Client.Interfaces.Configuration
|
||||
using SFML.Window;
|
||||
|
||||
namespace SS14.Client.Interfaces.Configuration
|
||||
{
|
||||
public interface IPlayerConfigurationManager
|
||||
{
|
||||
@@ -26,7 +28,7 @@
|
||||
int GetRate();
|
||||
int GetUpdateRate();
|
||||
int GetCommandRate();
|
||||
char GetConsoleKey();
|
||||
Keyboard.Key GetConsoleKey();
|
||||
float GetInterpolation();
|
||||
}
|
||||
}
|
||||
@@ -22,5 +22,6 @@ namespace SS14.Client.Interfaces.State
|
||||
void MouseEntered(EventArgs e);
|
||||
void MouseLeft(EventArgs e);
|
||||
void FormResize();
|
||||
void TextEntered(TextEventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -20,5 +20,6 @@ namespace SS14.Client.Interfaces.State
|
||||
void MouseEntered(EventArgs e);
|
||||
void MouseLeft(EventArgs e);
|
||||
void FormResize();
|
||||
void TextEntered(TextEventArgs e);
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace SS14.Client.Interfaces.UserInterface
|
||||
void MouseMove(MouseMoveEventArgs e);
|
||||
bool MouseWheelMove(MouseWheelEventArgs e);
|
||||
bool KeyDown(KeyEventArgs e);
|
||||
bool TextEntered(TextEventArgs e);
|
||||
|
||||
void ComponentUpdate(params object[] args);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ namespace SS14.Client.Interfaces.UserInterface
|
||||
bool MouseDown(MouseButtonEventArgs e);
|
||||
void MouseEntered(EventArgs e);
|
||||
void MouseLeft(EventArgs e);
|
||||
bool TextEntered(TextEventArgs e);
|
||||
|
||||
void HandleNetMessage(NetIncomingMessage msg);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SS14.Client.Interfaces.Configuration;
|
||||
using SFML.Window;
|
||||
using System.IO;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
@@ -49,7 +50,7 @@ namespace SS14.Client.Services.Configuration
|
||||
return Configuration.PlayerName;
|
||||
}
|
||||
|
||||
public char GetConsoleKey()
|
||||
public Keyboard.Key GetConsoleKey()
|
||||
{
|
||||
return Configuration.ConsoleKey;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SFML.Window;
|
||||
|
||||
namespace SS14.Client.Services.Configuration
|
||||
{
|
||||
@@ -23,6 +24,6 @@ namespace SS14.Client.Services.Configuration
|
||||
public int UpdateRate = 20; //Updates from the server per second
|
||||
public int CommandRate = 30; //Commands to the server per second
|
||||
public float Interpolation = 0.1f; //Number of seconds behind to render interpolation
|
||||
public char ConsoleKey = '#';
|
||||
public Keyboard.Key ConsoleKey = Keyboard.Key.Home;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,12 @@ namespace SS14.Client.Services.State
|
||||
CurrentState.MouseLeft(e);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
if (CurrentState != null)
|
||||
CurrentState.TextEntered(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Updates & Statechanges
|
||||
|
||||
@@ -641,6 +641,11 @@ namespace SS14.Client.Services.State.States
|
||||
{
|
||||
PlayerManager.KeyUp(e.Code);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
UserInterfaceManager.TextEntered(e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Mouse
|
||||
|
||||
@@ -553,6 +553,10 @@ namespace SS14.Client.Services.State.States
|
||||
UserInterfaceManager.MouseLeft(e);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
UserInterfaceManager.TextEntered(e); //KeyDown returns true if the click is handled by the ui component.
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -355,6 +355,10 @@ namespace SS14.Client.Services.State.States
|
||||
UserInterfaceManager.MouseLeft(e);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
UserInterfaceManager.TextEntered(e);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -169,6 +169,10 @@ namespace SS14.Client.Services.State.States
|
||||
UserInterfaceManager.MouseLeft(e);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
UserInterfaceManager.TextEntered(e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void _buttExit_Clicked(ImageButton sender)
|
||||
|
||||
@@ -205,6 +205,10 @@ namespace SS14.Client.Services.State.States
|
||||
UserInterfaceManager.MouseLeft(e);
|
||||
}
|
||||
|
||||
public void TextEntered(TextEventArgs e)
|
||||
{
|
||||
UserInterfaceManager.TextEntered(e);
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void _chkvsync_ValueChanged(bool newValue, Checkbox sender)
|
||||
|
||||
@@ -25,18 +25,19 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
_okayButton.Clicked += OkayButtonClicked;
|
||||
_okayButton.mouseOverColor = new SFML.Graphics.Color(135, 206, 250);
|
||||
_textboxPassword.OnSubmit += textboxPassword_OnSubmit;
|
||||
_textboxPassword.ClearOnSubmit = false; // We dispose on submit so if it clears after disposal it'll nullref.
|
||||
components.Add(_textboxPassword);
|
||||
components.Add(_okayButton);
|
||||
Position = new Vector2i((int) ( CluwneLib.CurrentRenderTarget.Size.X/2f) - (int) (ClientArea.Width/2f),
|
||||
(int) (CluwneLib.CurrentRenderTarget.Size.Y/2f) - (int) (ClientArea.Height/2f));
|
||||
}
|
||||
}
|
||||
|
||||
private void textboxPassword_OnSubmit(string text, Textbox sender)
|
||||
{
|
||||
if (text.Length > 1 && !string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
TryAdminLogin(text);
|
||||
_textboxPassword.Text = string.Empty;
|
||||
// _textboxPassword.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
if (_textboxPassword.Text.Length <= 1 || string.IsNullOrWhiteSpace(_textboxPassword.Text)) return;
|
||||
|
||||
TryAdminLogin(_textboxPassword.Text);
|
||||
_textboxPassword.Text = string.Empty;
|
||||
// _textboxPassword.Text = string.Empty;
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
|
||||
@@ -140,6 +140,13 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
else return false;
|
||||
}
|
||||
|
||||
public override bool TextEntered(TextEventArgs e)
|
||||
{
|
||||
if (!base.TextEntered(e))
|
||||
return input.TextEntered(e);
|
||||
else return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes commands (chat messages starting with /)
|
||||
/// </summary>
|
||||
|
||||
@@ -97,6 +97,11 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool TextEntered(TextEventArgs e)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -299,5 +299,12 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
if (component.KeyDown(e)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TextEntered(TextEventArgs e)
|
||||
{
|
||||
foreach (GuiComponent component in components)
|
||||
if (component.TextEntered(e)) return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
_textboxRight.Draw();
|
||||
|
||||
if (Focus && blinkCount <= 0.25f)
|
||||
CluwneLib.drawRectangle(Label.Position.X+ _caretPos - _caretWidth, Label.Position.Y + (Label.Height/2f) - (_caretHeight/2f),_caretWidth, _caretHeight, new Color(255,255,250));
|
||||
CluwneLib.drawRectangle(Label.Position.X+ _caretPos - _caretWidth, Label.Position.Y + (Label.Height/2f) - (_caretHeight/2f),_caretWidth, _caretHeight, new Color(255,255,250));
|
||||
|
||||
|
||||
|
||||
@@ -217,7 +217,18 @@ namespace SS14.Client.Services.UserInterface.Components
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool TextEntered(TextEventArgs e)
|
||||
{
|
||||
if (Text.Length >= MaxCharacters || "\b\n\u001b\r".Contains(e.Unicode))
|
||||
return false;
|
||||
|
||||
Text = Text.Insert(_caretIndex, e.Unicode);
|
||||
if (_caretIndex < _text.Length) _caretIndex++;
|
||||
SetVisibleText();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SetVisibleText()
|
||||
|
||||
@@ -358,7 +358,7 @@ namespace SS14.Client.Services.UserInterface
|
||||
/// </summary>
|
||||
public virtual bool KeyDown(KeyEventArgs e)
|
||||
{
|
||||
if (e.Equals(_config.GetConsoleKey()))
|
||||
if (e.Code == _config.GetConsoleKey())
|
||||
{
|
||||
_console.ToggleVisible();
|
||||
return true;
|
||||
@@ -373,13 +373,30 @@ namespace SS14.Client.Services.UserInterface
|
||||
where comp.RecieveInput
|
||||
orderby comp.ZDepth ascending
|
||||
orderby comp.IsVisible() descending
|
||||
//Invisible controls still recieve input but after everyone else. This is mostly for the inventory and other toggleable components.
|
||||
// Invisible controls still recieve input but after everyone else. This is mostly for the inventory and other toggleable components.
|
||||
orderby comp.Focus descending
|
||||
select comp;
|
||||
|
||||
return inputList.Any(current => current.KeyDown(e));
|
||||
}
|
||||
|
||||
public virtual bool TextEntered(TextEventArgs e)
|
||||
{
|
||||
if (_console.IsVisible())
|
||||
{
|
||||
if (_console.TextEntered(e)) return true;
|
||||
}
|
||||
|
||||
IOrderedEnumerable<IGuiComponent> inputList = from IGuiComponent comp in _components
|
||||
where comp.RecieveInput
|
||||
orderby comp.ZDepth ascending
|
||||
orderby comp.IsVisible() descending
|
||||
// Invisible controls still recieve input but after everyone else. This is mostly for the inventory and other toggleable components.
|
||||
orderby comp.Focus descending
|
||||
select comp;
|
||||
|
||||
return inputList.Any(current => current.TextEntered(e));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component retrieval
|
||||
|
||||
@@ -220,6 +220,12 @@ namespace SS14.Client
|
||||
_stateManager.MouseLeft(e);
|
||||
}
|
||||
|
||||
private void TextEntered(object sender, TextEventArgs e)
|
||||
{
|
||||
if (_stateManager != null)
|
||||
_stateManager.TextEntered(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
@@ -270,18 +276,18 @@ namespace SS14.Client
|
||||
onetime = false;
|
||||
}
|
||||
CluwneLib.Screen.SetMouseCursorVisible(false);
|
||||
CluwneLib.Screen.BackgroundColor = Color.Black;
|
||||
CluwneLib.Screen.Resized += MainWindowResizeEnd;
|
||||
CluwneLib.Screen.Closed += MainWindowRequestClose;
|
||||
CluwneLib.Screen.KeyPressed += KeyDownEvent;
|
||||
CluwneLib.Screen.KeyReleased += KeyUpEvent;
|
||||
CluwneLib.Screen.MouseButtonPressed += MouseDownEvent;
|
||||
CluwneLib.Screen.BackgroundColor = Color.Black;
|
||||
CluwneLib.Screen.Resized += MainWindowResizeEnd;
|
||||
CluwneLib.Screen.Closed += MainWindowRequestClose;
|
||||
CluwneLib.Screen.KeyPressed += KeyDownEvent;
|
||||
CluwneLib.Screen.KeyReleased += KeyUpEvent;
|
||||
CluwneLib.Screen.MouseButtonPressed += MouseDownEvent;
|
||||
CluwneLib.Screen.MouseButtonReleased += MouseUpEvent;
|
||||
CluwneLib.Screen.MouseMoved += MouseMoveEvent;
|
||||
CluwneLib.Screen.MouseWheelMoved += MouseWheelMoveEvent;
|
||||
CluwneLib.Screen.MouseEntered += MouseEntered;
|
||||
CluwneLib.Screen.MouseLeft += MouseLeft;
|
||||
|
||||
CluwneLib.Screen.MouseMoved += MouseMoveEvent;
|
||||
CluwneLib.Screen.MouseWheelMoved += MouseWheelMoveEvent;
|
||||
CluwneLib.Screen.MouseEntered += MouseEntered;
|
||||
CluwneLib.Screen.MouseLeft += MouseLeft;
|
||||
CluwneLib.Screen.TextEntered += TextEntered;
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user