Permalink
Browse files

Allow holding down tab in Launcher

  • Loading branch information...
UnknownShadow200 committed Dec 6, 2018
1 parent 397f0f8 commit 8066a7685894a20854debbb60ab17874e004d336
Showing with 438 additions and 131 deletions.
  1. +1 −11 Launcher2/Gui/Screens/Screen.cs
  2. +179 −38 src/LScreens.c
  3. +1 −0 src/LScreens.h
  4. +218 −38 src/LWidgets.c
  5. +11 −10 src/LWidgets.h
  6. +18 −21 src/Launcher.c
  7. +6 −1 src/Launcher.h
  8. +4 −12 src/Screens.c
@@ -23,7 +23,6 @@ public abstract class Screen {
Mouse.Move += MouseMove;
Mouse.ButtonDown += MouseButtonDown;
Keyboard.KeyDown += KeyDown;
Keyboard.KeyUp += KeyUp;
}
/// <summary> Function that is repeatedly called multiple times every second. </summary>
@@ -37,7 +36,6 @@ public abstract class Screen {
Mouse.Move -= MouseMove;
Mouse.ButtonDown -= MouseButtonDown;
Keyboard.KeyDown -= KeyDown;
Keyboard.KeyUp -= KeyUp;
}
/// <summary> Function called when the pixels from the framebuffer
@@ -148,22 +146,14 @@ public abstract class Screen {
}
}
protected virtual void KeyUp(Key key) {
if (key == Key.Tab)
tabDown = false;
}
protected int IndexOfWidget(Widget w) {
for (int i = 0; i < widgets.Length; i++) {
if (widgets[i] == w) return i;
}
return -1;
}
protected bool tabDown = false;
protected void HandleTab() {
if (tabDown) return;
tabDown = true;
bool shiftDown = game.IsKeyDown(Key.ShiftLeft)
|| game.IsKeyDown(Key.ShiftRight);
@@ -4,6 +4,9 @@
#include "Gui.h"
#include "Game.h"
/*########################################################################################################################*
*---------------------------------------------------------Screen base-----------------------------------------------------*
*#########################################################################################################################*/
static void LScreen_NullFunc(struct LScreen* s) { }
static void LScreen_DrawAll(struct LScreen* s) {
struct LWidget* widget;
@@ -38,23 +41,26 @@ CC_NOINLINE static void LScreen_Reset(struct LScreen* s) {
s->HoverWidget = LScreen_HoverWidget;
s->UnhoverWidget = LScreen_UnhoverWidget;
/* reset all widgets to unselected */
/* reset all widgets mouse state */
for (i = 0; i < s->NumWidgets; i++) {
s->Widgets[i]->Hovered = false;
s->Widgets[i]->Hovered = false;
s->Widgets[i]->Selected = false;
}
s->OnEnterWidget = NULL;
s->HoveredWidget = NULL;
}
/*########################################################################################################################*
*---------------------------------------------------------Widget init-----------------------------------------------------*
*--------------------------------------------------------Widget helpers---------------------------------------------------*
*#########################################################################################################################*/
CC_NOINLINE static void LScreen_Button(struct LScreen* s, struct LButton* w, int width, int height, const char* text,
uint8_t horAnchor, uint8_t verAnchor, int xOffset, int yOffset) {
String str = String_FromReadonly(text);
LButton_Init(w, width, height);
LButton_SetText(w, &str, &Launcher_TitleFont);
w->Hovered = false;
s->Widgets[s->NumWidgets++] = (struct LWidget*)w;
LWidget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
@@ -65,7 +71,15 @@ CC_NOINLINE static void LScreen_Label(struct LScreen* s, struct LLabel* w, const
LLabel_Init(w);
LLabel_SetText(w, &str, &Launcher_TextFont);
w->Hovered = false;
s->Widgets[s->NumWidgets++] = (struct LWidget*)w;
LWidget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
CC_NOINLINE static void LScreen_Input(struct LScreen* s, struct LInput* w, int width, bool password, const char* hintText,
uint8_t horAnchor, uint8_t verAnchor, int xOffset, int yOffset) {
LInput_Init(w, width, 30, hintText, &Launcher_HintFont);
w->Password = password;
s->Widgets[s->NumWidgets++] = (struct LWidget*)w;
LWidget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
@@ -77,23 +91,47 @@ CC_NOINLINE static void LScreen_Slider(struct LScreen* s, struct LSlider* w, int
w->Value = initValue; w->MaxValue = maxValue;
w->ProgressCol = progressCol;
w->Hovered = false;
s->Widgets[s->NumWidgets++] = (struct LWidget*)w;
LWidget_SetLocation(w, horAnchor, verAnchor, xOffset, yOffset);
}
CC_NOINLINE static int LScreen_IndexOf(struct LScreen* s, void* w) {
int i;
for (i = 0; i < s->NumWidgets; i++) {
if (s->Widgets[i] == w) return i;
}
return -1;
}
static void SwitchToChooseMode(void* w, int x, int y) {
Launcher_SetScreen(ChooseModeScreen_MakeInstance(false));
}
static void SwitchToColours(void* w, int x, int y) {
Launcher_SetScreen(ColoursScreen_MakeInstance());
}
static void SwitchToMain(void* w, int x, int y) {
Launcher_SetScreen(MainScreen_MakeInstance());
}
static void SwitchToSettings(void* w, int x, int y) {
Launcher_SetScreen(SettingsScreen_MakeInstance());
}
static void SwitchToUpdates(void* w, int x, int y) {
Launcher_SetScreen(UpdatesScreen_MakeInstance());
}
/*########################################################################################################################*
*-------------------------------------------------------ChooseModeScreen--------------------------------------------------*
*#########################################################################################################################*/
/*static struct ChooseModeScreen {
static struct ChooseModeScreen {
LScreen_Layout
struct LWidget* Widgets[12];
struct LButton BtnEnhanced, BtnClassicHax, BtnClassic, BtnBack;
struct LLabel LblTitle, LblHelp, LblEnhanced[2], LblClassicHax[2], LblClassic[2];
bool FirstTime;
} ChooseModeScreen_Instance;
static void ChooseMode_Click(bool classic, bool classicHacks) {
CC_NOINLINE static void ChooseMode_Click(bool classic, bool classicHacks) {
Launcher_ClassicBackground = classic;
Options_Load();
Options_SetBool(OPT_CLASSIC_MODE, classic);
@@ -110,18 +148,9 @@ static void ChooseMode_Click(bool classic, bool classicHacks) {
Launcher_SetScreen(MainScreen_MakeInstance());
}
static void UseModeEnhanced(void* w, int x, int y) {
Launcher_SetScreen(ChooseModeScreen_MakeInstance(false));
}
static void UseModeClassicHax(void* w, int x, int y) {
Launcher_SetScreen(UpdatesScreen_MakeInstance());
}
static void UseModeClassic(void* w, int x, int y) {
Launcher_SetScreen(ColoursScreen_MakeInstance());
}
static void SwitchToSettings(void* w, int x, int y) {
Launcher_SetScreen(SettingsScreen_MakeInstance());
}
static void UseModeEnhanced(void* w, int x, int y) { ChooseMode_Click(false, false); }
static void UseModeClassicHax(void* w, int x, int y) { ChooseMode_Click(true, true); }
static void UseModeClassic(void* w, int x, int y) { ChooseMode_Click(true, false); }
static void ChooseModeScreenScreen_InitWidgets(struct ChooseModeScreen* s) {
struct LScreen* s_ = (struct LScreen*)s;
@@ -168,7 +197,7 @@ static void ChooseModeScreen_Init(struct LScreen* s_) {
s->LblHelp.Hidden = !s->FirstTime;
s->BtnBack.Hidden = s->FirstTime;
s->DrawAll(s);
s->DrawAll(s_);
}
struct LScreen* ChooseModeScreen_MakeInstance(bool firstTime) {
@@ -177,32 +206,145 @@ struct LScreen* ChooseModeScreen_MakeInstance(bool firstTime) {
s->Init = ChooseModeScreen_Init;
s->FirstTime = firstTime;
return (struct LScreen*)s;
}*/
}
/*########################################################################################################################*
*--------------------------------------------------------SettingsScreen---------------------------------------------------*
*------------------------------------------------------DirectConnectScreen------------------------------------------------*
*#########################################################################################################################*/
/*static struct SettingsScreen {
static struct DirectConnectScreen {
LScreen_Layout
struct LWidget* Widgets[7];
struct LButton BtnUpdates, BtnMode, BtnColours, BtnBack;
struct LLabel LblUpdates, LblMode, LblColours;
} SettingsScreen_Instance;
struct LWidget* Widgets[6];
struct LButton BtnConnect, BtnBack;
struct LInput IptUsername, IptAddress, IptMppass;
struct LLabel LblStatus;
bool FirstTime;
} DirectConnectScreen_Instance;
CC_NOINLINE static void DirectConnectScreen_SetStatus(const char* msg) {
String str = String_FromReadonly(msg);
struct LLabel* w = &DirectConnectScreen_Instance.LblStatus;
Launcher_ResetArea(w->X, w->Y, w->Width, w->Height);
static void SwitchToChooseMode(void* w, int x, int y) {
Launcher_SetScreen(ChooseModeScreen_MakeInstance(false));
LLabel_SetText(w, &str, &Launcher_TextFont);
w->VTABLE->Redraw(w);
}
static void SwitchToUpdates(void* w, int x, int y) {
Launcher_SetScreen(UpdatesScreen_MakeInstance());
static void DirectConnectScreen_Load(struct DirectConnectScreen* s) {
String addr; char addrBuffer[STRING_SIZE];
String mppass; char mppassBuffer[STRING_SIZE];
String user, ip, port;
Options_Load();
Options_UNSAFE_Get("launcher-dc-username", &user);
Options_UNSAFE_Get("launcher-dc-ip", &ip);
Options_UNSAFE_Get("launcher-dc-port", &port);
String_InitArray(mppass, mppassBuffer);
Launcher_LoadSecureOpt("launcher-dc-mppass", &mppass, &user);
String_InitArray(addr, addrBuffer);
String_Format2(&addr, "%s:%s", &ip, &port);
LInput_SetText(&s->IptUsername, &user, &Launcher_TextFont);
LInput_SetText(&s->IptAddress, &addr, &Launcher_TextFont);
LInput_SetText(&s->IptMppass, &mppass, &Launcher_TextFont);
}
static void SwitchToColours(void* w, int x, int y) {
Launcher_SetScreen(ColoursScreen_MakeInstance());
static void DirectConnectScreen_Save(const String* user, const String* mppass, const String* ip, const String* port) {
Options_Load();
Options_Set("launcher-dc-username", user);
Options_Set("launcher-dc-ip", ip);
Options_Set("launcher-dc-port", port);
Launcher_SaveSecureOpt("launcher-dc-mppass", mppass, user);
Options_Save();
}
static void StartClient(void* w, int x, int y) {
static String loopbackIp = String_FromConst("127.0.0.1");
static String defMppass = String_FromConst("(none)");
String* user = &DirectConnectScreen_Instance.IptUsername.Text;
String* addr = &DirectConnectScreen_Instance.IptAddress.Text;
String* mppass = &DirectConnectScreen_Instance.IptMppass.Text;
String ip, port;
uint8_t raw_ip[4];
uint16_t raw_port;
int index = String_LastIndexOf(addr, ':');
if (index <= 0 || index == addr->length - 1) {
DirectConnectScreen_SetStatus("&eInvalid address"); return;
}
ip = String_UNSAFE_Substring(addr, 0, index);
port = String_UNSAFE_SubstringAt(addr, index + 1);
if (String_CaselessEqualsConst(&ip, "localhost")) ip = loopbackIp;
if (!user->length) {
DirectConnectScreen_SetStatus("&eUsername required"); return;
}
if (!Utils_ParseIP(&ip, raw_ip)) {
DirectConnectScreen_SetStatus("&eInvalid ip"); return;
}
if (!Convert_TryParseUInt16(&port, &raw_port)) {
DirectConnectScreen_SetStatus("&eInvalid port"); return;
}
if (!mppass->length) mppass = &defMppass;
DirectConnectScreen_Save(user, mppass, &ip, &port);
DirectConnectScreen_SetStatus("");
Launcher_StartGame(user, mppass, &ip, &port, &String_Empty);
}
static void SwitchToMain(void* w, int x, int y) {
Launcher_SetScreen(MainScreen_MakeInstance());
static void DirectConnectScreen_InitWidgets(struct DirectConnectScreen* s) {
struct LScreen* s_ = (struct LScreen*)s;
LScreen_Input(s_, &s->IptUsername, 330, false, "&gUsername..",
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -120);
LScreen_Input(s_, &s->IptAddress, 330, false, "&gIP address:Port number..",
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -75);
LScreen_Input(s_, &s->IptMppass, 330, false, "&gMppass..",
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -30);
LScreen_Button(s_, &s->BtnConnect, 110, 35, "Connect",
ANCHOR_CENTRE, ANCHOR_CENTRE, -110, 20);
LScreen_Button(s_, &s->BtnBack, 80, 35, "Back",
ANCHOR_CENTRE, ANCHOR_CENTRE, 125, 20);
LScreen_Label(s_, &s->LblStatus, "",
ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 70);
s->BtnConnect.OnClick = StartClient;
s->BtnBack.OnClick = SwitchToMain;
/* Init input text from options */
DirectConnectScreen_Load(s);
}
static void DirectConnectScreen_Init(struct LScreen* s_) {
struct DirectConnectScreen* s = (struct DirectConnectScreen*)s_;
if (!s->NumWidgets) DirectConnectScreen_InitWidgets(s);
s->DrawAll(s_);
}
struct LScreen* DirectConnectScreen_MakeInstance(void) {
struct DirectConnectScreen* s = &DirectConnectScreen_Instance;
LScreen_Reset((struct LScreen*)s);
s->Init = DirectConnectScreen_Init;
s->OnEnterWidget = (struct LWidget*)&s->BtnConnect;
return (struct LScreen*)s;
}
/*########################################################################################################################*
*--------------------------------------------------------SettingsScreen---------------------------------------------------*
*#########################################################################################################################*/
static struct SettingsScreen {
LScreen_Layout
struct LWidget* Widgets[7];
struct LButton BtnUpdates, BtnMode, BtnColours, BtnBack;
struct LLabel LblUpdates, LblMode, LblColours;
} SettingsScreen_Instance;
static void SettingsScreen_InitWidgets(struct SettingsScreen* s) {
struct LScreen* s_ = (struct LScreen*)s;
@@ -236,7 +378,7 @@ static void SettingsScreen_Init(struct LScreen* s_) {
s->BtnColours.Hidden = Launcher_ClassicBackground;
s->LblColours.Hidden = Launcher_ClassicBackground;
s->DrawAll(s);
s->DrawAll(s_);
}
struct LScreen* SettingsScreen_MakeInstance(void) {
@@ -245,4 +387,3 @@ struct LScreen* SettingsScreen_MakeInstance(void) {
s->Init = SettingsScreen_Init;
return (struct LScreen*)s;
}
*/
@@ -19,6 +19,7 @@ typedef void (*LWidget_Func)(struct LScreen* s, struct LWidget* w);
LScreen_Func OnDisplay; /* Called when framebuffer is about to be displayed. */ \
LWidget_Func HoverWidget; /* Called when mouse is moved over a given widget. */ \
LWidget_Func UnhoverWidget; /* Called when the mouse is moved away from a previously hovered widget. */ \
struct LWidget* OnEnterWidget; /* Default widget to auto-click when Enter is pressed. Can be NULL. */ \
struct LWidget* HoveredWidget; /* Widget the mouse is currently hovering over. */ \
int NumWidgets; /* Number of widgets actually used. */
Oops, something went wrong.

0 comments on commit 8066a76

Please sign in to comment.