Integrated mouse control mappings.

This commit is contained in:
Steve 2016-03-05 13:21:17 +00:00
parent 6dfb51e8b0
commit d2a234839b
9 changed files with 49 additions and 29 deletions

View File

@ -2,6 +2,7 @@ Changelog
0.6 0.6
* Added control remapping
* New game mode: Challenges * New game mode: Challenges
* Add i18n support * Add i18n support

View File

@ -173,7 +173,7 @@ static void handleKeyboard(void)
{ {
if (battle.status == MS_IN_PROGRESS) if (battle.status == MS_IN_PROGRESS)
{ {
if (isKeyControl(CONTROL_BOOST)) if (isControl(CONTROL_BOOST))
{ {
if (battle.boostTimer == BOOST_RECHARGE_TIME) if (battle.boostTimer == BOOST_RECHARGE_TIME)
{ {
@ -189,14 +189,14 @@ static void handleKeyboard(void)
clearControl(CONTROL_BOOST); clearControl(CONTROL_BOOST);
} }
if (isKeyControl(CONTROL_TARGET)) if (isControl(CONTROL_TARGET))
{ {
selectTarget(); selectTarget();
clearControl(CONTROL_TARGET); clearControl(CONTROL_TARGET);
} }
if (isKeyControl(CONTROL_ECM)) if (isControl(CONTROL_ECM))
{ {
if (battle.ecmTimer == ECM_RECHARGE_TIME) if (battle.ecmTimer == ECM_RECHARGE_TIME)
{ {
@ -212,26 +212,26 @@ static void handleKeyboard(void)
clearControl(CONTROL_ECM); clearControl(CONTROL_ECM);
} }
if (isKeyControl(CONTROL_BRAKE)) if (isControl(CONTROL_BRAKE))
{ {
applyFighterBrakes(); applyFighterBrakes();
} }
if (isKeyControl(CONTROL_GUNS)) if (isControl(CONTROL_GUNS))
{ {
switchGuns(); switchGuns();
clearControl(CONTROL_GUNS); clearControl(CONTROL_GUNS);
} }
if (isKeyControl(CONTROL_RADAR)) if (isControl(CONTROL_RADAR))
{ {
cycleRadarZoom(); cycleRadarZoom();
clearControl(CONTROL_RADAR); clearControl(CONTROL_RADAR);
} }
if (isKeyControl(CONTROL_MISSILE)) if (isControl(CONTROL_MISSILE))
{ {
preFireMissile(); preFireMissile();
@ -251,7 +251,7 @@ static void handleMouse(void)
if (battle.status == MS_IN_PROGRESS) if (battle.status == MS_IN_PROGRESS)
{ {
if (app.mouse.button[SDL_BUTTON_LEFT] && !player->reload && player->guns[0].type) if (isControl(CONTROL_FIRE) && !player->reload && player->guns[0].type)
{ {
if (player->selectedGunType != BT_ROCKET) if (player->selectedGunType != BT_ROCKET)
{ {
@ -263,7 +263,7 @@ static void handleMouse(void)
} }
} }
if (app.mouse.button[SDL_BUTTON_RIGHT]) if (isControl(CONTROL_ACCELERATE))
{ {
if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost) if (battle.boostTimer > BOOST_FINISHED_TIME || game.currentMission->challengeData.noBoost)
{ {
@ -271,21 +271,21 @@ static void handleMouse(void)
} }
} }
if (app.mouse.button[SDL_BUTTON_MIDDLE]) if (isControl(CONTROL_MISSILE))
{ {
preFireMissile(); preFireMissile();
app.mouse.button[SDL_BUTTON_MIDDLE] = 0; app.mouse.button[SDL_BUTTON_MIDDLE] = 0;
} }
if (app.mouse.button[SDL_BUTTON_X1]) if (isControl(CONTROL_GUNS))
{ {
switchGuns(); switchGuns();
app.mouse.button[SDL_BUTTON_X1] = 0; app.mouse.button[SDL_BUTTON_X1] = 0;
} }
if (app.mouse.button[SDL_BUTTON_X2]) if (isControl(CONTROL_RADAR))
{ {
cycleRadarZoom(); cycleRadarZoom();

View File

@ -37,8 +37,7 @@ extern float getAngle(int x1, int y1, int x2, int y2);
extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2); extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2);
extern char *getTranslatedString(char *string); extern char *getTranslatedString(char *string);
extern void addECMEffect(Entity *ent); extern void addECMEffect(Entity *ent);
extern int isKeyControl(int type); extern int isControl(int type);
extern int isMouseControl(int type);
extern void clearControl(int type); extern void clearControl(int type);
extern App app; extern App app;

View File

@ -28,7 +28,6 @@ extern void retreatEnemies(void);
extern char *getTranslatedString(char *string); extern char *getTranslatedString(char *string);
extern char *getLookupName(char *prefix, long num); extern char *getLookupName(char *prefix, long num);
extern char *timeToString(long millis, int showHours); extern char *timeToString(long millis, int showHours);
extern int getPercent(float current, float total);
extern void updateAccuracyStats(unsigned int *stats); extern void updateAccuracyStats(unsigned int *stats);
extern char *timeToString(long millis, int showHours); extern char *timeToString(long millis, int showHours);

View File

@ -198,13 +198,16 @@ static void drawFighters(void)
static void handleKeyboard(void) static void handleKeyboard(void)
{ {
if (app.keyboard[SDL_SCANCODE_ESCAPE]) switch (show)
{ {
returnFromOptions(); case SHOW_STATS:
returnFromOptions();
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS); memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
playSound(SND_GUI_CLOSE);
playSound(SND_GUI_CLOSE); break;
case SHOW_OPTIONS:
break;
} }
} }

View File

@ -72,14 +72,28 @@ void initControlsDisplay(void)
} }
} }
int isKeyControl(int type) int isControl(int type)
{ {
return app.keyboard[app.keyControls[type]]; int key = app.keyControls[type];
int btn = app.mouseControls[type];
return ((key != -1 && app.keyboard[key]) || (btn != -1 && app.mouse.button[btn]));
} }
void clearControl(int type) void clearControl(int type)
{ {
app.keyboard[app.keyControls[type]] = 0; int key = app.keyControls[type];
int btn = app.mouseControls[type];
if (key != -1)
{
app.keyboard[key] = 0;
}
if (btn != -1)
{
app.mouse.button[btn] = 0;
}
} }
void updateControlKey(char *name) void updateControlKey(char *name)
@ -142,14 +156,20 @@ void drawControls(void)
controlWidget[i]->rect.x = r.x + 175; controlWidget[i]->rect.x = r.x + 175;
controlWidget[i]->rect.y = r.y; controlWidget[i]->rect.y = r.y;
r.y += 50; r.y += 65;
if (r.y > 400) if (r.y > 500)
{ {
r.y = 125; r.y = 125;
r.x += 400; r.x += 400;
} }
} }
limitTextWidth(r.w - 100);
drawText(SCREEN_WIDTH / 2, 525, 16, TA_CENTER, colors.white, _("Click a control to change it, and then the key or mouse button you want to use."));
drawText((SCREEN_WIDTH / 2) - 50, 560, 16, TA_RIGHT, colors.white, _("[BACKSPACE] - Clear"));
drawText((SCREEN_WIDTH / 2) + 50, 560, 16, TA_LEFT, colors.white, _("[ESCAPE] - Cancel"));
limitTextWidth(0);
drawWidgets("controls"); drawWidgets("controls");
} }

View File

@ -26,7 +26,7 @@ extern Widget *getWidget(const char *name, const char *group);
extern void drawWidgets(char *groupName); extern void drawWidgets(char *groupName);
extern char *getLookupName(char *prefix, long num); extern char *getLookupName(char *prefix, long num);
extern long lookup(char *name); extern long lookup(char *name);
extern void limitTextWidth(int width);
extern App app; extern App app;
extern Colors colors; extern Colors colors;
extern Game game;

View File

@ -113,7 +113,6 @@ static void drawMain(void)
#else #else
drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, _("Note: this device does not support changing the screen resolution.")); drawText(SCREEN_WIDTH / 2, r.y + r.h - 135, 16, TA_CENTER, colors.yellow, _("Note: this device does not support changing the screen resolution."));
#endif #endif
limitTextWidth(0); limitTextWidth(0);
} }

View File

@ -21,4 +21,3 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../common.h" #include "../common.h"
extern char **getFileList(char *dir, int *count); extern char **getFileList(char *dir, int *count);
extern void blitScaled(SDL_Texture *texture, int x, int y, int w, int h);