diff --git a/ClassicalSharp/2D/Screens/ChatScreen.cs b/ClassicalSharp/2D/Screens/ChatScreen.cs index 2c32a3c79..e7eb1c608 100644 --- a/ClassicalSharp/2D/Screens/ChatScreen.cs +++ b/ClassicalSharp/2D/Screens/ChatScreen.cs @@ -93,7 +93,7 @@ namespace ClassicalSharp.Gui.Screens { } if (chatInInputBuffer != null) { - OpenTextInputBar(chatInInputBuffer); + OpenInput(chatInInputBuffer); chatInInputBuffer = null; } } @@ -323,7 +323,7 @@ namespace ClassicalSharp.Gui.Screens { return handled; } - public void OpenTextInputBar(string initialText) { + public void OpenInput(string initialText) { game.CursorVisible = true; suppressNextPress = true; SetHandlesAllInput(true); @@ -371,9 +371,9 @@ namespace ClassicalSharp.Gui.Screens { } if (key == game.Mapping(KeyBind.Chat)) { - OpenTextInputBar(""); + OpenInput(""); } else if (key == Key.Slash) { - OpenTextInputBar("/"); + OpenInput("/"); } else { return false; } @@ -423,14 +423,7 @@ namespace ClassicalSharp.Gui.Screens { string url = Utils.StripColours(text); if (Utils.IsUrlPrefix(url, 0)) { - WarningOverlay overlay = new WarningOverlay(game, false, false); - overlay.Metadata = url; - overlay.SetHandlers(OpenUrl, AppendUrl); - overlay.lines[0] = "&eAre you sure you want to open this link?"; - - overlay.lines[1] = url; - overlay.lines[2] = "Be careful - links from strangers may be websites that"; - overlay.lines[3] = " have viruses, or things you may not want to open/see."; + Overlay overlay = new UrlWarningOverlay(game, url); game.Gui.ShowOverlay(overlay); } else if (game.ClickableChat) { input.Append(text); diff --git a/ClassicalSharp/2D/Screens/DisconnectScreen.cs b/ClassicalSharp/2D/Screens/DisconnectScreen.cs index 26bc3f301..18ee4ccd3 100644 --- a/ClassicalSharp/2D/Screens/DisconnectScreen.cs +++ b/ClassicalSharp/2D/Screens/DisconnectScreen.cs @@ -5,11 +5,12 @@ using ClassicalSharp.Gui.Widgets; using OpenTK.Input; namespace ClassicalSharp.Gui.Screens { - public class DisconnectScreen : ClickableScreen { + public class DisconnectScreen : Screen { string title, message; readonly Font titleFont, messageFont; - Widget[] widgets; + TextWidget titleWidget, messageWidget; + ButtonWidget reconnect; DateTime initTime, clearTime; bool canReconnect; @@ -32,8 +33,7 @@ namespace ClassicalSharp.Gui.Screens { // NOTE: We need to make sure that both the front and back buffers have // definitely been drawn over, so we redraw the background multiple times. - if (DateTime.UtcNow < clearTime) - Redraw(delta); + if (DateTime.UtcNow < clearTime) Redraw(delta); } public override void Init() { @@ -57,10 +57,11 @@ namespace ClassicalSharp.Gui.Screens { } public override void OnResize(int width, int height) { - RepositionWidgets(widgets); + titleWidget.Reposition(); + messageWidget.Reposition(); + reconnect.Reposition(); clearTime = DateTime.UtcNow.AddSeconds(0.5); } - public override bool HandlesKeyDown(Key key) { return key < Key.F1 || key > Key.F35; } @@ -69,33 +70,43 @@ namespace ClassicalSharp.Gui.Screens { public override bool HandlesKeyUp(Key key) { return true; } public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button) { - return HandleMouseClick(widgets, mouseX, mouseY, button); + if (button != MouseButton.Left) return true; + + if (!reconnect.Disabled && reconnect.Bounds.Contains(mouseX, mouseY)) { + string connect = "Connecting to " + game.IPAddress + ":" + game.Port + ".."; + for (int i = 0; i < game.Components.Count; i++) + game.Components[i].Reset(game); + BlockInfo.Reset(); + + game.Gui.SetNewScreen(new LoadingMapScreen(game, connect, "")); + game.Server.Connect(game.IPAddress, game.Port); + } + return true; } public override bool HandlesMouseMove(int mouseX, int mouseY) { - return HandleMouseMove(widgets, mouseX, mouseY); + reconnect.Active = !reconnect.Disabled && reconnect.Bounds.Contains(mouseX, mouseY); + return true; } public override bool HandlesMouseScroll(float delta) { return true; } - public override bool HandlesMouseUp(int mouseX, int mouseY, MouseButton button) { return true; } - + public override bool HandlesMouseUp(int mouseX, int mouseY, MouseButton button) { return true; } int lastSecsLeft; const int delay = 5; bool lastActive = false; void UpdateDelayLeft(double delta) { - ButtonWidget btn = (ButtonWidget)widgets[2]; double elapsed = (DateTime.UtcNow - initTime).TotalSeconds; int secsLeft = Math.Max(0, (int)(delay - elapsed)); - if (lastSecsLeft == secsLeft && btn.Active == lastActive) return; + if (lastSecsLeft == secsLeft && reconnect.Active == lastActive) return; - btn.SetText(ReconnectMessage()); - btn.Disabled = secsLeft != 0; + reconnect.SetText(ReconnectMessage()); + reconnect.Disabled = secsLeft != 0; Redraw(delta); lastSecsLeft = secsLeft; - lastActive = btn.Active; + lastActive = reconnect.Active; clearTime = DateTime.UtcNow.AddSeconds(0.5); } @@ -103,21 +114,12 @@ namespace ClassicalSharp.Gui.Screens { void Redraw(double delta) { game.Graphics.Draw2DQuad(0, 0, game.Width, game.Height, top, bottom); game.Graphics.Texturing = true; - RenderWidgets(widgets, delta); + titleWidget.Render(delta); + messageWidget.Render(delta); + if (canReconnect) reconnect.Render(delta); game.Graphics.Texturing = false; } - void ReconnectClick(Game g, Widget w, MouseButton btn, int x, int y) { - if (btn != MouseButton.Left) return; - string connectString = "Connecting to " + game.IPAddress + ":" + game.Port + ".."; - for (int i = 0; i < game.Components.Count; i++) - game.Components[i].Reset(game); - BlockInfo.Reset(); - - game.Gui.SetNewScreen(new LoadingMapScreen(game, connectString, "")); - game.Server.Connect(game.IPAddress, game.Port); - } - string ReconnectMessage() { if (!canReconnect) return "Reconnect"; @@ -126,22 +128,25 @@ namespace ClassicalSharp.Gui.Screens { return secsLeft > 0 ? "Reconnect in " + secsLeft : "Reconnect"; } - protected override void ContextLost() { DisposeWidgets(widgets); } + protected override void ContextLost() { + titleWidget.Dispose(); + messageWidget.Dispose(); + reconnect.Dispose(); + } protected override void ContextRecreated() { if (game.Graphics.LostContext) return; clearTime = DateTime.UtcNow.AddSeconds(0.5); - widgets = new Widget[canReconnect ? 3 : 2]; - widgets[0] = TextWidget.Create(game, title, titleFont) + titleWidget = TextWidget.Create(game, title, titleFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, -30); - widgets[1] = TextWidget.Create(game, message, messageFont) + messageWidget = TextWidget.Create(game, message, messageFont) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 10); string msg = ReconnectMessage(); - if (!canReconnect) return; - widgets[2] = ButtonWidget.Create(game, 300, msg, titleFont, ReconnectClick) + reconnect = ButtonWidget.Create(game, 300, msg, titleFont, null) .SetLocation(Anchor.Centre, Anchor.Centre, 0, 80); + reconnect.Disabled = !canReconnect; } } } diff --git a/ClassicalSharp/2D/Screens/HudScreen.cs b/ClassicalSharp/2D/Screens/HudScreen.cs index 1e616bc4b..98f094c82 100644 --- a/ClassicalSharp/2D/Screens/HudScreen.cs +++ b/ClassicalSharp/2D/Screens/HudScreen.cs @@ -159,9 +159,9 @@ namespace ClassicalSharp.Gui.Screens { return chat.HandlesKeyUp(key) || hotbar.HandlesKeyUp(key); } - public void OpenTextInputBar(string text) { - chat.OpenTextInputBar(text); - } + public void OpenInput(string text) { chat.OpenInput(text); } + + public void AppendInput(string text) { chat.input.Append(text); } public override bool HandlesMouseScroll(float delta) { return chat.HandlesMouseScroll(delta); diff --git a/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs b/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs index abae7c5da..14001941a 100644 --- a/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs +++ b/ClassicalSharp/2D/Screens/Menu/MenuOptionsScreen.cs @@ -52,8 +52,7 @@ namespace ClassicalSharp.Gui.Screens { if (key == Key.Escape) { game.Gui.SetNewScreen(null); return true; - } else if ((key == Key.Enter || key == Key.KeypadEnter) - && input != null) { + } else if ((key == Key.Enter || key == Key.KeypadEnter) && input != null) { ChangeSetting(); return true; } diff --git a/ClassicalSharp/2D/Screens/Overlays/Overlay.cs b/ClassicalSharp/2D/Screens/Overlays/Overlay.cs index eca070301..b27e6ab33 100644 --- a/ClassicalSharp/2D/Screens/Overlays/Overlay.cs +++ b/ClassicalSharp/2D/Screens/Overlays/Overlay.cs @@ -51,6 +51,8 @@ namespace ClassicalSharp.Gui.Screens { } protected void CloseOverlay() { + Dispose(); + if (game.Gui.overlays.Count > 0) game.Gui.overlays.RemoveAt(0); if (game.Gui.overlays.Count == 0) diff --git a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs index 6f9249bac..70774f3c0 100644 --- a/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs +++ b/ClassicalSharp/2D/Screens/Overlays/TexIdsOverlay.cs @@ -100,8 +100,7 @@ namespace ClassicalSharp.Gui.Screens { } public override bool HandlesKeyDown(Key key) { - if (key == Key.F10 || key == game.Input.Keys[KeyBind.PauseOrExit]) { - Dispose(); + if (key == game.Input.Keys[KeyBind.IDOverlay] || key == game.Input.Keys[KeyBind.PauseOrExit]) { CloseOverlay(); return true; } diff --git a/ClassicalSharp/2D/Screens/Overlays/WarningOverlay.cs b/ClassicalSharp/2D/Screens/Overlays/WarningOverlay.cs index 6644f51c1..c3138c0a0 100644 --- a/ClassicalSharp/2D/Screens/Overlays/WarningOverlay.cs +++ b/ClassicalSharp/2D/Screens/Overlays/WarningOverlay.cs @@ -1,5 +1,6 @@ // Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 using System; +using System.Diagnostics; using System.Drawing; using ClassicalSharp.Gui.Widgets; using OpenTK.Input; @@ -8,6 +9,91 @@ namespace ClassicalSharp.Gui.Screens { public delegate void WarningClickHandler(WarningOverlay screen, bool isAlways); + public sealed class UrlWarningOverlay : Overlay { + + public UrlWarningOverlay(Game game, string url) : base(game) { + widgets = new ButtonWidget[2]; + Metadata = url; + lines[0] = "&eAre you sure you want to open this link?"; + lines[1] = url; + lines[2] = "Be careful - links from strangers may be websites that"; + lines[3] = " have viruses, or things you may not want to open/see."; + } + + public override void RedrawText() { + SetTextWidgets(lines); + } + + public override void MakeButtons() { + DisposeWidgets(widgets); + widgets[0] = ButtonWidget.Create(game, 160, "Yes", titleFont, OpenUrl) + .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); + widgets[1] = ButtonWidget.Create(game, 160, "No", titleFont, AppendUrl) + .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); + } + + void OpenUrl(Game g, Widget w, MouseButton btn, int x, int y) { + if (btn != MouseButton.Left) return; + + try { + Process.Start(Metadata); + } catch (Exception ex) { + ErrorHandler.LogError("UrlWarningOverlay.OpenUrl", ex); + } + CloseOverlay(); + } + + void AppendUrl(Game g, Widget w, MouseButton btn, int x, int y) { + if (btn != MouseButton.Left) return; + + if (game.ClickableChat) { + game.Gui.hudScreen.AppendInput(Metadata); + } + CloseOverlay(); + } + } + + public sealed class ConfirmDenyOverlay : Overlay { + WarningClickHandler noClick; + bool alwaysDeny; + + public ConfirmDenyOverlay(Game game, string url, bool always, WarningClickHandler noClick) : base(game) { + Metadata = url; + alwaysDeny = always; + this.noClick = noClick; + widgets = new ButtonWidget[2]; + lines[0] = "&eYou might be missing out.", + lines[1] = "Texture packs can play a vital role in the look and feel of maps.", + lines[2] = ""; + lines[3] = "Sure you don't want to download the texture pack?"; + } + + public override void RedrawText() { + SetTextWidgets(lines); + } + + public override void MakeButtons() { + DisposeWidgets(widgets); + widgets[0] = ButtonWidget.Create(game, 160, "I'm sure", titleFont, ConfirmNoClick) + .SetLocation(Anchor.Centre, Anchor.Centre, -110, 30); + widgets[1] = ButtonWidget.Create(game, 160, "Go back", titleFont, GoBackClick) + .SetLocation(Anchor.Centre, Anchor.Centre, 110, 30); + } + + void ConfirmNoClick(Game g, Widget w, MouseButton btn, int x, int y) { + if (btn != MouseButton.Left) return; + noClick(this, alwaysDeny); + CloseOverlay(); + } + + void GoBackClick(Game g, Widget w, MouseButton btn, int x, int y) { + if (btn != MouseButton.Left) return; + + // TODO: Do the back thingy here + CloseOverlay(); + } + } + public sealed class WarningOverlay : Overlay { public WarningOverlay(Game game, bool showAlways, bool confirmNo) : base(game) { @@ -69,7 +155,6 @@ namespace ClassicalSharp.Gui.Screens { bool always = IndexOfWidget(w) >= alwaysIndex; if (yesClick != null) yesClick(this, always); - Dispose(); CloseOverlay(); } @@ -84,7 +169,6 @@ namespace ClassicalSharp.Gui.Screens { } if (noClick != null) noClick(this, always); - Dispose(); CloseOverlay(); } diff --git a/ClassicalSharp/Game/InputHandler.cs b/ClassicalSharp/Game/InputHandler.cs index 6d692bbeb..52db4174a 100644 --- a/ClassicalSharp/Game/InputHandler.cs +++ b/ClassicalSharp/Game/InputHandler.cs @@ -189,7 +189,7 @@ namespace ClassicalSharp { if (!more) { game.Server.SendChat(text); } else if (game.Gui.activeScreen == null) { - game.Gui.hudScreen.OpenTextInputBar(text); + game.Gui.hudScreen.OpenInput(text); } } diff --git a/src/Client/Drawer2D.h b/src/Client/Drawer2D.h index f4f3c5a05..f41c7050f 100644 --- a/src/Client/Drawer2D.h +++ b/src/Client/Drawer2D.h @@ -1,8 +1,5 @@ #ifndef CC_DRAWER2D_H #define CC_DRAWER2D_H -/* Responsible for performing drawing operations on bitmaps, and for converting bitmaps into textures. -Copyright 2017 ClassicalSharp | Licensed under BSD-3 -*/ #include "Typedefs.h" #include "Platform.h" #include "Bitmap.h" @@ -10,6 +7,9 @@ Copyright 2017 ClassicalSharp | Licensed under BSD-3 #include "2DStructs.h" #include "Texture.h" #include "Constants.h" +/* Responsible for performing drawing operations on bitmaps, and for converting bitmaps into textures. + Copyright 2017 ClassicalSharp | Licensed under BSD-3 +*/ typedef struct DrawTextArgs_ { String Text; FontDesc Font; bool UseShadow; } DrawTextArgs; void DrawTextArgs_Make(DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow); diff --git a/src/Client/InputHandler.h b/src/Client/InputHandler.h index b3100b430..af6cddf1d 100644 --- a/src/Client/InputHandler.h +++ b/src/Client/InputHandler.h @@ -1,6 +1,7 @@ #ifndef CC_INPUTHANDLER_H #define CC_INPUTHANDLER_H #include "Typedefs.h" +#include "Gui.h" /* Implements base handlers for mouse and keyboard input. Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 */ diff --git a/src/Client/IsometricDrawer.h b/src/Client/IsometricDrawer.h index 5c9d27e43..7c403120f 100644 --- a/src/Client/IsometricDrawer.h +++ b/src/Client/IsometricDrawer.h @@ -10,10 +10,7 @@ /* Maximum number of vertices used to draw a block in isometric way. */ #define ISOMETRICDRAWER_MAXVERTICES 16 -/* Sets up state for drawing a batch of isometric blocks. */ void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb); -/* Adds a block to the current batch. */ void IsometricDrawer_DrawBatch(BlockID block, Real32 size, Real32 x, Real32 y); -/* Finishes drawing a batch of isometric blocks. */ void IsometricDrawer_EndBatch(void); #endif \ No newline at end of file diff --git a/src/Client/Matrix.h b/src/Client/Matrix.h index 0644efb6e..2ea7bceec 100644 --- a/src/Client/Matrix.h +++ b/src/Client/Matrix.h @@ -9,43 +9,21 @@ typedef struct Vector3_ Vector3; typedef struct Vector4_ { Real32 X, Y, Z, W; } Vector4; -typedef struct Matrix_ { - /* Top row of the matrix */ - Vector4 Row0; - /* 2nd row of the matrix */ - Vector4 Row1; - /* 3rd row of the matrix */ - Vector4 Row2; - /* Bottom row of the matrix */ - Vector4 Row3; -} Matrix; -/* Identity matrix. */ +typedef struct Matrix_ { Vector4 Row0, Row1, Row2, Row3; } Matrix; extern Matrix Matrix_Identity; -/* Transformation matrix representing rotation angle radians around X axis. */ void Matrix_RotateX(Matrix* result, Real32 angle); -/* Transformation matrix representing rotation angle radians around Y axis. */ void Matrix_RotateY(Matrix* result, Real32 angle); -/* Transformation matrix representing rotation angle radians around Z axis. */ void Matrix_RotateZ(Matrix* result, Real32 angle); -/* Transformation matrix representing translation of given coordinates. */ void Matrix_Translate(Matrix* result, Real32 x, Real32 y, Real32 z); -/* Transformation matrix representing scaling of given axes. */ void Matrix_Scale(Matrix* result, Real32 x, Real32 y, Real32 z); -/* Multiplies a matrix by another.*/ #define Matrix_MulBy(dst, right) Matrix_Mul(dst, dst, right) -/* Multiplies two matrices.*/ void Matrix_Mul(Matrix* result, Matrix* left, Matrix* right); -/* Transformation matrix representing orthographic projection. */ void Matrix_Orthographic(Matrix* result, Real32 width, Real32 height, Real32 zNear, Real32 zFar); -/* Transformation matrix representing orthographic projection. */ void Matrix_OrthographicOffCenter(Matrix* result, Real32 left, Real32 right, Real32 bottom, Real32 top, Real32 zNear, Real32 zFar); -/* Transformation matrix representing perspective projection. */ void Matrix_PerspectiveFieldOfView(Matrix* result, Real32 fovy, Real32 aspect, Real32 zNear, Real32 zFar); -/* Transformation matrix representing perspective projection. */ void Matrix_PerspectiveOffCenter(Matrix* result, Real32 left, Real32 right, Real32 bottom, Real32 top, Real32 zNear, Real32 zFar); -/* Transformation matrix representing camera look at. */ void Matrix_LookAt(Matrix* result, Vector3 eye, Vector3 target, Vector3 up); #endif \ No newline at end of file diff --git a/src/Client/Screens.c b/src/Client/Screens.c index d60a9a169..ba2e23f4a 100644 --- a/src/Client/Screens.c +++ b/src/Client/Screens.c @@ -1669,6 +1669,12 @@ void HUDScreen_OpenInput(Screen* hud, STRING_PURE String* text) { ChatScreen_OpenInput((ChatScreen*)chat, text); } +void HUDScreen_AppendInput(Screen* hud, STRING_PURE String* text) { + Screen* chat = ((HUDScreen*)hud)->Chat; + ChatInputWidget* widget = &((ChatScreen*)chat)->Input; + InputWidget_AppendString(&widget->Base, text); +} + DisconnectScreen DisconnectScreen_Instance; #define DISCONNECT_DELAY_MS 5000 @@ -1695,7 +1701,7 @@ void DisconnectScreen_Redraw(DisconnectScreen* screen, Real64 delta) { Gfx_SetTexturing(true); Widget_Render(&screen->Title, delta); Widget_Render(&screen->Message, delta); - Widget_Render(&screen->Reconnect, delta); + if (screen->CanReconnect) { Widget_Render(&screen->Reconnect, delta); } Gfx_SetTexturing(false); } @@ -1718,29 +1724,6 @@ void DisconnectScreen_UpdateDelayLeft(DisconnectScreen* screen, Real64 delta) { screen->ClearTime = DateTime_TotalMs(&now) + 500; } -bool DisconnectScreen_ReconnectClick(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) { - if (btn != MouseButton_Left) return false; - Int32 i; - for (i = 0; i < Game_ComponentsCount; i++) { - Game_Components[i].Reset(); - } - Block_Reset(); - - UInt8 connectBuffer[String_BufferSize(STRING_SIZE)]; - String connect = String_FromConst(connectBuffer); - String empty = String_MakeNull(); - String_AppendConst(&connect, "Connecting to "); - String_AppendString(&connect, &Game_IPAddress); - String_Append(&connect, ':'); - String_AppendInt32(&connect, Game_Port); - String_AppendConst(&connect, ".."); - - Screen* screen = LoadingScreen_MakeInstance(&connect, &empty); - Gui_SetNewScreen(screen); - ServerConnection_Connect(&Game_IPAddress, Game_Port); - return true; -} - void DisconnectScreen_ContextLost(void* obj) { DisconnectScreen* screen = (DisconnectScreen*)obj; Widget_Free(&screen->Title); @@ -1765,8 +1748,10 @@ void DisconnectScreen_ContextRecreated(void* obj) { UInt8 msgBuffer[String_BufferSize(STRING_SIZE)]; String msg = String_InitAndClearArray(msgBuffer); DisconnectScreen_ReconnectMessage(screen, &msg); - ButtonWidget_Create(&screen->Reconnect, &msg, 300, &screen->TitleFont, DisconnectScreen_ReconnectClick); + + ButtonWidget_Create(&screen->Reconnect, &msg, 300, &screen->TitleFont, NULL); Widget_SetLocation((Widget*)(&screen->Reconnect), ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 80); + screen->Reconnect.Disabled = !screen->CanReconnect; } void DisconnectScreen_Init(GuiElement* elem) { @@ -1821,21 +1806,37 @@ bool DisconnectScreen_HandlesKeyUp(GuiElement* elem, Key key) { return true; } bool DisconnectScreen_HandlesMouseDown(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) { DisconnectScreen* screen = (DisconnectScreen*)elem; - ButtonWidget* w = &screen->Reconnect; + ButtonWidget* widget = &screen->Reconnect; + if (btn != MouseButton_Left) return true; - if (screen->CanReconnect && !w->Disabled && Widget_Contains((Widget*)w, x, y)) { - elem = &w->Base; elem->HandlesMouseDown(elem, x, y, btn); + if (!widget->Disabled && Widget_Contains((Widget*)widget, x, y)) { + Int32 i; + for (i = 0; i < Game_ComponentsCount; i++) { + Game_Components[i].Reset(); + } + Block_Reset(); + + UInt8 connectBuffer[String_BufferSize(STRING_SIZE)]; + String connect = String_FromConst(connectBuffer); + String empty = String_MakeNull(); + + String_AppendConst(&connect, "Connecting to "); + String_AppendString(&connect, &Game_IPAddress); + String_Append(&connect, ':'); + String_AppendInt32(&connect, Game_Port); + String_AppendConst(&connect, ".."); + + Screen* loadScreen = LoadingScreen_MakeInstance(&connect, &empty); + Gui_SetNewScreen(loadScreen); + ServerConnection_Connect(&Game_IPAddress, Game_Port); } return true; } bool DisconnectScreen_HandlesMouseMove(GuiElement* elem, Int32 x, Int32 y) { DisconnectScreen* screen = (DisconnectScreen*)elem; - ButtonWidget* w = &screen->Reconnect; - - if (screen->CanReconnect && !w->Disabled && Widget_Contains((Widget*)w, x, y)) { - elem = &w->Base; elem->HandlesMouseMove(elem, x, y); - } + ButtonWidget* widget = &screen->Reconnect; + widget->Active = !widget->Disabled && Widget_Contains((Widget*)widget, x, y); return true; } diff --git a/src/Client/Screens.h b/src/Client/Screens.h index 6c31ed495..0e7d9cfb2 100644 --- a/src/Client/Screens.h +++ b/src/Client/Screens.h @@ -16,6 +16,7 @@ Screen* GeneratingScreen_MakeInstance(void); Screen* HUDScreen_MakeInstance(void); IGameComponent HUDScreen_MakeComponent(void); void HUDScreen_OpenInput(Screen* hud, STRING_PURE String* text); +void HUDScreen_AppendInput(Screen* hud, STRING_PURE String* text); Screen* DisconnectScreen_MakeInstance(STRING_PURE String* title, STRING_PURE String* message); Screen* OptionsGroupScreen_MakeInstance(void); diff --git a/src/Client/Stream.h b/src/Client/Stream.h index 315a77f11..6a7f047eb 100644 --- a/src/Client/Stream.h +++ b/src/Client/Stream.h @@ -47,50 +47,28 @@ void Stream_FromFile(Stream* stream, void* file, STRING_PURE String* name); but only allowing reading up to 'len' bytes from the wrapped stream. */ void Stream_ReadonlyPortion(Stream* stream, Stream* underlying, UInt32 len); -/* Reads an unsigned 8 bit integer from the given stream. */ UInt8 Stream_ReadUInt8(Stream* stream); -/* Reads a nsigned 8 bit integer from the given stream. */ #define Stream_ReadInt8(stream) ((Int8)Stream_ReadUInt8(stream)) -/* Reads a little endian unsigned 16 bit integer from the given stream. */ UInt16 Stream_ReadUInt16_LE(Stream* stream); -/* Reads a little endian signed 16 bit integer from the given stream. */ #define Stream_ReadInt16_LE(stream) ((Int16)Stream_ReadUInt16_LE(stream)) -/* Reads a big endian unsigned 16 bit integer from the given stream. */ UInt16 Stream_ReadUInt16_BE(Stream* stream); -/* Reads a big endian signed 16 bit integer from the given stream. */ #define Stream_ReadInt16_BE(stream) ((Int16)Stream_ReadUInt16_BE(stream)) -/* Reads a little endian unsigned 32 bit integer from the given stream. */ UInt32 Stream_ReadUInt32_LE(Stream* stream); -/* Reads a little endian signed 32 bit integer from the given stream. */ #define Stream_ReadInt32_LE(stream) ((Int32)Stream_ReadUInt32_LE(stream)) -/* Reads a big endian unsigned 64 bit integer from the given stream. */ UInt32 Stream_ReadUInt32_BE(Stream* stream); -/* Reads a big endian signed 64 bit integer from the given stream. */ #define Stream_ReadInt32_BE(stream) ((Int32)Stream_ReadUInt32_BE(stream)) -/* Reads a big endian unsigned 64 bit integer from the given stream. */ UInt64 Stream_ReadUInt64_BE(Stream* stream); -/* Reads a big endian signed 64 bit integer from the given stream. */ #define Stream_ReadInt64_BE(stream) ((Int64)Stream_ReadUInt64_BE(stream)) -/* Writes an unsigned 8 bit integer to the given stream. */ void Stream_WriteUInt8(Stream* stream, UInt8 value); -/* Writes a signed 8 bit integer to the given stream. */ #define Stream_WriteInt8(stream, value) Stream_WriteUInt8(stream, (UInt8)(value)) -/* Writes a little endian unsigned 16 bit integer to the given stream. */ void Stream_WriteUInt16_LE(Stream* stream, UInt16 value); -/* Writes a little endian signed 16 bit integer to the given stream. */ #define Stream_WriteInt16_LE(stream, value) Stream_WriteUInt16_LE(stream, (UInt16)(value)) -/* Writes a big endian unsigned 16 bit integer to the given stream. */ void Stream_WriteUInt16_BE(Stream* stream, UInt16 value); -/* Writes a big endian signed 16 bit integer to the given stream. */ #define Stream_WriteInt16_BE(stream, value) Stream_WriteUInt16_BE(stream, (UInt16)(value)) -/* Writes a little endian unsigned 32 bit integer to the given stream. */ void Stream_WriteUInt32_LE(Stream* stream, UInt32 value); -/* Writes a little endian signed 32 bit integer to the given stream. */ #define Stream_WriteInt32_LE(stream, value) Stream_WriteUInt32_LE(stream, (UInt32)(value)) -/* Writes a big endian unsigned 32 bit integer to the given stream. */ void Stream_WriteUInt32_BE(Stream* stream, UInt32 value); -/* Writes a big endian signed 32 bit integer to the given stream. */ #define Stream_WriteInt32_BE(stream, value) Stream_WriteUInt32_BE(stream, (UInt32)(value)) /* Reads a line of UTF8 encoding text from the given stream. Returns false if end of stream. */