Skip to content

Commit

Permalink
bug: add popup for jump into chasm confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jun 16, 2023
1 parent a23fc3d commit f6e8bf7
Show file tree
Hide file tree
Showing 22 changed files with 145 additions and 92 deletions.
2 changes: 1 addition & 1 deletion python/things/dungeon/chasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def chasm_init(name, text_long_name, tiles=[]):
my.is_biome_chasms(self, True)
my.is_biome_dungeon(self, True)
my.is_chasm(self, True)
my.is_cursor_can_hover_over_x2_click(self, True)
my.is_cursor_can_hover_over_needs_confirm(self, True)
my.is_cursor_path_hazard(self, True)
my.is_described_when_hovering_over(self, True)
my.is_hazard(self, True)
Expand Down
2 changes: 1 addition & 1 deletion python/things/dungeon/lava.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def lava_init(name, text_long_name, tiles=[]):
my.is_biome_chasms(self, True)
my.is_biome_dungeon(self, True)
my.is_biome_lava(self, True)
my.is_cursor_can_hover_over_x2_click(self, True)
my.is_cursor_can_hover_over_needs_confirm(self, True)
my.is_cursor_path_hazard(self, True)
my.is_described_when_hovering_over(self, True)
my.is_flat(self, True)
Expand Down
2 changes: 0 additions & 2 deletions src/game_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,8 +1242,6 @@ std::istream &operator>>(std::istream &in, Bits< class Game & > my)
in >> bits(my.t.started);
in >> bits(my.t.things_are_moving);
in >> bits(my.t.player_is_ready_for_messages);
in >> bits(my.t.warning_shown_jump_into_chasm);
in >> bits(my.t.warning_shown_jump_into_lava);
in >> bits(MAP_WIDTH);
in >> bits(MAP_HEIGHT);

Expand Down
66 changes: 36 additions & 30 deletions src/game_mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ static uint8_t game_mouse_down_(int x, int y, uint32_t button)
return false;
}

//
// Waiting on move confirmation
//
if (wid_warning_window) {
return true;
}

if (game->state == Game::STATE_CHOOSING_LEVEL) {
DBG2("Game mouse down; choosing level");
return false;
Expand Down Expand Up @@ -287,40 +294,31 @@ static uint8_t game_mouse_down_(int x, int y, uint32_t button)
//
// If hovering over a double click thing then don't jump in unless the user really means it.
//
if (! wid_mouse_two_clicks) {
auto to = level->cursor->curr_at;
FOR_ALL_NON_INTERNAL_THINGS(level, t, to.x, to.y)
{
if (t->is_cursor_can_hover_over_x2_click()) {
IF_DEBUG2 { player->log("Needs double click"); }
TOPCON("Double click to jump into the abyss.");
if (level->is_chasm(to)) {
if (! game->warning_shown_jump_into_chasm) {
game->warning_shown_jump_into_chasm = true;
std::string msg
= "Double click or press '" + ::to_string(game->config.key_jump) + "' to leap into a chasm.";
wid_warning(msg);
}
} else if (level->is_lava(to)) {
TOPCON("Double click to jump into the lava.");
if (! game->warning_shown_jump_into_lava) {
game->warning_shown_jump_into_lava = true;
std::string msg
= "Double click or press '" + ::to_string(game->config.key_jump) + "' to leap into lava.";
wid_warning(msg);
}
} else {
TOPCON("Double click to move to move onto that.");
auto to = level->cursor->curr_at;
FOR_ALL_NON_INTERNAL_THINGS(level, t, to.x, to.y)
{
if (t->is_cursor_can_hover_over_needs_confirm()) {
IF_DEBUG2 { player->log("Needs confirm"); }

if (level->is_chasm(to)) {
if (! player->is_ethereal() && ! player->is_floating() && ! player->is_flying()) {
std::string msg = "Do you really want to leap into a chasm.";
game->warning_popup_exists_for_move_confirm = to;
wid_warning(msg);
return true;
}
} else if (level->is_lava(to)) {
if (! player->is_immune_to_fire() && ! player->is_ethereal() && ! player->is_floating()
&& ! player->is_flying()) {
std::string msg = "Do you really want to leap into lava.";
game->warning_popup_exists_for_move_confirm = to;
wid_warning(msg);
return true;
}
return true;
}
}
FOR_ALL_THINGS_END()
}

if (wid_warning_window) {
return true;
}
FOR_ALL_THINGS_END()

//
// Have we moved close enough to collect? Do this after the double
Expand Down Expand Up @@ -379,6 +377,14 @@ static uint8_t game_mouse_motion_(int x, int y, int relx, int rely, int wheelx,
return false;
}

//
// If move confirmation exists, do not remake the cursor or the path will end up
// under the Yes buttion
//
if (wid_warning_window) {
return false;
}

//
// Make the cursor visible once we enter a level.
//
Expand Down
2 changes: 0 additions & 2 deletions src/game_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,6 @@ std::ostream &operator<<(std::ostream &out, Bits< const class Game & > const my)
out << bits(my.t.started);
out << bits(my.t.things_are_moving);
out << bits(my.t.player_is_ready_for_messages);
out << bits(my.t.warning_shown_jump_into_chasm);
out << bits(my.t.warning_shown_jump_into_lava);
out << bits(MAP_WIDTH);
out << bits(MAP_HEIGHT);

Expand Down
8 changes: 8 additions & 0 deletions src/level_cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "my_wid_bag.hpp"
#include "my_wid_popups.hpp"
#include "my_wid_thing_info.hpp"
#include "my_wid_warning.hpp"

void Level::cursor_warp_check(void)
{
Expand Down Expand Up @@ -155,6 +156,13 @@ void Level::cursor_recreate(point curr_at)
return;
}

//
// If move confirmation is present, do not recreate the cursor
//
if (wid_warning_window) {
return;
}

if (game->robot_mode) {
return;
}
Expand Down
10 changes: 9 additions & 1 deletion src/level_cursor_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "my_game.hpp"
#include "my_thing.hpp"
#include "my_wid_thing_info.hpp"
#include "my_wid_warning.hpp"

void Level::cursor_find_on_visible_things(const int16_t minx, const int16_t miny, const int16_t maxx,
const int16_t maxy)
Expand Down Expand Up @@ -51,6 +52,13 @@ void Level::cursor_find_on_visible_things(const int16_t minx, const int16_t miny
return;
}

//
// If move confirmation is present, do not recreate the cursor
//
if (wid_warning_window) {
return;
}

dbg3("Cursor find on visible things");
TRACE_AND_INDENT();
pcg_random_allowed++;
Expand All @@ -64,7 +72,7 @@ void Level::cursor_find_on_visible_things(const int16_t minx, const int16_t miny
if (cursor) {
FOR_ALL_NON_INTERNAL_THINGS(this, t, to.x, to.y)
{
if (t->is_cursor_can_hover_over_x2_click()) {
if (t->is_cursor_can_hover_over_needs_confirm()) {
goto done;
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/my_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,6 @@ class Game
//
bool things_are_moving {};

//
// Player warnings
//
bool warning_shown_jump_into_chasm {};
bool warning_shown_jump_into_lava {};

//
// Player ready to see console messages
//
Expand Down Expand Up @@ -313,6 +307,11 @@ class Game
// v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v
/////////////////////////////////////////////////////////////////////////

//
// Player warnings on moving onto bad terrain.
//
point warning_popup_exists_for_move_confirm = point(-1, -1);

//
// Game is paused choosing a level? Prrvents the level tick from running.
//
Expand Down
2 changes: 1 addition & 1 deletion src/my_py_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ PyObject *level_is_crushable_at(PyObject *obj, PyObject *args, PyObject *keywds)
PyObject *level_is_crystal_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_can_hover_over_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_can_hover_over_x2_click_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_can_hover_over_needs_confirm_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_path_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_path_blocker_at(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *level_is_cursor_path_hazard_at(PyObject *obj, PyObject *args, PyObject *keywds);
Expand Down
2 changes: 1 addition & 1 deletion src/my_py_thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ PyObject *thing_is_critical_to_level(PyObject *obj, PyObject *args, PyObject *ke
PyObject *thing_is_crushable(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_crystal(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_can_hover_over(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_can_hover_over_x2_click(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_can_hover_over_needs_confirm(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_path_blocker(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_path_hazard(PyObject *obj, PyObject *args, PyObject *keywds);
PyObject *thing_is_cursor_path(PyObject *obj, PyObject *args, PyObject *keywds);
Expand Down
2 changes: 1 addition & 1 deletion src/my_py_tp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ TP_SET_PROTO(is_crushable)
TP_SET_PROTO(is_crystal)
TP_SET_PROTO(is_cursor)
TP_SET_PROTO(is_cursor_can_hover_over)
TP_SET_PROTO(is_cursor_can_hover_over_x2_click)
TP_SET_PROTO(is_cursor_can_hover_over_needs_confirm)
TP_SET_PROTO(is_cursor_path)
TP_SET_PROTO(is_cursor_path_blocker)
TP_SET_PROTO(is_cursor_path_hazard)
Expand Down
2 changes: 1 addition & 1 deletion src/my_thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ typedef class Thing_
int is_crushable(void);
int is_crystal(void);
int is_cursor_can_hover_over(void);
int is_cursor_can_hover_over_x2_click(void);
int is_cursor_can_hover_over_needs_confirm(void);
int is_cursor_path_blocker(void);
int is_cursor_path_hazard(void);
int is_cursor_path(void);
Expand Down
6 changes: 3 additions & 3 deletions src/my_thing_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ class Tp
int _is_crystal {};
int _is_cursor {};
int _is_cursor_can_hover_over {};
int _is_cursor_can_hover_over_x2_click {};
int _is_cursor_can_hover_over_needs_confirm {};
int _is_cursor_path {};
int _is_cursor_path_blocker {};
int _is_cursor_path_hazard {};
Expand Down Expand Up @@ -1692,7 +1692,7 @@ class Tp
int is_crushable(void) const;
int is_crystal(void) const;
int is_cursor_can_hover_over(void) const;
int is_cursor_can_hover_over_x2_click(void) const;
int is_cursor_can_hover_over_needs_confirm(void) const;
int is_cursor_path_blocker(void) const;
int is_cursor_path_hazard(void) const;
int is_cursor_path(void) const;
Expand Down Expand Up @@ -2441,7 +2441,7 @@ class Tp
void is_crushable_set(int v);
void is_crystal_set(int v);
void is_cursor_can_hover_over_set(int v);
void is_cursor_can_hover_over_x2_click_set(int v);
void is_cursor_can_hover_over_needs_confirm_set(int v);
void is_cursor_path_blocker_set(int v);
void is_cursor_path_hazard_set(int v);
void is_cursor_path_set(int v);
Expand Down
2 changes: 1 addition & 1 deletion src/py_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ LEVEL_BODY_GET_BOOL_AT(level_is_crushable_at, is_crushable)
LEVEL_BODY_GET_BOOL_AT(level_is_crystal_at, is_crystal)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_at, is_cursor)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_can_hover_over_at, is_cursor_can_hover_over)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_can_hover_over_x2_click_at, is_cursor_can_hover_over_x2_click)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_can_hover_over_needs_confirm_at, is_cursor_can_hover_over_needs_confirm)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_path_at, is_cursor_path)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_path_blocker_at, is_cursor_path_blocker)
LEVEL_BODY_GET_BOOL_AT(level_is_cursor_path_hazard_at, is_cursor_path_hazard)
Expand Down
2 changes: 1 addition & 1 deletion src/py_thing_get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ THING_BODY_GET_BOOL(thing_is_critical_to_level, is_critical_to_level)
THING_BODY_GET_BOOL(thing_is_crushable, is_crushable)
THING_BODY_GET_BOOL(thing_is_crystal, is_crystal)
THING_BODY_GET_BOOL(thing_is_cursor_can_hover_over, is_cursor_can_hover_over)
THING_BODY_GET_BOOL(thing_is_cursor_can_hover_over_x2_click, is_cursor_can_hover_over_x2_click)
THING_BODY_GET_BOOL(thing_is_cursor_can_hover_over_needs_confirm, is_cursor_can_hover_over_needs_confirm)
THING_BODY_GET_BOOL(thing_is_cursor, is_cursor)
THING_BODY_GET_BOOL(thing_is_cursor_path_blocker, is_cursor_path_blocker)
THING_BODY_GET_BOOL(thing_is_cursor_path_hazard, is_cursor_path_hazard)
Expand Down
2 changes: 1 addition & 1 deletion src/py_tp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ TP_BODY_SET_INT(is_crushable)
TP_BODY_SET_INT(is_crystal)
TP_BODY_SET_INT(is_cursor)
TP_BODY_SET_INT(is_cursor_can_hover_over)
TP_BODY_SET_INT(is_cursor_can_hover_over_x2_click)
TP_BODY_SET_INT(is_cursor_can_hover_over_needs_confirm)
TP_BODY_SET_INT(is_cursor_path)
TP_BODY_SET_INT(is_cursor_path_blocker)
TP_BODY_SET_INT(is_cursor_path_hazard)
Expand Down
4 changes: 2 additions & 2 deletions src/python_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ static PyMethodDef python_c_METHODS[] = {
MY_ADD_PYTHON_FUNCTION(thing_is_crystal),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_can_hover_over),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_can_hover_over_x2_click),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_can_hover_over_needs_confirm),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_path),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_path_blocker),
MY_ADD_PYTHON_FUNCTION(thing_is_cursor_path_hazard),
Expand Down Expand Up @@ -1372,7 +1372,7 @@ static PyMethodDef python_c_METHODS[] = {
MY_ADD_PYTHON_TP_FUNCTION(is_crystal),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_can_hover_over),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_can_hover_over_x2_click),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_can_hover_over_needs_confirm),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_path),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_path_blocker),
MY_ADD_PYTHON_TP_FUNCTION(is_cursor_path_hazard),
Expand Down

0 comments on commit f6e8bf7

Please sign in to comment.