"keymap" command configures only 2 gamepads #496

removed KEYMAP command
This commit is contained in:
BADIM-PC\Vadim 2018-01-10 11:18:55 +03:00
parent 4188b92432
commit 53ccf8fba0
6 changed files with 18 additions and 247 deletions

View File

@ -123,7 +123,6 @@ SOURCES=\
src/history.c \
src/world.c \
src/config.c \
src/keymap.c \
src/code.c \
src/dialog.c \
src/menu.c \
@ -215,9 +214,6 @@ bin/world.o: src/world.c $(TIC80_H) $(TIC_H)
bin/config.o: src/config.c $(TIC80_H) $(TIC_H) $(DEMO_ASSETS)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
bin/keymap.o: src/keymap.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
bin/code.o: src/code.c $(TIC80_H) $(TIC_H)
$(CC) $< $(OPT) $(INCLUDES) -c -o $@
@ -253,7 +249,6 @@ TIC_O=\
bin/history.o \
bin/world.o \
bin/config.o \
bin/keymap.o \
bin/code.o \
bin/net.o \
bin/dialog.o \

View File

@ -1293,13 +1293,6 @@ static void onConsoleCodeCommand(Console* console, const char* param)
commandDone(console);
}
static void onConsoleKeymapCommand(Console* console, const char* param)
{
setStudioMode(TIC_KEYMAP_MODE);
commandDone(console);
}
static void onConsoleVersionCommand(Console* console, const char* param)
{
printBack(console, "\n");
@ -2242,7 +2235,6 @@ static const struct
{"cls", NULL, "clear screen", onConsoleClsCommand},
{"demo", NULL, "install demo carts", onConsoleInstallDemosCommand},
{"config", NULL, "edit TIC config", onConsoleConfigCommand},
{"keymap", NULL, "configure keyboard mapping", onConsoleKeymapCommand},
{"version", NULL, "show the current version", onConsoleVersionCommand},
{"edit", NULL, "open cart editor", onConsoleCodeCommand},
{"surf", NULL, "open carts browser", onConsoleSurfCommand},

View File

@ -1,178 +0,0 @@
// MIT License
// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#include "keymap.h"
#include "fs.h"
#define BUTTONS_COUNT BITS_IN_BYTE
static const char* ButtonNames[] = {"UP", "DOWN", "LEFT", "RIGHT", "A", "B", "X", "Y"};
static void saveMapping(Keymap* keymap)
{
fsSaveRootFile(keymap->fs, KEYMAP_DAT_PATH, getKeymap(), KEYMAP_SIZE, true);
}
static void processKeydown(Keymap* keymap, SDL_Keysym* keysum)
{
SDL_Scancode scancode = keysum->scancode;
switch(scancode)
{
case SDL_SCANCODE_ESCAPE: break;
default:
if(keymap->button >= 0)
{
SDL_Scancode* codes = getKeymap();
codes[keymap->button] = scancode;
keymap->button = -1;
saveMapping(keymap);
}
}
}
static void drawPlayer(Keymap* keymap, s32 x, s32 y, s32 id)
{
{
char label[] = "PLAYER #%i";
sprintf(label, label, id+1);
keymap->tic->api.text(keymap->tic, label, x, y, (tic_color_white));
}
enum{OffsetX = 32, OffsetY = 16, Height = TIC_FONT_HEIGHT+1, Buttons = BUTTONS_COUNT};
y += OffsetY;
SDL_Scancode* codes = getKeymap();
for(s32 i = 0; i < COUNT_OF(ButtonNames); i++)
{
SDL_Rect rect = {x, y + i * Height, (TIC80_WIDTH-OffsetX)/2, Height};
bool over = false;
if(checkMousePos(&rect))
{
setCursor(SDL_SYSTEM_CURSOR_HAND);
over = true;
if(checkMouseClick(&rect, SDL_BUTTON_LEFT))
keymap->button = id * Buttons + i;
}
s32 button = id * Buttons + i;
bool selected = keymap->button == button;
if(over)
keymap->tic->api.rect(keymap->tic, rect.x-1, rect.y-1, rect.w, rect.h, (tic_color_dark_red));
if(selected)
keymap->tic->api.rect(keymap->tic, rect.x-1, rect.y-1, rect.w, rect.h, (tic_color_white));
keymap->tic->api.text(keymap->tic, ButtonNames[i], rect.x, rect.y, selected ? (tic_color_black) : (tic_color_gray));
keymap->tic->api.text(keymap->tic, SDL_GetKeyName(SDL_GetKeyFromScancode(codes[button])), rect.x + OffsetX, rect.y, selected ? (tic_color_black) : (tic_color_white));
}
}
static void drawCenterText(Keymap* keymap, const char* text, s32 y, u8 color)
{
keymap->tic->api.fixed_text(keymap->tic, text, (TIC80_WIDTH - (s32)strlen(text) * TIC_FONT_WIDTH)/2, y, color);
}
static void drawKeymap(Keymap* keymap)
{
keymap->tic->api.rect(keymap->tic, 0, 0, TIC80_WIDTH, TIC_FONT_HEIGHT * 3, (tic_color_white));
{
static const char Label[] = "CONFIGURE BUTTONS MAPPING";
keymap->tic->api.text(keymap->tic, Label, (TIC80_WIDTH - sizeof Label * TIC_FONT_WIDTH)/2, TIC_FONT_HEIGHT, (tic_color_black));
}
drawPlayer(keymap, 16, 40, 0);
drawPlayer(keymap, 120+16, 40, 1);
if(keymap->button < 0)
{
if(keymap->ticks % TIC_FRAMERATE < TIC_FRAMERATE/2)
drawCenterText(keymap, "SELECT BUTTON", 120, (tic_color_white));
}
else
{
char label[256];
sprintf(label, "PRESS A KEY FOR '%s'", ButtonNames[keymap->button % BUTTONS_COUNT]);
drawCenterText(keymap, label, 120, (tic_color_white));
drawCenterText(keymap, "ESC TO CANCEL", 126, (tic_color_white));
}
}
static void escape(Keymap* keymap)
{
if(keymap->button < 0)
setStudioMode(TIC_CONSOLE_MODE);
else keymap->button = -1;
}
static void tick(Keymap* keymap)
{
keymap->ticks++;
SDL_Event* event = NULL;
while ((event = pollEvent()))
{
switch(event->type)
{
case SDL_KEYDOWN:
processKeydown(keymap, &event->key.keysym);
break;
}
}
keymap->tic->api.clear(keymap->tic, TIC_COLOR_BG);
drawKeymap(keymap);
}
void initKeymap(Keymap* keymap, tic_mem* tic, FileSystem* fs)
{
*keymap = (Keymap)
{
.tic = tic,
.fs = fs,
.tick = tick,
.escape = escape,
.ticks = 0,
.button = -1,
};
s32 size = 0;
char* data = (char*)fsLoadFile(fs, KEYMAP_DAT_PATH, &size);
if(data)
{
if(size == KEYMAP_SIZE)
memcpy(getKeymap(), data, KEYMAP_SIZE);
SDL_free(data);
}
}

View File

@ -1,41 +0,0 @@
// MIT License
// Copyright (c) 2017 Vadim Grigoruk @nesbox // grigoruk@gmail.com
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#pragma once
#include "studio.h"
typedef struct Keymap Keymap;
struct Keymap
{
tic_mem* tic;
struct FileSystem* fs;
s32 ticks;
s32 button;
void(*tick)(Keymap* keymap);
void(*escape)(Keymap* keymap);
};
void initKeymap(Keymap* keymap, tic_mem* tic, struct FileSystem* fs);

View File

@ -32,7 +32,6 @@
#include "music.h"
#include "history.h"
#include "config.h"
#include "keymap.h"
#include "code.h"
#include "dialog.h"
#include "menu.h"
@ -223,7 +222,6 @@ static struct
Run* run;
World* world;
Config* config;
Keymap* keymap;
Dialog* dialog;
Menu* menu;
Surf* surf;
@ -1007,7 +1005,6 @@ void setStudioMode(EditorMode mode)
case TIC_START_MODE:
case TIC_CONSOLE_MODE:
case TIC_RUN_MODE:
case TIC_KEYMAP_MODE:
case TIC_DIALOG_MODE:
case TIC_MENU_MODE:
break;
@ -1851,13 +1848,6 @@ static bool processShortcuts(SDL_KeyboardEvent* event)
return true;
}
// TODO: move this to keymap
if(studio.mode == TIC_KEYMAP_MODE)
{
studio.keymap->escape(studio.keymap);
return true;
}
if(studio.mode == TIC_DIALOG_MODE)
{
studio.dialog->escape(studio.dialog);
@ -2418,7 +2408,6 @@ static void renderStudio()
break;
case TIC_WORLD_MODE: studio.world->tick(studio.world); break;
case TIC_KEYMAP_MODE: studio.keymap->tick(studio.keymap); break;
case TIC_DIALOG_MODE: studio.dialog->tick(studio.dialog); break;
case TIC_MENU_MODE: studio.menu->tick(studio.menu); break;
case TIC_SURF_MODE: studio.surf->tick(studio.surf); break;
@ -2669,6 +2658,22 @@ u32 unzip(u8** dest, const u8* source, size_t size)
return 0;
}
static void initKeymap()
{
FileSystem* fs = studio.fs;
s32 size = 0;
u8* data = (u8*)fsLoadFile(fs, KEYMAP_DAT_PATH, &size);
if(data)
{
if(size == KEYMAP_SIZE)
memcpy(getKeymap(), data, KEYMAP_SIZE);
SDL_free(data);
}
}
static void onFSInitialized(FileSystem* fs)
{
studio.fs = fs;
@ -2709,7 +2714,6 @@ static void onFSInitialized(FileSystem* fs)
studio.run = SDL_calloc(1, sizeof(Run));
studio.world = SDL_calloc(1, sizeof(World));
studio.config = SDL_calloc(1, sizeof(Config));
studio.keymap = SDL_calloc(1, sizeof(Keymap));
studio.dialog = SDL_calloc(1, sizeof(Dialog));
studio.menu = SDL_calloc(1, sizeof(Menu));
studio.surf = SDL_calloc(1, sizeof(Surf));
@ -2717,7 +2721,8 @@ static void onFSInitialized(FileSystem* fs)
fsMakeDir(fs, TIC_LOCAL);
initConfig(studio.config, studio.tic, studio.fs);
initKeymap(studio.keymap, studio.tic, studio.fs);
initKeymap();
initStart(studio.start, studio.tic);
initConsole(studio.console, studio.tic, studio.fs, studio.config, studio.argc, studio.argv);
@ -2848,7 +2853,6 @@ s32 main(s32 argc, char **argv)
SDL_free(studio.run);
SDL_free(studio.world);
SDL_free(studio.config);
SDL_free(studio.keymap);
SDL_free(studio.dialog);
SDL_free(studio.menu);
SDL_free(studio.surf);

View File

@ -116,7 +116,6 @@ typedef enum
TIC_WORLD_MODE,
TIC_SFX_MODE,
TIC_MUSIC_MODE,
TIC_KEYMAP_MODE,
TIC_DIALOG_MODE,
TIC_MENU_MODE,
TIC_SURF_MODE,