This commit is contained in:
Steve 2018-01-24 08:14:11 +00:00
parent 26730dcdc3
commit e59085b133
4 changed files with 154 additions and 1 deletions

View File

@ -79,6 +79,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define JUMP_POWER 1
#define MAX_KEY_TYPES 12
#define MAX_WIDGET_OPTIONS 8
#define ET_ENEMY 0
#define ET_KEY 1
#define ET_MIA 2
@ -218,3 +220,10 @@ enum
CH_WEAPON,
CH_MAX
};
enum
{
WT_BUTTON,
WT_SPINNER,
WT_PLAIN_BUTTON
};

View File

@ -29,6 +29,7 @@ typedef struct Particle Particle;
typedef struct Sprite Sprite;
typedef struct Tuple Tuple;
typedef struct HubMission HubMission;
typedef struct Widget Widget;
typedef struct {
int debug;
@ -295,3 +296,20 @@ typedef struct {
Objective objectiveHead, *objectiveTail;
Trigger triggerHead, *triggerTail;
} World;
struct Widget {
int type;
int x;
int y;
int w;
int h;
int visible;
int enabled;
char name[MAX_NAME_LENGTH];
char group[MAX_NAME_LENGTH];
char label[MAX_NAME_LENGTH];
char options[MAX_WIDGET_OPTIONS][MAX_NAME_LENGTH];
int value;
int clicked;
Widget *next;
};

View File

@ -20,6 +20,130 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "widgets.h"
void showWidgetGroup(char *groupName)
Widget *getWidgetAt(int x, int y);
static Widget widgetHead;
static Widget *widgetTail;
static Widget *selectedWidget;
void initWidgets(void)
{
memset(&widgetHead, 0, sizeof(Widget));
widgetTail = &widgetHead;
}
Widget *getWidget(char *name, char *group)
{
Widget *w;
for (w = widgetHead.next ; w != NULL ; w = w->next)
{
if (strcmp(w->name, name) == 0 && strcmp(w->group, group) == 0)
{
return w;
}
}
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such widget '%s', '%s'", name, group);
exit(1);
return NULL;
}
void handleWidgetClick(int x, int y)
{
Widget *w;
w = getWidgetAt(x, y);
if (w != NULL)
{
if (w->type == WT_SPINNER)
{
w->value++;
w->value %= MAX_WIDGET_OPTIONS;
}
w->clicked = 1;
}
}
void activeSelected(void)
{
if (selectedWidget->type == WT_SPINNER)
{
selectedWidget->value++;
selectedWidget->value %= MAX_WIDGET_OPTIONS;
}
selectedWidget->clicked = 1;
}
Widget *getWidgetAt(int x, int y)
{
Widget *w;
for (w = widgetHead.next ; w != NULL ; w = w->next)
{
if (w->visible && w->enabled && collision(x, y, 1, 1, w->x - (w->w / 2), w->y, w->w, w->h))
{
return w;
}
}
return NULL;
}
void hideAll(void)
{
Widget *w;
for (w = widgetHead.next ; w != NULL ; w = w->next)
{
w->visible = 0;
}
selectedWidget = NULL;
}
void showWidgetGroup(char *group)
{
Widget *w;
hideAll();
for (w = widgetHead.next ; w != NULL ; w = w->next)
{
if (strcmp(w->group, group) == 0)
{
if (selectedWidget == NULL)
{
selectedWidget = w;
}
w->visible = 1;
}
}
}
int wasWidgetClicked(Widget *w)
{
int wasClicked;
wasClicked = w->clicked;
w->clicked = 0;
return wasClicked;
}
void loadWidgets(char *filename)
{
}
void destroy(void)
{
}

View File

@ -19,3 +19,5 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "../common.h"
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);