@ -10,11 +10,12 @@
# include "onClickFunctions.h"
Selectable * SelectableInit ( Texture2D * texture , Texture2D * * backgroundTextures , int hasBackground , Vector2 * position , char * description ,
int showDescripton , int descriptionLEN , int fontSize , int id , int groupID , int unselectAfterExecute ){
int showDescripton , int descriptionLEN , int fontSize , int id , int groupID , int unselectAfterExecute , float scale ){
Selectable * selectable = malloc ( sizeof ( Selectable ) ) ;
selectable - > texture = texture ;
selectable - > hasBackground = hasBackground ;
selectable - > scale = scale ;
if ( selectable - > hasBackground = = 1 ) {
selectable - > backgroundTexture = backgroundTextures ;
}
@ -33,6 +34,12 @@ Selectable * SelectableInit(Texture2D *texture, Texture2D **backgroundTextures,
selectable - > groupID = groupID ;
selectable - > unselectAfterExecute = unselectAfterExecute ;
int i = 0 ;
if ( selectable - > id > SELECTABLE_ID_DRAWING_TILE & & selectable - > id < ISOMETRICMAP_TILE_TEXTURE_AMOUNT + SELECTABLE_ID_DRAWING_TILE ) {
selectable - > onSelected = & OnSelectedDrawTile ;
return selectable ;
}
switch ( selectable - > id ) {
case SELECTABLE_ID_SPAWN_BUILDING :
selectable - > onSelected = & OnSelectedSpawnBuilding ;
@ -43,6 +50,9 @@ Selectable * SelectableInit(Texture2D *texture, Texture2D **backgroundTextures,
case SELECTABLE_ID_SPAWN_LUMBERJACK :
selectable - > onSelected = & OnSelectedSpawnLumberjack ;
break ;
case SELECTABLE_ID_DRAWING_TILE :
selectable - > onSelected = & OnSelectedDrawTile ;
break ;
default :
selectable - > onSelected = & OnSelectedSelectable ;
printf ( " \n \n \n \n \n \n WARNING: Unsupported SELECTABLE ID %d \n \n \n \n \n \n " , selectable - > id ) ;
@ -60,9 +70,9 @@ void SelectableExecuteSelectable(Selectable *selectable, Game * game){
int SelectableUpdateSelectableState ( Selectable * selectable , Game * game ) {
int mouseOnElement = 0 ;
if ( GetMouseX ( ) > selectable - > position . x & &
GetMouseX ( ) < selectable - > position . x + ( * selectable - > backgroundTexture ) [ selectable - > state ] . width &&
GetMouseX ( ) < selectable - > position . x + ( * selectable - > backgroundTexture ) [ selectable - > state ] . width * selectable - > scale &&
GetMouseY ( ) > selectable - > position . y & &
GetMouseY ( ) < selectable - > position . y + ( * selectable - > backgroundTexture ) [ selectable - > state ] . height
GetMouseY ( ) < selectable - > position . y + ( * selectable - > backgroundTexture ) [ selectable - > state ] . height * selectable - > scale
) {
mouseOnElement = 1 ;
game - > mouseOnUI = 1 ;
@ -93,17 +103,21 @@ int SelectableUnselectSelectable(Selectable * selectable){
}
void SelectableDrawSelectable ( Selectable * selectable ) {
int targetWidth = 0 ;
int padding = 19 ;
Rectangle from = { 0 , 0 , selectable - > backgroundTexture [ 0 ] - > width , selectable - > backgroundTexture [ 0 ] - > height } ;
Rectangle to = { selectable - > position . x , selectable - > position . y , selectable - > backgroundTexture [ 0 ] - > width * selectable - > scale , selectable - > backgroundTexture [ 0 ] - > height * selectable - > scale } ;
if ( selectable - > hasBackground = = 1 ) {
targetWidth = selectable - > backgroundTexture [ selectable - > state ] - > width ;
DrawTexture ( ( * ( selectable - > backgroundTexture ) ) [ selectable - > state ] , selectable - > position . x , selectable - > position . y , WHITE ) ;
DrawTexturePro ( ( * ( selectable - > backgroundTexture ) ) [ selectable - > state ] , from , to , ( Vector2 ) { 0 , 0 } , 0.0f , WHITE ) ;
}
// ich weiss zwar nicht wieso genau aber das hier skaliert die Texturen richtig
int padding = 19 ;
Rectangle from = { 0 , 0 , selectable - > texture - > width , selectable - > texture - > height } ;
Rectangle to = { selectable - > position . x + padding , selectable - > position . y + padding , selectable - > backgroundTexture [ 0 ] - > width - 2 * padding , selectable - > backgroundTexture [ 0 ] - > height - 2 * padding } ;
from . width = selectable - > texture - > width ;
from . height = selectable - > texture - > height ;
to . x + = padding * selectable - > scale ;
to . y + = padding * selectable - > scale ;
to . width - = 2 * padding * selectable - > scale ;
to . height - = 2 * padding * selectable - > scale ;
DrawTexturePro ( * selectable - > texture , from , to , ( Vector2 ) { 0 , 0 } , 0.0f , WHITE ) ;
if ( selectable - > state = = SELECTABLE_STATE_SELECTED ) {
DrawTexture ( * selectable - > texture , GetMouseX ( ) - selectable - > texture - > width / 2 , GetMouseY ( ) - selectable - > texture - > height * 0.75 , ( Color ) { 255 , 255 , 255 , 150 } ) ;
DrawRectangleLines ( GetMouseX ( ) - selectable - > texture - > width / 2 , GetMouseY ( ) - selectable - > texture - > height * 0.75 , selectable - > texture - > width , selectable - > texture - > height , GREEN ) ;