parent
4d99781ea1
commit
088f401128
@ -0,0 +1,82 @@
|
||||
#include "selectable.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id){
|
||||
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;
|
||||
|
||||
return selectable;
|
||||
}
|
||||
|
||||
// TODO: Variable die den Maus Input freigibt solange nichts mit der Maus gemacht wurde
|
||||
// Sobald ein Button gedrückt wurde in diesem Frame oder rect gezogen wird oder so ist sind Maus Funktionen gesperrt
|
||||
// verhindert Spawnen von entities wenn man UI Elemente Drückt etc
|
||||
void SelectableExecuteSelectable(Selectable *selectable, Game * game){
|
||||
// reset state after executing?
|
||||
//selectable->state = SELECTABLE_STATE_DEFAULT;
|
||||
switch(selectable->id){
|
||||
case SELECTABLE_ID_TEST: // Test Case Platzhalter
|
||||
//printf("SELECTED\n");
|
||||
break;
|
||||
default:
|
||||
printf("\n\n\n\n\n\n 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){
|
||||
selectable->state = SELECTABLE_STATE_DEFAULT;
|
||||
}
|
||||
|
||||
void SelectableDrawSelectable(Selectable * selectable){
|
||||
if(selectable->hasBackground) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
#ifndef SELECTABLE_H_
|
||||
#define SELECTABLE_H_
|
||||
|
||||
#include "raylib.h"
|
||||
#include "../game.h"
|
||||
|
||||
typedef struct Selectable Selctable;
|
||||
|
||||
#define SELECTABLE_STATE_DEFAULT 0
|
||||
#define SELECTABLE_STATE_HOVERED 1
|
||||
#define SELECTABLE_STATE_SELECTED 2
|
||||
|
||||
#define SELECTABLE_ID_TEST 0
|
||||
|
||||
typedef struct Selectable{
|
||||
Vector2 position; // Linke obere Ecke
|
||||
Vector2 centerPosition; // Die Mitte des Selectables
|
||||
Texture2D texture[3];// [0]: Normal | [1]: Hovered | [2]: Selected
|
||||
Texture2D backgroundTexture[3]; // [0]: Normal | [1]: Hovered | [2]: Selected
|
||||
int hasBackground; // 0: hat keine Background Textur | 1: hat Background Textur
|
||||
char description[20]; //Text der unter dem selectable angezeigt werden kann
|
||||
int showDescription; //0: zeigt Description nicht | 1: zeigt Description
|
||||
int id; // Durch die ID wird dem Selectable eine Funktion zugeordnet
|
||||
int state; // 0: not selected | 1: hovered | 2: selected
|
||||
int fontSize; // FontSize kann für jede Selectable Description individuell festgelegt werden
|
||||
}Selectable;
|
||||
|
||||
// Textures+backgroundTextures: [0]: Normal | [1]: Hovered | [2]: Selected
|
||||
// hasBackground: 0: hat keine Background Textur | 1: hat Background Textur
|
||||
// showDescription 0: zeigt Description nicht | 1: zeigt Description
|
||||
// Max Description LEN 20
|
||||
Selectable * SelectableInit(Texture2D textures[3], Texture2D backgroundTextures[3], int hasBackground, Vector2 *position, char *description, int showDescripton, int descriptionLEN, int fontSize, int id);
|
||||
|
||||
void SelectableExecuteSelectable(Selectable *selectable, Game * game);
|
||||
|
||||
int SelectableUpdateSelectableState(Selectable * selectable);
|
||||
|
||||
int SelectableUnselectSelectable(Selectable * selectable);
|
||||
|
||||
void SelectableDrawSelectable(Selectable * selectable);
|
||||
|
||||
#endif
|
||||
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 761 B |
|
After Width: | Height: | Size: 762 B |
|
After Width: | Height: | Size: 761 B |
Loading…
Reference in new issue