Skip to content

Commit

Permalink
navigate map
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaPomaskin committed Nov 22, 2023
1 parent 3d099e6 commit 2be9dfa
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/fheroes2/game/game_wallpaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,54 +256,65 @@ Java_org_libsdl_app_SDLActivity_nativeUpdateConfigs([[maybe_unused]] JNIEnv *env
forceConfigUpdate = true;
}

void handleKeyUp(SDL_Scancode scancode) {
void handleKeyUp(SDL_Keysym keysym) {
Settings &conf = Settings::Get();

switch (scancode) {
int offsetMultiplier = keysym.mod & KMOD_SHIFT ? 10 : 1;
int offset = TILEWIDTH * offsetMultiplier;

switch (keysym.scancode) {
case SDL_SCANCODE_SPACE: {
forceMapUpdate = true;
break;
}
case SDL_SCANCODE_1: {
conf.SetLWPScale(1);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}
case SDL_SCANCODE_2: {
conf.SetLWPScale(2);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}
case SDL_SCANCODE_3: {
conf.SetLWPScale(3);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}
case SDL_SCANCODE_4: {
conf.SetLWPScale(4);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}
case SDL_SCANCODE_5: {
conf.SetLWPScale(5);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}
case SDL_SCANCODE_0: {
conf.SetLWPScale(0);
conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
break;
}

case SDL_SCANCODE_UP: {
Interface::AdventureMap::Get().getGameArea().ShiftCenter(fheroes2::Point(0, -offset));
return;
}
case SDL_SCANCODE_DOWN: {
Interface::AdventureMap::Get().getGameArea().ShiftCenter(fheroes2::Point(0, offset));
return;
}
case SDL_SCANCODE_LEFT: {
Interface::AdventureMap::Get().getGameArea().ShiftCenter(fheroes2::Point(-offset, 0));
return;
}
case SDL_SCANCODE_RIGHT: {
Interface::AdventureMap::Get().getGameArea().ShiftCenter(fheroes2::Point(offset, 0));
return;
}

default: {
}
}

conf.Save(Settings::configFileName);
rereadAndApplyConfigs();
}

bool handleSDLEvents(SDL_Event &event, LocalEvent &le, fheroes2::Display &display) {
Expand All @@ -322,14 +333,11 @@ bool handleSDLEvents(SDL_Event &event, LocalEvent &le, fheroes2::Display &displa
}

case SDL_KEYUP: {
VERBOSE_LOG("Scancode: " << event.key.keysym.scancode <<
" Keycode: " << event.key.keysym.sym)

if (event.key.keysym.scancode == SDL_SCANCODE_ESCAPE) {
return true;
}

handleKeyUp(event.key.keysym.scancode);
handleKeyUp(event.key.keysym);
}
}
}
Expand All @@ -350,7 +358,6 @@ fheroes2::GameMode renderWallpaper() {
forceUpdates();

const bool isEscapePressed = handleSDLEvents(event, le, display);

if (isEscapePressed) {
return fheroes2::GameMode::QUIT_GAME;
}
Expand Down

0 comments on commit 2be9dfa

Please sign in to comment.