DJUI: Added controls menu

This commit is contained in:
MysterD 2021-06-27 15:52:16 -07:00
parent 8b403d4509
commit 4504b2c21b
20 changed files with 489 additions and 19 deletions

View file

@ -3943,8 +3943,10 @@
<ClCompile Include="..\src\pc\discord\discordrpc.c" />
<ClCompile Include="..\src\pc\djui\djui.c" />
<ClCompile Include="..\src\pc\djui\djui_base.c" />
<ClCompile Include="..\src\pc\djui\djui_bind.c" />
<ClCompile Include="..\src\pc\djui\djui_button.c" />
<ClCompile Include="..\src\pc\djui\djui_checkbox.c" />
<ClCompile Include="..\src\pc\djui\djui_panel_controls.c" />
<ClCompile Include="..\src\pc\djui\djui_selectionbox.c" />
<ClCompile Include="..\src\pc\djui\djui_cursor.c" />
<ClCompile Include="..\src\pc\djui\djui_flow_layout.c" />
@ -4379,8 +4381,10 @@
<ClInclude Include="..\src\pc\debuglog.h" />
<ClInclude Include="..\src\pc\djui\djui.h" />
<ClInclude Include="..\src\pc\djui\djui_base.h" />
<ClInclude Include="..\src\pc\djui\djui_bind.h" />
<ClInclude Include="..\src\pc\djui\djui_button.h" />
<ClInclude Include="..\src\pc\djui\djui_checkbox.h" />
<ClInclude Include="..\src\pc\djui\djui_panel_controls.h" />
<ClInclude Include="..\src\pc\djui\djui_selectionbox.h" />
<ClInclude Include="..\src\pc\djui\djui_cursor.h" />
<ClInclude Include="..\src\pc\djui\djui_flow_layout.h" />

View file

@ -15234,6 +15234,12 @@
<ClCompile Include="..\src\pc\djui\djui_selectionbox.c">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_panel_controls.c">
<Filter>Source Files\src\pc\djui\panel</Filter>
</ClCompile>
<ClCompile Include="..\src\pc\djui\djui_bind.c">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\actors\common0.h">
@ -16288,5 +16294,11 @@
<ClInclude Include="..\src\pc\djui\djui_selectionbox.h">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_panel_controls.h">
<Filter>Source Files\src\pc\djui\panel</Filter>
</ClInclude>
<ClInclude Include="..\src\pc\djui\djui_bind.h">
<Filter>Source Files\src\pc\djui\component\compound</Filter>
</ClInclude>
</ItemGroup>
</Project>

203
misc/n64-controller.svg Normal file
View file

@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="210mm"
height="297mm"
viewBox="0 0 210 297"
version="1.1"
id="svg3123"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)"
sodipodi:docname="n64-controller.svg">
<defs
id="defs3117">
<pattern
id="EMFhbasepattern"
patternUnits="userSpaceOnUse"
width="6"
height="6"
x="0"
y="0" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98422794"
inkscape:cx="366.87429"
inkscape:cy="482.24232"
inkscape:document-units="mm"
inkscape:current-layer="layer1"
inkscape:document-rotation="0"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1387"
inkscape:window-x="1272"
inkscape:window-y="-8"
inkscape:window-maximized="1" />
<metadata
id="metadata3120">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="opacity:1;fill:#999999;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 159.02164,179.47574 c 4.22025,-1.90449 6.28702,-7.08236 7.60023,-19.04089 1.49599,-13.62284 0.24084,-34.30392 -1.99705,-47.32577 -0.20446,-1.18966 -0.20446,-1.18966 -0.81578,1.12198 -2.98495,11.28726 -13.59592,24.03716 -29.26288,26.03289 -0.81252,0.1035 -3.77405,0.3089 -3.60094,0.36847 0.53476,0.18404 2.20561,0.19552 2.97591,0.42882 2.64606,0.8014 6.14267,5.68736 7.86503,13.7161 4.7533,22.15739 9.09126,28.37366 17.23548,24.6984 z"
id="path3879"
sodipodi:nodetypes="sssssssss" />
<path
style="opacity:1;fill:#999999;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 32.861846,179.99085 c 5.00628,-1.30397 7.90516,-7.49824 11.63722,-24.86622 1.74689,-8.12955 4.040457,-12.01723 6.760691,-13.41247 1.175878,-0.60312 7.936069,-0.81879 7.254723,-1.00324 -0.347508,-0.0941 -7.714416,-0.40085 -8.622923,-0.51096 -13.947408,-1.69042 -24.46162,-12.73569 -27.45118,-23.32573 -0.3377,-1.19622 -0.67694,-2.2379 -0.75388,-2.31484 -0.0769,-0.0769 -0.4002,1.61825 -0.71836,3.76707 -2.15481,14.55314 -2.561091,37.51868 -0.08673,49.90929 1.46209,7.32157 4.05435,11.05512 8.25242,11.88568 1.64494,0.32544 2.03682,0.31192 3.728019,-0.12858 z"
id="path3877"
sodipodi:nodetypes="ssssssscsss" />
<path
style="opacity:1;fill:#666666;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 34.669026,91.826028 27.72169,-6.884126 1.818325,-6.455174 c 0,0 -24.936365,1.49832 -32.278785,8.638042 l 0.172599,5.12895 z"
id="path3885"
sodipodi:nodetypes="cccccc" />
<path
style="opacity:1;fill:#666666;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 151.88386,91.82585 -27.72169,-6.884125 -1.81832,-6.455175 c 0,0 24.93636,1.49832 32.27878,8.638043 l -0.1726,5.128949 z"
id="path3885-3"
sodipodi:nodetypes="cccccc" />
<path
style="opacity:1;fill:#b3b3b3;stroke:#000000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 96.641306,210.13404 c 3.380854,-1.51705 6.454544,-6.19977 9.099164,-13.8624 2.68812,-7.78869 3.74969,-12.87923 6.70151,-32.13562 3.19508,-20.84329 4.75644,-22.60184 20.76255,-23.38477 21.1825,-1.03614 31.92894,-10.58468 31.38845,-27.88957 -0.43636,-13.97068 -8.39177,-24.158157 -21.67654,-27.75838 -3.41038,-0.924226 -14.1984,-2.461285 -17.10739,-2.719429 0,0 -2.8761,-5.127414 -4.06555,-6.958522 -0.83939,-1.771386 -15.39779,-6.171957 -28.038814,-6.171957 -11.83651,0 -27.511412,3.714691 -28.56411,6.145662 l -3.466375,6.79723 -7.516145,1.067272 c -19.91914,2.168581 -30.28071,10.635003 -32.25997,26.359574 -2.35782,18.73214 9.00373,30.06503 31.20249,31.12376 15.92894,0.7597 17.70816,2.72014 20.74733,22.86039 2.41524,16.0055 3.44807,21.53411 5.14373,27.53369 4.49992,15.9216 10.38385,22.25339 17.64967,18.99307 z"
id="path3819"
sodipodi:nodetypes="ssssssccscccsssss" />
<ellipse
style="opacity:1;fill:#666666;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4050"
cx="93.281662"
cy="149.23048"
rx="15.356243"
ry="15.389847" />
<path
style="opacity:1;fill:#1a1a1a;stroke:#000000;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 97.472306,157.25386 c 2.869884,-1.16156 2.592834,-0.84172 4.226594,-4.87944 1.31925,-3.26043 1.31925,-3.26043 -0.004,-6.51708 -1.62318,-3.99318 -1.25715,-3.62328 -5.222619,-5.27796 -3.293655,-1.37436 -3.293655,-1.37436 -6.766293,0.0702 -3.472637,1.44446 -3.472637,1.44446 -4.955151,4.95638 -1.482514,3.51191 -1.482514,3.51191 0,7.02456 1.482514,3.51266 1.482514,3.51266 4.934707,4.95635 3.352146,1.40187 3.480201,1.43206 4.418804,1.04148 0.531635,-0.22124 2.047475,-0.83971 3.368526,-1.37439 z"
id="path3827" />
<path
style="fill:#e6e6e6;stroke-width:0.5;opacity:1;stroke:#000000;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none"
d="m 90.808556,156.06467 c -3.19709,-0.95777 -5.44345,-4.93001 -4.69055,-8.29433 1.46124,-6.52952 10.04671,-7.88776 13.29527,-2.10334 3.226694,5.74546 -2.20892,12.31367 -8.60472,10.39767 z"
id="path3829" />
<path
style="opacity:1;fill:#cccccc;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 65.017829,75.401478 -3.343628,6.794806 c 0,0 6.248151,22.468596 5.826195,20.433286 -0.827522,-9.076031 -2.462914,-28.250425 -2.482567,-27.228092 z"
id="path3881"
sodipodi:nodetypes="cccc" />
<path
style="fill:#000000;stroke-width:0.264369"
id="path3138"
d="" />
<circle
style="opacity:1;fill:#ff0000;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892"
cx="93.14756"
cy="119.22792"
r="6.7085466" />
<path
id="rect3924"
style="opacity:1;fill:none;stroke:#000000;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 123.98074,122.64871 1.54028,-1.51666 3.96468,3.71008 -1.77651,1.15706 z"
sodipodi:nodetypes="ccccc" />
<circle
style="opacity:1;fill:#00ff00;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0"
cx="121.27341"
cy="118.1497"
r="5.2315807" />
<circle
style="opacity:1;fill:#0000ff;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0-9"
cx="131.88081"
cy="129.24153"
r="5.2315807" />
<rect
style="opacity:0.645161;fill:#999999;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect3948"
width="29.365215"
height="6.4055333"
x="78.46347"
y="84.188957"
ry="3.1025405"
rx="3.1738269" />
<path
style="opacity:1;fill:#666666;stroke:#000000;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 121.7435,75.425349 3.34362,6.794806 c 0,0 -6.24815,22.468595 -5.82619,20.433285 0.82752,-9.07603 2.46291,-28.250424 2.48257,-27.228091 z"
id="path3881-7"
sodipodi:nodetypes="cccc" />
<ellipse
style="opacity:1;fill:#999999;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;fill-opacity:1"
id="path3982"
cx="46.353729"
cy="114.51382"
rx="16.790049"
ry="16.844238" />
<path
id="rect3984"
style="opacity:1;fill:#333333;fill-opacity:1;stroke:#000000;stroke-width:3.77953;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 174.89453 390.91992 C 168.15317 390.91992 162.72656 393.73545 162.72656 397.23242 L 162.72656 419.83789 L 140.12109 419.83789 C 136.62412 419.83789 133.80859 425.26451 133.80859 432.00586 L 133.80859 432.81445 C 133.80859 439.55581 136.62412 444.98242 140.12109 444.98242 L 162.72656 444.98242 L 162.72656 467.58789 C 162.72656 471.08486 168.15317 473.90039 174.89453 473.90039 L 175.70312 473.90039 C 182.44449 473.90039 187.87109 471.08486 187.87109 467.58789 L 187.87109 444.98242 L 210.47656 444.98242 C 213.97353 444.98242 216.78906 439.55581 216.78906 432.81445 L 216.78906 432.00586 C 216.78906 425.26451 213.97353 419.83789 210.47656 419.83789 L 187.87109 419.83789 L 187.87109 397.23242 C 187.87109 393.73545 182.44449 390.91992 175.70312 390.91992 L 174.89453 390.91992 z "
transform="scale(0.26458333)" />
<circle
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#000000;stroke-width:0.5;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4048"
cy="109.39449"
cx="143.2998"
r="11.098639" />
<circle
style="opacity:1;fill:#ffff00;stroke:#000000;stroke-width:0.82998;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0-5"
cx="134.47882"
cy="108.94062"
r="4.3421068" />
<circle
style="opacity:1;fill:#ffff00;stroke:#000000;stroke-width:0.829979;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0-5-2"
cx="152.28836"
cy="108.94061"
r="4.3421068" />
<circle
style="opacity:1;fill:#ffff00;stroke:#000000;stroke-width:0.829979;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0-5-5"
cx="142.94675"
cy="100.47269"
r="4.3421068" />
<circle
style="opacity:1;fill:#ffff00;stroke:#000000;stroke-width:0.829979;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path3892-0-5-7"
cx="143.04756"
cy="118.31582"
r="4.3421068" />
<path
style="opacity:1;fill:#e6e6e6;stroke:#ffffff;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 91.310516,154.60644 c -2.517257,-0.75411 -4.28595,-3.88169 -3.693146,-6.53061 1.15052,-5.14108 7.910368,-6.2105 10.468147,-1.65608 2.540573,4.52373 -1.739209,9.69528 -6.775001,8.18669 z"
id="path3829-4" />
<path
style="opacity:1;fill:#e6e6e6;stroke:#ffffff;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 91.933837,152.79309 c -1.6719,-0.50086 -2.846622,-2.57812 -2.452896,-4.33746 0.764147,-3.41458 5.253869,-4.12486 6.952682,-1.09993 1.687385,3.00455 -1.15514,6.43936 -4.499786,5.43739 z"
id="path3829-4-2" />
<path
style="opacity:1;fill:#e6e6e6;stroke:#ffffff;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 92.606431,150.83354 c -0.758421,-0.2272 -1.291308,-1.1695 -1.112703,-1.96759 0.346639,-1.54895 2.383302,-1.87115 3.153935,-0.49896 0.765443,1.36295 -0.524004,2.92108 -2.041232,2.46655 z"
id="path3829-4-2-1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -25,12 +25,14 @@
#include "djui_slider.h"
#include "djui_checkbox.h"
#include "djui_selectionbox.h"
#include "djui_bind.h"
#include "djui_panel.h"
#include "djui_panel_debug.h"
#include "djui_panel_main.h"
#include "djui_panel_options.h"
#include "djui_panel_camera.h"
#include "djui_panel_controls.h"
#include "djui_panel_display.h"
#include "djui_panel_sound.h"
#include "djui_panel_quit.h"

View file

@ -43,6 +43,7 @@ struct DjuiBase {
struct DjuiBaseRect comp;
struct DjuiBaseRect clip;
struct DjuiInteractable* interactable;
s32 tag;
void (*on_child_render)(struct DjuiBase*, struct DjuiBase*);
void (*on_render_pre)(struct DjuiBase*, bool*);
void (*render)(struct DjuiBase*);

98
src/pc/djui/djui_bind.c Normal file
View file

@ -0,0 +1,98 @@
#include <stdio.h>
#include <string.h>
#include "djui.h"
#include "src/pc/controller/controller_api.h"
#include "audio_defines.h"
#include "audio/external.h"
#define VK_ESCAPE 1
static void djui_bind_button_on_click(struct DjuiBase* caller) {
struct DjuiButton* button = (struct DjuiButton*)caller;
djui_text_set_text(button->text, "...");
controller_get_raw_key(); // consume lingering controller button press
djui_interactable_set_binding(caller);
}
static void djui_bind_button_on_bind(struct DjuiBase* caller) {
struct DjuiButton* button = (struct DjuiButton*)caller;
struct DjuiBind* bind = (struct DjuiBind*) caller->parent->parent;
// get key
u32 key = controller_get_raw_key();
if (key == VK_INVALID) { return; }
// invalidate key
if (key == VK_ESCAPE) { key = VK_INVALID; }
for (int i = 0; i < MAX_BINDS; i++) {
if (i == button->base.tag) { continue; }
if (bind->configKey[i] == key) {
key = VK_INVALID;
}
}
// set key
bind->configKey[button->base.tag] = key;
char keyStr[5] = { 0 };
if (key != VK_INVALID) {
sprintf(keyStr, "%04x", key);
}
djui_text_set_text(button->text, keyStr);
djui_interactable_set_binding(NULL);
play_sound(SOUND_MENU_CHANGE_SELECT, gDefaultSoundArgs);
}
static void djui_bind_destroy(struct DjuiBase* base) {
struct DjuiBind* bind = (struct DjuiBind*)base;
free(bind);
}
struct DjuiBind* djui_bind_create(struct DjuiBase* parent, const char* message, unsigned int configKey[]) {
struct DjuiBind* bind = malloc(sizeof(struct DjuiBind));
struct DjuiBase* base = &bind->base;
bind->configKey = configKey;
djui_base_init(parent, base, NULL, djui_bind_destroy);
djui_base_set_size_type(&bind->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&bind->base, 1.0f, 32);
djui_base_set_color(&bind->base, 0, 0, 0, 0);
struct DjuiText* text = djui_text_create(&bind->base, message);
djui_base_set_alignment(&text->base, DJUI_HALIGN_LEFT, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&text->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&text->base, 0.3f, 1.0f);
djui_text_set_alignment(text, DJUI_HALIGN_LEFT, DJUI_VALIGN_BOTTOM);
djui_text_set_drop_shadow(text, 120, 120, 120, 64);
djui_base_set_color(&text->base, 200, 200, 200, 255);
bind->text = text;
struct DjuiRect* rect = djui_rect_create(&bind->base);
djui_base_set_alignment(&rect->base, DJUI_HALIGN_RIGHT, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&rect->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&rect->base, 0.7f, 1.0f);
djui_base_set_color(&rect->base, 0, 0, 0, 0);
bind->rect = rect;
for (int i = 0; i < MAX_BINDS; i++) {
unsigned int key = configKey[i];
char keyStr[5] = { 0 };
if (key != VK_INVALID) {
sprintf(keyStr, "%04x", key);
}
struct DjuiButton* button = djui_button_create(&rect->base, keyStr);
djui_base_set_size_type(&button->base, DJUI_SVT_RELATIVE, DJUI_SVT_RELATIVE);
djui_base_set_size(&button->base, 0.33f, 1.0f);
button->base.tag = i;
djui_interactable_hook_click(&button->base, djui_bind_button_on_click);
djui_interactable_hook_bind(&button->base, djui_bind_button_on_bind);
enum DjuiHAlign hAlign = DJUI_HALIGN_LEFT;
if (i > 0) { hAlign = (i == 1) ? DJUI_HALIGN_CENTER : DJUI_HALIGN_RIGHT; }
djui_base_set_alignment(&button->base, hAlign, DJUI_VALIGN_CENTER);
bind->buttons[i] = button;
}
return bind;
}

14
src/pc/djui/djui_bind.h Normal file
View file

@ -0,0 +1,14 @@
#pragma once
#include "djui.h"
#include "src/pc/configfile.h"
#pragma pack(1)
struct DjuiBind {
struct DjuiBase base;
struct DjuiText* text;
struct DjuiRect* rect;
struct DjuiButton* buttons[MAX_BINDS];
unsigned int* configKey;
};
struct DjuiBind* djui_bind_create(struct DjuiBase* parent, const char* message, unsigned int configKey[]);

View file

@ -104,6 +104,8 @@ void djui_cursor_move(s8 xDir, s8 yDir) {
void djui_cursor_update(void) {
#if defined(CAPI_SDL2) || defined(CAPI_SDL1)
if (djui_interactable_is_binding()) { return; }
controller_sdl_read_mouse_window();
// check if mouse is in control again

View file

@ -1,5 +1,4 @@
#include "djui.h"
#include <stdio.h>
////////////////
// properties //

View file

@ -6,6 +6,9 @@
#include "src/pc/controller/controller_mouse.h"
#include "src/pc/controller/controller_keyboard.h"
#include "audio_defines.h"
#include "audio/external.h"
#define SCANCODE_UP 328
#define SCANCODE_DOWN 336
#define SCANCODE_LEFT 331
@ -19,7 +22,10 @@ enum PadHoldDirection { PAD_HOLD_DIR_NONE, PAD_HOLD_DIR_UP, PAD_HOLD_DIR_DOWN, P
static enum PadHoldDirection sKeyboardHoldDirection = PAD_HOLD_DIR_NONE;
static u16 sKeyboardButtons = 0;
static bool sIgnoreInteractableUntilCursorReleased = false;
static struct DjuiBase* sInteractableFocus = NULL;
static struct DjuiBase* sInteractableBinding = NULL;
static struct DjuiBase* sHovered = NULL;
static struct DjuiBase* sMouseDown = NULL;
bool gInteractableOverridePad = false;
@ -107,6 +113,13 @@ static void djui_interactable_on_value_change(struct DjuiBase* base) {
base->interactable->on_value_change(base);
}
static void djui_interactable_on_bind(struct DjuiBase* base) {
if (base == NULL) { return; }
if (base->interactable == NULL) { return; }
if (base->interactable->on_bind == NULL) { return; }
base->interactable->on_bind(base);
}
static void djui_interactable_cursor_update_active(struct DjuiBase* base) {
if (!base->visible) { return; }
if (!base->enabled) { return; }
@ -134,6 +147,18 @@ static void djui_interactable_cursor_update_active(struct DjuiBase* base) {
}
}
bool djui_interactable_is_binding(void) {
return sInteractableBinding != NULL;
}
void djui_interactable_set_binding(struct DjuiBase* base) {
sInteractableBinding = base;
djui_cursor_set_visible(base == NULL);
if (base == NULL) {
sIgnoreInteractableUntilCursorReleased = true;
}
}
void djui_interactable_set_input_focus(struct DjuiBase* base) {
djui_interactable_on_focus_end(base);
sInteractableFocus = base;
@ -215,20 +240,34 @@ void djui_interactable_update(void) {
// update pad
djui_interactable_update_pad();
if (sInteractableFocus != NULL) {
// prevent pressing buttons when they should be ignored
int mouseButtons = mouse_window_buttons;
u16 padButtons = gInteractablePad.button;
if (sIgnoreInteractableUntilCursorReleased) {
if ((padButtons & PAD_BUTTON_A) || (mouseButtons & MOUSE_BUTTON_1)) {
padButtons &= ~PAD_BUTTON_A;
mouseButtons &= ~MOUSE_BUTTON_1;
} else {
sIgnoreInteractableUntilCursorReleased = false;
}
}
if (sInteractableBinding != NULL) {
djui_interactable_on_bind(sInteractableBinding);
} else if (sInteractableFocus != NULL) {
// escape focus
u16 buttons = PAD_BUTTON_A | PAD_BUTTON_B;
if ((gInteractablePad.button & buttons) && !(sLastInteractablePad.button & buttons)) {
if ((padButtons & buttons) && !(sLastInteractablePad.button & buttons)) {
djui_interactable_set_input_focus(NULL);
} else {
djui_interactable_on_focus(sInteractableFocus);
}
} else if ((gInteractablePad.button & PAD_BUTTON_A) || (mouse_window_buttons & MOUSE_BUTTON_1)) {
} else if ((padButtons & PAD_BUTTON_A) || (mouseButtons & MOUSE_BUTTON_1)) {
// cursor down events
if (sHovered != NULL) {
sMouseDown = sHovered;
sHovered = NULL;
djui_interactable_on_cursor_down_begin(sMouseDown, !mouse_window_buttons);
djui_interactable_on_cursor_down_begin(sMouseDown, !mouseButtons);
} else {
djui_interactable_on_cursor_down(sMouseDown);
}
@ -243,6 +282,7 @@ void djui_interactable_update(void) {
djui_interactable_cursor_update_active(&gDjuiRoot->base);
if (lastHovered != sHovered) {
djui_interactable_on_hover_end(lastHovered);
play_sound(SOUND_MENU_MESSAGE_NEXT_PAGE, gDefaultSoundArgs);
}
djui_interactable_on_hover(sHovered);
}
@ -290,6 +330,12 @@ void djui_interactable_hook_value_change(struct DjuiBase* base,
interactable->on_value_change = on_value_change;
}
void djui_interactable_hook_bind(struct DjuiBase* base,
void (*on_bind)(struct DjuiBase*)) {
struct DjuiInteractable* interactable = base->interactable;
interactable->on_bind = on_bind;
}
void djui_interactable_create(struct DjuiBase* base) {
if (base->interactable != NULL) {

View file

@ -20,17 +20,19 @@ struct DjuiInteractable {
void (*on_focus_end)(struct DjuiBase*);
void (*on_click)(struct DjuiBase*);
void (*on_value_change)(struct DjuiBase*);
void (*on_bind)(struct DjuiBase*);
};
extern bool gInteractableOverridePad;
extern OSContPad gInteractablePad;
bool djui_interactable_is_binding(void);
void djui_interactable_set_binding(struct DjuiBase* base);
void djui_interactable_set_input_focus(struct DjuiBase* base);
void djui_interactable_on_key_down(int scancode);
void djui_interactable_on_key_up(int scancode);
void djui_interactable_update(void);
void djui_interactable_hook_hover(struct DjuiBase* base,
void (*on_hover)(struct DjuiBase*),
void (*on_hover_end)(struct DjuiBase*));
@ -51,4 +53,6 @@ void djui_interactable_hook_click(struct DjuiBase* base,
void djui_interactable_hook_value_change(struct DjuiBase* base,
void (*on_value_change)(struct DjuiBase*));
void djui_interactable_hook_bind(struct DjuiBase* base,
void (*on_bind)(struct DjuiBase*));
void djui_interactable_create(struct DjuiBase* base);

View file

@ -1,5 +1,7 @@
#include "djui.h"
#include "src/pc/utils/misc.h"
#include "audio_defines.h"
#include "audio/external.h"
struct DjuiPanel {
struct DjuiBase* base;
@ -45,6 +47,8 @@ void djui_panel_add(struct DjuiBase* caller, struct DjuiBase* panelBase, struct
djui_base_set_location(panelBase, 0, 0);
djui_cursor_input_controlled_center(panel->defaultElementBase);
djui_base_set_enabled(panel->base, true);
} else {
play_sound(SOUND_MENU_CLICK_FILE_SELECT, gDefaultSoundArgs);
}
}
@ -69,6 +73,9 @@ void djui_panel_back(void) {
// set new active as visible
djui_base_set_visible(sPanelList->base, true);
// play a sound
play_sound(SOUND_MENU_CLICK_FILE_SELECT, gDefaultSoundArgs);
}
void djui_panel_update(void) {

View file

@ -78,7 +78,7 @@ void djui_panel_camera_create(struct DjuiBase* caller) {
struct DjuiButton* button6 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
button6->base.interactable->on_click = djui_panel_camera_back;
djui_interactable_hook_click(&button6->base, djui_panel_camera_back);
}
}

View file

@ -0,0 +1,73 @@
#include "djui.h"
#include "src/pc/utils/misc.h"
#include "src/pc/configfile.h"
static void djui_panel_controls_back(struct DjuiBase* base) {
djui_panel_back();
}
void djui_panel_controls_create(struct DjuiBase* caller) {
f32 bindBodyHeight = 32 * 11 + 1 * 10;
f32 bodyHeight = bindBodyHeight + 16 * 3 + 32 * 2 + 64;
struct DjuiBind* bind1 = NULL;
struct DjuiThreePanel* panel = djui_three_panel_create(&gDjuiRoot->base, 64, bodyHeight, 0);
djui_base_set_size_type(&panel->base, DJUI_SVT_ABSOLUTE, DJUI_SVT_RELATIVE);
djui_base_set_size(&panel->base, 340.0f + (16 * 2.0f), 1.0f);
djui_base_set_color(&panel->base, 0, 0, 0, 240);
djui_base_set_border_color(&panel->base, 0, 0, 0, 200);
djui_base_set_border_width(&panel->base, 8);
djui_base_set_padding(&panel->base, 16, 16, 16, 16);
{
struct DjuiText* header = djui_text_create(&panel->base, "\\#ff0800\\C\\#1be700\\O\\#00b3ff\\N\\#ffef00\\T\\#ff0800\\R\\#1be700\\O\\#00b3ff\\L\\#ffef00\\S");
djui_base_set_size_type(&header->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&header->base, 1.0f, 1.0f);
djui_base_set_color(&header->base, 255, 8, 0, 255);
djui_text_set_alignment(header, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_text_set_font(header, &gDjuiFonts[1]);
djui_text_set_font_scale(header, gDjuiFonts[1].defaultFontScale);
struct DjuiFlowLayout* body = djui_flow_layout_create(&panel->base);
djui_base_set_alignment(&body->base, DJUI_HALIGN_CENTER, DJUI_VALIGN_CENTER);
djui_base_set_size_type(&body->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&body->base, 1.0f, bodyHeight);
djui_base_set_color(&body->base, 0, 0, 0, 0);
djui_flow_layout_set_margin(body, 16);
{
struct DjuiFlowLayout* bindBody = djui_flow_layout_create(&body->base);
djui_base_set_size_type(&bindBody->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&bindBody->base, 1.0f, bindBodyHeight);
djui_base_set_color(&bindBody->base, 0, 0, 0, 0);
djui_flow_layout_set_margin(bindBody, 1);
{
bind1 = djui_bind_create(&bindBody->base, "A", configKeyA);
struct DjuiBind* bind2 = djui_bind_create(&bindBody->base, "B", configKeyB);
struct DjuiBind* bind3 = djui_bind_create(&bindBody->base, "Start", configKeyStart);
struct DjuiBind* bind4 = djui_bind_create(&bindBody->base, "L", configKeyL);
struct DjuiBind* bind5 = djui_bind_create(&bindBody->base, "R", configKeyR);
struct DjuiBind* bind6 = djui_bind_create(&bindBody->base, "Z", configKeyZ);
struct DjuiBind* bind7 = djui_bind_create(&bindBody->base, "C Up", configKeyCUp);
struct DjuiBind* bind8 = djui_bind_create(&bindBody->base, "C Down", configKeyCDown);
struct DjuiBind* bind9 = djui_bind_create(&bindBody->base, "C Left", configKeyCLeft);
struct DjuiBind* bind10 = djui_bind_create(&bindBody->base, "C Right", configKeyCRight);
struct DjuiBind* bind11 = djui_bind_create(&bindBody->base, "Chat", configKeyChat);
}
struct DjuiSlider* slider1 = djui_slider_create(&body->base, "Deadzone", &configStickDeadzone, 0, 100);
djui_base_set_size_type(&slider1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&slider1->base, 1.0f, 32);
struct DjuiSlider* slider2 = djui_slider_create(&body->base, "Rumble Strength", &configRumbleStrength, 0, 100);
djui_base_set_size_type(&slider2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&slider2->base, 1.0f, 32);
struct DjuiButton* button6 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
djui_interactable_hook_click(&button6->base, djui_panel_controls_back);
}
}
djui_panel_add(caller, &panel->base, &bind1->base);
}

View file

@ -0,0 +1,4 @@
#pragma once
#include "djui.h"
void djui_panel_controls_create(struct DjuiBase* caller);

View file

@ -61,7 +61,7 @@ void djui_panel_display_create(struct DjuiBase* caller) {
struct DjuiButton* button6 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
button6->base.interactable->on_click = djui_panel_display_back;
djui_interactable_hook_click(&button6->base, djui_panel_display_back);
}
}

View file

@ -37,7 +37,7 @@ void djui_panel_main_create(struct DjuiBase* caller) {
djui_base_set_size_type(&buttonHost->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&buttonHost->base, 1.0f, 64);
djui_cursor_input_controlled_center(&buttonHost->base);
buttonHost->base.interactable->on_click = djui_panel_main_close;
djui_interactable_hook_click(&buttonHost->base, djui_panel_main_close);
struct DjuiButton* button2 = djui_button_create(&body->base, "Join");
djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
@ -46,12 +46,12 @@ void djui_panel_main_create(struct DjuiBase* caller) {
struct DjuiButton* button3 = djui_button_create(&body->base, "Options");
djui_base_set_size_type(&button3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button3->base, 1.0f, 64);
button3->base.interactable->on_click = djui_panel_options_create;
djui_interactable_hook_click(&button3->base, djui_panel_options_create);
struct DjuiButton* button4 = djui_button_create(&body->base, "Quit");
djui_base_set_size_type(&button4->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button4->base, 1.0f, 64);
button4->base.interactable->on_click = djui_panel_quit_create;
djui_interactable_hook_click(&button4->base, djui_panel_quit_create);
}
char* version = get_version();

View file

@ -41,26 +41,27 @@ void djui_panel_options_create(struct DjuiBase* caller) {
struct DjuiButton* button2 = djui_button_create(&body->base, "Camera");
djui_base_set_size_type(&button2->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button2->base, 1.0f, 64);
button2->base.interactable->on_click = djui_panel_camera_create;
djui_interactable_hook_click(&button2->base, djui_panel_camera_create);
struct DjuiButton* button3 = djui_button_create(&body->base, "Controls");
djui_base_set_size_type(&button3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button3->base, 1.0f, 64);
djui_interactable_hook_click(&button3->base, djui_panel_controls_create);
struct DjuiButton* button4 = djui_button_create(&body->base, "Display");
djui_base_set_size_type(&button4->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button4->base, 1.0f, 64);
button4->base.interactable->on_click = djui_panel_display_create;
djui_interactable_hook_click(&button4->base, djui_panel_display_create);
struct DjuiButton* button5 = djui_button_create(&body->base, "Sound");
djui_base_set_size_type(&button5->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button5->base, 1.0f, 64);
button5->base.interactable->on_click = djui_panel_sound_create;
djui_interactable_hook_click(&button5->base, djui_panel_sound_create);
struct DjuiButton* button6 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
button6->base.interactable->on_click = djui_panel_options_back;
djui_interactable_hook_click(&button6->base, djui_panel_options_back);
}
}

View file

@ -48,12 +48,12 @@ void djui_panel_quit_create(struct DjuiBase* caller) {
struct DjuiButton* button1 = djui_button_create(&body->base, "Yes");
djui_base_set_size_type(&button1->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button1->base, 1.0f, 64);
button1->base.interactable->on_click = djui_panel_quit_yes;
djui_interactable_hook_click(&button1->base, djui_panel_quit_yes);
buttonNo = djui_button_create(&body->base, "No");
djui_base_set_size_type(&buttonNo->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&buttonNo->base, 1.0f, 64);
buttonNo->base.interactable->on_click = djui_panel_quit_no;
djui_interactable_hook_click(&buttonNo->base, djui_panel_quit_no);
}
}

View file

@ -54,7 +54,7 @@ void djui_panel_sound_create(struct DjuiBase* caller) {
struct DjuiButton* button6 = djui_button_create(&body->base, "Back");
djui_base_set_size_type(&button6->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
djui_base_set_size(&button6->base, 1.0f, 64);
button6->base.interactable->on_click = djui_panel_sound_back;
djui_interactable_hook_click(&button6->base, djui_panel_sound_back);
}
}