mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Mostly port KeyBindingsScreen to C
This commit is contained in:
parent
12144741e6
commit
0c8b76e3d7
@ -12,42 +12,40 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
static string[] keyNames;
|
static string[] keyNames;
|
||||||
protected string[] desc;
|
protected string[] desc;
|
||||||
protected KeyBind[] binds;
|
protected KeyBind[] binds;
|
||||||
protected int leftLength = -1;
|
|
||||||
|
|
||||||
protected int btnWidth = 260;
|
|
||||||
protected string title;
|
|
||||||
protected int index;
|
|
||||||
protected ClickHandler leftPage, rightPage;
|
protected ClickHandler leftPage, rightPage;
|
||||||
|
int curI = -1;
|
||||||
|
|
||||||
protected void MakeWidgets(int y, int arrowsY) {
|
protected int MakeWidgets(int y, int arrowsY, int leftLength, string title, int btnWidth) {
|
||||||
index = 0;
|
int i, origin = y, xOffset = btnWidth / 2 + 5;
|
||||||
int origin = y;
|
for (i = 0; i < binds.Length; i++) {
|
||||||
|
if (i == leftLength) y = origin; // reset y for next column
|
||||||
|
int xDir = leftLength == -1 ? 0 : (i < leftLength ? -1 : 1);
|
||||||
|
|
||||||
if (leftLength == -1) {
|
string text = ButtonText(i);
|
||||||
for (; index < binds.Length;)
|
widgets[i] = ButtonWidget.Create(game, btnWidth, text, titleFont, OnBindingClick)
|
||||||
Make(0, ref y);
|
.SetLocation(Anchor.Centre, Anchor.Centre, xDir * xOffset, y);
|
||||||
} else {
|
y += 50; // distance between buttons
|
||||||
for (; index < leftLength;)
|
|
||||||
Make(-btnWidth / 2 - 5, ref y);
|
|
||||||
|
|
||||||
y = origin;
|
|
||||||
for (; index < binds.Length;)
|
|
||||||
Make(btnWidth / 2 + 5, ref y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MakeOthers();
|
widgets[i++] = TextWidget.Create(game, title, titleFont)
|
||||||
MakePages(arrowsY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MakeOthers() {
|
|
||||||
widgets[index++] = TextWidget.Create(game, title, titleFont)
|
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -180);
|
.SetLocation(Anchor.Centre, Anchor.Centre, 0, -180);
|
||||||
|
|
||||||
if (game.UseClassicOptions) {
|
if (game.UseClassicOptions) {
|
||||||
widgets[index++] = MakeBack(false, titleFont, SwitchClassicOptions);
|
widgets[i++] = MakeBack(false, titleFont, SwitchClassicOptions);
|
||||||
} else {
|
} else {
|
||||||
widgets[index++] = MakeBack(false, titleFont, SwitchOptions);
|
widgets[i++] = MakeBack(false, titleFont, SwitchOptions);
|
||||||
}
|
}
|
||||||
|
if (leftPage == null && rightPage == null) return i;
|
||||||
|
|
||||||
|
ButtonWidget left = ButtonWidget.Create(game, 40, "<", titleFont, leftPage)
|
||||||
|
.SetLocation(Anchor.Centre, Anchor.Centre, -btnWidth - 35, arrowsY);
|
||||||
|
left.Disabled = leftPage == null;
|
||||||
|
widgets[i++] = left;
|
||||||
|
|
||||||
|
ButtonWidget right = ButtonWidget.Create(game, 40, ">", titleFont, rightPage)
|
||||||
|
.SetLocation(Anchor.Centre, Anchor.Centre, btnWidth + 35, arrowsY);
|
||||||
|
right.Disabled = rightPage == null;
|
||||||
|
widgets[i++] = right;
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SwitchClassicOptions(Game g, Widget w) { g.Gui.SetNewScreen(new ClassicOptionsScreen(g)); }
|
static void SwitchClassicOptions(Game g, Widget w) { g.Gui.SetNewScreen(new ClassicOptionsScreen(g)); }
|
||||||
@ -58,41 +56,15 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
protected static void SwitchOther(Game g, Widget w) { g.Gui.SetNewScreen(new OtherKeyBindingsScreen(g)); }
|
protected static void SwitchOther(Game g, Widget w) { g.Gui.SetNewScreen(new OtherKeyBindingsScreen(g)); }
|
||||||
protected static void SwitchMouse(Game g, Widget w) { g.Gui.SetNewScreen(new MouseKeyBindingsScreen(g)); }
|
protected static void SwitchMouse(Game g, Widget w) { g.Gui.SetNewScreen(new MouseKeyBindingsScreen(g)); }
|
||||||
|
|
||||||
void MakePages(int btnY) {
|
|
||||||
if (leftPage == null && rightPage == null) return;
|
|
||||||
|
|
||||||
ButtonWidget left = ButtonWidget.Create(game, 40, "<", titleFont, leftPage)
|
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, -btnWidth - 35, btnY);
|
|
||||||
left.Disabled = leftPage == null;
|
|
||||||
widgets[index++] = left;
|
|
||||||
|
|
||||||
ButtonWidget right = ButtonWidget.Create(game, 40, ">", titleFont, rightPage)
|
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, btnWidth + 35, btnY);
|
|
||||||
right.Disabled = rightPage == null;
|
|
||||||
widgets[index++] = right;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Make(int x, ref int y) {
|
|
||||||
string text = ButtonText(index);
|
|
||||||
widgets[index++] = ButtonWidget.Create(game, btnWidth, text, titleFont, OnBindingClick)
|
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, x, y);
|
|
||||||
y += 50; // distance between buttons
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ButtonWidget curWidget;
|
|
||||||
void OnBindingClick(Game game, Widget widget) {
|
void OnBindingClick(Game game, Widget widget) {
|
||||||
int index = 0;
|
if (curI >= 0) {
|
||||||
if (curWidget != null) {
|
ButtonWidget curButton = (ButtonWidget)widgets[curI];
|
||||||
index = IndexOfWidget(curWidget);
|
curButton.SetText(ButtonText(curI));
|
||||||
curWidget.SetText(ButtonText(index));
|
|
||||||
curWidget = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
index = IndexOfWidget(widget);
|
curI = IndexOfWidget(widget);
|
||||||
string text = ButtonText(index);
|
string text = ButtonText(curI);
|
||||||
curWidget = (ButtonWidget)widget;
|
((ButtonWidget)widget).SetText("> " + text + " <");
|
||||||
curWidget.SetText("> " + text + " <");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string ButtonText(int i) {
|
string ButtonText(int i) {
|
||||||
@ -102,12 +74,12 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override bool HandlesKeyDown(Key key) {
|
public override bool HandlesKeyDown(Key key) {
|
||||||
if (curWidget == null) return base.HandlesKeyDown(key);
|
if (curI == -1) return base.HandlesKeyDown(key);
|
||||||
|
|
||||||
int index = IndexOfWidget(curWidget);
|
game.Input.Keys[binds[curI]] = key;
|
||||||
game.Input.Keys[binds[index]] = key;
|
ButtonWidget curButton = (ButtonWidget)widgets[curI];
|
||||||
curWidget.SetText(ButtonText(index));
|
curButton.SetText(ButtonText(curI));
|
||||||
curWidget = null;
|
curI = -1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,13 +90,10 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
int i = HandleMouseDown(widgets, mouseX, mouseY, button);
|
int i = HandleMouseDown(widgets, mouseX, mouseY, button);
|
||||||
if (i == -1) return false;
|
if (i == -1) return false;
|
||||||
|
|
||||||
if (curWidget == null || curWidget == widgets[i]) {
|
|
||||||
// Reset a key binding
|
// Reset a key binding
|
||||||
if (i < binds.Length) {
|
if ((curI == -1 || curI == i) && i < binds.Length) {
|
||||||
curWidget = (ButtonWidget)widgets[i];
|
curI = i;
|
||||||
KeyBind mapping = binds[i];
|
HandlesKeyDown(game.Input.Keys.GetDefault(binds[i]));
|
||||||
HandlesKeyDown(game.Input.Keys.GetDefault(mapping));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,18 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
desc = new string[] { "Forward", "Back", "Jump", "Chat", "Save loc",
|
desc = new string[] { "Forward", "Back", "Jump", "Chat", "Save loc",
|
||||||
"Left", "Right", "Build", "Toggle fog", "Load loc" };
|
"Left", "Right", "Build", "Toggle fog", "Load loc" };
|
||||||
leftLength = 5;
|
|
||||||
|
|
||||||
if (game.ClassicHacks) {
|
if (game.ClassicHacks) rightPage = SwitchClassicHacks;
|
||||||
title = "Normal controls";
|
|
||||||
rightPage = SwitchClassicHacks;
|
|
||||||
} else {
|
|
||||||
title = "Controls";
|
|
||||||
btnWidth = 300;
|
|
||||||
}
|
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 4];
|
widgets = new Widget[binds.Length + 4];
|
||||||
MakeWidgets(-140, -40);
|
if (game.ClassicHacks) {
|
||||||
|
MakeWidgets(-140, -40, 5, "Normal controls", 260);
|
||||||
|
} else {
|
||||||
|
MakeWidgets(-140, -40, 5, "Controls", 300);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,17 +47,14 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
desc = new string[] { "Speed", "Noclip", "Half speed",
|
desc = new string[] { "Speed", "Noclip", "Half speed",
|
||||||
"Fly", "Fly up", "Fly down" };
|
"Fly", "Fly up", "Fly down" };
|
||||||
leftLength = 3;
|
|
||||||
|
|
||||||
|
|
||||||
leftPage = SwitchClassic;
|
leftPage = SwitchClassic;
|
||||||
title = "Hacks controls";
|
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 4];
|
widgets = new Widget[binds.Length + 4];
|
||||||
MakeWidgets(-90, -40);
|
MakeWidgets(-90, -40, 3, "Hacks controls", 260);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,16 +72,14 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
desc = new string[] { "Forward", "Back", "Jump", "Chat", "Set spawn", "Player list",
|
desc = new string[] { "Forward", "Back", "Jump", "Chat", "Set spawn", "Player list",
|
||||||
"Left", "Right", "Inventory", "Toggle fog", "Respawn", "Send chat" };
|
"Left", "Right", "Inventory", "Toggle fog", "Respawn", "Send chat" };
|
||||||
leftLength = 6;
|
|
||||||
|
|
||||||
title = "Normal controls";
|
|
||||||
rightPage = SwitchHacks;
|
rightPage = SwitchHacks;
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 4];
|
widgets = new Widget[binds.Length + 4];
|
||||||
MakeWidgets(-140, 10);
|
MakeWidgets(-140, 10, 6, "Normal controls", 260);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,9 +95,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
desc = new string[] { "Speed", "Noclip", "Half speed", "Scroll zoom",
|
desc = new string[] { "Speed", "Noclip", "Half speed", "Scroll zoom",
|
||||||
"Fly", "Fly up", "Fly down", "Third person" };
|
"Fly", "Fly up", "Fly down", "Third person" };
|
||||||
leftLength = 4;
|
|
||||||
|
|
||||||
title = "Hacks controls";
|
|
||||||
leftPage = SwitchNormal;
|
leftPage = SwitchNormal;
|
||||||
rightPage = SwitchOther;
|
rightPage = SwitchOther;
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
@ -113,7 +103,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 4];
|
widgets = new Widget[binds.Length + 4];
|
||||||
MakeWidgets(-40, 10);
|
MakeWidgets(-40, 10, 4, "Hacks controls", 260);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,9 +121,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
desc = new string[] { "Show ext input", "Hide FPS", "Hide gui", "Hotbar switching", "Drop block",
|
desc = new string[] { "Show ext input", "Hide FPS", "Hide gui", "Hotbar switching", "Drop block",
|
||||||
"Screenshot", "Fullscreen", "Show axis lines", "Auto-rotate", "Smooth camera", "ID overlay" };
|
"Screenshot", "Fullscreen", "Show axis lines", "Auto-rotate", "Smooth camera", "ID overlay" };
|
||||||
leftLength = 6;
|
|
||||||
|
|
||||||
title = "Other controls";
|
|
||||||
leftPage = SwitchHacks;
|
leftPage = SwitchHacks;
|
||||||
rightPage = SwitchMouse;
|
rightPage = SwitchMouse;
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
@ -141,7 +129,7 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 4];
|
widgets = new Widget[binds.Length + 4];
|
||||||
MakeWidgets(-140, 10);
|
MakeWidgets(-140, 10, 6, "Other controls", 260);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,14 +143,13 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
binds[0] = KeyBind.MouseLeft; binds[1] = KeyBind.MouseMiddle; binds[2] = KeyBind.MouseRight;
|
binds[0] = KeyBind.MouseLeft; binds[1] = KeyBind.MouseMiddle; binds[2] = KeyBind.MouseRight;
|
||||||
desc = new string[] { "Left", "Middle", "Right" };
|
desc = new string[] { "Left", "Middle", "Right" };
|
||||||
|
|
||||||
title = "Mouse key bindings";
|
|
||||||
leftPage = SwitchOther;
|
leftPage = SwitchOther;
|
||||||
ContextRecreated();
|
ContextRecreated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ContextRecreated() {
|
protected override void ContextRecreated() {
|
||||||
widgets = new Widget[binds.Length + 5];
|
widgets = new Widget[binds.Length + 5];
|
||||||
MakeWidgets(-40, 10);
|
int index = MakeWidgets(-40, 10, -1, "Mouse key bindings", 260);
|
||||||
|
|
||||||
widgets[index++] = TextWidget.Create(game, "&eRight click to remove the key binding", textFont)
|
widgets[index++] = TextWidget.Create(game, "&eRight click to remove the key binding", textFont)
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 100);
|
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 100);
|
||||||
|
@ -13,19 +13,14 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputWidget input;
|
InputWidget input;
|
||||||
TextWidget desc;
|
|
||||||
const int overwriteIndex = 2;
|
const int overwriteIndex = 2;
|
||||||
static FastColour grey = new FastColour(150, 150, 150);
|
static FastColour grey = new FastColour(150, 150, 150);
|
||||||
|
|
||||||
public override void Render(double delta) {
|
public override void Render(double delta) {
|
||||||
RenderMenuBounds();
|
base.Render(delta);
|
||||||
game.Graphics.Texturing = true;
|
|
||||||
RenderWidgets(widgets, delta);
|
|
||||||
if (desc != null) desc.Render(delta);
|
|
||||||
game.Graphics.Texturing = false;
|
|
||||||
|
|
||||||
int cX = game.Width / 2, cY = game.Height / 2;
|
int cX = game.Width / 2, cY = game.Height / 2;
|
||||||
game.Graphics.Draw2DQuad(cX - 250, cY + 90, 500, 2, grey);
|
game.Graphics.Draw2DQuad(cX - 250, cY + 90, 500, 2, grey);
|
||||||
|
|
||||||
if (textPath == null) return;
|
if (textPath == null) return;
|
||||||
SaveMap(textPath);
|
SaveMap(textPath);
|
||||||
textPath = null;
|
textPath = null;
|
||||||
@ -141,14 +136,14 @@ namespace ClassicalSharp.Gui.Screens {
|
|||||||
|
|
||||||
void MakeDescWidget(string text) {
|
void MakeDescWidget(string text) {
|
||||||
DisposeDescWidget();
|
DisposeDescWidget();
|
||||||
desc = TextWidget.Create(game, text, textFont)
|
widgets[widgets.Length - 1] = TextWidget.Create(game, text, textFont)
|
||||||
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 65);
|
.SetLocation(Anchor.Centre, Anchor.Centre, 0, 65);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisposeDescWidget() {
|
void DisposeDescWidget() {
|
||||||
if (desc != null) {
|
if (widgets[widgets.Length - 1] != null) {
|
||||||
desc.Dispose();
|
widgets[widgets.Length - 1].Dispose();
|
||||||
desc = null;
|
widgets[widgets.Length - 1] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
#include "Funcs.h"
|
#include "Funcs.h"
|
||||||
#include "ExtMath.h"
|
#include "ExtMath.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
|
||||||
void GfxCommon_Init(void) {
|
void GfxCommon_Init(void) {
|
||||||
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
|
GfxCommon_quadVb = Gfx_CreateDynamicVb(VERTEX_FORMAT_P3FC4B, 4);
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#ifndef CC_GFXCOMMON_H
|
#ifndef CC_GFXCOMMON_H
|
||||||
#define CC_GFXCOMMON_H
|
#define CC_GFXCOMMON_H
|
||||||
#include "String.h"
|
#include "String.h"
|
||||||
#include "Texture.h"
|
|
||||||
#include "VertexStructs.h"
|
#include "VertexStructs.h"
|
||||||
|
|
||||||
/* Provides common/shared methods for a 3D graphics rendering API.
|
/* Provides common/shared methods for a 3D graphics rendering API.
|
||||||
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3
|
||||||
*/
|
*/
|
||||||
|
typedef struct Texture_ Texture;
|
||||||
|
|
||||||
void GfxCommon_Init(void);
|
void GfxCommon_Init(void);
|
||||||
void GfxCommon_Free(void);
|
void GfxCommon_Free(void);
|
||||||
|
@ -94,6 +94,17 @@ typedef struct ClassicGenScreen_ {
|
|||||||
ButtonWidget Buttons[4];
|
ButtonWidget Buttons[4];
|
||||||
} ClassicGenScreen;
|
} ClassicGenScreen;
|
||||||
|
|
||||||
|
typedef struct KeyBindingsScreen_ {
|
||||||
|
MenuScreen_Layout
|
||||||
|
Int32 CurI, BindsCount;
|
||||||
|
const UInt8** Descs;
|
||||||
|
KeyBind* Binds;
|
||||||
|
Widget_LeftClick LeftPage, RightPage;
|
||||||
|
ButtonWidget* Buttons;
|
||||||
|
TextWidget Title;
|
||||||
|
ButtonWidget Back, Left, Right;
|
||||||
|
} KeyBindingsScreen;
|
||||||
|
|
||||||
|
|
||||||
void Menu_FreeWidgets(Widget** widgets, Int32 widgetsCount) {
|
void Menu_FreeWidgets(Widget** widgets, Int32 widgetsCount) {
|
||||||
if (widgets == NULL) return;
|
if (widgets == NULL) return;
|
||||||
@ -1314,3 +1325,134 @@ Screen* LoadLevelScreen_MakeInstance(void) {
|
|||||||
}
|
}
|
||||||
return (Screen*)screen;
|
return (Screen*)screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*########################################################################################################################*
|
||||||
|
*---------------------------------------------------KeyBindingsScreen-----------------------------------------------------*
|
||||||
|
*#########################################################################################################################*/
|
||||||
|
KeyBindingsScreen KeyBindingsScreen_Instance;
|
||||||
|
GuiElementVTABLE KeyBindingsScreen_VTABLE;
|
||||||
|
void KeyBindingsScreen_ClassicOptions(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(ClassicOptionsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_Classic(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(ClassicKeyBindingsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_ClassicHacks(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(ClassicHacksKeyBindingsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_Normal(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(NormalKeyBindingsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_Hacks(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(HacksKeyBindingsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_Other(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(OtherKeyBindingsScreen_MakeInstance()); }
|
||||||
|
void KeyBindingsScreen_Mouse(GuiElement* a, GuiElement* b) { Gui_SetNewScreen(MouseKeyBindingsScreen_MakeInstance()); }
|
||||||
|
|
||||||
|
void KeyBindingsScreen_OnBindingClick(GuiElement* screenElem, GuiElement* widget) {
|
||||||
|
KeyBindingsScreen* screen = (KeyBindingsScreen*)screenElem;
|
||||||
|
UInt8 textBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
|
String text = String_InitAndClearArray(textBuffer);
|
||||||
|
|
||||||
|
if (screen->CurI >= 0) {
|
||||||
|
KeyBindingsScreen_ButtonText(screen, screen->CurI, &text);
|
||||||
|
ButtonWidget* curButton = (ButtonWidget*)screen->WidgetsPtr[screen->CurI];
|
||||||
|
ButtonWidget_SetText(curButton, &text);
|
||||||
|
}
|
||||||
|
screen->CurI = Menu_Index(screen->WidgetsPtr, screen->WidgetsCount, (Widget*)widget);
|
||||||
|
|
||||||
|
String_Clear(&text);
|
||||||
|
String_AppendConst(&text, "> ");
|
||||||
|
KeyBindingsScreen_ButtonText(screen, screen->CurI, &text);
|
||||||
|
String_AppendConst(&text, " <");
|
||||||
|
ButtonWidget_SetText((ButtonWidget*)widget, &text);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KeyBindingsScreen_ButtonText(KeyBindingsScreen* screen, Int32 i, STRING_TRANSIENT String* text) {
|
||||||
|
Key key = KeyBind_Get(screen->Binds[i]);
|
||||||
|
String_AppendConst(text, screen->Descs[i]);
|
||||||
|
String_AppendConst(text, ": ");
|
||||||
|
String_AppendConst(text, Key_Names[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KeyBindingsScreen_HandlesKeyDown(GuiElement* elem, Key key) {
|
||||||
|
KeyBindingsScreen* screen = (KeyBindingsScreen*)elem;
|
||||||
|
if (screen->CurI == -1) return MenuScreen_HandlesKeyDown(elem, key);
|
||||||
|
KeyBind_Set(screen->Binds[screen->CurI], key);
|
||||||
|
|
||||||
|
UInt8 textBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
|
String text = String_InitAndClearArray(textBuffer);
|
||||||
|
KeyBindingsScreen_ButtonText(screen, screen->CurI, &text);
|
||||||
|
|
||||||
|
ButtonWidget* curButton = (ButtonWidget*)screen->WidgetsPtr[screen->CurI];
|
||||||
|
ButtonWidget_SetText(curButton, &text);
|
||||||
|
screen->CurI = -1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KeyBindingsScreen_HandlesMouseDown(GuiElement* elem, Int32 x, Int32 y, MouseButton btn) {
|
||||||
|
if (btn != MouseButton_Right) {
|
||||||
|
return MenuScreen_HandlesMouseDown(elem, x, y, btn);
|
||||||
|
}
|
||||||
|
|
||||||
|
KeyBindingsScreen* screen = (KeyBindingsScreen*)elem;
|
||||||
|
Int32 i = Menu_HandleMouseDown(elem, screen->WidgetsPtr, screen->WidgetsCount, x, y, btn);
|
||||||
|
if (i == -1) return false;
|
||||||
|
|
||||||
|
/* Reset a key binding */
|
||||||
|
if ((screen->CurI == -1 || screen->CurI == i) && i < screen->BindsCount) {
|
||||||
|
screen->CurI = i;
|
||||||
|
Elem_HandlesKeyDown(elem, KeyBind_GetDefault(screen->Binds[i]));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Int32 KeyBindingsScreen_MakeWidgets(KeyBindingsScreen* screen, Int32 y, Int32 arrowsY, Int32 leftLength, STRING_PURE const UInt8* title, Int32 btnWidth) {
|
||||||
|
Int32 i, origin = y, xOffset = btnWidth / 2 + 5;
|
||||||
|
screen->CurI = -1;
|
||||||
|
|
||||||
|
Widget** widgets = screen->WidgetsPtr;
|
||||||
|
UInt8 textBuffer[String_BufferSize(STRING_SIZE)];
|
||||||
|
String text = String_InitAndClearArray(textBuffer);
|
||||||
|
|
||||||
|
for (i = 0; i < screen->BindsCount; i++) {
|
||||||
|
if (i == leftLength) y = origin; /* reset y for next column */
|
||||||
|
Int32 xDir = leftLength == -1 ? 0 : (i < leftLength ? -1 : 1);
|
||||||
|
|
||||||
|
String_Clear(&text);
|
||||||
|
KeyBindingsScreen_ButtonText(screen, i, &text);
|
||||||
|
|
||||||
|
ButtonWidget_Create(&screen->Buttons[i], btnWidth, &text, &screen->TitleFont, KeyBindingsScreen_OnBindingClick);
|
||||||
|
widgets[i] = (Widget*)(&screen->Buttons[i]);
|
||||||
|
Widget_SetLocation(widgets[i], ANCHOR_CENTRE, ANCHOR_CENTRE, xDir * xOffset, y);
|
||||||
|
y += 50; /* distance between buttons */
|
||||||
|
}
|
||||||
|
|
||||||
|
String titleText = String_FromReadonly(title);
|
||||||
|
TextWidget_Create(&screen->Title, &titleText, &screen->TitleFont);
|
||||||
|
Widget_SetLocation((Widget*)(&screen->Title), ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -180);
|
||||||
|
widgets[i++] = (Widget*)(&screen->Title);
|
||||||
|
|
||||||
|
Widget_LeftClick backClick = Game_UseClassicOptions ? KeyBindingsScreen_ClassicOptions : Menu_SwitchOptions;
|
||||||
|
Menu_MakeDefaultBack(&screen->Back, false, &screen->TitleFont, backClick);
|
||||||
|
widgets[i++] = (Widget*)(&screen->Back);
|
||||||
|
if (screen->LeftPage == NULL && screen->RightPage == NULL) return i;
|
||||||
|
|
||||||
|
String lArrow = String_FromConst("<");
|
||||||
|
ButtonWidget_Create(&screen->Left, &lArrow, 40, &screen->TitleFont, screen->LeftPage);
|
||||||
|
Widget_SetLocation((Widget*)(&screen->Left), ANCHOR_CENTRE, ANCHOR_CENTRE, -btnWidth - 35, arrowsY);
|
||||||
|
screen->Left.Disabled = screen->LeftPage == NULL;
|
||||||
|
widgets[i++] = (Widget*)(&screen->Left);
|
||||||
|
|
||||||
|
String rArrow = String_FromConst("<");
|
||||||
|
ButtonWidget_Create(&screen->Right, &rArrow, 40, &screen->TitleFont, screen->LeftPage);
|
||||||
|
Widget_SetLocation((Widget*)(&screen->Right), ANCHOR_CENTRE, ANCHOR_CENTRE, btnWidth + 35, arrowsY);
|
||||||
|
screen->Right.Disabled = screen->RightPage == NULL;
|
||||||
|
widgets[i++] = (Widget*)(&screen->Right);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Screen* KeyBindingsScreen_MakeInstance(Int32 CurI, BindsCount, const UInt8** Descs, KeyBind* Binds, Widget_LeftClick LeftPage, RightPage, ButtonWidget* Buttons) {
|
||||||
|
ButtonWidget Back, Left, Right;
|
||||||
|
KeyBindingsScreen* screen = &KeyBindingsScreen_Instance;
|
||||||
|
MenuScreen_MakeInstance((MenuScreen*)screen, screen->Widgets,
|
||||||
|
Array_Elems(screen->Widgets), ClassicGenScreen_ContextRecreated);
|
||||||
|
KeyBindingsScreen_VTABLE = *screen->VTABLE;
|
||||||
|
screen->VTABLE = &KeyBindingsScreen_VTABLE;
|
||||||
|
|
||||||
|
screen->VTABLE->Init = KeyBindingsScreen_Init;
|
||||||
|
screen->VTABLE->HandlesKeyDown = KeyBindingsScreen_HandlesKeyDown;
|
||||||
|
screen->VTABLE->HandlesMouseDown = KeyBindingsScreen_HandlesMouseDown;
|
||||||
|
return (Screen*)screen;
|
||||||
|
}
|
@ -105,9 +105,9 @@ void TextWidget_SetText(TextWidget* widget, STRING_PURE String* text) {
|
|||||||
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
*------------------------------------------------------ButtonWidget-------------------------------------------------------*
|
||||||
*#########################################################################################################################*/
|
*#########################################################################################################################*/
|
||||||
#define BUTTON_uWIDTH (200.0f / 256.0f)
|
#define BUTTON_uWIDTH (200.0f / 256.0f)
|
||||||
Texture Button_ShadowTex = { 0, 0, 0, 0, 0, 0.0f, 66.0f / 256.0f, 200.0f / 256.0f, 86.0f / 256.0f };
|
Texture Button_ShadowTex = { 0, 0, 0, 0, 0, 0.0f, 66.0f / 256.0f, BUTTON_uWIDTH, 86.0f / 256.0f };
|
||||||
Texture Button_SelectedTex = { 0, 0, 0, 0, 0, 0.0f, 86.0f / 256.0f, 200.0f / 256.0f, 106.0f / 256.0f };
|
Texture Button_SelectedTex = { 0, 0, 0, 0, 0, 0.0f, 86.0f / 256.0f, BUTTON_uWIDTH, 106.0f / 256.0f };
|
||||||
Texture Button_DisabledTex = { 0, 0, 0, 0, 0, 0.0f, 46.0f / 256.0f, 200.0f / 256.0f, 66.0f / 256.0f };
|
Texture Button_DisabledTex = { 0, 0, 0, 0, 0, 0.0f, 46.0f / 256.0f, BUTTON_uWIDTH, 66.0f / 256.0f };
|
||||||
|
|
||||||
void ButtonWidget_Init(GuiElement* elem) {
|
void ButtonWidget_Init(GuiElement* elem) {
|
||||||
ButtonWidget* widget = (ButtonWidget*)elem;
|
ButtonWidget* widget = (ButtonWidget*)elem;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user