Skip to content

Commit

Permalink
Merge pull request #76 from retro-esp32/Feature-Controls-In-HUD
Browse files Browse the repository at this point in the history
Feature controls in hud
  • Loading branch information
32teeth committed Jun 5, 2020
2 parents 3236a1d + 5999ceb commit 5730169
Show file tree
Hide file tree
Showing 25 changed files with 1,213 additions and 348 deletions.
Binary file modified Assets/retro-esp32/icons/icons.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/retro-esp32/logos/logo3d.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
bool INIT = false;
bool SAVED = false;
bool forceConsoleReset;

int32_t VOLUME = 0;
int32_t BRIGHTNESS = 0;
const int32_t BRIGHTNESS_COUNT = 10;
const int32_t BRIGHTNESS_LEVELS[10] = {10,20,30,40,50,60,70,80,90,100};
//}#pragma endregion Globals

//{#pragma region Structs
Expand All @@ -79,20 +84,23 @@
int action;
int offset;
} STATES;
STATES WITHSAVE[6] = {
STATES WITHSAVE[5] = {
{"Resume Game",0, 0},
{"Restart Game",1, 10},
{"Reload Game",2, 5},
{"Overwrite Game",4, 25},
{"Delete Save",5, 15},
{"Exit Game",6, 20}
{"Delete Save",5, 15}
};
STATES WITHOUTSAVE[4] = {
STATES WITHOUTSAVE[3] = {
{"Resume Game",0, 0},
{"Restart Game",1, 10},
{"Save Game",3, 25},
{"Exit Game",6, 20}
{"Save Game",3, 25}
};
STATES EXTRAS[3] = {
{"Volume",8, 45},
{"Brightness",9, 50},
{"Quit Game",6, 20}
};
STATES STATE;

// THEME
Expand Down Expand Up @@ -140,43 +148,62 @@ const uint16_t FONT_5x7[7][250] = {
{65535,0,0,0,65535,65535,65535,65535,65535,0,0,65535,65535,65535,0,65535,65535,65535,65535,0,65535,65535,65535,65535,65535,65535,0,0,0,0,0,65535,65535,65535,0,65535,0,0,0,65535,65535,65535,65535,65535,65535,0,65535,65535,0,0,65535,0,0,0,65535,65535,65535,65535,65535,65535,65535,0,0,0,65535,65535,0,0,0,65535,0,65535,65535,65535,0,65535,0,0,0,0,0,0,0,0,65535,65535,0,0,0,65535,0,65535,65535,65535,0,0,0,65535,0,0,0,65535,65535,65535,0,0,0,65535,0,0,0,65535,0,65535,0,65535,0,0,0,65535,0,0,65535,0,0,65535,65535,65535,65535,65535,0,65535,65535,65535,0,65535,65535,65535,65535,65535,65535,65535,65535,65535,65535,0,65535,65535,65535,0,0,0,0,0,65535,0,65535,65535,65535,0,0,65535,65535,65535,0,65535,0,0,0,0,0,65535,65535,65535,0,0,65535,65535,65535,0,0,0,65535,0,0,0,0,0,0,0,0,0,0,0,0,0,65535,65535,65535,0,0,0,65535,0,0,0,0,65535,0,0,0,0,65535,0,0,65535,0,0,0,0,0,0,0,65535,0,0,65535,0,0,0,0,65535,65535,65535,0,0,65535,65535,65535,0,0,0,0,0,0,0,0,0,0,0},
};

const uint16_t icons[35][5] = {
{0,65535,65535,0,0},
{0,65535,65535,65535,0},
{0,65535,65535,65535,65535},
{0,65535,65535,65535,0},
{0,65535,65535,0,0},
{65535,0,65535,0,0},
{65535,0,65535,65535,0},
{65535,0,65535,65535,65535},
{65535,0,65535,65535,0},
{65535,0,65535,0,0},
{0,65535,65535,0,65535},
{65535,0,0,65535,65535},
{65535,0,0,0,65535},
{65535,65535,0,0,65535},
{65535,0,65535,65535,0},
{0,65535,65535,65535,0},
{65535,0,65535,0,65535},
{65535,65535,0,65535,65535},
{65535,0,65535,0,65535},
{0,65535,65535,65535,0},
{65535,0,0,0,65535},
{0,65535,0,65535,0},
{0,0,65535,0,0},
{0,65535,0,65535,0},
{65535,0,0,0,65535},
{0,0,0,0,0},
{0,0,0,0,65535},
{0,0,0,65535,0},
{65535,0,65535,0,0},
{0,65535,0,0,0},
{0,65535,65535,65535,0},
{65535,0,65535,0,65535},
{65535,0,65535,65535,65535},
{65535,0,0,0,65535},
{0,65535,65535,65535,0},

const uint16_t icons[55][5] = {
{0,65535,65535,0,0},
{0,65535,65535,65535,0},
{0,65535,65535,65535,65535},
{0,65535,65535,65535,0},
{0,65535,65535,0,0},
{65535,0,65535,0,0},
{65535,0,65535,65535,0},
{65535,0,65535,65535,65535},
{65535,0,65535,65535,0},
{65535,0,65535,0,0},
{0,65535,65535,0,65535},
{65535,0,0,65535,65535},
{65535,0,0,0,65535},
{65535,65535,0,0,65535},
{65535,0,65535,65535,0},
{0,65535,65535,65535,0},
{65535,0,65535,0,65535},
{65535,65535,0,65535,65535},
{65535,0,65535,0,65535},
{0,65535,65535,65535,0},
{65535,0,0,0,65535},
{0,65535,0,65535,0},
{0,0,65535,0,0},
{0,65535,0,65535,0},
{65535,0,0,0,65535},
{0,0,0,0,0},
{0,0,0,0,65535},
{0,0,0,65535,0},
{65535,0,65535,0,0},
{0,65535,0,0,0},
{0,65535,65535,65535,0},
{65535,0,65535,0,65535},
{65535,0,65535,65535,65535},
{65535,0,0,0,65535},
{0,65535,65535,65535,0},
{0,65535,0,65535,0},
{65535,65535,65535,65535,65535},
{65535,65535,65535,65535,65535},
{0,65535,65535,65535,0},
{0,0,65535,0,0},
{0,65535,0,65535,0},
{65535,0,65535,0,65535},
{65535,0,0,0,65535},
{0,65535,0,65535,0},
{0,0,65535,0,0},
{0,0,0,65535,0},
{0,65535,0,0,65535},
{0,0,65535,0,65535},
{0,65535,0,0,65535},
{0,0,0,65535,0},
{65535,0,0,0,65535},
{0,0,65535,0,0},
{0,65535,0,65535,0},
{0,0,65535,0,0},
{65535,0,0,0,65535},
};

const uint16_t logo[12][64] = {
Expand Down Expand Up @@ -404,42 +431,102 @@ const uint16_t FONT_5x7[7][250] = {
usleep(15000);
}
}
}

void hud_bar(int x, int y, int percent, bool active) {
int w, h;

int i = 0;
for(h = 0; h < 7; h++) {
for(w = 0; w < 100; w++) {
buffer[i] = (w+h)%2 == 0 ? GUI.fg : GUI.bg;
i++;
}
}
ili9341_write_frame_rectangleLE(x, y, 100, 7, buffer);

if(percent > 0) {
i = 0;
for(h = 0; h < 7; h++) {
for(w = 0; w < percent; w++) {
buffer[i] = active ? GUI.hl : GUI.fg;
i++;
}
}
ili9341_write_frame_rectangleLE(x, y, percent, 7, buffer);
}
}

void hud_volume() {
// y=176;
int32_t VOLUME = odroid_settings_Volume_get();
int LIMIT = OPTIONS - 3;
bool active = OPTION == LIMIT ? true : false;
hud_bar((SCREEN.w - 120), 176, VOLUME * 12.5, active);
}

void hud_brightness() {
// y=176;
int LIMIT = OPTIONS - 2;
bool active = OPTION == LIMIT ? true : false;
BRIGHTNESS = odroid_settings_Backlight_get();

hud_bar((SCREEN.w - 120), 196, (BRIGHTNESS_COUNT * BRIGHTNESS)+BRIGHTNESS+1, active);
}

void hud_options() {
x = 16;
y = 28;
w = 5;
h = 5;
i = 0;
int n;
if(OPTIONS == 6) {
for(n = 0; n < OPTIONS; n++) {
if(OPTIONS == 8) {
for(n = 0; n < 5; n++) {
STATE = WITHSAVE[n];
y+=20;
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? GUI.hl : GUI.fg : GUI.bg;i++;
}}
if(n == OPTIONS-1) {y = 216;}
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
i = 0;
}
STATE = WITHSAVE[OPTION];
} else {
for(n = 0; n < OPTIONS; n++) {
for(n = 0; n < 3; n++) {
STATE = WITHOUTSAVE[n];
y+=20;
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == n ? GUI.hl : GUI.fg : GUI.bg;i++;
}}
if(n == OPTIONS-1) {y = 216;}
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
hud_text(x+10,y,STATE.label,false,OPTION == n?true:false);
i = 0;
}
STATE = WITHOUTSAVE[OPTION];
}

y=156;
for(n = 0; n < 3; n++) {
STATE = EXTRAS[n];
y+=20;
for(int r = 0; r < 5; r++){for(int c = 0; c < 5; c++) {
buffer[i] = icons[r+STATE.offset][c] == WHITE ? OPTION == (n+OPTIONS-3) ? GUI.hl : GUI.fg : GUI.bg;i++;
}}
ili9341_write_frame_rectangleLE(x, y, w, h, buffer);
hud_text(x+10,y,STATE.label,false,OPTION == (n+OPTIONS-3)?true:false);
i = 0;
}

int LIMIT = OPTIONS - 3;
if(OPTION < LIMIT) {
STATE = OPTIONS == 8 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
} else {
STATE = EXTRAS[OPTION-LIMIT];
}
printf("\n**********\n%s - %d:%d\n**********\n", STATE.label, OPTION, LIMIT);

hud_volume();
hud_brightness();
}
//}#pragma endregion Display

Expand All @@ -450,10 +537,10 @@ const uint16_t FONT_5x7[7][250] = {
buffer = (uint16_t *)malloc(size);
if (!buffer) abort();
OPTION = 0;
OPTIONS = SAVED ? 6 : 4;
OPTIONS = SAVED ? 8 : 6;
hud_theme();
GUI = THEMES[USER];
STATE = OPTIONS == 6 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
STATE = OPTIONS == 8 ? WITHSAVE[OPTION] : WITHOUTSAVE[OPTION];
INIT = true;
}
}
Expand All @@ -468,9 +555,9 @@ const uint16_t FONT_5x7[7][250] = {

//{#pragma region Menu
void hud_menu(void) {
int volume = odroid_audio_volume_get();
VOLUME = odroid_audio_volume_get();
#ifdef CONFIG_LCD_DRIVER_CHIP_RETRO_ESP32
volume = 8;
//volume = 8;
#endif
odroid_audio_terminate();
hud_init();
Expand Down Expand Up @@ -501,6 +588,49 @@ const uint16_t FONT_5x7[7][250] = {
usleep(200000);
//debounce(ODROID_INPUT_DOWN);
}
/*
LEFT
*/
if(gamepad.values[ODROID_INPUT_LEFT]) {
if(OPTION == OPTIONS - 3) {
if(VOLUME > 0) {
VOLUME--;
odroid_settings_Volume_set(VOLUME);
hud_options();
usleep(200000);
}
}
if(OPTION == OPTIONS - 3 + 1) {
if(BRIGHTNESS > 0) {
BRIGHTNESS--;
odroid_settings_Backlight_set(BRIGHTNESS);
hud_options();
usleep(200000);
}
}
}

/*
RIGHT
*/
if(gamepad.values[ODROID_INPUT_RIGHT]) {
if(OPTION == OPTIONS - 3) {
if(VOLUME < 8) {
VOLUME++;
odroid_settings_Volume_set(VOLUME);
hud_options();
usleep(200000);
}
}
if(OPTION == OPTIONS - 3 + 1) {
if(BRIGHTNESS < (BRIGHTNESS_COUNT-1)) {
BRIGHTNESS++;
odroid_settings_Backlight_set(BRIGHTNESS);
hud_options();
usleep(200000);
}
}
}
/*
BUTTON B
*/
Expand All @@ -513,7 +643,7 @@ const uint16_t FONT_5x7[7][250] = {
BUTTON A
*/
if (gamepad.values[ODROID_INPUT_A]) {
odroid_audio_volume_set(volume);
odroid_audio_volume_set(VOLUME);
hud_debug(STATE.label);
ACTION = STATE.action;
switch(ACTION) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ void hud_menu();
*/
void hud_logo(void);
void hud_progress(char *string, bool bar);
void hud_bar(int x, int y, int percent, bool active);
void hud_volume();
void hud_brightness();
void hud_options();
Loading

0 comments on commit 5730169

Please sign in to comment.