You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
6.2 KiB

#include "uiContainer.h"
#include "../game.h"
#include "button.h"
#include "raylib.h"
#include "stdlib.h"
#include "stdio.h"
UiContainer * UiContainerInitPauseUiContainer(){
UiContainer *uiContainer = malloc(sizeof(UiContainer));
Texture2D textures[4] = { LoadTexture("assets/button.png"), //DEFAULT
LoadTexture("assets/button_hovered.png"), //HOVERED
LoadTexture("assets/button_pressed.png"), //PRESSED
LoadTexture("assets/button_pressed.png")}; //RELEASED
Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 - 50};
int buttonFontSize = 36;
Button *continuebutton = ButtonInitButton(textures, &position, "Continue", 9, buttonFontSize, BUTTON_ID_CONTINUE);
uiContainer->buttons[0] = continuebutton;
uiContainer->buttonCounter = 1;
position.y += 250;
Button *exitButton = ButtonInitButton(textures, &position, "EXIT", 5, buttonFontSize, BUTTON_ID_EXIT);
uiContainer->buttons[1] = exitButton;
uiContainer->buttonCounter = 2;
// Methode funktioniert wieso auch immer auch ohne dieses return. C returned Implizit odder was O_o
return uiContainer;
}
UiContainer * UiContainerInitMainMenuUiContainer(){
UiContainer *uiContainer = malloc(sizeof(UiContainer));
Texture2D textures[4] = { LoadTexture("assets/button.png"), //DEFAULT
LoadTexture("assets/button_hovered.png"), //HOVERED
LoadTexture("assets/button_pressed.png"), //PRESSED
LoadTexture("assets/button_pressed.png")}; //RELEASED
Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 - 50};
int buttonFontSize = 36;
Button *continuebutton = ButtonInitButton(textures, &position, "Start Game", 11, buttonFontSize, BUTTON_ID_START_GAME);
uiContainer->buttons[0] = continuebutton;
uiContainer->buttonCounter = 1;
position.y += 250;
Button *exitButton = ButtonInitButton(textures, &position, "EXIT", 5, buttonFontSize, BUTTON_ID_EXIT);
uiContainer->buttons[1] = exitButton;
uiContainer->buttonCounter = 2;
// Methode funktioniert wieso auch immer auch ohne dieses return. C returned Implizit odder was O_o
return uiContainer;
}
UiContainer * UiContainerInitGameUiContainer(){
UiContainer *uiContainer = malloc(sizeof(UiContainer));
uiContainer->buttonCounter = 0;
Texture2D textures[3] = { LoadTexture("assets/selectable.png"), //DEFAULT
LoadTexture("assets/selectable.png"), //HOVERED
LoadTexture("assets/selectable.png") //SELECTED
};
Texture2D backgroundTextures[3] = { LoadTexture("assets/selectable_background.png"), //DEFAULT
LoadTexture("assets/selectable_background_hovered.png"), //HOVERED
LoadTexture("assets/selectable_background_selected.png") //SELECTED
};
Vector2 position = (Vector2){50, 250};
int showDescription = 0;
Selectable *selectable1 = SelectableInit(textures, backgroundTextures, 1, &position, "Building", showDescription, 9, 16, SELECTABLE_ID_TEST);
position.y += 100;
Selectable *selectable2 = SelectableInit(textures, backgroundTextures, 1,&position, "Building2", showDescription, 10, 16, SELECTABLE_ID_TEST);
position.y += 100;
Selectable *selectable3 = SelectableInit(textures, backgroundTextures, 1,&position, "Building3", showDescription, 10, 16, SELECTABLE_ID_TEST);
position.y += 100;
Selectable *selectable4 = SelectableInit(textures, backgroundTextures, 1,&position, "Building4", showDescription, 10, 16, SELECTABLE_ID_TEST);
position.x += 100;
Selectable *selectable5 = SelectableInit(textures, backgroundTextures, 1,&position, "Building5", showDescription, 10, 16, SELECTABLE_ID_TEST);
position.x += 100;
Selectable *selectable6 = SelectableInit(textures, backgroundTextures, 1,&position, "Building6", showDescription, 10, 16, SELECTABLE_ID_TEST);
uiContainer->selectables[0] = selectable1;
uiContainer->selectables[1] = selectable2;
uiContainer->selectables[2] = selectable3;
uiContainer->selectables[3] = selectable4;
uiContainer->selectables[4] = selectable5;
uiContainer->selectables[5] = selectable6;
uiContainer->selectableCounter = 6;
return uiContainer;
}
// Updated alle Buttons und führt gegebenenfalls deren Code aus
void UiContainerUpdateUiContainer(UiContainer *uiContainer, Game *game){
int i = 0;
for(i=0 ; i < uiContainer->buttonCounter; i++){
ButtonUpdateButtonState(uiContainer->buttons[i]);
if(uiContainer->buttons[i]->state == BUTTON_STATE_RELEASED){
ButtonExecuteButton(uiContainer->buttons[i], game);
}
}
for(i=0 ; i < uiContainer->selectableCounter; i++){
int setState = SelectableUpdateSelectableState(uiContainer->selectables[i]);
// Unselecting every selectable if one is selected
if(setState == SELECTABLE_STATE_SELECTED){
int j;
for(j=0 ; j < uiContainer->selectableCounter; j++){
if(i != j){
SelectableUnselectSelectable(uiContainer->selectables[j]);
}
}
}
if(uiContainer->selectables[i]->state == SELECTABLE_STATE_SELECTED){
SelectableExecuteSelectable(uiContainer->selectables[i], game);
}
}
}
// Drawed alle Buttons
void UiContainerDrawUiContainer(UiContainer *uiContainer){
int i = 0;
for(i=0 ; i < uiContainer->buttonCounter; i++){
ButtonDrawButton(uiContainer->buttons[i]);
}
for(i=0 ; i < uiContainer->selectableCounter; i++){
SelectableDrawSelectable(uiContainer->selectables[i]);
}
}