Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Random to the counterpick CSS in ranked #6

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions Components/CharPickerDialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#include "../m-ex/MexTK/mex.h"
#include "CharStageIcon.h"

void SelectRandomChar(CharPickerDialog *cpd) {
cpd->state.char_selection_idx = HSD_Randi(CPD_LAST_INDEX);
}

static void _SetPos(CharPickerDialog *cpd, Vec3 pos) {
cpd->root_jobj->trans = pos;
JOBJ_SetMtxDirtySub(cpd->root_jobj);
Expand All @@ -30,6 +34,9 @@ static void _InputsThink(GOBJ *gobj) {

if (downInputs & HSD_BUTTON_A) {
SFX_PlayCommon(CommonSound_ACCEPT); // Play "accept" sound
if (cpd->state.char_selection_idx == CKIND_RANDOM) { // Select random
SelectRandomChar(cpd);
}
CharPickerDialog_CloseDialog(cpd);
cpd->on_close(cpd, true);
return;
Expand All @@ -52,7 +59,7 @@ static void _InputsThink(GOBJ *gobj) {

if (scrollInputs & (HSD_BUTTON_RIGHT | HSD_BUTTON_DPAD_RIGHT)) {
// Handle a right input
if (cpd->state.char_selection_idx >= CKIND_GANONDORF) {
if (cpd->state.char_selection_idx >= CKIND_RANDOM) {
cpd->state.char_selection_idx = CKIND_YOUNGLINK;
} else if ((cpd->state.char_selection_idx + 1) % 7 == 0) {
cpd->state.char_selection_idx -= 6;
Expand All @@ -66,7 +73,7 @@ static void _InputsThink(GOBJ *gobj) {
} else if (scrollInputs & (HSD_BUTTON_LEFT | HSD_BUTTON_DPAD_LEFT)) {
// Handle a left input
if (cpd->state.char_selection_idx == CKIND_YOUNGLINK) {
cpd->state.char_selection_idx = CKIND_GANONDORF;
cpd->state.char_selection_idx = CKIND_RANDOM;
} else if (cpd->state.char_selection_idx % 7 == 0) {
cpd->state.char_selection_idx += 6;
} else {
Expand All @@ -78,7 +85,7 @@ static void _InputsThink(GOBJ *gobj) {
SFX_PlayCommon(CommonSound_NEXT); // Play "next" sound
} else if (scrollInputs & (HSD_BUTTON_DOWN | HSD_BUTTON_DPAD_DOWN)) {
// Handle a down input
if (cpd->state.char_selection_idx % 7 >= 5 && cpd->state.char_selection_idx >= CKIND_SHEIK) {
if (cpd->state.char_selection_idx % 7 >= 6 && cpd->state.char_selection_idx > CKIND_SHEIK) {
cpd->state.char_selection_idx -= 14;
} else if (cpd->state.char_selection_idx >= CKIND_YOUNGLINK) {
cpd->state.char_selection_idx -= 21;
Expand All @@ -92,7 +99,7 @@ static void _InputsThink(GOBJ *gobj) {
} else if (scrollInputs & (HSD_BUTTON_UP | HSD_BUTTON_DPAD_UP)) {
// Handle a up input
if (cpd->state.char_selection_idx % 7 >= 5 && cpd->state.char_selection_idx <= CKIND_LINK) {
cpd->state.char_selection_idx += 14;
cpd->state.char_selection_idx += 21;
} else if (cpd->state.char_selection_idx <= CKIND_LINK) {
cpd->state.char_selection_idx += 21;
} else {
Expand All @@ -105,16 +112,19 @@ static void _InputsThink(GOBJ *gobj) {
}

// Update which icon shows up selected
for (int i = CKIND_FALCON; i <= CKIND_GANONDORF; i++) {
for (int i = CKIND_FALCON; i <= CKIND_RANDOM; i++) {
CSIcon_Select_State state = CSIcon_Select_State_NotSelected;
u8 colorId = 0;
if (i == cpd->state.char_selection_idx) {
state = CSIcon_Select_State_Hover;
colorId = cpd->state.char_color_idx;
}

CSIcon_SetStockIconVisibility(cpd->char_icons[i], i == cpd->state.char_selection_idx);
StockIcon_SetIcon(cpd->char_icons[i]->stock_icon, i, colorId);
// Only show stock icons on characters
if (i < CKIND_RANDOM) {
CSIcon_SetStockIconVisibility(cpd->char_icons[i], i == cpd->state.char_selection_idx);
StockIcon_SetIcon(cpd->char_icons[i]->stock_icon, i, colorId);
}
CSIcon_SetSelectState(cpd->char_icons[i], state);
}
}
Expand All @@ -133,9 +143,12 @@ CharPickerDialog *CharPickerDialog_Init(GUI_GameSetup *gui, void *on_close, void

// Connect CharStageIcons for each character to the dialog
JOBJ *cur_joint = cpd->root_jobj->child->child->sibling->child;
for (int i = CKIND_FALCON; i <= CKIND_GANONDORF; i++) {
for (int i = CKIND_FALCON; i <= CKIND_RANDOM; i++) {
cpd->char_icons[i] = CSIcon_Init(gui);
CSIcon_SetMaterial(cpd->char_icons[i], CSIcon_ConvertCharToMat(i));
CSIcon_Material material;
// Assign material to chars / random
int matIdx = i < CKIND_RANDOM ? CSIcon_ConvertCharToMat(i) : CSIcon_Material_Question;
CSIcon_SetMaterial(cpd->char_icons[i], matIdx);

// Attach icon to cur joint and move to next joint
JOBJ_AddChild(cur_joint, cpd->char_icons[i]->root_jobj);
Expand Down
7 changes: 6 additions & 1 deletion Components/CharPickerDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

// How to style code: https://stackoverflow.com/a/50489812/1249024

#define CPD_LAST_INDEX 26 // Last index in char picker dialog JObj set
#define CKIND_RANDOM 26 // Index of Random in char picker dialog

typedef struct CharPickerDialog_State {
Vec3 pos;
u8 is_open;
Expand All @@ -19,13 +22,15 @@ typedef struct CharPickerDialog {
GOBJ *gobj;
JOBJ *root_jobj;
JOBJSet *jobj_set;
CSIcon *char_icons[CKIND_GANONDORF + 1];
CSIcon *char_icons[CPD_LAST_INDEX + 1];
CharPickerDialog_State state;

void (*on_close)();
u8 (*get_next_color)();
} CharPickerDialog;

void SelectRandomChar();

CharPickerDialog *CharPickerDialog_Init(GUI_GameSetup *gui, void *on_close, void *get_next_color);
void CharPickerDialog_Free(CharPickerDialog *cpd);

Expand Down