mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-24 05:10:42 -04:00
Style: Refactor gui widget layout code.
This commit is contained in:
parent
2fa379746a
commit
d4b38709e1
@ -34,9 +34,6 @@ namespace ClassicalSharp.Gui {
|
||||
/// <remarks> Typically used when bitmap font changes. </remarks>
|
||||
public void Recreate() { Dispose(); Init(); }
|
||||
|
||||
/// <summary> Called when the game window is resized. </summary>
|
||||
public abstract void OnResize( int width, int height );
|
||||
|
||||
public virtual bool HandlesKeyDown( Key key ) { return false; }
|
||||
|
||||
public virtual bool HandlesKeyPress( char key ) { return false; }
|
||||
@ -51,10 +48,10 @@ namespace ClassicalSharp.Gui {
|
||||
|
||||
public virtual bool HandlesMouseUp( int mouseX, int mouseY, MouseButton button ) { return false; }
|
||||
|
||||
protected static int CalcOffset( int axisSize, int elemSize, int offset, Anchor mode ) {
|
||||
if( mode == Anchor.LeftOrTop ) return offset;
|
||||
if( mode == Anchor.BottomOrRight) return axisSize - elemSize - offset;
|
||||
return (axisSize - elemSize) / 2 + offset;
|
||||
protected static int CalcPos( Anchor anchor, int offset, int size, int axisLen ) {
|
||||
if( anchor == Anchor.LeftOrTop ) return offset;
|
||||
if( anchor == Anchor.BottomOrRight ) return axisLen - size - offset;
|
||||
return (axisLen - size) / 2 + offset;
|
||||
}
|
||||
|
||||
public static bool Contains( int recX, int recY, int width, int height, int x, int y ) {
|
||||
|
@ -18,7 +18,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
HudScreen hud;
|
||||
int chatLines;
|
||||
ChatTextWidget announcement;
|
||||
TextWidget announcement;
|
||||
InputWidget textInput;
|
||||
TextGroupWidget status, bottomRight, normalChat, clientStatus;
|
||||
bool suppressNextPress = true;
|
||||
@ -75,7 +75,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
clientStatus.XOffset = 10;
|
||||
clientStatus.YOffset = hud.BottomOffset + 15;
|
||||
clientStatus.Init();
|
||||
announcement = ChatTextWidget.Create( game, 0, 0, null,
|
||||
announcement = TextWidget.Create( game, 0, 0, null,
|
||||
Anchor.Centre, Anchor.Centre, announcementFont );
|
||||
announcement.YOffset = -game.Height / 4;
|
||||
}
|
||||
@ -200,12 +200,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
int height = InputUsedHeight;
|
||||
if( force || height != inputOldHeight ) {
|
||||
clientStatus.YOffset = Math.Max( hud.BottomOffset + 15, height );
|
||||
int y = game.Height - clientStatus.Height - clientStatus.YOffset;
|
||||
clientStatus.MoveTo( clientStatus.X, y );
|
||||
clientStatus.CalculatePosition();
|
||||
|
||||
normalChat.YOffset = clientStatus.YOffset + clientStatus.GetUsedHeight();
|
||||
y = game.Height - normalChat.Height - normalChat.YOffset;
|
||||
normalChat.MoveTo( normalChat.X, y );
|
||||
normalChat.CalculatePosition();
|
||||
inputOldHeight = height;
|
||||
}
|
||||
}
|
||||
@ -414,9 +412,9 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
warning.SetHandlers( OpenUrl, AppendUrl, null );
|
||||
|
||||
warning.SetTextData(
|
||||
"Are you sure you want to go to this url?",
|
||||
url, "Be careful - urls from strangers may link to websites that",
|
||||
" may have viruses, or things you may not want to open/see." );
|
||||
"&eAre you sure you want to open this link?",
|
||||
url, "Be careful - links from strangers may be websites that",
|
||||
" have viruses, or things you may not want to open/see." );
|
||||
game.Gui.ShowWarning( warning );
|
||||
} else if( game.ClickableChat ) {
|
||||
for( int i = 0; i < text.Length; i++ ) {
|
||||
|
@ -15,8 +15,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
regularFont = new Font( game.FontName, 40, FontStyle.Regular );
|
||||
|
||||
widgets = new Widget[] {
|
||||
ChatTextWidget.Create( game, 0, -150, "Game over!", Anchor.Centre, Anchor.Centre, regularFont ),
|
||||
ChatTextWidget.Create( game, 0, -75, "Score: 0", Anchor.Centre, Anchor.Centre, titleFont ),
|
||||
TextWidget.Create( game, 0, -150, "Game over!", Anchor.Centre, Anchor.Centre, regularFont ),
|
||||
TextWidget.Create( game, 0, -75, "Score: 0", Anchor.Centre, Anchor.Centre, titleFont ),
|
||||
ButtonWidget.Create( game, 0, 25, 401, 40, "Generate new level...",
|
||||
Anchor.Centre, Anchor.Centre, titleFont, GenLevelClick ),
|
||||
ButtonWidget.Create( game, 0, 75, 401, 40, "Load level...",
|
||||
|
@ -37,8 +37,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
game.SkipClear = true;
|
||||
string msg = canReconnect ? "Reconnect in " + delay : "Reconnect";
|
||||
widgets = new Widget[] {
|
||||
ChatTextWidget.Create( game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont ),
|
||||
ChatTextWidget.Create( game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont ),
|
||||
TextWidget.Create( game, 0, -30, title, Anchor.Centre, Anchor.Centre, titleFont ),
|
||||
TextWidget.Create( game, 0, 10, message, Anchor.Centre, Anchor.Centre, messageFont ),
|
||||
ButtonWidget.Create( game, 0, 80, 301, 40, msg,
|
||||
Anchor.Centre, Anchor.Centre, titleFont, ReconnectClick ),
|
||||
};
|
||||
@ -61,7 +61,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
for( int i = 0; i < widgets.Length; i++ )
|
||||
widgets[i].OnResize( width, height );
|
||||
widgets[i].CalculatePosition();
|
||||
clearTime = DateTime.UtcNow.AddSeconds( 0.5 );
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
posFont = new Font( game.FontName, 14, FontStyle.Italic );
|
||||
game.Events.ChatFontChanged += ChatFontChanged;
|
||||
|
||||
fpsText = new ChatTextWidget( game, font );
|
||||
fpsText = new TextWidget( game, font );
|
||||
fpsText.XOffset = 2;
|
||||
fpsText.YOffset = 2;
|
||||
fpsText.ReducePadding = true;
|
||||
@ -87,7 +87,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
posAtlas.Pack( "0123456789-, ()", posFont, "Feet pos: " );
|
||||
posAtlas.tex.Y = (short)(fpsText.Height + 2);
|
||||
|
||||
hackStates = new ChatTextWidget( game, posFont );
|
||||
hackStates = new TextWidget( game, posFont );
|
||||
hackStates.XOffset = 2;
|
||||
hackStates.YOffset = fpsText.Height + posAtlas.tex.Height + 2;
|
||||
hackStates.ReducePadding = true;
|
||||
|
@ -86,11 +86,13 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
PlayerListWidget widget = playerList;
|
||||
chat.OnResize( width, height );
|
||||
hotbar.OnResize( width, height );
|
||||
if( widget != null )
|
||||
CreatePlayerListWidget();
|
||||
hotbar.CalculatePosition();
|
||||
|
||||
if( playerList != null ) {
|
||||
playerList.RecalcYOffset();
|
||||
playerList.CalculatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
@ -137,8 +139,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
} else {
|
||||
playerList = new NormalPlayerListWidget( game, playerFont );
|
||||
}
|
||||
|
||||
playerList.Init();
|
||||
playerList.MoveTo( playerList.X, game.Height / 4 );
|
||||
playerList.RecalcYOffset();
|
||||
playerList.CalculatePosition();
|
||||
}
|
||||
|
||||
public override bool HandlesKeyUp( Key key ) {
|
||||
|
@ -20,7 +20,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
string serverName, serverMotd;
|
||||
float progress;
|
||||
ChatTextWidget titleWidget, messageWidget;
|
||||
TextWidget titleWidget, messageWidget;
|
||||
const int progWidth = 220, progHeight = 10;
|
||||
readonly FastColour backCol = new FastColour( 128, 128, 128 );
|
||||
readonly FastColour progressCol = new FastColour( 128, 255, 128 );
|
||||
@ -84,13 +84,13 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
public void SetTitle( string title ) {
|
||||
if( titleWidget != null )
|
||||
titleWidget.Dispose();
|
||||
titleWidget = ChatTextWidget.Create( game, 0, -80, title, Anchor.Centre, Anchor.Centre, font );
|
||||
titleWidget = TextWidget.Create( game, 0, -80, title, Anchor.Centre, Anchor.Centre, font );
|
||||
}
|
||||
|
||||
public void SetMessage( string message ) {
|
||||
if( messageWidget != null )
|
||||
messageWidget.Dispose();
|
||||
messageWidget = ChatTextWidget.Create( game, 0, -30, message, Anchor.Centre, Anchor.Centre, font );
|
||||
messageWidget = TextWidget.Create( game, 0, -30, message, Anchor.Centre, Anchor.Centre, font );
|
||||
}
|
||||
|
||||
public void SetProgress( float progress ) {
|
||||
@ -109,8 +109,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
messageWidget.OnResize( width, height );
|
||||
titleWidget.OnResize( width, height );
|
||||
messageWidget.CalculatePosition();
|
||||
titleWidget.CalculatePosition();
|
||||
}
|
||||
|
||||
public override bool BlocksWorld { get { return true; } }
|
||||
|
@ -23,7 +23,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
textFont = new Font( game.FontName, 16, FontStyle.Bold );
|
||||
arrowFont = new Font( game.FontName, 18, FontStyle.Bold );
|
||||
titleFont = new Font( game.FontName, 16, FontStyle.Bold );
|
||||
title = ChatTextWidget.Create( game, 0, -155, titleText,
|
||||
title = TextWidget.Create( game, 0, -155, titleText,
|
||||
Anchor.Centre, Anchor.Centre, titleFont );
|
||||
|
||||
buttons = new ButtonWidget[] {
|
||||
@ -114,8 +114,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
for( int i = 0; i < buttons.Length; i++ )
|
||||
buttons[i].OnResize( width, height );
|
||||
title.OnResize( width, height );
|
||||
buttons[i].CalculatePosition();
|
||||
title.CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Render( double delta ) {
|
||||
|
@ -48,11 +48,11 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
MakeInput( -40, false, game.World.Height.ToString() ),
|
||||
MakeInput( 0, false, game.World.Length.ToString() ),
|
||||
MakeInput( 40, true, "" ),
|
||||
|
||||
|
||||
MakeLabel( -150, -80, "Width:" ), MakeLabel( -150, -40, "Height:" ),
|
||||
MakeLabel( -150, 0, "Length:" ), MakeLabel( -140, 40, "Seed:" ),
|
||||
ChatTextWidget.Create( game, 0, -130, "Generate new level",
|
||||
Anchor.Centre, Anchor.Centre, regularFont ),
|
||||
TextWidget.Create( game, 0, -130, "Generate new level",
|
||||
Anchor.Centre, Anchor.Centre, regularFont ),
|
||||
|
||||
ButtonWidget.Create( game, -120, 100, 201, 40, "Flatgrass", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, GenFlatgrassClick ),
|
||||
@ -74,10 +74,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
TextWidget MakeLabel( int x, int y, string text ) {
|
||||
TextWidget widget = ChatTextWidget.Create( game, x, y, text,
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
int start = game.Width / 2 - 110;
|
||||
widget.MoveTo( start - widget.Width, widget.Y );
|
||||
TextWidget widget = TextWidget.Create( game, x, y, text,
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
widget.XOffset = -110 - widget.Width / 2;
|
||||
widget.CalculatePosition();
|
||||
widget.Colour = new FastColour( 224, 224, 224 );
|
||||
return widget;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void Init() {
|
||||
base.Init();
|
||||
extHelpY = 100;
|
||||
|
||||
widgets = new Widget[] {
|
||||
|
||||
|
@ -47,7 +47,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
}
|
||||
|
||||
void MakeOthers() {
|
||||
widgets[index++] = ChatTextWidget.Create( game, 0, -180, title,
|
||||
widgets[index++] = TextWidget.Create( game, 0, -180, title,
|
||||
Anchor.Centre, Anchor.Centre, keyFont );
|
||||
if( game.ClassicMode ) {
|
||||
widgets[index++] = MakeBack( false, titleFont,
|
||||
|
@ -132,7 +132,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
leftPage = (g, w) => g.Gui.SetNewScreen( new HacksKeyBindingsScreen( g ) );
|
||||
MakeWidgets( -50 );
|
||||
|
||||
widgets[index++] = ChatTextWidget.Create(
|
||||
widgets[index++] = TextWidget.Create(
|
||||
game, 0, 80, "&eRight click to remove the key binding",
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
public override void OnResize( int width, int height ) {
|
||||
base.OnResize( width, height );
|
||||
if( extendedHelp == null ) return;
|
||||
extendedHelp.OnResize( width, height );
|
||||
extendedHelp.YOffset = game.Height / 2 + extHelpY;
|
||||
extendedHelp.CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
@ -157,10 +158,11 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
static FastColour tableCol = new FastColour( 20, 20, 20, 200 );
|
||||
int tableWidth, tableHeight;
|
||||
protected int extHelpY = 100;
|
||||
const int extHelpY = 100;
|
||||
|
||||
void MakeExtendedHelp( string[] desc ) {
|
||||
extendedHelp = new TextGroupWidget( game, desc.Length, regularFont, null,
|
||||
Anchor.Centre, Anchor.Centre );
|
||||
Anchor.Centre, Anchor.LeftOrTop );
|
||||
extendedHelp.Init();
|
||||
|
||||
for( int i = 0; i < desc.Length; i++ )
|
||||
@ -170,7 +172,8 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
tableWidth = extendedHelp.Width;
|
||||
tableHeight = extendedHelp.Height;
|
||||
extendedHelp.MoveTo( extendedHelp.X, extHelpY + tableHeight / 2 );
|
||||
extendedHelp.YOffset = game.Height / 2 + extHelpY;
|
||||
extendedHelp.CalculatePosition();
|
||||
}
|
||||
|
||||
void DisposeExtendedHelp() {
|
||||
|
@ -32,7 +32,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
MakeBool( 1, 0, "Use server textures", OptionsKey.AllowServerTextures,
|
||||
OnWidgetClick, g => g.AllowServerTextures, (g, v) => g.AllowServerTextures = v ),
|
||||
|
||||
ChatTextWidget.Create( game, 0, 100,
|
||||
TextWidget.Create( game, 0, 100,
|
||||
"&eButtons on the right require a client restart",
|
||||
Anchor.Centre, Anchor.Centre, regularFont ),
|
||||
MakeBack( false, titleFont,
|
||||
|
@ -67,7 +67,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
if( button == null ) return;
|
||||
|
||||
string text = descriptions[Array.IndexOf<Widget>(widgets, button)];
|
||||
descWidget = ChatTextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont );
|
||||
descWidget = TextWidget.Create( game, 0, 100, text, Anchor.Centre, Anchor.Centre, regularFont );
|
||||
}
|
||||
|
||||
ButtonWidget Make( int dir, int y, string text, Action<Game, Widget> onClick ) {
|
||||
@ -83,7 +83,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
if( descWidget != null )
|
||||
descWidget.OnResize( width, height );
|
||||
descWidget.CalculatePosition();
|
||||
base.OnResize( width, height );
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
Anchor.Centre, titleFont, SaveClassic ),
|
||||
ButtonWidget.Create( game, -150, 120, 201, 40, "Save schematic", Anchor.Centre,
|
||||
Anchor.Centre, titleFont, SaveSchematic ),
|
||||
ChatTextWidget.Create( game, 110, 120, "&eCan be imported into MCEdit", Anchor.Centre,
|
||||
TextWidget.Create( game, 110, 120, "&eCan be imported into MCEdit", Anchor.Centre,
|
||||
Anchor.Centre, regularFont ),
|
||||
null,
|
||||
MakeBack( false, titleFont,
|
||||
@ -74,7 +74,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
inputWidget.OnResize( width, height );
|
||||
inputWidget.CalculatePosition();
|
||||
base.OnResize( width, height );
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
void MakeDescWidget( string text ) {
|
||||
DisposeDescWidget();
|
||||
descWidget = ChatTextWidget.Create( game, 0, 65, text,
|
||||
descWidget = TextWidget.Create( game, 0, 65, text,
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
public override void OnResize( int width, int height ) {
|
||||
for( int i = 0; i < widgets.Length; i++ ) {
|
||||
if( widgets[i] == null ) continue;
|
||||
widgets[i].OnResize( width, height );
|
||||
widgets[i].CalculatePosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,9 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
/// <summary> Whether the normal in-game hud should be drawn over the top of this screen. </summary>
|
||||
public virtual bool RenderHudAfter { get { return false; } }
|
||||
|
||||
|
||||
/// <summary> Called when the game window is resized. </summary>
|
||||
public abstract void OnResize( int width, int height );
|
||||
|
||||
protected ClickHandler LeftOnly( Action<Game, Widget> action ) {
|
||||
if( action == null ) return (g, w, btn) => {};
|
||||
|
@ -12,7 +12,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
this.showAlways = showAlways;
|
||||
}
|
||||
|
||||
public void SetHandlers(Action<WarningScreen> yesClick,
|
||||
public void SetHandlers(Action<WarningScreen> yesClick,
|
||||
Action<WarningScreen> noClick,
|
||||
Action<WarningScreen> renderFrame) {
|
||||
this.yesClick = yesClick;
|
||||
@ -60,10 +60,10 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
|
||||
labels = new TextWidget[body.Length + 1];
|
||||
labels[0] = TextWidget.Create( game, 0, -120, title,
|
||||
Anchor.Centre, Anchor.Centre, titleFont );
|
||||
Anchor.Centre, Anchor.Centre, titleFont );
|
||||
for( int i = 0; i < body.Length; i++ ) {
|
||||
labels[i + 1] = ChatTextWidget.Create( game, 0, -70 + 20 * i, body[i],
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
labels[i + 1] = TextWidget.Create( game, 0, -70 + 20 * i, body[i],
|
||||
Anchor.Centre, Anchor.Centre, regularFont );
|
||||
labels[i + 1].Colour = new FastColour( 224, 224, 224 );
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace ClassicalSharp.Gui.Screens {
|
||||
public override void OnResize( int width, int height ) {
|
||||
base.OnResize( width, height );
|
||||
for( int i = 0; i < labels.Length; i++ )
|
||||
labels[i].OnResize( width, height );
|
||||
labels[i].CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
@ -68,8 +68,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
public override void Dispose() { }
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
X = newX; Y = newY;
|
||||
public override void CalculatePosition() {
|
||||
base.CalculatePosition();
|
||||
Recreate();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ using OpenTK.Input;
|
||||
using Android.Graphics;
|
||||
#endif
|
||||
|
||||
namespace ClassicalSharp.Gui.Widgets {
|
||||
namespace ClassicalSharp.Gui.Widgets {
|
||||
public sealed class ButtonWidget : Widget {
|
||||
|
||||
public ButtonWidget( Game game, Font font ) : base( game ) {
|
||||
@ -26,6 +26,12 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
return widget;
|
||||
}
|
||||
|
||||
public void SetLocation( Anchor horAnchor, Anchor verAnchor, int xOffset, int yOffset ) {
|
||||
HorizontalAnchor = horAnchor; VerticalAnchor = verAnchor;
|
||||
XOffset = xOffset; YOffset = yOffset;
|
||||
CalculatePosition();
|
||||
}
|
||||
|
||||
Texture texture;
|
||||
public int DesiredMaxWidth, DesiredMaxHeight;
|
||||
int defaultHeight;
|
||||
@ -56,8 +62,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
Width = Math.Max( texture.Width, DesiredMaxWidth );
|
||||
Height = Math.Max( texture.Height, DesiredMaxHeight );
|
||||
|
||||
X = CalcOffset( game.Width, Width, XOffset, HorizontalAnchor );
|
||||
Y = CalcOffset( game.Height, Height, YOffset, VerticalAnchor );
|
||||
CalculatePosition();
|
||||
texture.X1 = X + (Width / 2 - texture.Width / 2);
|
||||
texture.Y1 = Y + (Height / 2 - texture.Height / 2);
|
||||
}
|
||||
@ -84,10 +89,12 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture( ref texture );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int deltaX = newX - X, deltaY = newY - Y;
|
||||
texture.X1 += deltaX; texture.Y1 += deltaY;
|
||||
X = newX; Y = newY;
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
texture.X1 += X - oldX;
|
||||
texture.Y1 += Y - oldY;
|
||||
}
|
||||
|
||||
public Func<Game, string> GetValue;
|
||||
|
@ -1,45 +0,0 @@
|
||||
// ClassicalSharp copyright 2014-2016 UnknownShadow200 | Licensed under MIT
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
namespace ClassicalSharp.Gui.Widgets {
|
||||
/// <summary> Draws text to the screen, uses the given font when the user has specified 'use arial' in options,
|
||||
/// otherwise draws text using the bitmapped font in default.png </summary>
|
||||
public sealed class ChatTextWidget : TextWidget {
|
||||
|
||||
public ChatTextWidget( Game game, Font font ) : base( game, font ) {
|
||||
}
|
||||
|
||||
public static new ChatTextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font ) {
|
||||
ChatTextWidget widget = new ChatTextWidget( game, font );
|
||||
widget.Init();
|
||||
widget.HorizontalAnchor = horizontal; widget.VerticalAnchor = vertical;
|
||||
widget.XOffset = x; widget.YOffset = y;
|
||||
widget.SetText( text );
|
||||
return widget;
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
||||
int height = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||
SetHeight( height );
|
||||
}
|
||||
|
||||
public override void SetText( string text ) {
|
||||
gfx.DeleteTexture( ref texture );
|
||||
if( String.IsNullOrEmpty( text ) ) {
|
||||
texture = new Texture();
|
||||
Width = 0; Height = defaultHeight;
|
||||
} else {
|
||||
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
||||
texture = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 );
|
||||
if( ReducePadding )
|
||||
game.Drawer2D.ReducePadding( ref texture, Utils.Floor( font.Size ) );
|
||||
Width = texture.Width; Height = texture.Height;
|
||||
|
||||
X = texture.X1 = CalcOffset( game.Width, Width, XOffset, HorizontalAnchor );
|
||||
Y = texture.Y1 = CalcOffset( game.Height, Height, YOffset, VerticalAnchor );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
DrawAdvanced( ref args, index, text );
|
||||
game.Drawer2D.ReducePadding( ref tex, Utils.Floor( args.Font.Size ), 3 );
|
||||
|
||||
tex.X1 = CalcOffset( game.Width, tex.Width, XOffset, HorizontalAnchor );
|
||||
tex.X1 = CalcPos( HorizontalAnchor, XOffset, Width, game.Width );
|
||||
tex.Y1 = CalcY( index, tex.Height );
|
||||
Textures[index] = tex;
|
||||
lines[index] = text;
|
||||
|
@ -103,9 +103,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
Width = Math.Max( Width, Textures[i].Width );
|
||||
Height += Textures[i].Height;
|
||||
}
|
||||
|
||||
X = CalcOffset( game.Width, Width, XOffset, HorizontalAnchor );
|
||||
Y = CalcOffset( game.Height, Height, YOffset, VerticalAnchor );
|
||||
CalculatePosition();
|
||||
}
|
||||
|
||||
public override void Render( double delta ) {
|
||||
@ -121,13 +119,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture( ref Textures[i] );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int dx = newX - X, dy = newY - Y;
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
for( int i = 0; i < Textures.Length; i++ ) {
|
||||
Textures[i].X1 += dx;
|
||||
Textures[i].Y1 += dy;
|
||||
Textures[i].X1 += X - oldX;
|
||||
Textures[i].Y1 += Y - oldY;
|
||||
}
|
||||
X = newX; Y = newY;
|
||||
}
|
||||
|
||||
public string GetSelected( int mouseX, int mouseY ) {
|
||||
|
@ -186,11 +186,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture( ref prefixTex );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int dx = newX - X, dy = newY - Y;
|
||||
X = newX; Y = newY;
|
||||
caretTex.Y1 += dy;
|
||||
inputTex.Y1 += dy;
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
caretTex.X1 += X - oldX;
|
||||
caretTex.Y1 += Y - oldY;
|
||||
inputTex.X1 += X - oldX;
|
||||
inputTex.Y1 += Y - oldY;
|
||||
}
|
||||
|
||||
/// <summary> Invoked when the user presses enter. </summary>
|
||||
|
@ -94,10 +94,9 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
drawer.DrawChatText( ref args, hintX, yOffset );
|
||||
chatInputTexture = drawer.Make2DTexture( bmp, size, 0, 0 );
|
||||
}
|
||||
Width = size.Width; Height = size.Height;
|
||||
Width = size.Width; Height = size.Height;
|
||||
CalculatePosition();
|
||||
|
||||
X = CalcOffset( game.Width, Width, XOffset, HorizontalAnchor );
|
||||
Y = CalcOffset( game.Height, Height, YOffset, VerticalAnchor );
|
||||
chatCaretTexture.X1 = chatInputTexture.X1 = X;
|
||||
chatCaretTexture.X1 += textSize.Width;
|
||||
chatCaretTexture.Y1 = chatInputTexture.Y1 = Y;
|
||||
@ -111,13 +110,14 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture( ref chatInputTexture );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int dx = newX - X, dy = newY - Y;
|
||||
X = newX; Y = newY;
|
||||
chatCaretTexture.X1 += dx;
|
||||
chatCaretTexture.Y1 += dy;
|
||||
chatInputTexture.X1 += dx;
|
||||
chatInputTexture.Y1 += dy;
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
chatCaretTexture.X1 += X - oldX;
|
||||
chatCaretTexture.Y1 += Y - oldY;
|
||||
chatInputTexture.X1 += X - oldX;
|
||||
chatInputTexture.Y1 += Y - oldY;
|
||||
}
|
||||
|
||||
static bool IsInvalidChar( char c ) {
|
||||
|
@ -5,7 +5,7 @@ using System.Drawing;
|
||||
namespace ClassicalSharp.Gui.Widgets {
|
||||
public sealed class ClassicPlayerListWidget : NormalPlayerListWidget {
|
||||
|
||||
ChatTextWidget overview;
|
||||
TextWidget overview;
|
||||
static FastColour topCol = new FastColour( 0, 0, 0, 180 );
|
||||
static FastColour bottomCol = new FastColour( 50, 50, 50, 205 );
|
||||
public ClassicPlayerListWidget( Game game, Font font ) : base( game, font ) {
|
||||
@ -34,8 +34,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.Draw2DQuad( X, Y - offset, Width, height, topCol, bottomCol );
|
||||
|
||||
gfx.Texturing = true;
|
||||
overview.MoveTo( game.Width / 2 - overview.Width / 2,
|
||||
Y - offset + boundsSize / 2 );
|
||||
overview.YOffset = Y - offset + 5;
|
||||
overview.CalculatePosition();
|
||||
overview.Render( delta );
|
||||
|
||||
for( int i = 0; i < namesCount; i++ ) {
|
||||
@ -48,8 +48,8 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
|
||||
public override void Init() {
|
||||
overview = ChatTextWidget.Create( game, 0, 0, "Connected players:",
|
||||
Anchor.Centre, Anchor.Centre, font );
|
||||
overview = TextWidget.Create( game, 0, 0, "Connected players:",
|
||||
Anchor.Centre, Anchor.LeftOrTop, font );
|
||||
base.Init();
|
||||
}
|
||||
|
||||
|
@ -101,13 +101,18 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
protected virtual bool ShouldOffset( int i ) { return true; }
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int diffX = newX - X; int diffY = newY - Y;
|
||||
public void RecalcYOffset() {
|
||||
YOffset = -Math.Max( 0, game.Height / 4 - Height / 2 );
|
||||
}
|
||||
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
for( int i = 0; i < namesCount; i++ ) {
|
||||
textures[i].X1 += diffX;
|
||||
textures[i].Y1 += diffY;
|
||||
textures[i].X1 += X - oldX;
|
||||
textures[i].Y1 += Y - oldY;
|
||||
}
|
||||
X = newX; Y = newY;
|
||||
}
|
||||
|
||||
protected abstract void CreateInitialPlayerInfo();
|
||||
@ -158,10 +163,10 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
OnSort();
|
||||
UpdateTableDimensions();
|
||||
MoveTo( X, game.Height / 4 );
|
||||
RecalcYOffset();
|
||||
CalculatePosition();
|
||||
}
|
||||
|
||||
protected virtual void OnSort() {
|
||||
}
|
||||
protected virtual void OnSort() { }
|
||||
}
|
||||
}
|
@ -52,7 +52,5 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
static TextureRec halfRec = new TextureRec( 62 / 256f, 1 / 256f, 7 / 256f, 7 / 256f );
|
||||
|
||||
public override void Dispose() { }
|
||||
|
||||
public override void MoveTo( int newX, int newY ) { X = newX; Y = newY; }
|
||||
}
|
||||
}
|
@ -10,14 +10,19 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
}
|
||||
|
||||
public static TextWidget Create( Game game, int x, int y, string text, Anchor horizontal, Anchor vertical, Font font ) {
|
||||
TextWidget widget = new TextWidget( game, font );
|
||||
widget.Init();
|
||||
widget.HorizontalAnchor = horizontal;
|
||||
widget.VerticalAnchor = vertical;
|
||||
widget.XOffset = x;
|
||||
widget.YOffset = y;
|
||||
widget.SetText( text );
|
||||
return widget;
|
||||
TextWidget w = new TextWidget( game, font );
|
||||
w.Init();
|
||||
w.HorizontalAnchor = horizontal; w.VerticalAnchor = vertical;
|
||||
w.XOffset = x; w.YOffset = y;
|
||||
w.SetText( text );
|
||||
return w;
|
||||
}
|
||||
|
||||
public TextWidget SetLocation( Anchor horAnchor, Anchor verAnchor, int xOffset, int yOffset ) {
|
||||
HorizontalAnchor = horAnchor; VerticalAnchor = verAnchor;
|
||||
XOffset = xOffset; YOffset = yOffset;
|
||||
CalculatePosition();
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Texture texture;
|
||||
@ -30,7 +35,7 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
|
||||
public override void Init() {
|
||||
DrawTextArgs args = new DrawTextArgs( "I", font, true );
|
||||
int height = game.Drawer2D.MeasureSize( ref args ).Height;
|
||||
int height = game.Drawer2D.MeasureChatSize( ref args ).Height;
|
||||
SetHeight( height );
|
||||
}
|
||||
|
||||
@ -41,20 +46,20 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
Height = height;
|
||||
}
|
||||
|
||||
public virtual void SetText( string text ) {
|
||||
public void SetText( string text ) {
|
||||
gfx.DeleteTexture( ref texture );
|
||||
if( String.IsNullOrEmpty( text ) ) {
|
||||
texture = new Texture();
|
||||
Width = 0; Height = defaultHeight;
|
||||
} else {
|
||||
DrawTextArgs args = new DrawTextArgs( text, font, true );
|
||||
texture = game.Drawer2D.MakeTextTexture( ref args, 0, 0 );
|
||||
texture = game.Drawer2D.MakeChatTextTexture( ref args, 0, 0 );
|
||||
if( ReducePadding )
|
||||
game.Drawer2D.ReducePadding( ref texture, Utils.Floor( font.Size ) );
|
||||
Width = texture.Width; Height = texture.Height;
|
||||
|
||||
X = texture.X1 = CalcOffset( game.Width, Width, XOffset, HorizontalAnchor );
|
||||
Y = texture.Y1 = CalcOffset( game.Height, Height, YOffset, VerticalAnchor );
|
||||
|
||||
CalculatePosition();
|
||||
texture.X1 = X; texture.Y1 = Y;
|
||||
}
|
||||
}
|
||||
|
||||
@ -67,10 +72,12 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
gfx.DeleteTexture( ref texture );
|
||||
}
|
||||
|
||||
public override void MoveTo( int newX, int newY ) {
|
||||
int dx = newX - X, dy = newY - Y;
|
||||
texture.X1 += dx; texture.Y1 += dy;
|
||||
X = newX; Y = newY;
|
||||
public override void CalculatePosition() {
|
||||
int oldX = X, oldY = Y;
|
||||
base.CalculatePosition();
|
||||
|
||||
texture.X1 += X - oldX;
|
||||
texture.Y1 += Y - oldY;
|
||||
}
|
||||
}
|
||||
}
|
@ -57,15 +57,9 @@ namespace ClassicalSharp.Gui.Widgets {
|
||||
/// <summary> Specifies the boundaries of the widget in pixels. </summary>
|
||||
public Rectangle Bounds { get { return new Rectangle( X, Y, Width, Height ); } }
|
||||
|
||||
/// <summary> Moves the widget to the specified pixel coordinates. </summary>
|
||||
public virtual void MoveTo( int newX, int newY ) {
|
||||
X = newX; Y = newY;
|
||||
}
|
||||
|
||||
public override void OnResize( int width, int height ) {
|
||||
int x = CalcOffset( width, Width, XOffset, HorizontalAnchor );
|
||||
int y = CalcOffset( height, Height, YOffset, VerticalAnchor );
|
||||
MoveTo( x, y );
|
||||
public virtual void CalculatePosition() {
|
||||
X = CalcPos( HorizontalAnchor, XOffset, Width, game.Width );
|
||||
Y = CalcPos( VerticalAnchor, YOffset, Height, game.Height );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,6 @@
|
||||
<Compile Include="2D\Widgets\BlockHotbarWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\AltTextInputWidget.Types.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\ChatInputWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\ChatTextWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\AltTextInputWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\TextGroupWidget.cs" />
|
||||
<Compile Include="2D\Widgets\Chat\TextGroupWidget.Formatter.cs" />
|
||||
|
@ -46,8 +46,7 @@ namespace Launcher.Gui.Widgets {
|
||||
/// <summary> Sets the reference points for when this widget is resized,
|
||||
/// and the offsets from the reference points (anchors) in pixels. </summary>
|
||||
/// <remarks> Updates the position of the widget. </remarks>
|
||||
public void SetLocation( Anchor horAnchor, Anchor verAnchor,
|
||||
int xOffset, int yOffset ) {
|
||||
public void SetLocation( Anchor horAnchor, Anchor verAnchor, int xOffset, int yOffset ) {
|
||||
HorizontalAnchor = horAnchor; VerticalAnchor = verAnchor;
|
||||
XOffset = xOffset; YOffset = yOffset;
|
||||
CalculatePosition();
|
||||
@ -61,13 +60,9 @@ namespace Launcher.Gui.Widgets {
|
||||
}
|
||||
|
||||
static int CalcPos( Anchor anchor, int offset, int size, int axisLen ) {
|
||||
if( anchor == Anchor.LeftOrTop )
|
||||
return offset;
|
||||
if( anchor == Anchor.Centre )
|
||||
return offset + axisLen / 2 - size / 2;
|
||||
if( anchor == Anchor.BottomOrRight )
|
||||
return offset + axisLen - size;
|
||||
return 0;
|
||||
if( anchor == Anchor.LeftOrTop ) return offset;
|
||||
if( anchor == Anchor.BottomOrRight ) return offset + axisLen - size;
|
||||
return offset + axisLen / 2 - size / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user