Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASD movement in control options as checkbox #1243

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions assets/alice.csv
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ zoom_mode_centered;Centered;;;Centrado;;;;;;;;;x
zoom_speed_label;Zoom Acceleration
river_label;Rivers;;;Rios;;;;;;;;;x
mute_on_focus_lost_label;Mute On Focus Lost
wasd_for_map_movement_label;WASD for map movement
vassal_color_label;Vassal coloring
vassal_color_inherit;Inherit
vassal_color_same;Same
Expand Down
16 changes: 16 additions & 0 deletions assets/alice.gui
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ guiTypes = {
position = { 51 300 }
quadTextureSprite = "GFX_checkbox_default"
}
# WASD for map movement
instantTextBoxType = {
name = "wasd_for_map_movement_label"
position = { 78 320 }
text = "wasd_for_map_movement_label"
font = "Arial16"
borderSize = { 0 0 }
maxsize = { 236 18 }
orientation = "UPPER_LEFT"
format = left
}
guiButtonType = {
name = "wasd_for_map_movement_checkbox"
position = { 51 320 }
quadTextureSprite = "GFX_checkbox_default"
}
# Zoom style
instantTextBoxType = {
name = "zoom_mode_label"
Expand Down
24 changes: 10 additions & 14 deletions src/gamestate/system_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,14 @@ void state::on_key_down(virtual_key keycode, key_modifiers mod) {
keycode = sys::virtual_key::SUBTRACT;
else if(keycode == sys::virtual_key::PLUS)
keycode = sys::virtual_key::ADD;
if(cheat_data.wasd_move_cam) {
if(user_settings.wasd_for_map_movement) {
if(keycode == sys::virtual_key::W)
keycode = sys::virtual_key::UP;
else
if(keycode == sys::virtual_key::A)
else if(keycode == sys::virtual_key::A)
keycode = sys::virtual_key::LEFT;
else
if(keycode == sys::virtual_key::S)
else if(keycode == sys::virtual_key::S)
keycode = sys::virtual_key::DOWN;
else
if(keycode == sys::virtual_key::D)
else if(keycode == sys::virtual_key::D)
keycode = sys::virtual_key::RIGHT;
}
if(ui_state.root->impl_on_key_down(*this, keycode, mod) != ui::message_result::consumed) {
Expand Down Expand Up @@ -558,17 +555,14 @@ void state::on_key_up(virtual_key keycode, key_modifiers mod) {
if(keycode == virtual_key::CONTROL)
ui_state.ctrl_held_down = false;

if(cheat_data.wasd_move_cam) {
if(user_settings.wasd_for_map_movement) {
if(keycode == sys::virtual_key::W)
keycode = sys::virtual_key::UP;
else
if(keycode == sys::virtual_key::A)
else if(keycode == sys::virtual_key::A)
keycode = sys::virtual_key::LEFT;
else
if(keycode == sys::virtual_key::S)
else if(keycode == sys::virtual_key::S)
keycode = sys::virtual_key::DOWN;
else
if(keycode == sys::virtual_key::D)
else if(keycode == sys::virtual_key::D)
keycode = sys::virtual_key::RIGHT;
}

Expand Down Expand Up @@ -2236,6 +2230,7 @@ void state::save_user_settings() const {
US_SAVE(zoom_speed);
US_SAVE(mute_on_focus_lost);
US_SAVE(diplomatic_message_popup);
US_SAVE(wasd_for_map_movement);
#undef US_SAVE

simple_fs::write_file(settings_location, NATIVE("user_settings.dat"), &buffer[0], uint32_t(ptr - buffer));
Expand Down Expand Up @@ -2299,6 +2294,7 @@ void state::load_user_settings() {
US_LOAD(zoom_speed);
US_LOAD(mute_on_focus_lost);
US_LOAD(diplomatic_message_popup);
US_LOAD(wasd_for_map_movement);
#undef US_LOAD
} while(false);

Expand Down
2 changes: 1 addition & 1 deletion src/gamestate/system_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ struct user_settings_s {
float zoom_speed = 20.f;
bool mute_on_focus_lost = true;
bool diplomatic_message_popup = false;
bool wasd_for_map_movement = false;
};

struct global_scenario_data_s { // this struct holds miscellaneous global properties of the scenario
Expand All @@ -388,7 +389,6 @@ struct cheat_data_s {
bool always_allow_reforms = false;
bool always_accept_deals = false;
bool show_province_id_tooltip = false;
bool wasd_move_cam = false;
bool instant_army = false;
bool instant_industry = false;
std::vector<dcon::nation_id> instant_research_nations;
Expand Down
5 changes: 3 additions & 2 deletions src/gui/gui_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,9 @@ void ui::console_edit::edit_box_enter(sys::state& state, std::string_view s) noe
}
case command_info::type::wasd:
{
state.cheat_data.wasd_move_cam = not state.cheat_data.wasd_move_cam;
log_to_console(state, parent, state.cheat_data.wasd_move_cam ? "\x02" : "\x01");
state.user_settings.wasd_for_map_movement = not state.user_settings.wasd_for_map_movement;
log_to_console(state, parent, state.user_settings.wasd_for_map_movement ? "\x02" : "\x01");
state.save_user_settings();
break;
}
case command_info::type::next_song:
Expand Down
7 changes: 7 additions & 0 deletions src/gui/gui_main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ void spoilers_checkbox::button_action(sys::state& state) noexcept {
bool spoilers_checkbox::is_active(sys::state& state) noexcept {
return state.user_settings.spoilers;
}
void wasd_for_map_movement_checkbox::button_action(sys::state& state) noexcept {
state.user_settings.wasd_for_map_movement = !state.user_settings.wasd_for_map_movement;
send(state, parent, notify_setting_update{});
}
bool wasd_for_map_movement_checkbox::is_active(sys::state& state) noexcept {
return state.user_settings.wasd_for_map_movement;
}
void dm_popup_checkbox::button_action(sys::state& state) noexcept {
state.user_settings.diplomatic_message_popup = !state.user_settings.diplomatic_message_popup;
send(state, parent, notify_setting_update{});
Expand Down
7 changes: 7 additions & 0 deletions src/gui/gui_main_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ class spoilers_checkbox : public checkbox_button {
void button_action(sys::state& state) noexcept override;
bool is_active(sys::state& state) noexcept override;
};
class wasd_for_map_movement_checkbox : public checkbox_button {
public:
void button_action(sys::state& state) noexcept override;
bool is_active(sys::state& state) noexcept override;
};
class dm_popup_checkbox : public checkbox_button {
public:
void button_action(sys::state& state) noexcept override;
Expand Down Expand Up @@ -278,6 +283,8 @@ class controls_menu_window : public window_element_base {
return make_element_by_type<zoom_speed_scrollbar>(state, id);
} else if(name == "mouse_edge_scrolling_checkbox") {
return make_element_by_type<map_mouse_edge_scrolling>(state, id);
} else if(name == "wasd_for_map_movement_checkbox") {
return make_element_by_type<wasd_for_map_movement_checkbox>(state, id);
} else {
return nullptr;
}
Expand Down
Loading