Files
coah80-LegacyVulkEdition/Minecraft.Client/CrossPlatform/NkSettingsMenus.cpp

459 lines
14 KiB
C++

#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_STANDARD_IO
#define NK_INCLUDE_STANDARD_VARARGS
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#include "nuklear.h"
#include "NkSettingsMenus.h"
#include "NkCommon.h"
#include "MenuScreens.h"
#include "NuklearBridge.h"
#include <cstring>
#include <cstdio>
namespace lve { namespace ui {
static const float BASE_W = 1280.0f;
static const float BASE_H = 720.0f;
static const float BUTTON_W = 600.0f;
static const float BUTTON_X = (BASE_W - BUTTON_W) * 0.5f;
static const float BUTTON_H = 40.0f;
static const float BUTTON_Y_START = 200.0f;
static const float BUTTON_Y_STEP = 50.0f;
static void formatSliderLabel(char *buf, int bufSize, const char *prefix, int value, const char *suffix)
{
snprintf(buf, bufSize, "%s: %d%s", prefix, value, suffix);
}
SettingsAction renderHelpAndOptions(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
SettingsAction result = kSettingsAction_None;
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
pushCleanStyle(ctx);
if (nk_begin(ctx, "HelpAndOptions", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
static const int BUTTON_COUNT = 5;
static const char *LABELS[BUTTON_COUNT] = {
"Change Skin",
"How to Play",
"Controls",
"Settings",
"Credits"
};
static const SettingsAction ACTIONS[BUTTON_COUNT] = {
kSettingsAction_ChangeSkin,
kSettingsAction_HowToPlay,
kSettingsAction_Controls,
kSettingsAction_Settings,
kSettingsAction_Credits
};
float btnW = BUTTON_W * scaleX;
float btnH = BUTTON_H * scaleY;
float btnX = BUTTON_X * scaleX;
const struct nk_input *input = &ctx->input;
for (int i = 0; i < BUTTON_COUNT; i++) {
float btnY = (BUTTON_Y_START + (float)i * BUTTON_Y_STEP) * scaleY;
struct nk_rect btnRect = nk_rect(btnX, btnY, btnW, btnH);
bool hovering = nk_input_is_mouse_hovering_rect(input, btnRect) != 0;
if (drawBtn(ctx, LABELS[i], btnX, btnY, btnW, btnH, hovering, winH, tex)) {
result = ACTIONS[i];
}
}
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
return result;
}
SettingsAction renderSettingsHub(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
SettingsAction result = kSettingsAction_None;
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsHub", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
static const int BUTTON_COUNT = 6;
static const char *LABELS[BUTTON_COUNT] = {
"Options",
"Audio",
"Control",
"Graphics",
"User Interface",
"Reset to Defaults"
};
static const SettingsAction ACTIONS[BUTTON_COUNT] = {
kSettingsAction_Options,
kSettingsAction_Audio,
kSettingsAction_Control,
kSettingsAction_Graphics,
kSettingsAction_UserInterface,
kSettingsAction_ResetDefaults
};
float btnW = BUTTON_W * scaleX;
float btnH = BUTTON_H * scaleY;
float btnX = BUTTON_X * scaleX;
const struct nk_input *input = &ctx->input;
for (int i = 0; i < BUTTON_COUNT; i++) {
float btnY = (BUTTON_Y_START + (float)i * BUTTON_Y_STEP) * scaleY;
struct nk_rect btnRect = nk_rect(btnX, btnY, btnW, btnH);
bool hovering = nk_input_is_mouse_hovering_rect(input, btnRect) != 0;
if (drawBtn(ctx, LABELS[i], btnX, btnY, btnW, btnH, hovering, winH, tex)) {
result = ACTIONS[i];
}
}
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
return result;
}
void renderSettingsOptions(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
static bool viewBobbing = true;
static bool hints = true;
static bool inGameTooltips = true;
static bool inGameGamertags = true;
static int autosaveIndex = 2;
static int difficulty = 1;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsOptions", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
float rowW = BUTTON_W * scaleX;
float rowH = BUTTON_H * scaleY;
float rowX = BUTTON_X * scaleX;
float step = BUTTON_Y_STEP * scaleY;
int row = 0;
float baseY = BUTTON_Y_START * scaleY;
viewBobbing = drawCheckbox(ctx, "View Bobbing",
rowX, baseY + step * (float)row, rowW, rowH,
viewBobbing, true, winH, tex);
row++;
hints = drawCheckbox(ctx, "Hints",
rowX, baseY + step * (float)row, rowW, rowH,
hints, true, winH, tex);
row++;
inGameTooltips = drawCheckbox(ctx, "In-Game Tooltips",
rowX, baseY + step * (float)row, rowW, rowH,
inGameTooltips, true, winH, tex);
row++;
inGameGamertags = drawCheckbox(ctx, "In-Game Gamertags",
rowX, baseY + step * (float)row, rowW, rowH,
inGameGamertags, true, winH, tex);
row++;
static const char *AUTOSAVE_LABELS[9] = {
"Autosave Interval: OFF",
"Autosave Interval: 15 Minutes",
"Autosave Interval: 30 Minutes",
"Autosave Interval: 45 Minutes",
"Autosave Interval: 60 Minutes",
"Autosave Interval: 75 Minutes",
"Autosave Interval: 90 Minutes",
"Autosave Interval: 105 Minutes",
"Autosave Interval: 120 Minutes"
};
autosaveIndex = drawSlider(ctx, AUTOSAVE_LABELS[autosaveIndex],
rowX, baseY + step * (float)row, rowW, rowH,
autosaveIndex, 0, 8, winH, tex);
row++;
static const char *DIFFICULTY_LABELS[4] = {
"Difficulty: Peaceful",
"Difficulty: Easy",
"Difficulty: Normal",
"Difficulty: Hard"
};
difficulty = drawSlider(ctx, DIFFICULTY_LABELS[difficulty],
rowX, baseY + step * (float)row, rowW, rowH,
difficulty, 0, 3, winH, tex);
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
}
void renderSettingsAudio(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
static int musicVolume = 100;
static int soundVolume = 100;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsAudio", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
float rowW = BUTTON_W * scaleX;
float rowH = BUTTON_H * scaleY;
float rowX = BUTTON_X * scaleX;
float step = BUTTON_Y_STEP * scaleY;
float baseY = BUTTON_Y_START * scaleY;
char label[128];
int row = 0;
formatSliderLabel(label, sizeof(label), "Music", musicVolume, "%");
musicVolume = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
musicVolume, 0, 100, winH, tex);
row++;
formatSliderLabel(label, sizeof(label), "Sound", soundVolume, "%");
soundVolume = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
soundVolume, 0, 100, winH, tex);
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
}
void renderSettingsControl(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
static int sensitivityInGame = 100;
static int sensitivityInMenu = 100;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsControl", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
float rowW = BUTTON_W * scaleX;
float rowH = BUTTON_H * scaleY;
float rowX = BUTTON_X * scaleX;
float step = BUTTON_Y_STEP * scaleY;
float baseY = BUTTON_Y_START * scaleY;
char label[128];
int row = 0;
formatSliderLabel(label, sizeof(label), "Game Sensitivity", sensitivityInGame, "%");
sensitivityInGame = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
sensitivityInGame, 0, 200, winH, tex);
row++;
formatSliderLabel(label, sizeof(label), "Interface Sensitivity", sensitivityInMenu, "%");
sensitivityInMenu = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
sensitivityInMenu, 0, 200, winH, tex);
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
}
void renderSettingsGraphics(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
static bool renderClouds = true;
static bool bedrockFog = false;
static bool customSkinAnim = true;
static int gamma = 100;
static int interfaceOpacity = 80;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsGraphics", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
float rowW = BUTTON_W * scaleX;
float rowH = BUTTON_H * scaleY;
float rowX = BUTTON_X * scaleX;
float step = BUTTON_Y_STEP * scaleY;
float baseY = BUTTON_Y_START * scaleY;
char label[128];
int row = 0;
renderClouds = drawCheckbox(ctx, "Render Clouds",
rowX, baseY + step * (float)row, rowW, rowH,
renderClouds, true, winH, tex);
row++;
bedrockFog = drawCheckbox(ctx, "Bedrock Fog",
rowX, baseY + step * (float)row, rowW, rowH,
bedrockFog, true, winH, tex);
row++;
customSkinAnim = drawCheckbox(ctx, "Custom Skin Animation",
rowX, baseY + step * (float)row, rowW, rowH,
customSkinAnim, true, winH, tex);
row++;
formatSliderLabel(label, sizeof(label), "Gamma", gamma, "%");
gamma = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
gamma, 0, 100, winH, tex);
row++;
formatSliderLabel(label, sizeof(label), "Interface Opacity", interfaceOpacity, "%");
interfaceOpacity = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
interfaceOpacity, 0, 100, winH, tex);
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
}
void renderSettingsUI(nk_context *ctx, int winW, int winH, MenuTextures &tex)
{
float scaleX = (float)winW / BASE_W;
float scaleY = (float)winH / BASE_H;
static bool displayHUD = true;
static bool displayHand = true;
static bool deathMessages = true;
static bool animatedCharacter = true;
static bool verticalSplitScreen = false;
static bool splitscreenGamertags = true;
static int uiSize = 2;
static int uiSizeSplitscreen = 3;
pushCleanStyle(ctx);
if (nk_begin(ctx, "SettingsUI", nk_rect(0, 0, (float)winW, (float)winH),
NK_WINDOW_NO_SCROLLBAR | NK_WINDOW_NO_INPUT | NK_WINDOW_BACKGROUND)) {
drawPanoramaBg(ctx, winW, winH, tex);
drawLogo(ctx, winW, winH, tex);
float rowW = BUTTON_W * scaleX;
float rowH = BUTTON_H * scaleY;
float rowX = BUTTON_X * scaleX;
float step = BUTTON_Y_STEP * scaleY;
float baseY = BUTTON_Y_START * scaleY;
char label[128];
int row = 0;
displayHUD = drawCheckbox(ctx, "Display HUD",
rowX, baseY + step * (float)row, rowW, rowH,
displayHUD, true, winH, tex);
row++;
displayHand = drawCheckbox(ctx, "Display Hand",
rowX, baseY + step * (float)row, rowW, rowH,
displayHand, true, winH, tex);
row++;
deathMessages = drawCheckbox(ctx, "Death Messages",
rowX, baseY + step * (float)row, rowW, rowH,
deathMessages, true, winH, tex);
row++;
animatedCharacter = drawCheckbox(ctx, "Animated Character",
rowX, baseY + step * (float)row, rowW, rowH,
animatedCharacter, true, winH, tex);
row++;
verticalSplitScreen = drawCheckbox(ctx, "2 Player Split-screen Vertical",
rowX, baseY + step * (float)row, rowW, rowH,
verticalSplitScreen, true, winH, tex);
row++;
splitscreenGamertags = drawCheckbox(ctx, "Splitscreen Gamertags",
rowX, baseY + step * (float)row, rowW, rowH,
splitscreenGamertags, true, winH, tex);
row++;
snprintf(label, sizeof(label), "HUD Size: %d", uiSize);
uiSize = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
uiSize, 1, 3, winH, tex);
row++;
snprintf(label, sizeof(label), "HUD Size (Splitscreen): %d", uiSizeSplitscreen);
uiSizeSplitscreen = drawSlider(ctx, label,
rowX, baseY + step * (float)row, rowW, rowH,
uiSizeSplitscreen, 1, 3, winH, tex);
drawControllerPrompts(ctx, winW, winH, tex);
}
nk_end(ctx);
popCleanStyle(ctx);
}
}}