Skip to content

Commit

Permalink
One Click Highlight - SHIFT to get DK2+ style marking (#1016)
Browse files Browse the repository at this point in the history
Use SHIFT and LMB to drag an area of slabs to tag/untag
Hold SHIFT and RMB to drag an area of slabs to tag/untag, and then click LMB to tag/untag the selected slabs

Also resolved some build warnings
  • Loading branch information
eddebaby authored Apr 20, 2021
1 parent 8fb49ec commit 3f11642
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/config_campaigns.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ short parse_campaign_common_blocks(struct GameCampaign *campgn,char *buf,long le
else {
k = atoi(word_buf);
if (k > 0) {
char* newname = get_string(STRINGS_MAX+k);
const char* newname = get_string(STRINGS_MAX+k);
if (strcasecmp(newname,"") != 0) {
LbStringCopy(campgn->name,newname,LINEMSG_SIZE); // use the index provided in the config file to get a specific UI string
}
Expand Down
3 changes: 3 additions & 0 deletions src/dungeon_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ struct DungeonAdd
unsigned long evil_creatures_converted;
unsigned long good_creatures_converted;
TbBool one_click_lock_cursor;
TbBool ignore_next_PCtr_RBtnRelease;
TbBool ignore_next_PCtr_LBtnRelease;
long swap_to_untag_mode; // 0 = no, 1 = maybe, 2= yes, -1 = disable
};
/******************************************************************************/
extern struct Dungeon bad_dungeon;
Expand Down
13 changes: 9 additions & 4 deletions src/front_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ void update_gui_layer()
// Determine the current/correct GUI Layer to use at this moment

struct PlayerInfo* player = get_my_player();
struct DungeonAdd *dungeonadd = get_dungeonadd(player->id_number);
if ( ((player->work_state == PSt_Sell) || (player->work_state == PSt_BuildRoom) || (render_roomspace.highlight_mode)) &&
(is_game_key_pressed(Gkey_BestRoomSpace, NULL, true) || is_game_key_pressed(Gkey_SquareRoomSpace, NULL, true)) )
{
Expand Down Expand Up @@ -194,6 +193,12 @@ int is_game_key_pressed(long key_id, long *val, TbBool ignore_mods)
{
return 0;
}
if ( (key_id == Gkey_CrtrContrlMod) && (
(settings.kbkeys[Gkey_CrtrContrlMod].code == settings.kbkeys[Gkey_BestRoomSpace].code) ||
(settings.kbkeys[Gkey_CrtrContrlMod].code == settings.kbkeys[Gkey_SquareRoomSpace].code) ) )
{
return 0;
}
}
if ((key_id == Gkey_RotateMod) || (key_id == Gkey_SpeedMod) || (key_id == Gkey_CrtrContrlMod) || (key_id == Gkey_CrtrQueryMod))
{
Expand Down Expand Up @@ -1818,7 +1823,7 @@ TbBool get_player_coords_and_context(struct Coord3d *pos, unsigned char *context
unsigned int slb_y = subtile_slab_fast(y);
struct SlabMap* slb = get_slabmap_block(slb_x, slb_y);
struct SlabAttr* slbattr = get_slab_attrs(slb);
if (slab_kind_is_door(slb->kind) && (slabmap_owner(slb) == player->id_number))
if (slab_kind_is_door(slb->kind) && (slabmap_owner(slb) == player->id_number) && (dungeonadd->one_click_lock_cursor == 0))
{
*context = CSt_DoorKey;
pos->x.val = (x<<8) + top_pointed_at_frac_x;
Expand All @@ -1836,13 +1841,13 @@ TbBool get_player_coords_and_context(struct Coord3d *pos, unsigned char *context
pos->x.val = (x<<8) + top_pointed_at_frac_x;
pos->y.val = (y<<8) + top_pointed_at_frac_y;
} else
if ((slb_x >= map_tiles_x) || (slb_y >= map_tiles_y))
if (((slb_x >= map_tiles_x) || (slb_y >= map_tiles_y)) && (dungeonadd->one_click_lock_cursor == 0))
{
*context = CSt_DefaultArrow;
pos->x.val = (block_pointed_at_x<<8) + pointed_at_frac_x;
pos->y.val = (block_pointed_at_y<<8) + pointed_at_frac_y;
} else
if (((slbattr->block_flags & (SlbAtFlg_Filled|SlbAtFlg_Digable|SlbAtFlg_Valuable)) != 0) || dungeonadd->one_click_lock_cursor == 1)
if (((slbattr->block_flags & (SlbAtFlg_Filled|SlbAtFlg_Digable|SlbAtFlg_Valuable)) != 0) || (dungeonadd->one_click_lock_cursor == 1))
{
*context = CSt_PickAxe;
pos->x.val = (x<<8) + top_pointed_at_frac_x;
Expand Down
7 changes: 5 additions & 2 deletions src/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,15 @@ void create_message_box(const char *title, const char *line1, const char *line2,

short game_is_busy_doing_gui(void)
{
struct PlayerInfo *player;
player = get_my_player();
struct DungeonAdd *dungeonadd = get_dungeonadd(player->id_number);
if (dungeonadd->one_click_lock_cursor)
return false;
if (!busy_doing_gui)
return false;
if (battle_creature_over <= 0)
return true;
struct PlayerInfo *player;
player = get_my_player();
PowerKind pwkind;
pwkind = 0;
if (player->work_state < PLAYER_STATES_COUNT)
Expand Down
4 changes: 3 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3102,7 +3102,9 @@ void tag_cursor_blocks_dig(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlC
{
SYNCDBG(7,"Starting for player %d at subtile (%d,%d)",(int)plyr_idx,(int)stl_x,(int)stl_y);
//_DK_tag_cursor_blocks_dig(plyr_idx, stl_x, stl_y, full_slab);
struct PlayerInfo* player = get_player(plyr_idx);
struct DungeonAdd* dungeonadd = get_dungeonadd(plyr_idx);
struct Packet* pckt = get_packet_direct(player->packet_num);
MapSlabCoord slb_x = subtile_slab_fast(stl_x);
MapSlabCoord slb_y = subtile_slab_fast(stl_y);
int floor_height_z = floor_height_for_volume_box(plyr_idx, slb_x, slb_y);
Expand All @@ -3124,7 +3126,7 @@ void tag_cursor_blocks_dig(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlC
{
line_color = SLC_YELLOW;
}
if (is_my_player_number(plyr_idx) && !game_is_busy_doing_gui() && (game.small_map_state != 2))
if (is_my_player_number(plyr_idx) && !game_is_busy_doing_gui() && (game.small_map_state != 2) && ((pckt->control_flags & PCtr_MapCoordsValid) != 0))
{
map_volume_box.visible = 1;
map_volume_box.color = line_color;
Expand Down
73 changes: 55 additions & 18 deletions src/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ TbBool process_dungeon_power_hand_state(long plyr_idx)
return false;
}
struct Thing* thing = get_nearest_thing_for_hand_or_slap(plyr_idx, x, y);
if (!thing_is_invalid(thing))
if (!thing_is_invalid(thing) && (dungeonadd->one_click_lock_cursor == 0))
{
SYNCDBG(19,"Thing %d under hand at (%d,%d)",(int)thing->index,(int)thing->mappos.x.stl.num,(int)thing->mappos.y.stl.num);
if (player->hand_thing_idx == 0)
Expand Down Expand Up @@ -689,7 +689,8 @@ void set_tag_untag_mode(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlCoor
struct PlayerInfo* player = get_player(plyr_idx);
// The commented out section is the old way, this check is now performed as part of keeper_highlight_roomspace() in roomspace.cabs
// which sets render_roomspace.untag_mode
/*i = get_subtile_number(stl_slab_center_subtile(stl_x),stl_slab_center_subtile(stl_y));
/*long i;
i = get_subtile_number(stl_slab_center_subtile(stl_x),stl_slab_center_subtile(stl_y));
if (find_from_task_list(plyr_idx,i) != -1)
player->allocflags |= PlaF_ChosenSlabHasActiveTask;
else
Expand All @@ -704,8 +705,6 @@ void set_tag_untag_mode(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlCoor
TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
{
struct Thing *thing;

long i;
struct PlayerInfo* player = get_player(plyr_idx);
struct Dungeon* dungeon = get_players_dungeon(player);
struct DungeonAdd* dungeonadd = get_dungeonadd(plyr_idx);
Expand All @@ -714,8 +713,6 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
MapCoord y = ((unsigned short)pckt->pos_y);
MapSubtlCoord stl_x = coord_subtile(x);
MapSubtlCoord stl_y = coord_subtile(y);
MapSubtlCoord cx = stl_slab_starting_subtile(stl_x);
MapSubtlCoord cy = stl_slab_starting_subtile(stl_y);
if ((pckt->control_flags & PCtr_LBtnAnyAction) == 0)
player->secondary_cursor_state = CSt_DefaultArrow;
player->primary_cursor_state = (unsigned short)(pckt->additional_packet_values & PCAdV_ContextMask) >> 1; // get current cursor state from pckt->additional_packet_values
Expand Down Expand Up @@ -786,15 +783,18 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
}
if (player->cursor_button_down != 0)
{
if (player->primary_cursor_state == player->secondary_cursor_state)
if (!render_roomspace.drag_mode) // allow drag and click to not place on LMB hold
{
if (player->secondary_cursor_state == CSt_PickAxe)
{
keeper_highlight_roomspace(plyr_idx, &render_roomspace, 0);
} else
if ((player->secondary_cursor_state == CSt_PowerHand) && ((player->additional_flags & PlaAF_NoThingUnderPowerHand) != 0))
if (player->primary_cursor_state == player->secondary_cursor_state)
{
keeper_highlight_roomspace(plyr_idx, &render_roomspace, 0);
if (player->secondary_cursor_state == CSt_PickAxe)
{
keeper_highlight_roomspace(plyr_idx, &render_roomspace, 0);
} else
if ((player->secondary_cursor_state == CSt_PowerHand) && ((player->additional_flags & PlaAF_NoThingUnderPowerHand) != 0))
{
keeper_highlight_roomspace(plyr_idx, &render_roomspace, 0);
}
}
}
unset_packet_control(pckt, PCtr_LBtnRelease);
Expand All @@ -809,6 +809,15 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
{
if (player->secondary_cursor_state == CSt_DefaultArrow)
player->secondary_cursor_state = player->primary_cursor_state;
if (dungeonadd->ignore_next_PCtr_LBtnRelease)
{
dungeonadd->ignore_next_PCtr_LBtnRelease = false;
if ((pckt->control_flags & PCtr_RBtnHeld) == 0)
{
player->cursor_button_down = 0;
}
unset_packet_control(pckt, PCtr_LBtnRelease);
} else
if (player->cursor_button_down != 0)
{
thing = thing_get(player->thing_under_hand);
Expand Down Expand Up @@ -850,7 +859,7 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
} else
if (player->secondary_cursor_state == player->primary_cursor_state)
{
if (player->primary_cursor_state == CSt_PickAxe)
if ((player->primary_cursor_state == CSt_PickAxe) || ((player->primary_cursor_state == CSt_PowerHand) && render_roomspace.drag_mode))
{
keeper_highlight_roomspace(plyr_idx, &render_roomspace, 9);
} else
Expand All @@ -865,19 +874,40 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
if ((pckt->control_flags & PCtr_RBtnHeld) == 0)
{
player->cursor_button_down = 0;
dungeonadd->one_click_lock_cursor = 0;
}
unset_packet_control(pckt, PCtr_LBtnRelease);
dungeonadd->one_click_lock_cursor = 0;
if (render_roomspace.drag_mode)
{
if ((pckt->control_flags & PCtr_RBtnHeld) == 0)
{
render_roomspace.drag_mode = false;
}
else
{
render_roomspace.untag_mode = !render_roomspace.untag_mode;
set_tag_untag_mode(plyr_idx, stl_x, stl_y);
}
}
player->secondary_cursor_state = CSt_DefaultArrow;
player->additional_flags &= ~PlaAF_NoThingUnderPowerHand;
}
}

if ((pckt->control_flags & PCtr_RBtnRelease) != 0)
{
if (dungeonadd->ignore_next_PCtr_RBtnRelease && (dungeonadd->one_click_lock_cursor == 0))
{
dungeonadd->ignore_next_PCtr_RBtnRelease = false;
if ((pckt->control_flags & PCtr_LBtnHeld) == 0)
{
player->cursor_button_down = 0;
}
unset_packet_control(pckt, PCtr_RBtnRelease);
} else
if (player->cursor_button_down != 0)
{
if (!power_hand_is_empty(player))
if (!power_hand_is_empty(player) && (dungeonadd->one_click_lock_cursor == 0))
{
if (dump_first_held_thing_on_map(player->id_number, stl_x, stl_y, 1)) {
if ((pckt->control_flags & PCtr_LBtnHeld) == 0)
Expand All @@ -888,18 +918,24 @@ TbBool process_dungeon_control_packet_dungeon_control(long plyr_idx)
}
} else
{
if (player->primary_cursor_state == CSt_PowerHand) {
if (player->primary_cursor_state == CSt_PowerHand && (dungeonadd->one_click_lock_cursor == 0)) {
thing = get_nearest_thing_for_slap(plyr_idx, subtile_coord_center(stl_x), subtile_coord_center(stl_y));
magic_use_available_power_on_thing(plyr_idx, PwrK_SLAP, 0, stl_x, stl_y, thing, PwMod_Default);
}
if ((pckt->control_flags & PCtr_LBtnHeld) == 0)
{
player->cursor_button_down = 0;
dungeonadd->one_click_lock_cursor = 0;
}
unset_packet_control(pckt, PCtr_RBtnRelease);
}
}
}
if (player->cursor_button_down == 0 || dungeonadd->one_click_lock_cursor == 0)
{
//if (untag_or_tag_completed_or_cancelled)
dungeonadd->swap_to_untag_mode = 0; // no
}
return true;
}

Expand All @@ -908,6 +944,7 @@ TbBool process_dungeon_control_packet_clicks(long plyr_idx)
struct Thing *thing;
PowerKind pwkind;
struct PlayerInfo* player = get_player(plyr_idx);
struct DungeonAdd *dungeonadd = get_dungeonadd(plyr_idx);
struct Packet* pckt = get_packet_direct(player->packet_num);
SYNCDBG(6,"Starting for player %d state %s",(int)plyr_idx,player_state_code_name(player->work_state));
player->full_slab_cursor = 1;
Expand Down Expand Up @@ -1824,7 +1861,7 @@ TbBool process_dungeon_control_packet_clicks(long plyr_idx)
}
if (((pckt->control_flags & PCtr_HeldAnyButton) != 0) && (influence_own_creatures))
{
if ((player->secondary_cursor_state == CSt_DefaultArrow) || (player->secondary_cursor_state == CSt_PowerHand))
if (((player->secondary_cursor_state == CSt_DefaultArrow) || (player->secondary_cursor_state == CSt_PowerHand)) && (dungeonadd->one_click_lock_cursor == 0))
stop_creatures_around_hand(plyr_idx, stl_x, stl_y);
}
return ret;
Expand Down
1 change: 1 addition & 0 deletions src/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void close_packet_file(void);
TbBool reinit_packets_after_load(void);
struct Room *keeper_build_room(long stl_x,long stl_y,long plyr_idx,long rkind);
TbBool player_sell_room_at_subtile(long plyr_idx, long stl_x, long stl_y);
void set_tag_untag_mode(PlayerNumber plyr_idx, MapSubtlCoord stl_x, MapSubtlCoord stl_y);
/******************************************************************************/
#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 3f11642

Please sign in to comment.