Further code changes for mouse support.

This commit is contained in:
Steve 2015-11-24 07:16:48 +00:00
parent 374ca825ce
commit d62d8e74ba
9 changed files with 237 additions and 395 deletions

View File

@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void selectTarget(void);
static void switchGuns(void);
static void cycleRadarZoom(void);
static void selectMissionTarget(void);
static void selectNewPlayer(int dir);
static void initPlayerSelect(void);
@ -85,6 +86,11 @@ void doPlayer(void)
handleKeyboard();
handleMouse();
if (!player->target || player->target->systemPower <= 0)
{
selectTarget();
}
}
player->angle = ((int)player->angle) % 360;
@ -115,71 +121,29 @@ void doPlayer(void)
static void handleKeyboard(void)
{
if (app.keyboard[SDL_SCANCODE_LEFT])
{
player->angle -= 4;
}
if (app.keyboard[SDL_SCANCODE_RIGHT])
{
player->angle += 4;
}
if (app.keyboard[SDL_SCANCODE_UP] && battle.boostTimer > BOOST_FINISHED_TIME)
{
applyFighterThrust();
}
if (app.keyboard[SDL_SCANCODE_DOWN])
{
applyFighterBrakes();
}
if (battle.status == MS_IN_PROGRESS)
{
if (app.keyboard[SDL_SCANCODE_LCTRL] && !player->reload && player->guns[0].type)
if (app.keyboard[SDL_SCANCODE_W])
{
fireGuns(player);
}
if (app.keyboard[SDL_SCANCODE_LSHIFT])
{
switchGuns();
cycleRadarZoom();
app.keyboard[SDL_SCANCODE_LSHIFT] = 0;
app.keyboard[SDL_SCANCODE_W] = 0;
}
if (app.keyboard[SDL_SCANCODE_RETURN] && player->missiles && player->target)
{
if (getDistance(player->x, player->y, player->target->x, player->target->y) <= SCREEN_WIDTH)
{
fireMissile(player);
}
else
{
addHudMessage(colors.white, "Target not in range");
}
app.keyboard[SDL_SCANCODE_RETURN] = 0;
}
if (!player->target || player->target->systemPower <= 0 || app.keyboard[SDL_SCANCODE_T])
{
selectTarget();
app.keyboard[SDL_SCANCODE_T] = 0;
}
if (app.keyboard[SDL_SCANCODE_SPACE] && battle.boostTimer == BOOST_RECHARGE_TIME)
if (app.keyboard[SDL_SCANCODE_D] && battle.boostTimer == BOOST_RECHARGE_TIME)
{
playSound(SND_BOOST);
activateBoost();
app.keyboard[SDL_SCANCODE_D] = 0;
}
if (app.keyboard[SDL_SCANCODE_E] && battle.ecmTimer == ECM_RECHARGE_TIME)
if (app.keyboard[SDL_SCANCODE_S] && battle.ecmTimer == ECM_RECHARGE_TIME)
{
activateECM();
app.keyboard[SDL_SCANCODE_S] = 0;
}
}
}
@ -202,10 +166,6 @@ static void handleMouse(void)
applyFighterThrust();
}
}
else
{
applyFighterBrakes();
}
if (app.mouse.button[SDL_BUTTON_MIDDLE] && player->missiles && player->target)
{
@ -220,6 +180,20 @@ static void handleMouse(void)
app.mouse.button[SDL_BUTTON_MIDDLE] = 0;
}
if (app.mouse.button[SDL_BUTTON_X1])
{
switchGuns();
app.mouse.button[SDL_BUTTON_X1] = 0;
}
if (app.mouse.button[SDL_BUTTON_X2])
{
selectTarget();
app.mouse.button[SDL_BUTTON_X2] = 0;
}
}
}
@ -462,3 +436,7 @@ static void selectMissionTarget(void)
}
}
}
static void cycleRadarZoom(void)
{
}

View File

@ -23,13 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void logic(void);
static void draw(void);
static void handleKeyboard(void);
static void handleMouse(void);
static void scrollGalaxy(void);
static void drawStarSystemDetail(void);
static void prevMission(void);
static void nextMission(void);
static void selectStarSystem(void);
static void drawGalaxy(void);
static void handleGalaxyKB(void);
static void handleSelectedSystemKB(void);
static void centerOnSelectedStarSystem(void);
static void doStarSystems(void);
void destroyGalacticMap(void);
@ -43,16 +41,16 @@ static void stats(void);
static void options(void);
static void statsOK(void);
static void quit(void);
static void startMission(void);
static void returnFromOptions(void);
static void doStarSystemView(void);
static StarSystem *selectedStarSystem;
static Mission *selectedMission = {0};
static int missionListStart, selectedMissionIndex;
static SDL_Texture *background;
static SDL_Texture *starSystemTexture;
static SDL_Texture *arrowTexture;
static SDL_Point camera;
static int viewingSystem;
static Pulse pulseHead = {0};
static Pulse *pulseTail;
static int pulseTimer;
@ -86,8 +84,6 @@ void initGalacticMap(void)
saveGame();
viewingSystem = 0;
pulseTimer = 0;
arrowPulse = 0;
@ -99,6 +95,8 @@ void initGalacticMap(void)
initBackground();
getWidget("startMission", "starSystem")->action = startMission;
getWidget("resume", "galacticMap")->action = resume;
getWidget("stats", "galacticMap")->action = stats;
getWidget("options", "galacticMap")->action = options;
@ -117,14 +115,24 @@ static void logic(void)
{
handleKeyboard();
doStarSystems();
handleMouse();
scrollBackground(-ssx, -ssy);
switch (show)
{
case SHOW_GALAXY:
doStarSystems();
scrollGalaxy();
scrollBackground(-ssx, -ssy);
doStars(ssx, ssy);
break;
case SHOW_STAR_SYSTEM:
doStarSystemView();
break;
}
doPulses();
doStars(ssx, ssy);
if (pulseTimer % FPS == 0)
{
addPulses();
@ -145,8 +153,8 @@ static void doStarSystems(void)
completedMissions = totalMissions = completedChallenges = totalChallenges = 0;
cx = (camera.x + SCREEN_WIDTH / 2) - 32;
cy = (camera.y + SCREEN_HEIGHT / 2) - 32;
cx = app.mouse.x - app.mouse.w / 2;
cy = app.mouse.y - app.mouse.h / 2;
selectedStarSystem = NULL;
@ -157,16 +165,81 @@ static void doStarSystems(void)
completedChallenges += starSystem->completedChallenges;
totalChallenges += starSystem->totalChallenges;
if (starSystem->totalMissions > 0 && collision(cx, cy, 64, 64, starSystem->x, starSystem->y, 4, 4))
if (starSystem->totalMissions > 0 && collision(cx, cy, app.mouse.w, app.mouse.y, starSystem->x - camera.x, starSystem->y - camera.y, 4, 4))
{
if (selectedStarSystem != starSystem)
{
selectedStarSystem = starSystem;
if (app.mouse.button[SDL_BUTTON_LEFT])
{
selectStarSystem();
app.mouse.button[SDL_BUTTON_LEFT] = 0;
}
}
}
}
}
static void scrollGalaxy(void)
{
int dist;
float dx, dy;
int lastX, lastY;
lastX = camera.x;
lastY = camera.y;
ssx = ssy = 0;
dist = getDistance(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, app.mouse.x, app.mouse.y);
if (dist > 196)
{
dx = (SCREEN_WIDTH / 2) - app.mouse.x;
dy = (SCREEN_HEIGHT / 2) - app.mouse.y;
dx /= 35;
dy /= 35;
camera.x -= dx;
camera.y -= dy;
ssx = -(dx / 5);
ssy = -(dy / 5);
camera.x = MAX(-800, MIN(camera.x, 2464));
camera.y = MAX(-475, MIN(camera.y, 1235));
}
if (lastX == camera.x)
{
ssx = 0;
}
if (lastY == camera.y)
{
ssy = 0;
}
}
static void doStarSystemView(void)
{
Mission *mission;
for (mission = selectedStarSystem->missionHead.next ; mission != NULL ; mission = mission->next)
{
if (mission->available && app.mouse.button[SDL_BUTTON_LEFT] && collision(app.mouse.x - app.mouse.w / 2, app.mouse.y - app.mouse.h / 2, app.mouse.w, app.mouse.h, mission->rect.x, mission->rect.y, mission->rect.w, mission->rect.h))
{
if (selectedMission != mission)
{
playSound(SND_GUI_CLICK);
}
selectedMission = mission;
}
}
}
static void addPulses(void)
{
Pulse *pulse;
@ -263,14 +336,10 @@ static void draw(void)
drawInfoBars();
if (viewingSystem)
{
drawStarSystemDetail();
}
switch (show)
{
case SHOW_GALAXY:
case SHOW_STAR_SYSTEM:
drawStarSystemDetail();
break;
case SHOW_MENU:
@ -315,19 +384,6 @@ static void drawGalaxy(void)
SDL_Color color;
float ax, ay, aa;
r.w = r.h = 64;
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
if (selectedStarSystem)
{
SDL_SetRenderDrawColor(app.renderer, 64, 100, 128, 255);
SDL_RenderFillRect(app.renderer, &r);
}
SDL_SetRenderDrawColor(app.renderer, 128, 200, 255, 255);
SDL_RenderDrawRect(app.renderer, &r);
arrowPulse += 0.1;
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
@ -398,7 +454,7 @@ static void drawInfoBars(void)
{
SDL_Rect r;
if (!viewingSystem && selectedStarSystem != NULL)
if (show != SHOW_STAR_SYSTEM && selectedStarSystem != NULL)
{
r.x = 0;
r.y = SCREEN_HEIGHT - 35;
@ -428,19 +484,18 @@ static void drawInfoBars(void)
static void selectStarSystem(void)
{
missionListStart = 0;
selectedMissionIndex = 0;
if (selectedStarSystem->totalMissions > 0)
{
viewingSystem = 1;
show = SHOW_STAR_SYSTEM;
STRNCPY(game.selectedStarSystem, selectedStarSystem->name, MAX_NAME_LENGTH);
selectedMission = selectedStarSystem->missionHead.next;
playSound(SND_GUI_SELECT);
}
}
static void drawStarSystemDetail(void)
{
int y, i;
int y;
Mission *mission;
Challenge *challenge;
SDL_Rect r;
@ -461,7 +516,7 @@ static void drawStarSystemDetail(void)
y = 70;
drawText(SCREEN_WIDTH / 2, y, 28, TA_CENTER, colors.cyan, "%s (%d / %d)", selectedStarSystem->name, selectedStarSystem->completedMissions, selectedStarSystem->totalMissions);
drawText(SCREEN_WIDTH / 2, y, 28, TA_CENTER, colors.cyan, "%s", selectedStarSystem->name);
SDL_RenderDrawLine(app.renderer, r.x, 120, r.x + r.w, 120);
@ -469,41 +524,28 @@ static void drawStarSystemDetail(void)
y += 80;
r.x = 200;
r.w = 300;
r.h = 40;
i = 0;
for (mission = selectedStarSystem->missionHead.next ; mission != NULL ; mission = mission->next)
{
if (i == selectedMissionIndex)
mission->rect.x = 200;
mission->rect.y = y - 2;
mission->rect.w = 300;
mission->rect.h = 40;
if (mission == selectedMission)
{
selectedMission = mission;
SDL_SetRenderDrawColor(app.renderer, 32, 64, 128, 255);
SDL_RenderFillRect(app.renderer, &mission->rect);
SDL_SetRenderDrawColor(app.renderer, 64, 96, 196, 255);
SDL_RenderDrawRect(app.renderer, &mission->rect);
}
if (i >= missionListStart && i < missionListStart + 10)
if (mission->available)
{
if (mission == selectedMission)
{
r.y = y - 2;
SDL_SetRenderDrawColor(app.renderer, 32, 64, 128, 255);
SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 64, 96, 196, 255);
SDL_RenderDrawRect(app.renderer, &r);
}
if (mission->available)
{
drawText(210, y, 24, TA_LEFT, mission->completed ? colors.white : colors.yellow, mission->name);
}
y += 50;
drawText(210, y, 24, TA_LEFT, mission->completed ? colors.white : colors.yellow, mission->name);
}
i++;
y += 50;
}
if (selectedMission->available)
@ -542,30 +584,27 @@ static void drawStarSystemDetail(void)
y += 25;
}
}
drawWidgets("starSystem");
}
static void handleKeyboard(void)
{
if (show == SHOW_GALAXY)
{
if (viewingSystem)
{
handleSelectedSystemKB();
}
else
{
handleGalaxyKB();
}
}
else if (show == SHOW_STATS)
{
handleStatsKB();
}
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
switch (show)
{
case SHOW_GALAXY:
selectWidget("resume", "galacticMap");
show = SHOW_MENU;
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
playSound(SND_GUI_CLOSE);
break;
case SHOW_STAR_SYSTEM:
show = SHOW_GALAXY;
break;
case SHOW_MENU:
show = SHOW_GALAXY;
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
@ -580,132 +619,27 @@ static void handleKeyboard(void)
}
playSound(SND_GUI_CLOSE);
}
}
static void handleGalaxyKB(void)
{
int lastX, lastY;
lastX = camera.x;
lastY = camera.y;
ssx = ssy = 0;
if (app.keyboard[SDL_SCANCODE_LEFT])
{
ssx = -1;
camera.x -= CAMERA_SPEED;
}
if (app.keyboard[SDL_SCANCODE_RIGHT])
{
ssx = 1;
camera.x += CAMERA_SPEED;
}
if (app.keyboard[SDL_SCANCODE_UP])
{
ssy = -1;
camera.y -= CAMERA_SPEED;
}
if (app.keyboard[SDL_SCANCODE_DOWN])
{
ssy = 1;
camera.y += CAMERA_SPEED;
}
if (app.keyboard[SDL_SCANCODE_RETURN] && selectedStarSystem)
{
playSound(SND_GUI_SELECT);
selectStarSystem();
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
}
camera.x = MAX(-800, MIN(camera.x, 2464));
camera.y = MAX(-475, MIN(camera.y, 1235));
if (lastX == camera.x)
}
static void handleMouse(void)
{
switch (show)
{
ssx = 0;
}
if (lastY == camera.y)
{
ssy = 0;
}
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
selectWidget("resume", "galacticMap");
show = SHOW_MENU;
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
playSound(SND_GUI_CLOSE);
case SHOW_STATS:
break;
}
}
static void handleSelectedSystemKB(void)
static void startMission(void)
{
if (app.keyboard[SDL_SCANCODE_UP])
{
prevMission();
}
playSound(SND_GUI_SELECT);
if (app.keyboard[SDL_SCANCODE_DOWN])
{
nextMission();
}
if (app.keyboard[SDL_SCANCODE_RETURN])
{
if (selectedMission->available)
{
playSound(SND_GUI_SELECT);
initBattle();
game.currentMission = selectedMission;
loadMission(selectedMission->filename);
}
else
{
playSound(SND_GUI_DENIED);
}
}
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
viewingSystem = 0;
playSound(SND_GUI_CLOSE);
}
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
}
static void prevMission(void)
{
selectedMissionIndex = MAX(0, selectedMissionIndex - 1);
if (selectedMissionIndex <= missionListStart + 3)
{
missionListStart = MAX(0, missionListStart - 1);
}
selectedMission = NULL;
}
static void nextMission(void)
{
selectedMissionIndex = MIN(selectedMissionIndex + 1, selectedStarSystem->totalMissions - 1);
if (selectedMissionIndex >= missionListStart + 5)
{
missionListStart = MIN(missionListStart + 1, selectedStarSystem->totalMissions - 9);
}
selectedMission = NULL;
initBattle();
game.currentMission = selectedMission;
loadMission(selectedMission->filename);
}
static void drawMenu(void)

View File

@ -23,12 +23,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../defs.h"
#include "../structs.h"
#define CAMERA_SPEED 8
#define SHOW_GALAXY 0
#define SHOW_MENU 1
#define SHOW_OPTIONS 2
#define SHOW_STATS 3
#define SHOW_GALAXY 0
#define SHOW_STAR_SYSTEM 1
#define SHOW_MENU 2
#define SHOW_OPTIONS 3
#define SHOW_STATS 4
extern void prepareScene(void);
extern void presentScene(void);
@ -63,9 +62,9 @@ extern void drawStats(void);
extern void playSound(int id);
extern void blitRotated(SDL_Texture *texture, int x, int y, int angle);
extern void initStatsDisplay(void);
extern void handleStatsKB(void);
extern void updateStarSystemMissions(void);
extern StarSystem *getStarSystem(char *name);
extern int getDistance(int x1, int y1, int x2, int y2);
extern App app;
extern Colors colors;

View File

@ -61,19 +61,6 @@ void initStatsDisplay(void)
pageNext = getTexture("gfx/widgets/optionsRight.png");
}
void handleStatsKB(void)
{
if (app.keyboard[SDL_SCANCODE_LEFT])
{
page = MIN(MAX(page - 1, 0), maxPages);
}
if (app.keyboard[SDL_SCANCODE_RIGHT])
{
page = MIN(MAX(page + 1, 0), maxPages);
}
}
void drawStats(void)
{
int i, y, hours, minutes, seconds, startIndex;

View File

@ -62,6 +62,10 @@ int main(int argc, char *argv[])
{
switch (event.type)
{
case SDL_MOUSEWHEEL:
doMouseWheel(&event.wheel);
break;
case SDL_MOUSEBUTTONDOWN:
doMouseDown(&event.button);
break;
@ -69,10 +73,6 @@ int main(int argc, char *argv[])
case SDL_MOUSEBUTTONUP:
doMouseUp(&event.button);
break;
case SDL_MOUSEMOTION:
doMouseMove(&event.motion);
break;
case SDL_KEYDOWN:
if (event.key.keysym.scancode >= 0 && event.key.keysym.scancode < MAX_KEYBOARD_KEYS)

View File

@ -33,7 +33,7 @@ extern void loadTestMission(char *filename);
extern void saveScreenshot(void);
extern void doMouseDown(SDL_MouseButtonEvent *event);
extern void doMouseUp(SDL_MouseButtonEvent *event);
extern void doMouseMove(SDL_MouseMotionEvent *event);
extern void doMouseWheel(SDL_MouseWheelEvent *event);
App app;
Colors colors;

View File

@ -209,6 +209,7 @@ struct Mission {
int available;
int completed;
int epic;
SDL_Rect rect;
Challenge challengeHead;
Mission *next;
};
@ -293,6 +294,8 @@ struct HudMessage {
typedef struct {
int x;
int y;
int w;
int h;
int button[MAX_MOUSE_BUTTONS];
} Mouse;

View File

@ -27,6 +27,8 @@ void initInput(void)
memset(&app.mouse, 0, sizeof(Mouse));
mousePointer = getTexture("gfx/input/mousePointer.png");
SDL_QueryTexture(mousePointer, NULL, NULL, &app.mouse.w, &app.mouse.h);
}
void doMouseDown(SDL_MouseButtonEvent *event)
@ -39,9 +41,17 @@ void doMouseUp(SDL_MouseButtonEvent *event)
app.mouse.button[event->button] = 0;
}
void doMouseMove(SDL_MouseMotionEvent *event)
void doMouseWheel(SDL_MouseWheelEvent *event)
{
if (event->y == -1)
{
app.mouse.button[SDL_BUTTON_X1] = 1;
}
if (event->y == 1)
{
app.mouse.button[SDL_BUTTON_X2] = 1;
}
}
void drawMouse(void)

View File

@ -22,9 +22,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static void loadWidgets(char *filename);
static void loadWidgetSet(char *filename);
static void handleKeyboard(void);
static void handleMouse(void);
static void createOptions(Widget *w, char *options);
static void changeSelectedValue(int dir);
static Widget head;
static Widget *tail;
@ -53,8 +53,6 @@ void doWidgets(void)
{
if (drawingWidgets)
{
handleKeyboard();
handleMouse();
}
@ -80,7 +78,7 @@ Widget *getWidget(const char *name, const char *group)
void selectWidget(const char *name, const char *group)
{
selectedWidget = getWidget(name, group);
/*selectedWidget = getWidget(name, group);*/
}
void drawWidgets(const char *group)
@ -89,17 +87,21 @@ void drawWidgets(const char *group)
Widget *w;
drawingWidgets = 1;
mouseOver = 0;
for (w = head.next; w != NULL ; w = w->next)
{
if (w->visible && strcmp(w->group, group) == 0)
{
mouseOver = (w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.mouse.x, app.mouse.y, 1, 1));
if (mouseOver && selectedWidget != w)
if (!mouseOver)
{
playSound(SND_GUI_CLICK);
selectedWidget = w;
mouseOver = (w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.mouse.x, app.mouse.y, 1, 1));
if (mouseOver && selectedWidget != w)
{
playSound(SND_GUI_CLICK);
selectedWidget = w;
}
}
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
@ -128,17 +130,8 @@ void drawWidgets(const char *group)
case WT_SELECT:
drawText(w->rect.x + 10, w->rect.y + 2, 20, TA_LEFT, colors.white, w->text);
drawText(w->rect.x + w->rect.w - 10, w->rect.y + 2, 20, TA_RIGHT, colors.white, w->options[w->currentOption]);
if (w->currentOption != 0)
{
blit(optionsLeft, w->rect.x - 24, w->rect.y + 16, 1);
}
if (w->currentOption != w->numOptions - 1)
{
blit(optionsRight, w->rect.x + w->rect.w + 24, w->rect.y + 16, 1);
}
blit(optionsLeft, w->rect.x - 24, w->rect.y + 16, 1);
blit(optionsRight, w->rect.x + w->rect.w + 24, w->rect.y + 16, 1);
break;
}
@ -151,6 +144,11 @@ void drawWidgets(const char *group)
}
}
}
if (!mouseOver)
{
selectedWidget = NULL;
}
}
void drawConfirmMessage(char *message)
@ -158,49 +156,7 @@ void drawConfirmMessage(char *message)
drawWidgets("okCancel");
}
static void gotoWidget(int dx, int dy)
{
Widget *w, *closest;
int distance;
int curDistance = -1;
closest = selectedWidget;
for (w = head.next; w != NULL ; w = w->next)
{
if (w == selectedWidget ||
!w->enabled ||
!w->visible ||
strcmp(w->group, selectedWidget->group) != 0 ||
(dx == -1 && w->rect.x > selectedWidget->rect.x) ||
(dx == 1 && w->rect.x < selectedWidget->rect.x) ||
(dx != 0 && w->rect.x == selectedWidget->rect.x) ||
(dy == -1 && w->rect.y > selectedWidget->rect.y) ||
(dy == 1 && w->rect.y < selectedWidget->rect.y) ||
(dy != 0 && w->rect.y == selectedWidget->rect.y)
)
{
continue;
}
distance = getDistance(w->rect.x, w->rect.y, selectedWidget->rect.x, selectedWidget->rect.y);
if (curDistance == -1 || distance < curDistance)
{
curDistance = distance;
closest = w;
}
}
if (selectedWidget != closest)
{
playSound(SND_GUI_CLICK);
selectedWidget = closest;
}
}
static void changeSelectValue(int dir)
static void changeSelectedValue(int dir)
{
int oldOption = selectedWidget->currentOption;
@ -234,59 +190,34 @@ void setWidgetOption(const char *name, const char *group, const char *value)
}
}
static void handleKeyboard(void)
{
if (app.keyboard[SDL_SCANCODE_UP])
{
gotoWidget(0, -1);
}
if (app.keyboard[SDL_SCANCODE_DOWN])
{
gotoWidget(0, 1);
}
if (app.keyboard[SDL_SCANCODE_LEFT])
{
if (selectedWidget->type != WT_SELECT)
{
gotoWidget(-1, 0);
}
else
{
changeSelectValue(-1);
}
}
if (app.keyboard[SDL_SCANCODE_RIGHT])
{
if (selectedWidget->type != WT_SELECT)
{
gotoWidget(1, 0);
}
else
{
changeSelectValue(1);
}
}
if (app.keyboard[SDL_SCANCODE_RETURN] && selectedWidget->action)
{
playSound(SND_GUI_SELECT);
selectedWidget->action();
}
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
}
static void handleMouse(void)
{
if (selectedWidget && selectedWidget->action && app.mouse.button[SDL_BUTTON_LEFT])
if (selectedWidget && collision(selectedWidget->rect.x, selectedWidget->rect.y, selectedWidget->rect.w, selectedWidget->rect.h, app.mouse.x, app.mouse.y, 1, 1))
{
if (collision(selectedWidget->rect.x, selectedWidget->rect.y, selectedWidget->rect.w, selectedWidget->rect.h, app.mouse.x, app.mouse.y, 1, 1))
if (app.mouse.button[SDL_BUTTON_LEFT])
{
playSound(SND_GUI_SELECT);
selectedWidget->action();
switch (selectedWidget->type)
{
case WT_BUTTON:
if (selectedWidget->action)
{
playSound(SND_GUI_SELECT);
selectedWidget->action();
app.mouse.button[SDL_BUTTON_LEFT] = 0;
}
break;
case WT_SELECT:
changeSelectedValue(-1);
app.mouse.button[SDL_BUTTON_LEFT] = 0;
break;
}
}
if (app.mouse.button[SDL_BUTTON_RIGHT] && selectedWidget->type == WT_SELECT)
{
changeSelectedValue(1);
app.mouse.button[SDL_BUTTON_RIGHT] = 0;
}
}
}