Skip to content

Commit

Permalink
record and replay mods on startup buttons. fix #394
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios authored and CelticMinstrel committed Aug 9, 2024
1 parent f8d319c commit 4e6306b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
6 changes: 1 addition & 5 deletions src/dialogxml/dialogs/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,11 +669,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) {
}
break;
case sf::Event::MouseButtonPressed:
key.mod = mod_none;
if(kb.isCtrlPressed()) key.mod += mod_ctrl;
if(kb.isMetaPressed()) key.mod += mod_ctrl;
if(kb.isAltPressed()) key.mod += mod_alt;
if(kb.isShiftPressed()) key.mod += mod_shift;
key.mod = current_key_mod();
where = {(int)(currentEvent.mouseButton.x / ui_scale()), (int)(currentEvent.mouseButton.y / ui_scale())};
process_click(where, key.mod);
break;
Expand Down
10 changes: 10 additions & 0 deletions src/dialogxml/keycodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//#include "mathutil.hpp"
//#include "prefs.hpp"
//#include "cursors.hpp"
#include "keymods.hpp"

eKeyMod operator + (eKeyMod lhs, eKeyMod rhs){
if(lhs == rhs) return lhs;
Expand Down Expand Up @@ -116,3 +117,12 @@ unsigned char removeShift(unsigned char c){
};
return afterUnShift[c - ' '];
}

eKeyMod current_key_mod() {
eKeyMod mod = mod_none;
if(kb.isCtrlPressed()) mod += mod_ctrl;
if(kb.isMetaPressed()) mod += mod_ctrl;
if(kb.isAltPressed()) mod += mod_alt;
if(kb.isShiftPressed()) mod += mod_shift;
return mod;
}
2 changes: 2 additions & 0 deletions src/dialogxml/keycodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,6 @@ unsigned char applyShift(unsigned char c);
/// Removes the shift key from the given character (assumes US keyboard layout)
unsigned char removeShift(unsigned char c);

eKeyMod current_key_mod();

#endif
3 changes: 2 additions & 1 deletion src/game/boe.actions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <SFML/Window/Event.hpp>
#include "location.hpp"
#include "dialogxml/keycodes.hpp"

void init_screen_locs();
bool prime_time();
Expand Down Expand Up @@ -36,7 +37,7 @@ short count_walls(location loc);
bool is_sign(ter_num_t ter);
bool check_for_interrupt();

void handle_startup_button_click(eStartButton btn);
void handle_startup_button_click(eStartButton btn, eKeyMod mods);
void handle_switch_pc(short which_pc, bool& need_redraw, bool& need_reprint);
void handle_switch_pc_items(short which_pc, bool& need_redraw);
void handle_equip_item(short item_hit, bool& need_redraw);
Expand Down
6 changes: 4 additions & 2 deletions src/game/boe.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ void replay_next_action() {
std::string t = next_action.Value();

if(overall_mode == MODE_STARTUP && t == "startup_button_click"){
eStartButton btn = static_cast<eStartButton>(std::stoi(next_action.GetText()));
handle_startup_button_click(btn);
auto info = info_from_action(next_action);
eStartButton btn = static_cast<eStartButton>(std::stoi(info["btn"]));
eKeyMod mods = static_cast<eKeyMod>(std::stoi(info["mods"]));
handle_startup_button_click(btn, mods);
}else if(t == "load_party"){
decode_file(next_action.GetText(), tempDir / "temp.exg");
load_party(tempDir / "temp.exg", univ);
Expand Down
1 change: 1 addition & 0 deletions src/game/boe.main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ int main(int argc, char* argv[]);
void update_everything();
void redraw_everything();
void Mouse_Pressed(const sf::Event&);
eKeyMod current_key_mod();
void close_program();
void change_cursor(location where_curs);
void set_up_apple_events();
Expand Down
16 changes: 12 additions & 4 deletions src/game/boe.startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ extern sf::View mainView;

enum_map(eStartButton, rectangle) startup_button;

void handle_startup_button_click(eStartButton btn) {
void handle_startup_button_click(eStartButton btn, eKeyMod mods) {
if(recording){
std::map<std::string, std::string> info;

std::ostringstream sstr;
sstr << btn;
record_action("startup_button_click", sstr.str());
info["btn"] = sstr.str();

sstr.str("");
sstr << mods;
info["mods"] = sstr.str();

record_action("startup_button_click", info);
}

std::string scen_name;
Expand Down Expand Up @@ -78,7 +86,7 @@ void handle_startup_button_click(eStartButton btn) {

case STARTBTN_JOIN:
if(!party_in_memory) {
if(kb.isAltPressed()) {
if(mod_contains(mods, mod_alt)) {
force_party = true;
start_new_game(true);
} else {
Expand Down Expand Up @@ -114,7 +122,7 @@ bool handle_startup_press(location the_point) {
for(auto btn : startup_button.keys()) {
if(btn == eStartButton::STARTBTN_SCROLL) continue;
if(the_point.in(startup_button[btn])) {
handle_startup_button_click(btn);
handle_startup_button_click(btn, current_key_mod());
}
}
return false;
Expand Down

0 comments on commit 4e6306b

Please sign in to comment.