Control settings, more server settings, selecting character face

This commit is contained in:
Regalis
2015-10-28 19:07:17 +02:00
parent 9ed2963cd9
commit 948285f6ab
46 changed files with 789 additions and 325 deletions
+6 -1
View File
@@ -143,6 +143,11 @@ namespace Barotrauma
set { selectedColor = value; }
}
public static KeyboardDispatcher KeyboardDispatcher
{
get { return keyboardDispatcher; }
}
protected GUIComponent(GUIStyle style)
{
Visible = true;
@@ -227,7 +232,7 @@ namespace Barotrauma
foreach (Sprite sprite in sprites)
{
Vector2 startPos = new Vector2(rect.X, rect.Y);
Vector2 size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height);
Vector2 size = new Vector2(Math.Min(sprite.SourceRect.Width,rect.Width), Math.Min(sprite.SourceRect.Height,rect.Height));
if (sprite.size.X == 0.0f) size.X = rect.Width;
if (sprite.size.Y == 0.0f) size.Y = rect.Height;
+6
View File
@@ -9,6 +9,10 @@ namespace Barotrauma
{
public class GUIDropDown : GUIComponent
{
public delegate bool OnSelectedHandler(GUIComponent selected);
public OnSelectedHandler OnSelected;
private GUIButton button;
private GUIListBox listBox;
@@ -65,6 +69,8 @@ namespace Barotrauma
Dropped = false;
if (OnSelected != null) OnSelected(component);
return true;
}
+1 -1
View File
@@ -90,7 +90,7 @@ namespace Barotrauma
parent.AddChild(this);
isHorizontal = (rect.Width > rect.Height);
frame = new GUIFrame(new Rectangle(0,0,0,0), Color.White, style, this);
frame = new GUIFrame(new Rectangle(0,0,0,0), Color.Black*0.8f, style, this);
//AddChild(frame);
//System.Diagnostics.Debug.WriteLine(frame.rect);
+7 -3
View File
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
namespace Barotrauma
{
@@ -120,7 +121,7 @@ namespace Barotrauma
this.alignment = alignment;
this.textAlignment = textAlignment;
if (parent != null)
parent.AddChild(this);
@@ -215,8 +216,8 @@ namespace Barotrauma
Color currColor = color;
if (state == ComponentState.Hover) currColor = hoverColor;
if (state == ComponentState.Selected) currColor = selectedColor;
GUI.DrawRectangle(spriteBatch, rect, currColor*(currColor.A/255.0f), true);
if (currColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, currColor * (currColor.A / 255.0f), true);
base.Draw(spriteBatch);
@@ -233,6 +234,9 @@ namespace Barotrauma
}
DrawChildren(spriteBatch);
if (OutlineColor.A * currColor.A > 0.0f) GUI.DrawRectangle(spriteBatch, rect, OutlineColor * (currColor.A / 255.0f), false);
}
}
}
+42 -22
View File
@@ -7,11 +7,11 @@ using Microsoft.Xna.Framework.Input;
namespace Barotrauma
{
delegate void TextBoxEvent(GUITextBox sender);
delegate void TextBoxEvent(GUITextBox sender, Keys key);
class GUITextBox : GUIComponent, IKeyboardSubscriber
{
public event TextBoxEvent Clicked;
public event TextBoxEvent OnSelected;
bool caretVisible;
float caretTimer;
@@ -19,11 +19,13 @@ namespace Barotrauma
GUITextBlock textBlock;
public delegate bool OnEnterHandler(GUITextBox textBox, string text);
public OnEnterHandler OnEnter;
public OnEnterHandler OnEnterPressed;
public event TextBoxEvent OnKeyHit;
public delegate bool OnTextChangedHandler(GUITextBox textBox, string text);
public OnTextChangedHandler OnTextChanged;
public GUITextBlock.TextGetterHandler TextGetter
{
get { return textBlock.TextGetter; }
@@ -68,6 +70,8 @@ namespace Barotrauma
}
}
public bool CaretEnabled;
public String Text
{
get
@@ -97,6 +101,7 @@ namespace Barotrauma
//ensure that text cannot be larger than the box
Text = textBlock.Text.Substring(0, textBlock.Text.Length - 1);
}
}
}
}
@@ -130,10 +135,13 @@ namespace Barotrauma
parent.AddChild(this);
textBlock = new GUITextBlock(new Rectangle(0,0,0,0), "", color, textColor, textAlignment, style, this);
textBlock.Padding = new Vector4(10.0f, 0.0f, 10.0f, 0.0f);
if (style != null) style.Apply(textBlock, this);
textBlock.Padding = new Vector4(3.0f, 0.0f, 3.0f, 0.0f);
previousMouse = PlayerInput.GetMouseState;
CaretEnabled = true;
//SetTextPos();
}
@@ -141,7 +149,7 @@ namespace Barotrauma
{
Selected = true;
keyboardDispatcher.Subscriber = this;
if (Clicked != null) Clicked(this);
//if (Clicked != null) Clicked(this);
}
public void Deselect()
@@ -158,27 +166,37 @@ namespace Barotrauma
if (flashTimer > 0.0f) flashTimer -= deltaTime;
if (!Enabled) return;
caretTimer += deltaTime;
caretVisible = ((caretTimer*1000.0f) % 1000) < 500;
if (CaretEnabled)
{
caretTimer += deltaTime;
caretVisible = ((caretTimer*1000.0f) % 1000) < 500;
}
if (rect.Contains(PlayerInput.MousePosition))
{
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked()) Select();
state = ComponentState.Hover;
if (PlayerInput.LeftButtonClicked())
{
Select();
if (OnSelected != null) OnSelected(this, Keys.None);
}
}
else
{
state = ComponentState.None;
}
textBlock.State = state;
if (keyboardDispatcher.Subscriber == this)
{
Character.DisableControls = true;
if (OnEnter != null && PlayerInput.KeyHit(Keys.Enter))
if (OnEnterPressed != null && PlayerInput.KeyHit(Keys.Enter))
{
string input = Text;
Text = "";
OnEnter(this, input);
OnEnterPressed(this, input);
}
}
@@ -191,6 +209,8 @@ namespace Barotrauma
if (!Visible) return;
DrawChildren(spriteBatch);
if (!CaretEnabled) return;
Vector2 caretPos = textBlock.CaretPos;
@@ -224,14 +244,14 @@ namespace Barotrauma
if (Text.Length > 0)
Text = Text.Substring(0, Text.Length - 1);
break;
case '\r': //return
if (OnEnterPressed != null)
OnEnterPressed(this);
break;
case '\t': //tab
if (OnTabPressed != null)
OnTabPressed(this);
break;
//case '\r': //return
// if (OnEnterPressed != null)
// OnEnterPressed(this);
// break;
//case '\t': //tab
// if (OnTabPressed != null)
// OnTabPressed(this);
// break;
}
if (OnTextChanged != null) OnTextChanged(this, Text);
@@ -239,10 +259,10 @@ namespace Barotrauma
public void ReceiveSpecialInput(Keys key)
{
if (OnKeyHit != null) OnKeyHit(this, key);
}
public event TextBoxEvent OnEnterPressed;
public event TextBoxEvent OnTabPressed;
//public event TextBoxEvent OnTabPressed;
public bool Selected
{
+1 -1
View File
@@ -9,7 +9,7 @@ namespace Barotrauma
GUIFrame box;
GUITextBlock text;
public delegate bool OnSelectedHandler(object obj);
public delegate bool OnSelectedHandler(GUITickBox obj);
public OnSelectedHandler OnSelected;
private bool selected;