|
|
|
|
@ -76,10 +76,14 @@ static UiContainer * UiContainerInitGameUiContainer(){
|
|
|
|
|
|
|
|
|
|
uiContainer->buttonCounter = 0;
|
|
|
|
|
|
|
|
|
|
Texture2D textures[3] = { LoadTexture("assets/selectable.png"), //DEFAULT
|
|
|
|
|
Texture2D textures[3] = { LoadTexture("assets/selectable.png"), //DEFAULT
|
|
|
|
|
LoadTexture("assets/selectable.png"), //HOVERED
|
|
|
|
|
LoadTexture("assets/selectable.png") //SELECTED
|
|
|
|
|
};
|
|
|
|
|
Texture2D textures2[3] = { LoadTexture("assets/entities/worker/arbeiten-4.png"), //DEFAULT
|
|
|
|
|
LoadTexture("assets/entities/worker/arbeiten-4.png"), //HOVERED
|
|
|
|
|
LoadTexture("assets/entities/worker/arbeiten-4.png") //SELECTED
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Texture2D backgroundTextures[3] = { LoadTexture("assets/selectable_background.png"), //DEFAULT
|
|
|
|
|
LoadTexture("assets/selectable_background_hovered.png"), //HOVERED
|
|
|
|
|
@ -92,31 +96,16 @@ static UiContainer * UiContainerInitGameUiContainer(){
|
|
|
|
|
int groupTwo = 1;
|
|
|
|
|
int fontSize = 16;
|
|
|
|
|
Selectable *selectable1 = SelectableInit(textures, backgroundTextures, hasBackground , &position, "Building",
|
|
|
|
|
showDescription, 9, fontSize, SELECTABLE_ID_TEST, groupOne);
|
|
|
|
|
showDescription, 9, fontSize, SELECTABLE_ID_SPAWN_BUILDING, groupOne);
|
|
|
|
|
position.y += 100;
|
|
|
|
|
Selectable *selectable2 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building2",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupOne);
|
|
|
|
|
Selectable *selectable2 = SelectableInit(textures2, backgroundTextures, hasBackground,&position, "Worker",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_SPAWN_WORKER, groupOne);
|
|
|
|
|
position.y += 100;
|
|
|
|
|
Selectable *selectable3 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building3",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupOne);
|
|
|
|
|
position.y += 100;
|
|
|
|
|
Selectable *selectable4 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building4",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
|
|
|
|
|
position.x += 100;
|
|
|
|
|
Selectable *selectable5 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building5",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
|
|
|
|
|
position.x += 100;
|
|
|
|
|
Selectable *selectable6 = SelectableInit(textures, backgroundTextures, hasBackground,&position, "Building6",
|
|
|
|
|
showDescription, 10, fontSize, SELECTABLE_ID_TEST, groupTwo);
|
|
|
|
|
|
|
|
|
|
int selectableCounter = 0;
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@ -141,7 +130,10 @@ UiContainer * UiContainerInitUiContainerForScreenID(int id){
|
|
|
|
|
static void UpdateButtons(Game *game, Button **buttons, int buttonCounter){
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(i=0 ; i < buttonCounter; i++){
|
|
|
|
|
ButtonUpdateButtonState(buttons[i]);
|
|
|
|
|
int state = ButtonUpdateButtonState(buttons[i]);
|
|
|
|
|
if(state == BUTTON_STATE_HOVERED || state == BUTTON_STATE_PRESSED){
|
|
|
|
|
game->mouseOnUI = 1;
|
|
|
|
|
}
|
|
|
|
|
if(buttons[i]->state == BUTTON_STATE_RELEASED){
|
|
|
|
|
ButtonExecuteButton(buttons[i], game);
|
|
|
|
|
}
|
|
|
|
|
@ -152,7 +144,11 @@ static void UpdateButtons(Game *game, Button **buttons, int buttonCounter){
|
|
|
|
|
static void UpdateSelectables(Game *game, Selectable **selectables, int selectableCounter){
|
|
|
|
|
int i = 0;
|
|
|
|
|
for(i=0 ; i < selectableCounter; i++){
|
|
|
|
|
int oldState = selectables[i]->state;
|
|
|
|
|
int setState = SelectableUpdateSelectableState(selectables[i]);
|
|
|
|
|
if(setState == SELECTABLE_STATE_HOVERED || (setState == SELECTABLE_STATE_SELECTED && oldState != SELECTABLE_STATE_SELECTED)){
|
|
|
|
|
game->mouseOnUI = 1;
|
|
|
|
|
}
|
|
|
|
|
// Unselecting every selectable if one is selected
|
|
|
|
|
if(setState == SELECTABLE_STATE_SELECTED){
|
|
|
|
|
int j;
|
|
|
|
|
@ -176,7 +172,10 @@ void UiContainerUpdateUiContainer(UiContainer *uiContainer, Game *game){
|
|
|
|
|
|
|
|
|
|
// Drawed alle Buttons und Selectables
|
|
|
|
|
void UiContainerDrawUiContainer(UiContainer *uiContainer){
|
|
|
|
|
if(uiContainer == 0) return;
|
|
|
|
|
if(uiContainer == 0){
|
|
|
|
|
printf("WARNING: Trying to draw not existing UiContainer!!\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int i = 0;
|
|
|
|
|
// Funktion kann genauso wie update auch noch aufgeteilt werden, aktuell aber noch nicht notwendig
|
|
|
|
|
for(i=0 ; i < uiContainer->buttonCounter; i++){
|
|
|
|
|
|