Selectable Groups added, minor fix

main
Jan 3 years ago
parent d68baac859
commit aa5fcf464e

@ -3,7 +3,8 @@
#include <stdlib.h>
#include <string.h>
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id){
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description,
int showDescripton, int descriptionLEN, int fontSize, int id, int groupID){
Selectable *selectable = malloc(sizeof(Selectable));
selectable->texture[0] = textures[0];
@ -27,13 +28,11 @@ Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[
selectable->fontSize = fontSize;
selectable->id = id;
selectable->state = 0;
selectable->groupID = groupID;
return selectable;
}
// TODO: Variable die den Maus Input freigibt solange nichts mit der Maus gemacht wurde
// Sobald ein Button gedrückt wurde in diesem Frame oder rect gezogen wird oder so ist sind Maus Funktionen gesperrt
// verhindert Spawnen von entities wenn man UI Elemente Drückt etc
void SelectableExecuteSelectable(Selectable *selectable, Game * game){
switch(selectable->id){
case SELECTABLE_ID_TEST: // Test Case Platzhalter
@ -69,7 +68,7 @@ int SelectableUpdateSelectableState(Selectable * selectable){
int SelectableUnselectSelectable(Selectable * selectable){
if(selectable->state == SELECTABLE_STATE_SELECTED){
selectable->state = SELECTABLE_STATE_DEFAULT;
return selectable->state = SELECTABLE_STATE_DEFAULT;
}
return selectable->state;
}

@ -4,8 +4,6 @@
#include "raylib.h"
#include "../game.h"
typedef struct Selectable Selctable;
#define SELECTABLE_STATE_DEFAULT 0
#define SELECTABLE_STATE_HOVERED 1
#define SELECTABLE_STATE_SELECTED 2
@ -23,13 +21,16 @@ typedef struct Selectable{
int id; // Durch die ID wird dem Selectable eine Funktion zugeordnet
int state; // 0: not selected | 1: hovered | 2: selected
int fontSize; // FontSize kann für jede Selectable Description individuell festgelegt werden
// Notiz: Die Selectables können auch in einem 2-Dimensionalen Array im UiContainer gespeichert werden, worüber die Groups auch definiert werden könnten
int groupID; // Selectables können gruppiert werden, man kann also mehrere Dinge gleichzeitig selected haben
}Selectable;
// Textures+backgroundTextures: [0]: Normal | [1]: Hovered | [2]: Selected
// hasBackground: 0: hat keine Background Textur | 1: hat Background Textur
// showDescription 0: zeigt Description nicht | 1: zeigt Description
// Max Description LEN 20
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id);
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id, int groupID);
void SelectableExecuteSelectable(Selectable *selectable, Game * game);

@ -88,26 +88,38 @@ static UiContainer * UiContainerInitGameUiContainer(){
};
Vector2 position = (Vector2){20, 300};
int showDescription = 1;
Selectable *selectable1 = SelectableInit(textures, backgroundTextures, 1, &position, "Building", showDescription, 9, 16, SELECTABLE_ID_TEST);
int hasBackground = 1;
int groupOne = 0;
int groupTwo = 1;
int fontSize = 16;
Selectable *selectable1 = SelectableInit(textures, backgroundTextures, hasBackground , &position, "Building",
showDescription, 9, fontSize, SELECTABLE_ID_TEST, groupOne);
position.y += 100;
Selectable *selectable2 = SelectableInit(textures, backgroundTextures, 1,&position, "Building2", showDescription, 10, 16, SELECTABLE_ID_TEST);
Selectable *selectable2 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building2",
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupOne);
position.y += 100;
Selectable *selectable3 = SelectableInit(textures, backgroundTextures, 1,&position, "Building3", showDescription, 10, 16, SELECTABLE_ID_TEST);
Selectable *selectable3 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building3",
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupOne);
position.y += 100;
Selectable *selectable4 = SelectableInit(textures, backgroundTextures, 1,&position, "Building4", showDescription, 10, 16, SELECTABLE_ID_TEST);
Selectable *selectable4 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building4",
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
position.x += 100;
Selectable *selectable5 = SelectableInit(textures, backgroundTextures, 1,&position, "Building5", showDescription, 10, 16, SELECTABLE_ID_TEST);
Selectable *selectable5 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building5",
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
position.x += 100;
Selectable *selectable6 = SelectableInit(textures, backgroundTextures, 1,&position, "Building6", showDescription, 10, 16, SELECTABLE_ID_TEST);
Selectable *selectable6 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building6",
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
uiContainer->selectables[0] = selectable1;
uiContainer->selectables[1] = selectable2;
uiContainer->selectables[2] = selectable3;
uiContainer->selectables[3] = selectable4;
uiContainer->selectables[4] = selectable5;
uiContainer->selectables[5] = selectable6;
int selectableCounter = 0;
uiContainer->selectableCounter = 6;
uiContainer->selectables[selectableCounter++] = selectable1;
uiContainer->selectables[selectableCounter++] = selectable2;
uiContainer->selectables[selectableCounter++] = selectable3;
uiContainer->selectables[selectableCounter++] = selectable4;
uiContainer->selectables[selectableCounter++] = selectable5;
uiContainer->selectables[selectableCounter++] = selectable6;
uiContainer->selectableCounter = selectableCounter;
return uiContainer;
}
@ -145,8 +157,8 @@ static void UpdateSelectables(Game *game, Selectable **selectables, int selectab
// Unselecting every selectable if one is selected
if(setState == SELECTABLE_STATE_SELECTED){
int j;
for(j=0 ; j < selectableCounter; j++){
if(i != j){
for(j=0 ; j < selectableCounter; j++){
if(i != j && selectables[j]->groupID == selectables[i]->groupID){
SelectableUnselectSelectable(selectables[j]);
}
}

@ -13,6 +13,11 @@
#include "Ui/uiContainer.h"
#include "Ui/debug.h"
// TODO: Variable die den Maus Input freigibt solange nichts mit der Maus gemacht wurde
// Sobald ein Button gedrückt wurde in diesem Frame oder rect gezogen wird oder so ist sind Maus Funktionen gesperrt
// verhindert Spawnen von entities wenn man UI Elemente Drückt etc
// Alternativ: Flag MouseOnHUD, aber nicht so universal einsetzbar, löst nur meine Probleme mit dem Spawnen bei klicks aufs HUD
int main(){
InitWindow(1280, 720, "basic window");
@ -92,7 +97,8 @@ int main(){
break;
}
// Always drawing UiContainer? Can still be put into cases:
// Drawen wir einfach immer den UI Container vom aktuellen Screen? Aktuell hat ja jeder Screen einen, es sollte also keine Probleme geben
// Kann man natürlich auch noch oben in die einzelnen Cases schieben falls es mal Probleme machen sollte
UiContainerUpdateUiContainer(game->UiContainers[game->screen], game);
UiContainerDrawUiContainer(game->UiContainers[game->screen]);

Loading…
Cancel
Save