Skip to content

Commit

Permalink
Main menu: mouse-over and selection for world creation menu
Browse files Browse the repository at this point in the history
  • Loading branch information
dseguin committed Jun 5, 2022
1 parent 067f7ab commit b0e7b5d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 36 deletions.
18 changes: 16 additions & 2 deletions data/raw/keybindings.json
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,20 @@
"name": "Move to previous category tab",
"bindings": [ { "input_method": "keyboard_char", "key": "<" }, { "input_method": "keyboard_code", "key": ",", "mod": [ "shift" ] } ]
},
{
"type": "keybinding",
"id": "MODMANAGER.QUIT",
"category": "MODMANAGER_DIALOG",
"name": "Quit",
"bindings": [
{ "input_method": "keyboard_any", "key": "ESC" },
{ "input_method": "keyboard_any", "key": "q" },
{ "input_method": "keyboard_char", "key": "Q" },
{ "input_method": "keyboard_code", "key": "q", "mod": [ "shift" ] },
{ "input_method": "keyboard_any", "key": "SPACE" },
{ "input_method": "mouse", "key": "MOUSE_RIGHT" }
]
},
{
"type": "keybinding",
"id": "PICK_RANDOM_WORLDNAME",
Expand All @@ -838,11 +852,11 @@
},
{
"type": "keybinding",
"id": "QUIT",
"id": "WORLDGEN_CONFIRM.QUIT",
"category": "WORLDGEN_CONFIRM_DIALOG",
"name": "Exit worldgen screen",
"//": "separate entry, because the global entry also has 'q' and 'Q' listed, which conflicts with the world name entry feature of this dialog",
"bindings": [ { "input_method": "keyboard_any", "key": "ESC" } ]
"bindings": [ { "input_method": "keyboard_any", "key": "ESC" }, { "input_method": "mouse", "key": "MOUSE_RIGHT" } ]
},
{
"type": "keybinding",
Expand Down
26 changes: 20 additions & 6 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,9 +1393,11 @@ void draw_subtab( const catacurses::window &w, int iOffsetX, const std::string &
}
}

void draw_tabs( const catacurses::window &w, const std::vector<std::string> &tab_texts,
size_t current_tab )
std::map<size_t, inclusive_rectangle<point>> draw_tabs( const catacurses::window &w,
const std::vector<std::string> &tab_texts, size_t current_tab )
{
std::map<size_t, inclusive_rectangle<point>> tab_map;

int width = getmaxx( w );
for( int i = 0; i < width; i++ ) {
mvwputch( w, point( i, 2 ), BORDER_COLOR, LINE_OXOX ); // -
Expand All @@ -1409,16 +1411,28 @@ void draw_tabs( const catacurses::window &w, const std::vector<std::string> &tab
for( size_t i = 0; i < tab_texts.size(); ++i ) {
const std::string &tab_text = tab_texts[i];
draw_tab( w, x, tab_text, i == current_tab );
x += utf8_width( tab_text, true ) + tab_step;
const int txt_width = utf8_width( tab_text, true );
tab_map.emplace( i, inclusive_rectangle<point>( point( x, 1 ), point( x + txt_width, 1 ) ) );
x += txt_width + tab_step;
}

return tab_map;
}

void draw_tabs( const catacurses::window &w, const std::vector<std::string> &tab_texts,
const std::string &current_tab )
std::map<std::string, inclusive_rectangle<point>> draw_tabs( const catacurses::window &w,
const std::vector<std::string> &tab_texts, const std::string &current_tab )
{
auto it = std::find( tab_texts.begin(), tab_texts.end(), current_tab );
cata_assert( it != tab_texts.end() );
draw_tabs( w, tab_texts, it - tab_texts.begin() );
std::map<size_t, inclusive_rectangle<point>> tab_map =
draw_tabs( w, tab_texts, it - tab_texts.begin() );
std::map<std::string, inclusive_rectangle<point>> ret_map;
for( size_t i = 0; i < tab_texts.size(); i++ ) {
if( tab_map.count( i ) > 0 ) {
ret_map.emplace( tab_texts.at( i ), tab_map.at( i ) );
}
}
return ret_map;
}

best_fit find_best_fit_in_size( const std::vector<int> &size_of_items_to_fit, const int &selected,
Expand Down
32 changes: 22 additions & 10 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cata_assert.h"
#include "catacharset.h"
#include "color.h"
#include "cuboid_rectangle.h"
#include "debug.h"
#include "enums.h"
#include "item.h"
Expand Down Expand Up @@ -801,11 +802,11 @@ void draw_subtab( const catacurses::window &w, int iOffsetX, const std::string &
// ┌──────┐ ┌──────┐
// │ TAB1 │ │ TAB2 │
// ┌─┴──────┴─┘ └───────────┐
void draw_tabs( const catacurses::window &, const std::vector<std::string> &tab_texts,
size_t current_tab );
std::map<size_t, inclusive_rectangle<point>> draw_tabs( const catacurses::window &,
const std::vector<std::string> &tab_texts, size_t current_tab );
// As above, but specify current tab by its label rather than position
void draw_tabs( const catacurses::window &, const std::vector<std::string> &tab_texts,
const std::string &current_tab );
std::map<std::string, inclusive_rectangle<point>> draw_tabs( const catacurses::window &,
const std::vector<std::string> &tab_texts, const std::string &current_tab );

// This overload of draw_tabs is intended for use when you track the current
// tab via some other value (like an enum) linked to each tab. Expected use
Expand All @@ -820,8 +821,8 @@ void draw_tabs( const catacurses::window &, const std::vector<std::string> &tab_
template<typename TabList, typename CurrentTab, typename = std::enable_if_t<
std::is_same<CurrentTab,
std::remove_const_t<typename TabList::value_type::first_type>>::value>>
void draw_tabs( const catacurses::window &w, const TabList &tab_list,
const CurrentTab &current_tab )
std::map<CurrentTab, inclusive_rectangle<point>> draw_tabs( const catacurses::window &w,
const TabList &tab_list, const CurrentTab &current_tab )
{
std::vector<std::string> tab_text;
std::transform( tab_list.begin(), tab_list.end(), std::back_inserter( tab_text ),
Expand All @@ -833,24 +834,35 @@ void draw_tabs( const catacurses::window &w, const TabList &tab_list,
return pair.first == current_tab;
} );
cata_assert( current_tab_it != tab_list.end() );
draw_tabs( w, tab_text, std::distance( tab_list.begin(), current_tab_it ) );
std::map<size_t, inclusive_rectangle<point>> tab_map =
draw_tabs( w, tab_text, std::distance( tab_list.begin(), current_tab_it ) );

std::map<CurrentTab, inclusive_rectangle<point>> ret_map;
size_t i = 0;
for( const typename TabList::value_type &pair : tab_list ) {
if( tab_map.count( i ) > 0 ) {
ret_map.emplace( pair.first, std::move( tab_map.at( i ) ) );
}
i++;
}
return ret_map;
}

// Similar to the above, but where the order of tabs is specified separately
// TabList is expected to be a map type.
template<typename TabList, typename TabKeys, typename CurrentTab, typename = std::enable_if_t<
std::is_same<CurrentTab,
std::remove_const_t<typename TabList::value_type::first_type>>::value>>
void draw_tabs( const catacurses::window &w, const TabList &tab_list, const TabKeys &keys,
const CurrentTab &current_tab )
std::map<CurrentTab, inclusive_rectangle<point>> draw_tabs( const catacurses::window &w,
const TabList &tab_list, const TabKeys &keys, const CurrentTab &current_tab )
{
std::vector<typename TabList::value_type> ordered_tab_list;
for( const auto &key : keys ) {
auto it = tab_list.find( key );
cata_assert( it != tab_list.end() );
ordered_tab_list.push_back( *it );
}
draw_tabs( w, ordered_tab_list, current_tab );
return draw_tabs( w, ordered_tab_list, current_tab );
}

/**
Expand Down
Loading

0 comments on commit b0e7b5d

Please sign in to comment.