Added cursor to Hub.

This commit is contained in:
Steve 2018-02-17 16:52:51 +00:00
parent dce71760e1
commit 94db89cc08
5 changed files with 120 additions and 40 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

@ -32,6 +32,12 @@ static void drawInfoBar(void);
static void drawMissionInfo(void);
static void logic(void);
static void draw(void);
static void startMission(void);
static void cancel(void);
static void options(void);
static void stats(void);
static void trophies(void);
static void quit(void);
static HubMission hubMissionHead;
static HubMission *hubMissionTail;
@ -39,12 +45,15 @@ static HubMission *selectedMission;
static Atlas *worldMap;
static Atlas *alert;
static Atlas *clouds;
static Sprite *cursorSpr;
static Sprite *keySprites[MAX_KEY_TYPES];
static Texture *atlasTexture;
static int completedMissions;
static int numMissions;
static PointF cursor;
static float blipSize;
static float blipValue;
static int showingWidgets;
void initHub(void)
{
@ -61,6 +70,7 @@ void initHub(void)
worldMap = getImageFromAtlas("gfx/hub/worldMap.jpg");
alert = getImageFromAtlas("gfx/hub/alert.png");
clouds = getImageFromAtlas("gfx/hub/clouds.png");
cursorSpr = getSprite("Cursor");
for (i = 0 ; i < MAX_KEY_TYPES ; i++)
{
@ -70,6 +80,16 @@ void initHub(void)
}
}
cursor.x = SCREEN_WIDTH / 2;
cursor.y = SCREEN_HEIGHT / 2;
getWidget("startMission", "mission")->action = startMission;
getWidget("cancel", "mission")->action = cancel;
getWidget("options", "hub")->action = options;
getWidget("stats", "hub")->action = stats;
getWidget("trophies", "hub")->action = trophies;
getWidget("quit", "hub")->action = quit;
loadMissions();
if (dev.cheatLevels)
@ -134,15 +154,13 @@ void initHub(void)
}
}
if (unlockTeeka)
if (!unlockTeeka)
{
teeka->status = MS_INCOMPLETE;
teeka->status = MS_LOCKED;
}
app.delegate.logic = &logic;
app.delegate.draw = &draw;
app.hideMouse = 0;
}
static void logic(void)
@ -157,14 +175,22 @@ static void logic(void)
if (selectedMission == NULL)
{
if (app.mouse.button[SDL_BUTTON_LEFT])
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
m = getMissionAt(app.mouse.x, app.mouse.y);
showWidgetGroup("hub");
showingWidgets = 1;
}
else if (isControl(CONTROL_FIRE) || app.mouse.button[SDL_BUTTON_LEFT])
{
m = getMissionAt(cursor.x, cursor.y);
if (m != NULL)
{
selectedMission = m;
app.mouse.button[SDL_BUTTON_LEFT] = 0;
clearControl(CONTROL_FIRE);
showWidgetGroup("mission");
}
}
}
@ -172,10 +198,35 @@ static void logic(void)
{
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
selectedMission = NULL;
app.keyboard[SDL_SCANCODE_ESCAPE] = 0;
cancel();
}
}
if (app.mouse.dx != 0 || app.mouse.dy != 0)
{
cursor.x = app.mouse.x;
cursor.y = app.mouse.y;
}
if (isControl(CONTROL_UP) || app.keyboard[SDL_SCANCODE_UP])
{
cursor.y -= CURSOR_SPEED;
}
if (isControl(CONTROL_DOWN) || app.keyboard[SDL_SCANCODE_DOWN])
{
cursor.y += CURSOR_SPEED;
}
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
{
cursor.x -= CURSOR_SPEED;
}
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
{
cursor.x += CURSOR_SPEED;
}
}
static void draw(void)
@ -190,6 +241,8 @@ static void draw(void)
{
drawMissionInfo();
}
blitRect(atlasTexture->texture, cursor.x, cursor.y, getCurrentFrame(cursorSpr), 1);
}
static void drawMissions(void)
@ -238,7 +291,6 @@ static void drawInfoBar(void)
static void drawMissionInfo(void)
{
int w, h, x, y, size, mid, i;
SDL_Rect r;
w = 800;
h = 550;
@ -273,9 +325,7 @@ static void drawMissionInfo(void)
if (game.keys[i].value.i > 0)
{
r = getCurrentFrame(keySprites[i]);
blitRect(atlasTexture->texture, x + mid, y + mid + 7, &r, 1);
blitRect(atlasTexture->texture, x + mid, y + mid + 7, getCurrentFrame(keySprites[i]), 1);
drawText(x + size - 5, y, 18, TA_RIGHT, colors.white, "%d", game.keys[i].value.i);
}
@ -416,6 +466,41 @@ HubMission *getMissionAt(int x, int y)
return rtn;
}
static void startMission(void)
{
STRNCPY(game.worldId, selectedMission->id, MAX_NAME_LENGTH);
saveGame();
}
static void cancel(void)
{
hideAllWidgets();
showingWidgets = 0;
selectedMission = NULL;
app.keyboard[SDL_SCANCODE_ESCAPE] = 0;
}
static void options(void)
{
}
static void stats(void)
{
}
static void trophies(void)
{
}
static void quit(void)
{
}
static void loadMissions(void)
{
cJSON *root, *node;
@ -463,5 +548,14 @@ static int missionComparator(const void *a, const void *b)
void destroyHub(void)
{
HubMission *m;
while (hubMissionHead.next)
{
m = hubMissionHead.next;
hubMissionHead.next = m->next;
free(m);
}
}

View File

@ -21,6 +21,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h"
#include "../json/cJSON.h"
#define CURSOR_SPEED 8
extern int getDistance(int x1, int y1, int x2, int y2);
extern char *readFile(const char *filename);
extern Atlas *getImageFromAtlas(char *filename);
@ -32,8 +34,14 @@ extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
extern void limitTextWidth(int width);
extern Sprite *getSprite(char *name);
extern SDL_Rect getCurrentFrame(Sprite *s);
extern SDL_Rect *getCurrentFrame(Sprite *s);
extern void animateSprites(void);
extern int isControl(int type);
extern int clearControl(int type);
extern void saveGame(void);
extern void hideAllWidgets(void);
extern void showWidgetGroup(char *group);
extern Widget *getWidget(char *name, char *group);
extern App app;
extern Colors colors;

View File

@ -103,6 +103,8 @@ void initSDL(void)
}
initJoypad();
SDL_ShowCursor(SDL_DISABLE);
}
static void initJoypad(void)

View File

@ -20,12 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "input.h"
static int mouseDownTimer;
static SDL_Point dragStart;
void initInput(void)
{
mouseDownTimer = 0;
}
static void doKeyDown(SDL_KeyboardEvent *event)
@ -59,13 +55,6 @@ static void doMouseUp(SDL_MouseButtonEvent *event)
if (event->button >= 0 && event->button < MAX_MOUSE_BUTTONS)
{
app.mouse.button[event->button] = 0;
if (event->button == SDL_BUTTON_LEFT)
{
app.mouse.dragging = 0;
mouseDownTimer = 0;
}
}
}
@ -87,21 +76,8 @@ static void doMouseWheel(SDL_MouseWheelEvent *event)
static void doMouseMotion(SDL_MouseMotionEvent *event)
{
if (event->state & SDL_BUTTON_LMASK)
{
if (++mouseDownTimer >= 4 && (abs(dragStart.x - event->x) >= MOUSE_DRAG_THRESHOLD || abs(dragStart.y - event->y) >= MOUSE_DRAG_THRESHOLD))
{
app.mouse.dx = event->xrel;
app.mouse.dy = event->yrel;
app.mouse.dragging = 1;
dragStart.x = event->x;
dragStart.y = event->y;
}
}
else
{
mouseDownTimer = 0;
}
app.mouse.dx = event->xrel;
app.mouse.dy = event->yrel;
}
static void doButtonDown(SDL_JoyButtonEvent *event)