parent
732efea2d3
commit
94a3b03a1a
@ -0,0 +1,31 @@
|
||||
#ifndef BUTTONS_H_
|
||||
#define BUTTONS_H_
|
||||
|
||||
#include "raylib.h"
|
||||
#include "../game.h"
|
||||
|
||||
#define BUTTON_FONT_SIZE 36
|
||||
|
||||
typedef struct Button{
|
||||
Texture2D textures[3]; // [0]: Normal [1]: Hovered [2]: Pressed
|
||||
Vector2 position;
|
||||
Vector2 centerPosition;
|
||||
char text[20];
|
||||
int state; // 0: default 1: hovered 2: pressed
|
||||
int id;
|
||||
} Button;
|
||||
|
||||
Button * InitButton(Texture2D textures[3], Vector2 *position, char *text, int textLEN, int id);
|
||||
|
||||
// executes the logic of one button of certain id - huge switch?
|
||||
void ButtonExecuteButton(Button *button, Game * game);
|
||||
|
||||
int ButtonUpdateButtonState(Button * button);
|
||||
|
||||
void ButtonDrawButton(Button * button);
|
||||
|
||||
int ButtonisButtonPressed(Button * button);
|
||||
|
||||
int ButtonisButtonHovered(Button * button);
|
||||
|
||||
#endif
|
||||
@ -1,26 +0,0 @@
|
||||
#ifndef BUTTONS_H_
|
||||
#define BUTTONS_H_
|
||||
|
||||
#include "raylib.h"
|
||||
#include "../game.h"
|
||||
|
||||
typedef struct Button{
|
||||
Texture2D *textures[3]; // [0]: Normal [1]: Hovered [2]: Pressed
|
||||
Vector2 position;
|
||||
//char text[20];
|
||||
int state; // 0: default 1: hovered 2: pressed
|
||||
int id;
|
||||
} Button;
|
||||
|
||||
// executes the logic of one button of certain id - huge switch?
|
||||
void executeButton(Button *button, Game * game);
|
||||
|
||||
int updateButtonState(Button * button);
|
||||
|
||||
void drawButton(Button * button);
|
||||
|
||||
int isButtonPressed(Button * button);
|
||||
|
||||
int isButtonHovered(Button * button);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,42 @@
|
||||
#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[3] = { LoadTexture("assets/button.png"),
|
||||
LoadTexture("assets/button_hovered.png"),
|
||||
LoadTexture("assets/button_pressed.png")};
|
||||
Vector2 position = (Vector2){GetScreenWidth()/2 - textures[0].width/2, GetScreenHeight()/2 + 150};
|
||||
|
||||
Button *continuebutton = InitButton(textures, &position, "Continue", 9, 0);
|
||||
uiContainer->buttons[0] = continuebutton;
|
||||
uiContainer->buttonCounter = 1;
|
||||
|
||||
// Methode funktioniert wieso auch immer auch ohne dieses return. C returned Implizit odder was O_o
|
||||
return uiContainer;
|
||||
}
|
||||
|
||||
UiContainer * UiContainerInitGameUiContainer(){
|
||||
|
||||
}
|
||||
|
||||
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 == 2){
|
||||
ButtonExecuteButton(uiContainer->buttons[i], game);
|
||||
}
|
||||
}
|
||||
}
|
||||
void UiContainerDrawUiContainer(UiContainer *uiContainer){
|
||||
int i = 0;
|
||||
for(i=0 ; i < uiContainer->buttonCounter; i++){
|
||||
ButtonDrawButton(uiContainer->buttons[i]);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
#ifndef UICONTAINER_H_
|
||||
#define UICONTAINER_H_
|
||||
|
||||
#include "raylib.h"
|
||||
#include "button.h"
|
||||
#include "../game.h"
|
||||
|
||||
typedef struct UiContainer{
|
||||
Button *buttons[15];
|
||||
int buttonCounter;
|
||||
} UiContainer;
|
||||
|
||||
// executes the logic of one button of certain id - huge switch?
|
||||
void UiContainerUpdateUiContainer(UiContainer *uiContainer, Game *game);
|
||||
void UiContainerDrawUiContainer(UiContainer *uiContainer);
|
||||
|
||||
UiContainer * UiContainerInitPauseUiContainer();
|
||||
UiContainer * UiContainerInitGameUiContainer();
|
||||
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue