Start work on joystick options

This commit is contained in:
James Lambert 2023-05-10 21:20:07 -06:00
parent da4f5e6a8f
commit 3fe76c2d30
9 changed files with 177 additions and 9 deletions

View file

@ -257,6 +257,8 @@ build/src/menu/landing_menu.o: build/assets/materials/ui.h build/src/audio/clips
build/src/menu/options_menu.o: build/assets/materials/ui.h
build/src/menu/joystick_options.o: build/assets/materials/ui.h
build/src/menu/controls.o: build/assets/materials/ui.h build/src/audio/clips.h
build/assets/models/player/chell.h: assets/materials/chell.skm.yaml

View file

@ -136,12 +136,13 @@ Where `/home/james/Blender/blender-2.93.1-linux-x64` is the folder where Blender
<br />
## Current New Feature TODO List
- [ ] Adding y-axis/x-axis inverting options #55
- [ ] Adding look axis sensitivity setting
- [ ] rotate auto uv
- [ ] disable portal surfaces manually on some surfaces #135
- [ ] Portal not rendering recursively sometimes #138
- [ ] Correct elevator timing
- [ ] Presort portal gun polygon order #102
- [ ] Adding y-axis/x-axis inverting options #55
- [ ] Adding loading notice between levels #45
- [ ] Vertex lighting #39
- [x] Adding a menu to game #47

View file

@ -338,9 +338,11 @@ void controlsMenuRender(struct ControlsMenu* controlsMenu, struct RenderState* r
gSPDisplayList(renderState->dl++, ui_material_list[SOLID_ENV_INDEX]);
gSPDisplayList(renderState->dl++, controlsMenu->scrollOutline);
gDPPipeSync(renderState->dl++);
gDPSetEnvColor(renderState->dl++, 0, 0, 0, 255);
renderStateInlineBranch(renderState, controlsMenu->headerSeparators);
if (controlsMenu->selectedRow >= 0 && controlsMenu->selectedRow < ControllerActionCount) {
struct ControlsMenuRow* selectedAction = &controlsMenu->actionRows[controlsMenu->selectedRow];
@ -377,6 +379,7 @@ void controlsMenuRender(struct ControlsMenu* controlsMenu, struct RenderState* r
gDPSetScissor(renderState->dl++, G_SC_NON_INTERLACE, CONTROLS_X, CONTROLS_Y, CONTROLS_X + CONTROLS_WIDTH, CONTROLS_Y + CONTROLS_HEIGHT);
gSPDisplayList(renderState->dl++, ui_material_list[DEJAVU_SANS_INDEX]);
gDPPipeSync(renderState->dl++);

View file

@ -0,0 +1,52 @@
#include "joystick_options.h"
#include "../controls/controller.h"
#include "../font/dejavusans.h"
#include "../build/assets/materials/ui.h"
#define JOYSTICK_Y 54
#define JOYSTICK_WIDTH 252
#define JOYSTICK_HEIGHT 124
#define JOYSTICK_X ((SCREEN_WD - JOYSTICK_WIDTH) / 2)
void joystickOptionsInit(struct JoystickOptions* joystickOptions) {
joystickOptions->selectedItem = 0;
joystickOptions->invertControls = menuBuildCheckbox(&gDejaVuSansFont, "Invert Camera", JOYSTICK_X + 8, JOYSTICK_Y + 8);
joystickOptions->lookSensitivity = menuBuildSlider(JOYSTICK_X + 8, JOYSTICK_Y + 20, 80, 8, 13);
}
enum MenuDirection joystickOptionsUpdate(struct JoystickOptions* joystickOptions) {
int controllerDir = controllerGetDirectionDown(0);
if (controllerGetButtonDown(0, B_BUTTON)) {
return MenuDirectionUp;
}
if (controllerDir & ControllerDirectionLeft) {
return MenuDirectionLeft;
}
if (controllerDir & ControllerDirectionRight) {
return MenuDirectionRight;
}
return MenuDirectionStay;
}
void joystickOptionsRender(struct JoystickOptions* joystickOptions, struct RenderState* renderState, struct GraphicsTask* task) {
gSPDisplayList(renderState->dl++, ui_material_list[SOLID_ENV_INDEX]);
gSPDisplayList(renderState->dl++, joystickOptions->invertControls.outline);
gSPDisplayList(renderState->dl++, joystickOptions->lookSensitivity.back);
gSPDisplayList(renderState->dl++, ui_material_revert_list[SOLID_ENV_INDEX]);
gSPDisplayList(renderState->dl++, ui_material_list[DEJAVU_SANS_INDEX]);
gSPDisplayList(renderState->dl++, joystickOptions->invertControls.text);
gSPDisplayList(renderState->dl++, ui_material_revert_list[DEJAVU_SANS_INDEX]);
}

View file

@ -0,0 +1,17 @@
#ifndef __MENU_JOYSTICK_OPTIONS_H__
#define __MENU_JOYSTICK_OPTIONS_H__
#include "./menu.h"
#include "../graphics/graphics.h"
struct JoystickOptions {
struct MenuCheckbox invertControls;
struct MenuSlider lookSensitivity;
short selectedItem;
};
void joystickOptionsInit(struct JoystickOptions* joystickOptions);
enum MenuDirection joystickOptionsUpdate(struct JoystickOptions* joystickOptions);
void joystickOptionsRender(struct JoystickOptions* joystickOptions, struct RenderState* renderState, struct GraphicsTask* task);
#endif

View file

@ -121,10 +121,7 @@ Gfx* menuBuildSolidBorder(int x, int y, int w, int h, int nx, int ny, int nw, in
return result;
}
Gfx* menuBuildOutline(int x, int y, int width, int height, int invert) {
Gfx* result = malloc(sizeof(Gfx) * 9);
Gfx* dl = result;
Gfx* menuRenderOutline(int x, int y, int width, int height, int invert, Gfx* dl) {
gDPPipeSync(dl++);
if (invert) {
gDPSetEnvColor(dl++, gBorderDark.r, gBorderDark.g, gBorderDark.b, gBorderDark.a);
@ -141,8 +138,14 @@ Gfx* menuBuildOutline(int x, int y, int width, int height, int invert) {
}
gDPFillRectangle(dl++, x, y + height - 1, x + width, y + height);
gDPFillRectangle(dl++, x + width - 1, y, x + width, y + height - 1);
gSPEndDisplayList(dl++);
return dl;
}
Gfx* menuBuildOutline(int x, int y, int width, int height, int invert) {
Gfx* result = malloc(sizeof(Gfx) * 9);
Gfx* dl = menuRenderOutline(x, y, width, height, invert, result);
gSPEndDisplayList(dl++);
return result;
}
@ -167,4 +170,63 @@ void menuSetRenderColor(struct RenderState* renderState, int isSelected, struct
} else {
gDPSetEnvColor(renderState->dl++, defaultColor->r, defaultColor->g, defaultColor->b, defaultColor->a);
}
}
#define CHECKBOX_SIZE 12
struct MenuCheckbox menuBuildCheckbox(struct Font* font, char* message, int x, int y) {
struct MenuCheckbox result;
result.x = x;
result.y = y;
result.outline = malloc(sizeof(Gfx) * 12);
Gfx* dl = result.outline;
gDPPipeSync(dl++);
gDPSetEnvColor(dl++, 93, 96, 97, 255);
gDPFillRectangle(dl++, x, y, x + CHECKBOX_SIZE, y + CHECKBOX_SIZE);
dl = menuRenderOutline(x, y, CHECKBOX_SIZE, CHECKBOX_SIZE, 1, dl);
gSPEndDisplayList(dl++);
result.text = menuBuildText(font, message, x + CHECKBOX_SIZE + 6, y);
result.checked = 0;
return result;
}
#define SLIDER_CENTER_HEIGHT 4
struct MenuSlider menuBuildSlider(int x, int y, int w, int h, int tickCount) {
struct MenuSlider result;
result.x = x;
result.y = y;
result.w = w;
result.h = h;
result.back = malloc(sizeof(Gfx) * 12 + tickCount + 2);
Gfx* dl = result.back;
int sliderX = x;
int sliderY = y + (h >> 1) - (SLIDER_CENTER_HEIGHT >> 1);
gDPPipeSync(dl++);
gDPSetEnvColor(dl++, 93, 96, 97, 255);
gDPFillRectangle(
dl++,
sliderX,
sliderY,
sliderX + w,
sliderY + SLIDER_CENTER_HEIGHT
);
dl = menuRenderOutline(sliderX, sliderY, w, SLIDER_CENTER_HEIGHT, 1, dl);
gSPEndDisplayList(dl++);
result.value = 0;
return result;
}

View file

@ -13,6 +13,21 @@ struct MenuButton {
short w, h;
};
struct MenuCheckbox {
Gfx* outline;
Gfx* text;
Gfx* checkedIndicator;
short x, y;
short checked;
};
struct MenuSlider {
Gfx* back;
float value;
short x, y;
short w, h;
};
enum MenuDirection {
MenuDirectionStay,
MenuDirectionUp,
@ -39,4 +54,7 @@ Gfx* menuBuildOutline(int x, int y, int width, int height, int invert);
struct MenuButton menuBuildButton(struct Font* font, char* message, int x, int y, int width, int height);
void menuSetRenderColor(struct RenderState* renderState, int isSelected, struct Coloru8* selected, struct Coloru8* defaultColor);
struct MenuCheckbox menuBuildCheckbox(struct Font* font, char* message, int x, int y);
struct MenuSlider menuBuildSlider(int x, int y, int w, int h, int tickCount);
#endif

View file

@ -14,6 +14,9 @@ struct Tab gOptionTabs[] = {
{
.message = "Controls",
},
{
.message = "Joystick",
},
{
.message = "Audio",
},
@ -42,6 +45,7 @@ void optionsMenuInit(struct OptionsMenu* options) {
);
controlsMenuInit(&options->controlsMenu);
joystickOptionsInit(&options->joystickOptions);
audioOptionsInit(&options->audioOptions);
}
@ -49,9 +53,12 @@ enum MenuDirection optionsMenuUpdate(struct OptionsMenu* options) {
enum MenuDirection menuDirection = MenuDirectionStay;
switch (options->tabs.selectedTab) {
case OptionsMenuTabsControls:
case OptionsMenuTabsControlMapping:
menuDirection = controlsMenuUpdate(&options->controlsMenu);
break;
case OptionsMenuTabsControlJoystick:
menuDirection = joystickOptionsUpdate(&options->joystickOptions);
break;
case OptionsMenuTabsAudio:
menuDirection = audioOptionsUpdate(&options->audioOptions);
break;
@ -104,9 +111,12 @@ void optionsMenuRender(struct OptionsMenu* options, struct RenderState* renderSt
gSPDisplayList(renderState->dl++, ui_material_revert_list[DEJAVU_SANS_INDEX]);
switch (options->tabs.selectedTab) {
case OptionsMenuTabsControls:
case OptionsMenuTabsControlMapping:
controlsMenuRender(&options->controlsMenu, renderState, task);
break;
case OptionsMenuTabsControlJoystick:
joystickOptionsRender(&options->joystickOptions, renderState, task);
break;
case OptionsMenuTabsAudio:
audioOptionsRender(&options->audioOptions, renderState, task);
break;

View file

@ -6,9 +6,11 @@
#include "./tabs.h"
#include "./controls.h"
#include "./audio_options.h"
#include "./joystick_options.h"
enum OptionsMenuTabs {
OptionsMenuTabsControls,
OptionsMenuTabsControlMapping,
OptionsMenuTabsControlJoystick,
OptionsMenuTabsAudio,
OptionsMenuTabsCount,
@ -21,6 +23,7 @@ struct OptionsMenu {
struct Tabs tabs;
struct ControlsMenu controlsMenu;
struct JoystickOptions joystickOptions;
struct AudioOptions audioOptions;
};