mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
Start rewriting overlays code
This commit is contained in:
parent
d847d269b7
commit
a298f55cb9
@ -93,7 +93,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (chatInInputBuffer != null) {
|
if (chatInInputBuffer != null) {
|
||||||
OpenTextInputBar(chatInInputBuffer);
|
OpenInput(chatInInputBuffer);
|
||||||
chatInInputBuffer = null;
|
chatInInputBuffer = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +323,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenTextInputBar(string initialText) {
|
public void OpenInput(string initialText) {
|
||||||
game.CursorVisible = true;
|
game.CursorVisible = true;
|
||||||
suppressNextPress = true;
|
suppressNextPress = true;
|
||||||
SetHandlesAllInput(true);
|
SetHandlesAllInput(true);
|
||||||
@ -371,9 +371,9 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key == game.Mapping(KeyBind.Chat)) {
|
if (key == game.Mapping(KeyBind.Chat)) {
|
||||||
OpenTextInputBar("");
|
OpenInput("");
|
||||||
} else if (key == Key.Slash) {
|
} else if (key == Key.Slash) {
|
||||||
OpenTextInputBar("/");
|
OpenInput("/");
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -423,14 +423,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
string url = Utils.StripColours(text);
|
string url = Utils.StripColours(text);
|
||||||
|
|
||||||
if (Utils.IsUrlPrefix(url, 0)) {
|
if (Utils.IsUrlPrefix(url, 0)) {
|
||||||
WarningOverlay overlay = new WarningOverlay(game, false, false);
|
Overlay overlay = new UrlWarningOverlay(game, url);
|
||||||
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.";
|
|
||||||
game.Gui.ShowOverlay(overlay);
|
game.Gui.ShowOverlay(overlay);
|
||||||
} else if (game.ClickableChat) {
|
} else if (game.ClickableChat) {
|
||||||
input.Append(text);
|
input.Append(text);
|
||||||
|
@ -5,11 +5,12 @@ using ClassicalSharp.Gui.Widgets;
|
|||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
|
|
||||||
namespace ClassicalSharp.Gui.Screens {
|
namespace ClassicalSharp.Gui.Screens {
|
||||||
public class DisconnectScreen : ClickableScreen {
|
public class DisconnectScreen : Screen {
|
||||||
|
|
||||||
string title, message;
|
string title, message;
|
||||||
readonly Font titleFont, messageFont;
|
readonly Font titleFont, messageFont;
|
||||||
Widget[] widgets;
|
TextWidget titleWidget, messageWidget;
|
||||||
|
ButtonWidget reconnect;
|
||||||
DateTime initTime, clearTime;
|
DateTime initTime, clearTime;
|
||||||
bool canReconnect;
|
bool canReconnect;
|
||||||
|
|
||||||
@ -32,8 +33,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
// NOTE: We need to make sure that both the front and back buffers have
|
// 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.
|
// definitely been drawn over, so we redraw the background multiple times.
|
||||||
if (DateTime.UtcNow < clearTime)
|
if (DateTime.UtcNow < clearTime) Redraw(delta);
|
||||||
Redraw(delta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Init() {
|
public override void Init() {
|
||||||
@ -57,10 +57,11 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void OnResize(int width, int height) {
|
public override void OnResize(int width, int height) {
|
||||||
RepositionWidgets(widgets);
|
titleWidget.Reposition();
|
||||||
|
messageWidget.Reposition();
|
||||||
|
reconnect.Reposition();
|
||||||
clearTime = DateTime.UtcNow.AddSeconds(0.5);
|
clearTime = DateTime.UtcNow.AddSeconds(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override bool HandlesKeyDown(Key key) { return key < Key.F1 || key > Key.F35; }
|
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 HandlesKeyUp(Key key) { return true; }
|
||||||
|
|
||||||
public override bool HandlesMouseClick(int mouseX, int mouseY, MouseButton button) {
|
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) {
|
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 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;
|
int lastSecsLeft;
|
||||||
const int delay = 5;
|
const int delay = 5;
|
||||||
bool lastActive = false;
|
bool lastActive = false;
|
||||||
void UpdateDelayLeft(double delta) {
|
void UpdateDelayLeft(double delta) {
|
||||||
ButtonWidget btn = (ButtonWidget)widgets[2];
|
|
||||||
double elapsed = (DateTime.UtcNow - initTime).TotalSeconds;
|
double elapsed = (DateTime.UtcNow - initTime).TotalSeconds;
|
||||||
int secsLeft = Math.Max(0, (int)(delay - elapsed));
|
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());
|
reconnect.SetText(ReconnectMessage());
|
||||||
btn.Disabled = secsLeft != 0;
|
reconnect.Disabled = secsLeft != 0;
|
||||||
|
|
||||||
Redraw(delta);
|
Redraw(delta);
|
||||||
lastSecsLeft = secsLeft;
|
lastSecsLeft = secsLeft;
|
||||||
lastActive = btn.Active;
|
lastActive = reconnect.Active;
|
||||||
clearTime = DateTime.UtcNow.AddSeconds(0.5);
|
clearTime = DateTime.UtcNow.AddSeconds(0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,21 +114,12 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
void Redraw(double delta) {
|
void Redraw(double delta) {
|
||||||
game.Graphics.Draw2DQuad(0, 0, game.Width, game.Height, top, bottom);
|
game.Graphics.Draw2DQuad(0, 0, game.Width, game.Height, top, bottom);
|
||||||
game.Graphics.Texturing = true;
|
game.Graphics.Texturing = true;
|
||||||
RenderWidgets(widgets, delta);
|
titleWidget.Render(delta);
|
||||||
|
messageWidget.Render(delta);
|
||||||
|
if (canReconnect) reconnect.Render(delta);
|
||||||
game.Graphics.Texturing = false;
|
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() {
|
string ReconnectMessage() {
|
||||||
if (!canReconnect) return "Reconnect";
|
if (!canReconnect) return "Reconnect";
|
||||||
|
|
||||||
@ -126,22 +128,25 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
return secsLeft > 0 ? "Reconnect in " + secsLeft : "Reconnect";
|
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() {
|
protected override void ContextRecreated() {
|
||||||
if (game.Graphics.LostContext) return;
|
if (game.Graphics.LostContext) return;
|
||||||
clearTime = DateTime.UtcNow.AddSeconds(0.5);
|
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);
|
.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);
|
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 10);
|
||||||
|
|
||||||
string msg = ReconnectMessage();
|
string msg = ReconnectMessage();
|
||||||
if (!canReconnect) return;
|
reconnect = ButtonWidget.Create(game, 300, msg, titleFont, null)
|
||||||
widgets[2] = ButtonWidget.Create(game, 300, msg, titleFont, ReconnectClick)
|
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 80);
|
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 80);
|
||||||
|
reconnect.Disabled = !canReconnect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -159,9 +159,9 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
return chat.HandlesKeyUp(key) || hotbar.HandlesKeyUp(key);
|
return chat.HandlesKeyUp(key) || hotbar.HandlesKeyUp(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenTextInputBar(string text) {
|
public void OpenInput(string text) { chat.OpenInput(text); }
|
||||||
chat.OpenTextInputBar(text);
|
|
||||||
}
|
public void AppendInput(string text) { chat.input.Append(text); }
|
||||||
|
|
||||||
public override bool HandlesMouseScroll(float delta) {
|
public override bool HandlesMouseScroll(float delta) {
|
||||||
return chat.HandlesMouseScroll(delta);
|
return chat.HandlesMouseScroll(delta);
|
||||||
|
@ -52,8 +52,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
if (key == Key.Escape) {
|
if (key == Key.Escape) {
|
||||||
game.Gui.SetNewScreen(null);
|
game.Gui.SetNewScreen(null);
|
||||||
return true;
|
return true;
|
||||||
} else if ((key == Key.Enter || key == Key.KeypadEnter)
|
} else if ((key == Key.Enter || key == Key.KeypadEnter) && input != null) {
|
||||||
&& input != null) {
|
|
||||||
ChangeSetting();
|
ChangeSetting();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,8 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void CloseOverlay() {
|
protected void CloseOverlay() {
|
||||||
|
Dispose();
|
||||||
|
|
||||||
if (game.Gui.overlays.Count > 0)
|
if (game.Gui.overlays.Count > 0)
|
||||||
game.Gui.overlays.RemoveAt(0);
|
game.Gui.overlays.RemoveAt(0);
|
||||||
if (game.Gui.overlays.Count == 0)
|
if (game.Gui.overlays.Count == 0)
|
||||||
|
@ -100,8 +100,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyDown(Key key) {
|
public override bool HandlesKeyDown(Key key) {
|
||||||
if (key == Key.F10 || key == game.Input.Keys[KeyBind.PauseOrExit]) {
|
if (key == game.Input.Keys[KeyBind.IDOverlay] || key == game.Input.Keys[KeyBind.PauseOrExit]) {
|
||||||
Dispose();
|
|
||||||
CloseOverlay();
|
CloseOverlay();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
// Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using ClassicalSharp.Gui.Widgets;
|
using ClassicalSharp.Gui.Widgets;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
@ -8,6 +9,91 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
public delegate void WarningClickHandler(WarningOverlay screen, bool isAlways);
|
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 sealed class WarningOverlay : Overlay {
|
||||||
|
|
||||||
public WarningOverlay(Game game, bool showAlways, bool confirmNo) : base(game) {
|
public WarningOverlay(Game game, bool showAlways, bool confirmNo) : base(game) {
|
||||||
@ -69,7 +155,6 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
bool always = IndexOfWidget(w) >= alwaysIndex;
|
bool always = IndexOfWidget(w) >= alwaysIndex;
|
||||||
|
|
||||||
if (yesClick != null) yesClick(this, always);
|
if (yesClick != null) yesClick(this, always);
|
||||||
Dispose();
|
|
||||||
CloseOverlay();
|
CloseOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +169,6 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (noClick != null) noClick(this, always);
|
if (noClick != null) noClick(this, always);
|
||||||
Dispose();
|
|
||||||
CloseOverlay();
|
CloseOverlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ namespace ClassicalSharp {
|
|||||||
if (!more) {
|
if (!more) {
|
||||||
game.Server.SendChat(text);
|
game.Server.SendChat(text);
|
||||||
} else if (game.Gui.activeScreen == null) {
|
} else if (game.Gui.activeScreen == null) {
|
||||||
game.Gui.hudScreen.OpenTextInputBar(text);
|
game.Gui.hudScreen.OpenInput(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
#ifndef CC_DRAWER2D_H
|
#ifndef CC_DRAWER2D_H
|
||||||
#define 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 "Typedefs.h"
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
#include "Bitmap.h"
|
#include "Bitmap.h"
|
||||||
@ -10,6 +7,9 @@ Copyright 2017 ClassicalSharp | Licensed under BSD-3
|
|||||||
#include "2DStructs.h"
|
#include "2DStructs.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Constants.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;
|
typedef struct DrawTextArgs_ { String Text; FontDesc Font; bool UseShadow; } DrawTextArgs;
|
||||||
void DrawTextArgs_Make(DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow);
|
void DrawTextArgs_Make(DrawTextArgs* args, STRING_REF String* text, FontDesc* font, bool useShadow);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef CC_INPUTHANDLER_H
|
#ifndef CC_INPUTHANDLER_H
|
||||||
#define CC_INPUTHANDLER_H
|
#define CC_INPUTHANDLER_H
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
#include "Gui.h"
|
||||||
/* Implements base handlers for mouse and keyboard input.
|
/* Implements base handlers for mouse and keyboard input.
|
||||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
*/
|
*/
|
||||||
|
@ -10,10 +10,7 @@
|
|||||||
|
|
||||||
/* Maximum number of vertices used to draw a block in isometric way. */
|
/* Maximum number of vertices used to draw a block in isometric way. */
|
||||||
#define ISOMETRICDRAWER_MAXVERTICES 16
|
#define ISOMETRICDRAWER_MAXVERTICES 16
|
||||||
/* Sets up state for drawing a batch of isometric blocks. */
|
|
||||||
void IsometricDrawer_BeginBatch(VertexP3fT2fC4b* vertices, GfxResourceID vb);
|
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);
|
void IsometricDrawer_DrawBatch(BlockID block, Real32 size, Real32 x, Real32 y);
|
||||||
/* Finishes drawing a batch of isometric blocks. */
|
|
||||||
void IsometricDrawer_EndBatch(void);
|
void IsometricDrawer_EndBatch(void);
|
||||||
#endif
|
#endif
|
@ -9,43 +9,21 @@
|
|||||||
typedef struct Vector3_ Vector3;
|
typedef struct Vector3_ Vector3;
|
||||||
|
|
||||||
typedef struct Vector4_ { Real32 X, Y, Z, W; } Vector4;
|
typedef struct Vector4_ { Real32 X, Y, Z, W; } Vector4;
|
||||||
typedef struct Matrix_ {
|
typedef struct Matrix_ { Vector4 Row0, Row1, Row2, Row3; } 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. */
|
|
||||||
extern Matrix Matrix_Identity;
|
extern Matrix Matrix_Identity;
|
||||||
|
|
||||||
/* Transformation matrix representing rotation angle radians around X axis. */
|
|
||||||
void Matrix_RotateX(Matrix* result, Real32 angle);
|
void Matrix_RotateX(Matrix* result, Real32 angle);
|
||||||
/* Transformation matrix representing rotation angle radians around Y axis. */
|
|
||||||
void Matrix_RotateY(Matrix* result, Real32 angle);
|
void Matrix_RotateY(Matrix* result, Real32 angle);
|
||||||
/* Transformation matrix representing rotation angle radians around Z axis. */
|
|
||||||
void Matrix_RotateZ(Matrix* result, Real32 angle);
|
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);
|
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);
|
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)
|
#define Matrix_MulBy(dst, right) Matrix_Mul(dst, dst, right)
|
||||||
/* Multiplies two matrices.*/
|
|
||||||
void Matrix_Mul(Matrix* result, Matrix* left, Matrix* right);
|
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);
|
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);
|
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);
|
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);
|
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);
|
void Matrix_LookAt(Matrix* result, Vector3 eye, Vector3 target, Vector3 up);
|
||||||
#endif
|
#endif
|
@ -1669,6 +1669,12 @@ void HUDScreen_OpenInput(Screen* hud, STRING_PURE String* text) {
|
|||||||
ChatScreen_OpenInput((ChatScreen*)chat, 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;
|
DisconnectScreen DisconnectScreen_Instance;
|
||||||
#define DISCONNECT_DELAY_MS 5000
|
#define DISCONNECT_DELAY_MS 5000
|
||||||
@ -1695,7 +1701,7 @@ void DisconnectScreen_Redraw(DisconnectScreen* screen, Real64 delta) {
|
|||||||
Gfx_SetTexturing(true);
|
Gfx_SetTexturing(true);
|
||||||
Widget_Render(&screen->Title, delta);
|
Widget_Render(&screen->Title, delta);
|
||||||
Widget_Render(&screen->Message, delta);
|
Widget_Render(&screen->Message, delta);
|
||||||
Widget_Render(&screen->Reconnect, delta);
|
if (screen->CanReconnect) { Widget_Render(&screen->Reconnect, delta); }
|
||||||
Gfx_SetTexturing(false);
|
Gfx_SetTexturing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1718,29 +1724,6 @@ void DisconnectScreen_UpdateDelayLeft(DisconnectScreen* screen, Real64 delta) {
|
|||||||
screen->ClearTime = DateTime_TotalMs(&now) + 500;
|
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) {
|
void DisconnectScreen_ContextLost(void* obj) {
|
||||||
DisconnectScreen* screen = (DisconnectScreen*)obj;
|
DisconnectScreen* screen = (DisconnectScreen*)obj;
|
||||||
Widget_Free(&screen->Title);
|
Widget_Free(&screen->Title);
|
||||||
@ -1765,8 +1748,10 @@ void DisconnectScreen_ContextRecreated(void* obj) {
|
|||||||
UInt8 msgBuffer[String_BufferSize(STRING_SIZE)];
|
UInt8 msgBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
String msg = String_InitAndClearArray(msgBuffer);
|
String msg = String_InitAndClearArray(msgBuffer);
|
||||||
DisconnectScreen_ReconnectMessage(screen, &msg);
|
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);
|
Widget_SetLocation((Widget*)(&screen->Reconnect), ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 80);
|
||||||
|
screen->Reconnect.Disabled = !screen->CanReconnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisconnectScreen_Init(GuiElement* elem) {
|
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) {
|
bool DisconnectScreen_HandlesMouseDown(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) {
|
||||||
DisconnectScreen* screen = (DisconnectScreen*)elem;
|
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)) {
|
if (!widget->Disabled && Widget_Contains((Widget*)widget, x, y)) {
|
||||||
elem = &w->Base; elem->HandlesMouseDown(elem, x, y, btn);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DisconnectScreen_HandlesMouseMove(GuiElement* elem, Int32 x, Int32 y) {
|
bool DisconnectScreen_HandlesMouseMove(GuiElement* elem, Int32 x, Int32 y) {
|
||||||
DisconnectScreen* screen = (DisconnectScreen*)elem;
|
DisconnectScreen* screen = (DisconnectScreen*)elem;
|
||||||
ButtonWidget* w = &screen->Reconnect;
|
ButtonWidget* widget = &screen->Reconnect;
|
||||||
|
widget->Active = !widget->Disabled && Widget_Contains((Widget*)widget, x, y);
|
||||||
if (screen->CanReconnect && !w->Disabled && Widget_Contains((Widget*)w, x, y)) {
|
|
||||||
elem = &w->Base; elem->HandlesMouseMove(elem, x, y);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ Screen* GeneratingScreen_MakeInstance(void);
|
|||||||
Screen* HUDScreen_MakeInstance(void);
|
Screen* HUDScreen_MakeInstance(void);
|
||||||
IGameComponent HUDScreen_MakeComponent(void);
|
IGameComponent HUDScreen_MakeComponent(void);
|
||||||
void HUDScreen_OpenInput(Screen* hud, STRING_PURE String* text);
|
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* DisconnectScreen_MakeInstance(STRING_PURE String* title, STRING_PURE String* message);
|
||||||
|
|
||||||
Screen* OptionsGroupScreen_MakeInstance(void);
|
Screen* OptionsGroupScreen_MakeInstance(void);
|
||||||
|
@ -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. */
|
but only allowing reading up to 'len' bytes from the wrapped stream. */
|
||||||
void Stream_ReadonlyPortion(Stream* stream, Stream* underlying, UInt32 len);
|
void Stream_ReadonlyPortion(Stream* stream, Stream* underlying, UInt32 len);
|
||||||
|
|
||||||
/* Reads an unsigned 8 bit integer from the given stream. */
|
|
||||||
UInt8 Stream_ReadUInt8(Stream* stream);
|
UInt8 Stream_ReadUInt8(Stream* stream);
|
||||||
/* Reads a nsigned 8 bit integer from the given stream. */
|
|
||||||
#define Stream_ReadInt8(stream) ((Int8)Stream_ReadUInt8(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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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);
|
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))
|
#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. */
|
/* Reads a line of UTF8 encoding text from the given stream. Returns false if end of stream. */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user