directional key screen-shift

This commit is contained in:
2025-01-18 18:57:45 -06:00
parent 3daf1d55e4
commit ed1d650450
3 changed files with 51 additions and 11 deletions

View File

@@ -1283,6 +1283,9 @@ static void handle_party_death() {
}
void screen_shift(int dx, int dy, bool& need_redraw) {
if(abs(dx) + abs(dy) == 0)
return;
if(recording){
std::map<std::string,std::string> info;
info["dx"] = boost::lexical_cast<std::string>(dx);
@@ -1292,8 +1295,15 @@ void screen_shift(int dx, int dy, bool& need_redraw) {
center.x += dx;
center.y += dy;
}
need_redraw = true;
// If configured to move the screen with arrow keys, do it and return true
bool handle_screen_shift(location delta, bool& need_redraw) {
if(scrollableModes.count(overall_mode) && get_bool_pref("DirectionalKeyScrolling", true)){
screen_shift(delta.x, delta.y, need_redraw);
return true;
}
return false;
}
void handle_print_pc_hp(int which_pc, bool& need_reprint) {
@@ -2249,6 +2259,13 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
{120,185},{150,185},{180,185},
{120,155},{150,155},{180,135}
};
// Screen shift deltas ordered to correspond with keypad keys
location screen_shift_delta[10] = {
{0,0},{-1,1},{0,1},{1,1},
{-1,0},{0,0},{1,0},
{-1,-1},{0,-1},{1,-1}
};
Key talk_chars[9] = {Key::L,Key::N,Key::J,Key::B,Key::S,Key::R,Key::D,Key::G,Key::A};
Key shop_chars[8] = {Key::A,Key::B,Key::C,Key::D,Key::E,Key::F,Key::G,Key::H};
@@ -2370,11 +2387,14 @@ bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
chr2 = Key::Z;
}
else {
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
are_done = handle_action(pass_event, fps_limiter);
return are_done;
if(!handle_screen_shift(screen_shift_delta[i], need_redraw)){
// Directional keys simulate directional click
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
are_done = handle_action(pass_event, fps_limiter);
return are_done;
}
}
}
}

View File

@@ -64,6 +64,7 @@ void handle_rename_pc();
void handle_begin_look(bool right_button, bool& need_redraw, bool& need_reprint);
void handle_look(location destination, bool right_button, eKeyMod mods, bool& need_redraw, bool& need_reprint);
void screen_shift(int dx, int dy, bool& need_redraw);
bool handle_screen_shift(location delta, bool& need_redraw);
void handle_rest(bool& need_redraw, bool& need_reprint);
void handle_spellcast(eSkill which_type, bool& did_something, bool& need_redraw, bool& need_reprint, bool record = true);
void handle_target_space(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);

View File

@@ -927,6 +927,18 @@ location terrain_click[8] = {
{120,185}, // west
{120,155}, // northwest
};
// Screen shift deltas ordered to correspond with eDirection
// TODO screen_shift_delta is duplicated (with different ordering) in boe.actions.cpp
location screen_shift_delta[8] = {
{0,-1}, // north
{1,-1}, // northeast
{1,0}, // east
{1,1}, // southeast
{0,1}, // south
{-1,1}, // southwest
{-1,0}, // west
{-1,-1}, // northwest
};
static void fire_delayed_key(Key code) {
bool isUpPressed = delayed_keys[Key::Up] > 0;
@@ -967,11 +979,18 @@ static void fire_delayed_key(Key code) {
}
if(dir != -1){
sf::Event pass_event = {sf::Event::MouseButtonPressed};
location pass_point = mainPtr.mapCoordsToPixel(terrain_click[dir], mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
queue_fake_event(pass_event);
bool need_redraw = false;
if(handle_screen_shift(screen_shift_delta[dir], need_redraw)){
if(need_redraw){
draw_terrain();
}
}else{
sf::Event pass_event = {sf::Event::MouseButtonPressed};
location pass_point = mainPtr.mapCoordsToPixel(terrain_click[dir], mainView);
pass_event.mouseButton.x = pass_point.x;
pass_event.mouseButton.y = pass_point.y;
queue_fake_event(pass_event);
}
}
}