#include "selectable.h" #include #include #include Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id, int groupID){ Selectable *selectable = malloc(sizeof(Selectable)); selectable->texture[0] = textures[0]; selectable->texture[1] = textures[1]; selectable->texture[2] = textures[2]; selectable->hasBackground = hasBackground; if(selectable->hasBackground == 1){ selectable->backgroundTexture[0] = backgroundTextures[0]; selectable->backgroundTexture[1] = backgroundTextures[1]; selectable->backgroundTexture[2] = backgroundTextures[2]; } //else{ // selectable->backgroundTexture[0] = 0; // selectable->backgroundTexture[1] = 0; // selectable->backgroundTexture[2] = 0; //} selectable->position.x = position->x; selectable->position.y = position->y; strncpy(selectable->description, description, descriptionLEN); selectable->showDescription = showDescripton; selectable->fontSize = fontSize; selectable->id = id; selectable->state = 0; selectable->groupID = groupID; return selectable; } void SelectableExecuteSelectable(Selectable *selectable, Game * game){ switch(selectable->id){ case SELECTABLE_ID_TEST: // Test Case Platzhalter // Hier sollte eine Bedingung stehen die nur in einem Frame true sein kann // Oder das selectable wird abgewählt indem seine ID auf default zurückgesetzt wird // Sonst kann das hier jeden Frame passieren. ID wird nicht automatisch zurückgesetzt break; default: printf("\n\n\n\n\n\n WARNING: Unsupported SELECTABLE ID %d \n\n\n\n\n\n", selectable->id); break; } } int SelectableUpdateSelectableState(Selectable * selectable){ if(selectable->state == SELECTABLE_STATE_SELECTED){ if(IsMouseButtonDown(MOUSE_BUTTON_RIGHT)){ return selectable->state = SELECTABLE_STATE_DEFAULT; } return SELECTABLE_STATE_SELECTED; } if(GetMouseX() > selectable->position.x && GetMouseX() < selectable->position.x + selectable->backgroundTexture[selectable->state].width && GetMouseY() > selectable->position.y && GetMouseY() < selectable->position.y + selectable->backgroundTexture[selectable->state].height ){ if(IsMouseButtonDown(MOUSE_BUTTON_LEFT)){ return selectable->state = SELECTABLE_STATE_SELECTED; } return selectable->state = SELECTABLE_STATE_HOVERED; } return selectable->state = SELECTABLE_STATE_DEFAULT; } int SelectableUnselectSelectable(Selectable * selectable){ if(selectable->state == SELECTABLE_STATE_SELECTED){ return selectable->state = SELECTABLE_STATE_DEFAULT; } return selectable->state; } void SelectableDrawSelectable(Selectable * selectable){ if(selectable->hasBackground == 1) { DrawTexture(selectable->backgroundTexture[selectable->state], selectable->position.x, selectable->position.y, WHITE); } DrawTexture(selectable->texture[selectable->state], selectable->position.x, selectable->position.y, WHITE); if(selectable->showDescription == 1){ DrawText(selectable->description, selectable->position.x, selectable->position.y, selectable->fontSize, WHITE); } }