mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Some simplification of 2D screens.
This commit is contained in:
parent
5db13ca535
commit
78d35a0b87
@ -29,8 +29,8 @@ namespace ClassicalSharp {
|
|||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
GraphicsApi.Fog = false;
|
GraphicsApi.Fog = false;
|
||||||
titleWidget = CreateTextWidget( 30, serverName );
|
titleWidget = TextWidget.Create( Window, 0, 30, serverName, Docking.Centre, Docking.LeftOrTop, font );
|
||||||
messageWidget = CreateTextWidget( 60, serverMotd );
|
messageWidget = TextWidget.Create( Window, 0, 60, serverMotd, Docking.Centre, Docking.LeftOrTop, font );
|
||||||
progX = Window.Width / 2f - progWidth / 2f;
|
progX = Window.Width / 2f - progWidth / 2f;
|
||||||
using( Bitmap bmp = new Bitmap( progWidth, progHeight ) ) {
|
using( Bitmap bmp = new Bitmap( progWidth, progHeight ) ) {
|
||||||
using( Graphics g = Graphics.FromImage( bmp ) ) {
|
using( Graphics g = Graphics.FromImage( bmp ) ) {
|
||||||
@ -55,15 +55,6 @@ namespace ClassicalSharp {
|
|||||||
Window.MapLoading -= MapLoading;
|
Window.MapLoading -= MapLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWidget CreateTextWidget( int yOffset, string text ) {
|
|
||||||
TextWidget widget = new TextWidget( Window, font );
|
|
||||||
widget.Init();
|
|
||||||
widget.HorizontalDocking = Docking.Centre;
|
|
||||||
widget.YOffset = yOffset;
|
|
||||||
widget.SetText( text );
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||||
int deltaX = ( width - oldWidth ) / 2;
|
int deltaX = ( width - oldWidth ) / 2;
|
||||||
messageWidget.OnResize( oldWidth, oldHeight, width, height );
|
messageWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||||
|
@ -32,50 +32,38 @@ namespace ClassicalSharp {
|
|||||||
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
titleFont = new Font( "Arial", 16, FontStyle.Bold );
|
||||||
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
|
keyStatusFont = new Font( "Arial", 13, FontStyle.Italic );
|
||||||
textFont = new Font( "Arial", 14, FontStyle.Bold );
|
textFont = new Font( "Arial", 14, FontStyle.Bold );
|
||||||
controlsWidget = CreateTextWidget( 0, 30, "&eControls list", Docking.Centre, Docking.LeftOrTop, titleFont );
|
controlsWidget = TextWidget.Create( Window, 0, 30, "&eControls list", Docking.Centre, Docking.LeftOrTop, titleFont );
|
||||||
keyStatusWidget = CreateTextWidget( 0, -80, "", Docking.Centre, Docking.BottomOrRight, keyStatusFont );
|
keyStatusWidget = TextWidget.Create( Window, 0, -80, "", Docking.Centre, Docking.BottomOrRight, keyStatusFont );
|
||||||
gameWidget = CreateTextWidget( 0, -50, "&eBack to game", Docking.Centre, Docking.BottomOrRight, titleFont );
|
gameWidget = TextWidget.Create( Window, 0, -50, "&eBack to game", Docking.Centre, Docking.BottomOrRight, titleFont );
|
||||||
exitWidget = CreateTextWidget( 0, -10, "&eExit", Docking.Centre, Docking.BottomOrRight, titleFont );
|
exitWidget = TextWidget.Create( Window, 0, -10, "&eExit", Docking.Centre, Docking.BottomOrRight, titleFont );
|
||||||
|
|
||||||
KeyMapping[] mappingsLeft = { KeyMapping.Forward, KeyMapping.Back, KeyMapping.Left, KeyMapping.Right,
|
KeyMapping[] mappingsLeft = { KeyMapping.Forward, KeyMapping.Back, KeyMapping.Left, KeyMapping.Right,
|
||||||
KeyMapping.Jump, KeyMapping.Respawn, KeyMapping.SetSpawn, KeyMapping.OpenChat, KeyMapping.SendChat,
|
KeyMapping.Jump, KeyMapping.Respawn, KeyMapping.SetSpawn, KeyMapping.OpenChat, KeyMapping.SendChat,
|
||||||
KeyMapping.PauseOrExit, KeyMapping.OpenInventory };
|
KeyMapping.PauseOrExit, KeyMapping.OpenInventory };
|
||||||
string[] descriptionsLeft = { "Forward", "Back", "Left", "Right", "Jump", "Respawn", "Set spawn",
|
string[] descriptionsLeft = { "Forward", "Back", "Left", "Right", "Jump", "Respawn", "Set spawn",
|
||||||
"Open chat", "Send chat", "Pause", "Open inventory" };
|
"Open chat", "Send chat", "Pause", "Open inventory" };
|
||||||
MakeKeysLeft( mappingsLeft, descriptionsLeft );
|
MakeKeys( mappingsLeft, descriptionsLeft, 10, out keysLeft );
|
||||||
|
leftEnd = CalculateMaxWidth( keysLeft );
|
||||||
|
|
||||||
KeyMapping[] mappingsRight = { KeyMapping.Screenshot, KeyMapping.Fullscreen, KeyMapping.ThirdPersonCamera,
|
KeyMapping[] mappingsRight = { KeyMapping.Screenshot, KeyMapping.Fullscreen, KeyMapping.ThirdPersonCamera,
|
||||||
KeyMapping.VSync, KeyMapping.ViewDistance, KeyMapping.Fly, KeyMapping.Speed, KeyMapping.NoClip,
|
KeyMapping.VSync, KeyMapping.ViewDistance, KeyMapping.Fly, KeyMapping.Speed, KeyMapping.NoClip,
|
||||||
KeyMapping.FlyUp, KeyMapping.FlyDown, KeyMapping.PlayerList };
|
KeyMapping.FlyUp, KeyMapping.FlyDown, KeyMapping.PlayerList };
|
||||||
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle 3rd person camera", "Toggle VSync",
|
string[] descriptionsRight = { "Take screenshot", "Toggle fullscreen", "Toggle 3rd person camera", "Toggle VSync",
|
||||||
"Change view distance", "Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list" };
|
"Change view distance", "Toggle fly", "Speed", "Toggle noclip", "Fly up", "Fly down", "Display player list" };
|
||||||
MakeKeysRight( mappingsRight, descriptionsRight );
|
MakeKeys( mappingsRight, descriptionsRight, leftEnd + 30, out keysRight );
|
||||||
}
|
}
|
||||||
|
|
||||||
int leftEnd;
|
int leftEnd;
|
||||||
void MakeKeysLeft( KeyMapping[] mappings, string[] descriptions ) {
|
void MakeKeys( KeyMapping[] mappings, string[] descriptions, int offset, out KeyMapWidget[] widgets ) {
|
||||||
int startY = controlsWidget.BottomRight.Y + 10;
|
int startY = controlsWidget.BottomRight.Y + 10;
|
||||||
keysLeft = new KeyMapWidget[mappings.Length];
|
widgets = new KeyMapWidget[mappings.Length];
|
||||||
|
|
||||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||||
string text = descriptions[i] + ": " + Window.Keys[mappings[i]];
|
string text = descriptions[i] + ": " + Window.Keys[mappings[i]];
|
||||||
TextWidget widget = CreateTextWidget( 0, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
TextWidget widget = TextWidget.Create( Window, 0, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
||||||
widget.XOffset = 10;
|
widget.XOffset = offset;
|
||||||
widget.MoveTo( widget.X + widget.XOffset, widget.Y );
|
widget.MoveTo( widget.X + widget.XOffset, widget.Y );
|
||||||
keysLeft[i] = new KeyMapWidget( widget, mappings[i], descriptions[i] );
|
widgets[i] = new KeyMapWidget( widget, mappings[i], descriptions[i] );
|
||||||
startY += widget.Height + 5;
|
|
||||||
}
|
|
||||||
leftEnd = CalculateMaxWidth( keysLeft );
|
|
||||||
}
|
|
||||||
|
|
||||||
void MakeKeysRight( KeyMapping[] mappings, string[] descriptions ) {
|
|
||||||
int startY = controlsWidget.BottomRight.Y + 10;
|
|
||||||
keysRight = new KeyMapWidget[mappings.Length];
|
|
||||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
|
||||||
string text = descriptions[i] + ": " + Window.Keys[mappings[i]];
|
|
||||||
TextWidget widget = CreateTextWidget( 0, startY, text, Docking.LeftOrTop, Docking.LeftOrTop, textFont );
|
|
||||||
widget.XOffset = leftEnd + 30;
|
|
||||||
widget.MoveTo( widget.X + widget.XOffset, widget.Y );
|
|
||||||
keysRight[i] = new KeyMapWidget( widget, mappings[i], descriptions[i] );
|
|
||||||
startY += widget.Height + 5;
|
startY += widget.Height + 5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,23 +77,10 @@ namespace ClassicalSharp {
|
|||||||
exitWidget.Dispose();
|
exitWidget.Dispose();
|
||||||
for( int i = 0; i < keysLeft.Length; i++ ) {
|
for( int i = 0; i < keysLeft.Length; i++ ) {
|
||||||
keysLeft[i].Dispose();
|
keysLeft[i].Dispose();
|
||||||
}
|
|
||||||
for( int i = 0; i < keysRight.Length; i++ ) {
|
|
||||||
keysRight[i].Dispose();
|
keysRight[i].Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextWidget CreateTextWidget( int x, int y, string text, Docking horizontal, Docking vertical, Font font ) {
|
|
||||||
TextWidget widget = new TextWidget( Window, font );
|
|
||||||
widget.Init();
|
|
||||||
widget.HorizontalDocking = horizontal;
|
|
||||||
widget.VerticalDocking = vertical;
|
|
||||||
widget.XOffset = x;
|
|
||||||
widget.YOffset = y;
|
|
||||||
widget.SetText( text );
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
public override void OnResize( int oldWidth, int oldHeight, int width, int height ) {
|
||||||
gameWidget.OnResize( oldWidth, oldHeight, width, height );
|
gameWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||||
controlsWidget.OnResize( oldWidth, oldHeight, width, height );
|
controlsWidget.OnResize( oldWidth, oldHeight, width, height );
|
||||||
|
@ -10,6 +10,17 @@ namespace ClassicalSharp {
|
|||||||
this.font = font;
|
this.font = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TextWidget Create( Game game, int x, int y, string text, Docking horizontal, Docking vertical, Font font ) {
|
||||||
|
TextWidget widget = new TextWidget( game, font );
|
||||||
|
widget.Init();
|
||||||
|
widget.HorizontalDocking = horizontal;
|
||||||
|
widget.VerticalDocking = vertical;
|
||||||
|
widget.XOffset = x;
|
||||||
|
widget.YOffset = y;
|
||||||
|
widget.SetText( text );
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
Texture texture;
|
Texture texture;
|
||||||
string textCache = null;
|
string textCache = null;
|
||||||
public int XOffset = 0, YOffset = 0;
|
public int XOffset = 0, YOffset = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user