feat: added recoloured 'selected' dice button alternatives
This commit is contained in:
parent
df86dd586c
commit
3b2ea85fe7
|
|
@ -35,13 +35,17 @@ void AddDieButton(enum Dice_Die die) {
|
|||
.sizing = { CLAY_SIZING_FIXED(100), CLAY_SIZING_FIXED(100) },
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
.image = { GetDiceImage(die) }
|
||||
.image = { GetDiceImage(die, Clay_Hovered()) },
|
||||
.border = {
|
||||
PanelBorder(0),
|
||||
CLAY_BORDER_ALL(1),
|
||||
}
|
||||
}) {
|
||||
Clay_OnHover(&HandleAddDieButtonInteraction, die);
|
||||
CLAY_TEXT(Dice_ToString(die), CLAY_TEXT_CONFIG({
|
||||
.textColor = TextColors(0),
|
||||
.H(2),
|
||||
.textAlignment = CLAY_TEXT_ALIGN_CENTER
|
||||
.textColor = TextColors(0),
|
||||
.textAlignment = CLAY_TEXT_ALIGN_CENTER,
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +97,7 @@ void RemoveDieButton(enum Dice_Die die, int index) {
|
|||
.sizing = { CLAY_SIZING_FIXED(200), CLAY_SIZING_FIXED(200) },
|
||||
.childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER },
|
||||
},
|
||||
.image = { GetDiceImage(die) },
|
||||
.image = { GetDiceImage(die, Clay_Hovered()) },
|
||||
}) {
|
||||
size_t result_length;
|
||||
struct Dice_ResultType const *result = Dice_GetLastResult(&result_length);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
TTF_Font *fonts[FONT_MAX];
|
||||
SDL_Texture *diceImages[DICE_IMAGE_MAX];
|
||||
SDL_Texture *diceImagesSelected[DICE_IMAGE_MAX];
|
||||
TTF_TextEngine *textEngine = nullptr;
|
||||
|
||||
static inline
|
||||
|
|
@ -32,33 +33,42 @@ void LoadDiceImages() {
|
|||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[COIN_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d2.svg");
|
||||
if(!(diceImages[D4_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d4.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D4_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d4.svg");
|
||||
if(!(diceImages[D6_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d6.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D6_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d6.svg");
|
||||
if(!(diceImages[D8_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d8.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D8_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d8.svg");
|
||||
if(!(diceImages[D10_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d10.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D10_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d10.svg");
|
||||
if(!(diceImages[D12_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d12.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D12_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d12.svg");
|
||||
if(!(diceImages[D20_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d20.svg"))) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "IMG_LoadTexture Failed to load die texture: %s", SDL_GetError());
|
||||
exit(7);
|
||||
}
|
||||
diceImagesSelected[D20_IMAGE] = IMG_LoadTexture(renderer, "assets/icons/d20.svg");
|
||||
for (size_t i = 0; i < DICE_IMAGE_MAX; ++i) {
|
||||
Clay_Color color = dieColors[i];
|
||||
SDL_SetTextureColorMod(diceImages[i], color.r, color.g, color.b);
|
||||
color = ToHoveredColor(dieColors[i]);
|
||||
SDL_SetTextureColorMod(diceImagesSelected[i], color.r, color.g, color.b);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,23 +77,22 @@ void LoadResources() {
|
|||
LoadDiceImages();
|
||||
}
|
||||
|
||||
SDL_Texture *GetDiceImage(enum Dice_Die die) {
|
||||
SDL_Texture *GetDiceImage(enum Dice_Die die, bool selected) {
|
||||
switch (die) {
|
||||
case COIN:
|
||||
return diceImages[COIN_IMAGE];
|
||||
return selected ? diceImagesSelected[COIN_IMAGE] : diceImages[COIN_IMAGE];
|
||||
case D4:
|
||||
return diceImages[D4_IMAGE];
|
||||
return selected ? diceImagesSelected[D4_IMAGE] : diceImages[D4_IMAGE];
|
||||
case D6:
|
||||
return diceImages[D6_IMAGE];
|
||||
return selected ? diceImagesSelected[D6_IMAGE] : diceImages[D6_IMAGE];
|
||||
case D8:
|
||||
return diceImages[D8_IMAGE];
|
||||
return selected ? diceImagesSelected[D8_IMAGE] : diceImages[D8_IMAGE];
|
||||
case D10:
|
||||
return diceImages[D10_IMAGE];
|
||||
case D12:
|
||||
return diceImages[D12_IMAGE];
|
||||
case D20:
|
||||
return diceImages[D20_IMAGE];
|
||||
case D100:
|
||||
return diceImages[D10_IMAGE];
|
||||
return selected ? diceImagesSelected[D10_IMAGE] : diceImages[D10_IMAGE];
|
||||
case D12:
|
||||
return selected ? diceImagesSelected[D12_IMAGE] : diceImages[D12_IMAGE];
|
||||
case D20:
|
||||
return selected ? diceImagesSelected[D20_IMAGE] : diceImages[D20_IMAGE];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,9 +26,10 @@ enum DiceImages {
|
|||
extern TTF_TextEngine *textEngine;
|
||||
extern TTF_Font *fonts[FONT_MAX];
|
||||
extern SDL_Texture *diceImages[DICE_IMAGE_MAX];
|
||||
extern SDL_Texture *diceImagesSelected[DICE_IMAGE_MAX];
|
||||
|
||||
extern void LoadResources();
|
||||
|
||||
extern SDL_Texture *GetDiceImage(enum Dice_Die die);
|
||||
extern SDL_Texture *GetDiceImage(enum Dice_Die die, bool selected);
|
||||
|
||||
#endif // !RESOURCES_H
|
||||
|
|
|
|||
Loading…
Reference in a new issue