@ -17,56 +17,48 @@ static UiContainer * UiContainerInitEmptyUiContainer(){
// Only for use in UiContainer
// Only for use in UiContainer
static UiContainer * UiContainerInitPauseUiContainer ( ) {
static UiContainer * UiContainerInitPauseUiContainer ( ) {
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
uiContainer - > buttonCounter = 0 ;
uiContainer - > selectableCounter = 0 ;
Texture2D textures [ 4 ] = { LoadTexture ( " assets/button.png " ) , //DEFAULT
Texture2D textures [ 4 ] = { LoadTexture ( " assets/button.png " ) , //DEFAULT
LoadTexture ( " assets/button_hovered.png " ) , //HOVERED
LoadTexture ( " assets/button_hovered.png " ) , //HOVERED
LoadTexture ( " assets/button_pressed.png " ) , //PRESSED
LoadTexture ( " assets/button_pressed.png " ) , //PRESSED
LoadTexture ( " assets/button_pressed.png " ) } ; //RELEASED
LoadTexture ( " assets/button_pressed.png " ) } ; //RELEASED
Vector2 position = ( Vector2 ) { GetScreenWidth ( ) / 2 - textures [ 0 ] . width / 2 , GetScreenHeight ( ) / 2 - 50 } ;
Vector2 position = ( Vector2 ) { GetScreenWidth ( ) / 2 - textures [ 0 ] . width / 2 , GetScreenHeight ( ) / 2 - 50 } ;
int buttonFontSize = 36 ;
int buttonFontSize = 36 ;
Button * continuebutton = ButtonInitButton ( textures , & position , " Continue " , 9 , buttonFontSize , BUTTON_ID_CONTINUE ) ;
Button * continuebutton = ButtonInitButton ( textures , & position , " Continue " , 9 /*String len*/ , buttonFontSize , BUTTON_ID_CONTINUE ) ;
uiContainer - > buttons [ 0 ] = continuebutton ;
uiContainer - > buttonCounter = 1 ;
position . y + = 250 ;
position . y + = 250 ;
Button * exitButton = ButtonInitButton ( textures , & position , " EXIT " , 5 /*String len*/ , buttonFontSize , BUTTON_ID_EXIT ) ;
Button * exitButton = ButtonInitButton ( textures , & position , " EXIT " , 5 , buttonFontSize , BUTTON_ID_EXIT ) ;
UiContainerAddButton ( uiContainer , continuebutton ) ;
uiContainer - > buttons [ 1 ] = exitButton ;
UiContainerAddButton ( uiContainer , exitButton ) ;
uiContainer - > buttonCounter = 2 ;
// WICHTIG, auch wenn der UiContainer gar keine selectables hat!
uiContainer - > selectableCounter = 0 ;
// Methode funktioniert wieso auch immer auch ohne dieses return. C returned Implizit odder was O_o
return uiContainer ;
return uiContainer ;
}
}
// Only for use in UiContainer
// Only for use in UiContainer
static UiContainer * UiContainerInitMainMenuUiContainer ( ) {
static UiContainer * UiContainerInitMainMenuUiContainer ( ) {
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
uiContainer - > buttonCounter = 0 ;
uiContainer - > selectableCounter = 0 ;
Texture2D textures [ 4 ] = { LoadTexture ( " assets/button.png " ) , //DEFAULT
Texture2D textures [ 4 ] = { LoadTexture ( " assets/button.png " ) , //DEFAULT
LoadTexture ( " assets/button_hovered.png " ) , //HOVERED
LoadTexture ( " assets/button_hovered.png " ) , //HOVERED
LoadTexture ( " assets/button_pressed.png " ) , //PRESSED
LoadTexture ( " assets/button_pressed.png " ) , //PRESSED
LoadTexture ( " assets/button_pressed.png " ) } ; //RELEASED
LoadTexture ( " assets/button_pressed.png " ) } ; //RELEASED
Vector2 position = ( Vector2 ) { GetScreenWidth ( ) / 2 - textures [ 0 ] . width / 2 , GetScreenHeight ( ) / 2 - 50 } ;
Vector2 position = ( Vector2 ) { GetScreenWidth ( ) / 2 - textures [ 0 ] . width / 2 , GetScreenHeight ( ) / 2 - 50 } ;
int buttonFontSize = 36 ;
int buttonFontSize = 36 ;
Button * continuebutton = ButtonInitButton ( textures , & position , " Start Game " , 11 , buttonFontSize , BUTTON_ID_START_GAME ) ;
Button * continuebutton = ButtonInitButton ( textures , & position , " Start Game " , 11 /*String len*/ , buttonFontSize , BUTTON_ID_START_GAME ) ;
uiContainer - > buttons [ 0 ] = continuebutton ;
uiContainer - > buttonCounter = 1 ;
// WICHTIG, auch wenn der UiContainer gar keine selectables hat!
uiContainer - > selectableCounter = 0 ;
position . y + = 250 ;
position . y + = 250 ;
Button * exitbutton = ButtonInitButton ( textures , & position , " EXIT " , 5 /*String len*/ , buttonFontSize , BUTTON_ID_EXIT ) ;
Button * exitButton = ButtonInitButton ( textures , & position , " EXIT " , 5 , buttonFontSize , BUTTON_ID_EXIT ) ;
UiContainerAddButton ( uiContainer , continuebutton ) ;
uiContainer - > buttons [ 1 ] = exitButton ;
UiContainerAddButton ( uiContainer , exitbutton ) ;
uiContainer - > buttonCounter = 2 ;
// Methode funktioniert wieso auch immer auch ohne dieses return. GCC returned Implizit odder was O_o
return uiContainer ;
return uiContainer ;
}
}
@ -75,6 +67,7 @@ static UiContainer * UiContainerInitGameUiContainer(){
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
UiContainer * uiContainer = malloc ( sizeof ( UiContainer ) ) ;
uiContainer - > buttonCounter = 0 ;
uiContainer - > buttonCounter = 0 ;
uiContainer - > selectableCounter = 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 " ) , //HOVERED
@ -84,11 +77,11 @@ static UiContainer * UiContainerInitGameUiContainer(){
LoadTexture ( " assets/entities/worker/arbeiten-4.png " ) , //HOVERED
LoadTexture ( " assets/entities/worker/arbeiten-4.png " ) , //HOVERED
LoadTexture ( " assets/entities/worker/arbeiten-4.png " ) //SELECTED
LoadTexture ( " assets/entities/worker/arbeiten-4.png " ) //SELECTED
} ;
} ;
Texture2D backgroundTextures [ 3 ] = { LoadTexture ( " assets/selectable_background.png " ) , //DEFAULT
Texture2D backgroundTextures [ 3 ] = { LoadTexture ( " assets/selectable_background.png " ) , //DEFAULT
LoadTexture ( " assets/selectable_background_hovered.png " ) , //HOVERED
LoadTexture ( " assets/selectable_background_hovered.png " ) , //HOVERED
LoadTexture ( " assets/selectable_background_selected.png " ) //SELECTED
LoadTexture ( " assets/selectable_background_selected.png " ) //SELECTED
} ;
} ;
Vector2 position = ( Vector2 ) { 20 , 300 } ;
Vector2 position = ( Vector2 ) { 20 , 300 } ;
int showDescription = 1 ;
int showDescription = 1 ;
int hasBackground = 1 ;
int hasBackground = 1 ;
@ -96,24 +89,18 @@ static UiContainer * UiContainerInitGameUiContainer(){
int groupTwo = 1 ;
int groupTwo = 1 ;
int fontSize = 16 ;
int fontSize = 16 ;
Selectable * selectable1 = SelectableInit ( textures , backgroundTextures , hasBackground , & position , " Building " ,
Selectable * selectable1 = SelectableInit ( textures , backgroundTextures , hasBackground , & position , " Building " ,
showDescription , 9 , fontSize , SELECTABLE_ID_SPAWN_BUILDING , groupOne , 1 ) ;
showDescription , 9 /*String len*/ , fontSize , SELECTABLE_ID_SPAWN_BUILDING , groupOne , 1 ) ;
position . y + = 100 ;
position . y + = 100 ;
Selectable * selectable2 = SelectableInit ( textures2 , backgroundTextures , hasBackground , & position , " Worker " ,
Selectable * selectable2 = SelectableInit ( textures2 , backgroundTextures , hasBackground , & position , " Worker " ,
showDescription , 7 , fontSize , SELECTABLE_ID_SPAWN_WORKER , groupOne , 1 ) ;
showDescription , 7 /*String len*/ , fontSize , SELECTABLE_ID_SPAWN_WORKER , groupOne , 1 ) ;
position . y + = 100 ;
position . y + = 100 ;
Selectable * selectable3 = SelectableInit ( textures2 , backgroundTextures , hasBackground , & position , " Lumberjack " ,
Selectable * selectable3 = SelectableInit ( textures2 , backgroundTextures , hasBackground , & position , " Lumberjack " ,
showDescription , 11 , fontSize , SELECTABLE_ID_SPAWN_LUMBERJACK , groupOne , 1 ) ;
showDescription , 11 /*String len*/ , fontSize , SELECTABLE_ID_SPAWN_LUMBERJACK , groupOne , 1 ) ;
position . y + = 100 ;
int selectableCounter = 0 ;
UiContainerAddSelectable ( uiContainer , selectable1 ) ;
UiContainerAddSelectable ( uiContainer , selectable2 ) ;
uiContainer - > selectables [ selectableCounter + + ] = selectable1 ;
UiContainerAddSelectable ( uiContainer , selectable3 ) ;
uiContainer - > selectables [ selectableCounter + + ] = selectable2 ;
UiContainerAddSelectable ( uiContainer , selectable4 ) ;
uiContainer - > selectables [ selectableCounter + + ] = selectable3 ;
uiContainer - > selectableCounter = selectableCounter ;
return uiContainer ;
return uiContainer ;
}
}
@ -195,4 +182,19 @@ void UiContainerDrawUiContainer(UiContainer *uiContainer){
for ( i = 0 ; i < uiContainer - > selectableCounter ; i + + ) {
for ( i = 0 ; i < uiContainer - > selectableCounter ; i + + ) {
SelectableDrawSelectable ( uiContainer - > selectables [ i ] ) ;
SelectableDrawSelectable ( uiContainer - > selectables [ i ] ) ;
}
}
}
void UiContainerAddButton ( UiContainer * uiContainer , Button * button ) {
if ( uiContainer - > buttonCounter = = UI_CONTAINER_MAX_BUTTONS ) {
printf ( " UI CONTAINER VOLL [BUTTONS] \n " ) ;
return ;
}
uiContainer - > buttons [ uiContainer - > buttonCounter + + ] = button ;
}
void UiContainerAddSelectable ( UiContainer * uiContainer , Selectable * selectable ) {
if ( uiContainer - > selectableCounter = = UI_CONTAINER_MAX_SELECTABLES ) {
printf ( " UI CONTAINER VOLL [SElECTABLES] \n " ) ;
return ;
}
uiContainer - > selectables [ uiContainer - > selectableCounter + + ] = selectable ;
}
}