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

feat: togglable message log window size #2511

Merged
merged 22 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
457bf08
feat: expand message log window to full height
scarf005 Mar 31, 2023
d1f26d7
feat: widen message log display
scarf005 Mar 31, 2023
bd3bbe7
feat: local keybind for toggling messages
scarf005 Apr 1, 2023
146bf69
feat: add local keybinding for messages
scarf005 Apr 1, 2023
e18de15
style: use for loop to load keybindings
scarf005 Apr 1, 2023
b5f6baf
feat: togglable messages
scarf005 Apr 1, 2023
4f1e228
feat: use wide display by default, use full height
scarf005 Apr 4, 2023
8c9d848
refactor: remove unnessary mark_resize in `init`
scarf005 Apr 4, 2023
22e32a1
refactor: simplify `set_size`
scarf005 Apr 4, 2023
a8f5543
chore: remove duplicate <locale>
scarf005 Apr 4, 2023
60cea47
refactor: move all keybindings to `data/raw/keybindings/`
scarf005 Apr 4, 2023
895841e
refactor: separate `user_keybindings`
scarf005 Apr 4, 2023
6251dd3
refactor: resursively load `data/raw/`
scarf005 Apr 4, 2023
daf2de6
feat: add `TOGGLE_FULL_HEIGHT_DISPLAY`
scarf005 Apr 4, 2023
a70ab54
feat: keep window size persistent
scarf005 Apr 4, 2023
9dd2765
fix: use `size_t`
scarf005 Apr 7, 2023
47bf38f
fix: remove redundant `set_size()`
scarf005 Apr 7, 2023
e52ab53
fix: clang complaint on `<set>` header inclusion
scarf005 Apr 7, 2023
4e614e1
feat: persistent wide and height size
scarf005 Apr 7, 2023
9b34689
feat: make option description less verbose
scarf005 Apr 7, 2023
226035e
feat: add description for toggleable description on messages panel
scarf005 Apr 7, 2023
103a905
refactor: use more specific name for msg window uistate
scarf005 Apr 8, 2023
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
File renamed without changes.
16 changes: 16 additions & 0 deletions data/raw/keybindings/messages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"id": "TOGGLE_WIDE_DISPLAY",
"type": "keybinding",
"category": "MESSAGE_LOG",
"name": "Toggle wide display",
"bindings": [ { "input_method": "keyboard", "key": "w" } ]
},
{
"id": "TOGGLE_FULL_HEIGHT_DISPLAY",
"type": "keybinding",
"category": "MESSAGE_LOG",
"name": "Toggle full height display",
"bindings": [ { "input_method": "keyboard", "key": "h" } ]
}
]
36 changes: 15 additions & 21 deletions src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,16 @@ void input_manager::init()
init_keycode_mapping();
reset_timeout();

try {
load( PATH_INFO::keybindings(), false );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
}
try {
load( PATH_INFO::keybindings_vehicle(), false );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
}
try {
load( PATH_INFO::keybindings_edit_creature(), false );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
// recursively load all keybindings from the data/raw directory
for( const auto &file : get_files_from_path( ".json", PATH_INFO::keybindingsdir(), true, true ) ) {
try {
load( file, false );
} catch( const JsonError &err ) {
throw std::runtime_error( err.what() );
}
}

// user keybindings are searched from separate directory
try {
load( PATH_INFO::user_keybindings(), true );
} catch( const JsonError &err ) {
Expand Down Expand Up @@ -464,8 +459,9 @@ std::string input_manager::get_keyname( int ch, input_event_t inp_type, bool por
const std::vector<input_event> &input_manager::get_input_for_action( const std::string
&action_descriptor, const std::string &context, bool *overwrites_default )
{
const action_attributes &attributes = get_action_attributes( action_descriptor, context,
overwrites_default );
const action_attributes &attributes =
get_action_attributes( action_descriptor, context, overwrites_default );

return attributes.input_events;
}

Expand Down Expand Up @@ -720,12 +716,10 @@ std::string input_context::key_bound_to( const std::string &action_descriptor, c

std::string input_context::get_available_single_char_hotkeys( std::string requested_keys )
{
for( std::vector<std::string>::const_iterator registered_action = registered_actions.begin();
registered_action != registered_actions.end();
++registered_action ) {
for( const auto &registered_action : registered_actions ) {
const std::vector<input_event> &events =
inp_mngr.get_input_for_action( registered_action, category );

const std::vector<input_event> &events = inp_mngr.get_input_for_action( *registered_action,
category );
for( const auto &events_event : events ) {
// Only consider keyboard events without modifiers
if( events_event.type == CATA_INPUT_KEYBOARD && events_event.modifiers.empty() ) {
Expand Down
72 changes: 49 additions & 23 deletions src/messages.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "messages.h"

#include "calendar.h"
#include "catacharset.h"
#include "color.h"
Expand All @@ -17,6 +16,7 @@
#include "string_utils.h"
#include "translations.h"
#include "ui_manager.h"
#include "uistate.h"

#if defined(__ANDROID__)
#include <optional>
Expand Down Expand Up @@ -398,17 +398,20 @@ static bool msg_type_from_name( game_message_type &type, const std::string &name

namespace Messages
{

// NOLINTNEXTLINE(cata-xy)
class dialog
{
public:
dialog();
void run();
private:
void init_first_time();
void init( ui_adaptor &ui );
void show();
void input();
void input( const ui_adaptor &ui );
void do_filter( const std::string &filter_str );
void set_size();
static std::vector<std::string> filter_help_text( int width );

const nc_color border_color;
Expand Down Expand Up @@ -474,29 +477,43 @@ Messages::dialog::dialog()
{
}

void Messages::dialog::init( ui_adaptor &ui )
inline void Messages::dialog::set_size()
{
w_width = std::min( TERMX, FULL_SCREEN_WIDTH );
w_height = std::min( TERMY, FULL_SCREEN_HEIGHT );
w_width
= std::min( TERMX, static_cast<int>( FULL_SCREEN_WIDTH * ( uistate.msg_window_wide_display ? 1.8 :
1 ) ) );
w_height = std::min( TERMY, uistate.msg_window_full_height_display ? TERMY : FULL_SCREEN_HEIGHT );
w_x = ( TERMX - w_width ) / 2;
w_y = ( TERMY - w_height ) / 2;
}

void Messages::dialog::init_first_time()
{
ctxt = input_context( "MESSAGE_LOG" );
ctxt.register_action( "UP", to_translation( "Scroll up" ) );
ctxt.register_action( "DOWN", to_translation( "Scroll down" ) );

static auto actionnames = {
"PAGE_UP", "PAGE_DOWN", "FILTER", "RESET_FILTER",
"QUIT", "HELP_KEYBINDINGS", "TOGGLE_WIDE_DISPLAY", "TOGGLE_FULL_HEIGHT_DISPLAY"
};
for( const auto &actionname : actionnames ) {
ctxt.register_action( actionname );
}

// Calculate time string display width. The translated strings are expected to
// be aligned, so we choose an arbitrary duration here to calculate the width.
time_width = utf8_width( to_string_clipped( 1_turns, clipped_align::right ) );
}

void Messages::dialog::init( ui_adaptor &ui )
{
set_size();

w = catacurses::newwin( w_height, w_width, point( w_x, w_y ) );

if( first_init ) {
ctxt = input_context( "MESSAGE_LOG" );
ctxt.register_action( "UP", to_translation( "Scroll up" ) );
ctxt.register_action( "DOWN", to_translation( "Scroll down" ) );
ctxt.register_action( "PAGE_UP" );
ctxt.register_action( "PAGE_DOWN" );
ctxt.register_action( "FILTER" );
ctxt.register_action( "RESET_FILTER" );
ctxt.register_action( "QUIT" );
ctxt.register_action( "HELP_KEYBINDINGS" );

// Calculate time string display width. The translated strings are expected to
// be aligned, so we choose an arbitrary duration here to calculate the width.
time_width = utf8_width( to_string_clipped( 1_turns, clipped_align::right ) );
init_first_time();
}

if( border_width * 2 + time_width + padding_width >= w_width ||
Expand All @@ -512,7 +529,7 @@ void Messages::dialog::init( ui_adaptor &ui )
w_fh_width = w_width;
w_fh_x = w_x;
help_text = filter_help_text( w_fh_width - border_width * 2 );
w_fh_height = help_text.size() + border_width * 2;
w_fh_height = static_cast<int>( help_text.size() ) + border_width * 2;
w_fh_y = w_y + w_height - w_fh_height;
w_filter_help = catacurses::newwin( w_fh_height, w_fh_width, point( w_fh_x, w_fh_y ) );

Expand Down Expand Up @@ -635,8 +652,10 @@ void Messages::dialog::show()
} else {
if( filter_str.empty() ) {
mvwprintz( w, point( border_width, w_height - 1 ), border_color,
_( "< Press %s to filter, %s to reset >" ),
ctxt.get_desc( "FILTER" ), ctxt.get_desc( "RESET_FILTER" ) );
_( "< Press %s to filter, %s to reset, %s or %s to adjust size >" ),
ctxt.get_desc( "FILTER" ), ctxt.get_desc( "RESET_FILTER" ),
ctxt.get_desc( "TOGGLE_WIDE_DISPLAY" ), ctxt.get_desc( "TOGGLE_FULL_HEIGHT_DISPLAY" )
);
} else {
mvwprintz( w, point( border_width, w_height - 1 ), border_color, "< %s >", filter_str );
mvwprintz( w, point( border_width + 2, w_height - 1 ), filter_color, "%s", filter_str );
Expand Down Expand Up @@ -683,7 +702,7 @@ void Messages::dialog::do_filter( const std::string &filter_str )
}
}

void Messages::dialog::input()
void Messages::dialog::input( const ui_adaptor &ui )
{
canceled = false;
if( filtering ) {
Expand Down Expand Up @@ -739,6 +758,13 @@ void Messages::dialog::input()
do_filter( filter_str );
} else if( action == "QUIT" ) {
canceled = true;
} else if( action == "TOGGLE_WIDE_DISPLAY" || action == "TOGGLE_FULL_HEIGHT_DISPLAY" ) {
if( action == "TOGGLE_WIDE_DISPLAY" ) {
uistate.msg_window_wide_display = !uistate.msg_window_wide_display;
} else {
uistate.msg_window_full_height_display = !uistate.msg_window_full_height_display;
}
ui.mark_resize();
}
}
}
Expand All @@ -756,7 +782,7 @@ void Messages::dialog::run()

while( !errored && !canceled ) {
ui_manager::redraw();
input();
input( ui );
}
}

Expand Down
1 change: 0 additions & 1 deletion src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#include <algorithm>
#include <cstdlib>
#include <exception>
#include <locale>
olanti-p marked this conversation as resolved.
Show resolved Hide resolved
#include <memory>
#include <sstream>
#include <string>
Expand Down
12 changes: 2 additions & 10 deletions src/path_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,9 @@ std::string PATH_INFO::help()
{
return datadir_value + "help/" + "texts.json";
}
std::string PATH_INFO::keybindings()
std::string PATH_INFO::keybindingsdir()
{
return datadir_value + "raw/" + "keybindings.json";
}
std::string PATH_INFO::keybindings_vehicle()
{
return datadir_value + "raw/" + "keybindings/vehicle.json";
}
std::string PATH_INFO::keybindings_edit_creature()
{
return datadir_value + "raw/" + "keybindings/edit_creature_effects.json";
return datadir_value + "raw/keybindings/";
}
std::string PATH_INFO::main_menu_tips()
{
Expand Down
4 changes: 1 addition & 3 deletions src/path_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ std::string user_fontdir();
std::string language_defs_file();
std::string graveyarddir();
std::string help();
std::string keybindings();
std::string keybindings_vehicle();
std::string keybindings_edit_creature();
std::string keybindingsdir();
std::string main_menu_tips();
std::string lastworld();
std::string memorialdir();
Expand Down
4 changes: 4 additions & 0 deletions src/savegame_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4295,6 +4295,8 @@ void uistatedata::serialize( JsonOut &json ) const
json.member( "bionic_ui_sort_mode", bionic_sort_mode );
json.member( "overmap_debug_weather", overmap_debug_weather );
json.member( "overmap_visible_weather", overmap_visible_weather );
json.member( "msg_window_wide_display", msg_window_wide_display );
json.member( "msg_window_full_height_display", msg_window_full_height_display );

json.member( "input_history" );
json.start_object();
Expand Down Expand Up @@ -4343,6 +4345,8 @@ void uistatedata::deserialize( const JsonObject &jo )
jo.read( "bionic_ui_sort_mode", bionic_sort_mode );
jo.read( "overmap_debug_weather", overmap_debug_weather );
jo.read( "overmap_visible_weather", overmap_visible_weather );
jo.read( "msg_window_wide_display", msg_window_wide_display );
jo.read( "msg_window_full_height_display", msg_window_full_height_display );

if( !jo.read( "vmenu_show_items", vmenu_show_items ) ) {
// This is an old save: 1 means view items, 2 means view monsters,
Expand Down
5 changes: 5 additions & 0 deletions src/uistate.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <list>
#include <map>
#include <set>
#include <optional>
#include <string>
#include <vector>
Expand Down Expand Up @@ -150,6 +151,10 @@ class uistatedata

std::map<ammotype, itype_id> lastreload; // id of ammo last used when reloading ammotype

// Wide and tall display for messages window
bool msg_window_wide_display = false;
bool msg_window_full_height_display = false;

// internal stuff
bool _testing_save = true; // internal: whine on json errors. set false if no complaints in 2 weeks.
bool _really_testing_save = false; // internal: spammy
Expand Down