Added in new hotkeys
This commit is contained in:
parent
335abcdb08
commit
278b0428dc
5 changed files with 226 additions and 166 deletions
|
@ -11,6 +11,16 @@ language="English"
|
|||
key=r
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=recruit
|
||||
key=r
|
||||
ctrl=yes
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=recall
|
||||
key=c
|
||||
ctrl=yes
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=cycle
|
||||
key=n
|
||||
[/hotkey]
|
||||
|
@ -50,10 +60,19 @@ language="English"
|
|||
ctrl=yes
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=describeunit
|
||||
key=d
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=terraintable
|
||||
key=t
|
||||
ctrl=yes
|
||||
[/hotkey]
|
||||
[hotkey]
|
||||
command=save
|
||||
key=s
|
||||
ctrl=yes
|
||||
[/hotkey]
|
||||
|
||||
game_title="The Battle for Wesnoth"
|
||||
version="Version"
|
||||
|
|
|
@ -41,6 +41,10 @@ HOTKEY_COMMAND string_to_command(const std::string& str)
|
|||
m.insert(val("accelerated",HOTKEY_ACCELERATED));
|
||||
m.insert(val("resistance",HOTKEY_ATTACK_RESISTANCE));
|
||||
m.insert(val("terraintable",HOTKEY_TERRAIN_TABLE));
|
||||
m.insert(val("describeunit",HOTKEY_UNIT_DESCRIPTION));
|
||||
m.insert(val("save",HOTKEY_SAVE_GAME));
|
||||
m.insert(val("recruit",HOTKEY_RECRUIT));
|
||||
m.insert(val("recall",HOTKEY_RECALL));
|
||||
}
|
||||
|
||||
const std::map<std::string,HOTKEY_COMMAND>::const_iterator i = m.find(str);
|
||||
|
|
|
@ -22,6 +22,8 @@ enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
|
|||
HOTKEY_ZOOM_IN, HOTKEY_ZOOM_OUT, HOTKEY_ZOOM_DEFAULT,
|
||||
HOTKEY_FULLSCREEN, HOTKEY_ACCELERATED,
|
||||
HOTKEY_TERRAIN_TABLE, HOTKEY_ATTACK_RESISTANCE,
|
||||
HOTKEY_UNIT_DESCRIPTION, HOTKEY_SAVE_GAME,
|
||||
HOTKEY_RECRUIT, HOTKEY_RECALL,
|
||||
HOTKEY_NULL };
|
||||
|
||||
void add_hotkeys(config& cfg);
|
||||
|
|
26
src/menu.cpp
26
src/menu.cpp
|
@ -322,7 +322,7 @@ public:
|
|||
}
|
||||
|
||||
int process(int x, int y, bool button,bool up_arrow,bool down_arrow,
|
||||
bool page_up, bool page_down) {
|
||||
bool page_up, bool page_down, int select_item) {
|
||||
if(items_.size() > size_t(max_menu_items)) {
|
||||
const bool up = uparrow_.process(x,y,button);
|
||||
if(up && first_item_on_screen_ > 0) {
|
||||
|
@ -341,6 +341,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
if(select_item >= 0 && size_t(select_item) < items_.size()) {
|
||||
selected_ = select_item;
|
||||
if(selected_ < first_item_on_screen_) {
|
||||
itemRects_.clear();
|
||||
first_item_on_screen_ = selected_;
|
||||
}
|
||||
|
||||
if(size_t(selected_ - first_item_on_screen_) >= max_menu_items) {
|
||||
itemRects_.clear();
|
||||
first_item_on_screen_ = selected_ - max_menu_items - 1;
|
||||
}
|
||||
|
||||
draw();
|
||||
}
|
||||
|
||||
if(up_arrow && !click_selects_ && selected_ > 0) {
|
||||
--selected_;
|
||||
if(selected_ < first_item_on_screen_) {
|
||||
|
@ -706,6 +721,12 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
const bool new_page_up = key[SDLK_PAGEUP];
|
||||
const bool new_page_down = key[SDLK_PAGEDOWN];
|
||||
|
||||
int select_item = -1;
|
||||
for(int item = 0; item != 10; ++item) {
|
||||
if(key['1' + item])
|
||||
select_item = item;
|
||||
}
|
||||
|
||||
|
||||
if(!key_down && key[KEY_ENTER] &&
|
||||
(type == YES_NO || type == OK_CANCEL)) {
|
||||
|
@ -747,7 +768,8 @@ int show_dialog(display& disp, SDL_Surface* image,
|
|||
!up_arrow && new_up_arrow,
|
||||
!down_arrow && new_down_arrow,
|
||||
!page_up && new_page_up,
|
||||
!page_down && new_page_down);
|
||||
!page_down && new_page_down,
|
||||
select_item);
|
||||
if(res != -1)
|
||||
return res;
|
||||
}
|
||||
|
|
341
src/playturn.cpp
341
src/playturn.cpp
|
@ -399,36 +399,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
|
||||
if(result == string_table["describe_unit"]) {
|
||||
|
||||
const std::string description
|
||||
= un->second.type().unit_description() +
|
||||
"\n\n" + string_table["see_also"];
|
||||
|
||||
std::vector<std::string> options;
|
||||
|
||||
options.push_back(string_table["terrain_info"]);
|
||||
options.push_back(string_table["attack_resistance"]);
|
||||
options.push_back(string_table["close_window"]);
|
||||
|
||||
std::vector<unit> units_list(options.size(),un->second);
|
||||
|
||||
SDL_Surface* const unit_image =
|
||||
gui.getImage(un->second.type().image_profile(),
|
||||
display::UNSCALED);
|
||||
|
||||
const int res = gui::show_dialog(gui,unit_image,
|
||||
un->second.type().language_name(),
|
||||
description,gui::MESSAGE,&options,&units_list);
|
||||
|
||||
//terrain table
|
||||
if(res == 0) {
|
||||
command = HOTKEY_TERRAIN_TABLE;
|
||||
}
|
||||
|
||||
//attack resistance table
|
||||
else if(res == 1) {
|
||||
command = HOTKEY_ATTACK_RESISTANCE;
|
||||
}
|
||||
command = HOTKEY_UNIT_DESCRIPTION;
|
||||
}
|
||||
|
||||
else if(result == string_table["preferences"]) {
|
||||
|
@ -456,125 +427,10 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
}
|
||||
|
||||
else if(result == string_table["recall"]) {
|
||||
//sort the available units into order by value
|
||||
//so that the most valuable units are shown first
|
||||
std::sort(state_of_game.available_units.begin(),
|
||||
state_of_game.available_units.end(),
|
||||
compare_unit_values());
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
if(state_of_game.available_units.empty()) {
|
||||
gui::show_dialog(gui,NULL,"",string_table["no_recall"]);
|
||||
} else if(current_team.gold() < game_config::recall_cost) {
|
||||
std::stringstream msg;
|
||||
msg << string_table["not_enough_gold_to_recall_1"]
|
||||
<< " " << game_config::recall_cost << " "
|
||||
<< string_table["not_enough_gold_to_recall_2"];
|
||||
gui::show_dialog(gui, NULL,"",msg.str());
|
||||
} else {
|
||||
std::vector<std::string> options;
|
||||
for(std::vector<unit>::const_iterator unit =
|
||||
state_of_game.available_units.begin();
|
||||
unit != state_of_game.available_units.end(); ++unit) {
|
||||
std::stringstream option;
|
||||
option << unit->type().language_name() << ","
|
||||
<< string_table["level"] << ": "
|
||||
<< unit->type().level() << ","
|
||||
<< string_table["xp"] << ": "
|
||||
<< unit->experience() << "/"
|
||||
<< unit->max_experience();
|
||||
options.push_back(option.str());
|
||||
}
|
||||
|
||||
const int res = gui::show_dialog(gui,NULL,"",
|
||||
string_table["select_unit"] + ":\n",
|
||||
gui::OK_CANCEL,&options,
|
||||
&state_of_game.available_units);
|
||||
if(res >= 0) {
|
||||
|
||||
const std::string err = recruit_unit(map,team_num,
|
||||
units,state_of_game.available_units[res],
|
||||
last_hex,&gui);
|
||||
if(!err.empty()) {
|
||||
gui::show_dialog(gui,NULL,"",err,gui::OK_ONLY);
|
||||
} else {
|
||||
current_team.spend_gold(
|
||||
game_config::recall_cost);
|
||||
state_of_game.available_units.erase(
|
||||
state_of_game.available_units.begin()+res);
|
||||
|
||||
recorder.add_recall(res,last_hex);
|
||||
|
||||
undo_stack.clear();
|
||||
redo_stack.clear();
|
||||
|
||||
gui.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
command = HOTKEY_RECALL;
|
||||
}
|
||||
else if(result == string_table["recruit"]) {
|
||||
|
||||
std::vector<unit> sample_units;
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
std::vector<std::string> item_keys;
|
||||
std::vector<std::string> items;
|
||||
const std::set<std::string>& recruits
|
||||
= current_team.recruits();
|
||||
for(std::set<std::string>::const_iterator it =
|
||||
recruits.begin(); it != recruits.end(); ++it) {
|
||||
item_keys.push_back(*it);
|
||||
const std::map<std::string,unit_type>::const_iterator
|
||||
u_type = gameinfo.unit_types.find(*it);
|
||||
if(u_type == gameinfo.unit_types.end()) {
|
||||
std::cerr << "could not find " << *it << std::endl;
|
||||
assert(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
const unit_type& type = u_type->second;
|
||||
std::stringstream description;
|
||||
|
||||
description << type.language_name() << ": "
|
||||
<< type.cost() << " gold";
|
||||
items.push_back(description.str());
|
||||
sample_units.push_back(unit(&type,team_num));
|
||||
}
|
||||
|
||||
const int recruit_res =
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["recruit_unit"] + ":\n",
|
||||
gui::OK_CANCEL,&items,&sample_units);
|
||||
if(recruit_res != -1) {
|
||||
const std::string& name = item_keys[recruit_res];
|
||||
const std::map<std::string,unit_type>::const_iterator
|
||||
u_type = gameinfo.unit_types.find(name);
|
||||
assert(u_type != gameinfo.unit_types.end());
|
||||
|
||||
if(u_type->second.cost() > current_team.gold()) {
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["not_enough_gold_to_recruit"],
|
||||
gui::OK_ONLY);
|
||||
} else {
|
||||
recorder.add_recruit(recruit_res,last_hex);
|
||||
|
||||
//create a unit with traits
|
||||
unit new_unit(&(u_type->second),team_num,true);
|
||||
const std::string& msg =
|
||||
recruit_unit(map,team_num,units,new_unit,
|
||||
last_hex,&gui);
|
||||
if(msg.empty())
|
||||
current_team.spend_gold(u_type->second.cost());
|
||||
else
|
||||
gui::show_dialog(gui,NULL,"",msg,gui::OK_ONLY);
|
||||
|
||||
undo_stack.clear();
|
||||
redo_stack.clear();
|
||||
|
||||
gui.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
command = HOTKEY_RECRUIT;
|
||||
} else if(result == string_table["unit_list"]) {
|
||||
const std::string heading = string_table["name"] + "," +
|
||||
string_table["hp"] + "," +
|
||||
|
@ -612,23 +468,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
gui::show_dialog(gui,NULL,string_table["unit_list"],"",
|
||||
gui::OK_ONLY,&items,&units_list);
|
||||
} else if(result == string_table["save_game"]) {
|
||||
std::stringstream stream;
|
||||
stream << string_table["scenario"]
|
||||
<< " " << (state_of_game.scenario+1)
|
||||
<< " " << string_table["turn"]
|
||||
<< " " << status.turn();
|
||||
std::string label = stream.str();
|
||||
|
||||
const int res = gui::show_dialog(gui, NULL, "", "",
|
||||
gui::OK_CANCEL,NULL,NULL,
|
||||
string_table["save_game_label"],
|
||||
&label);
|
||||
|
||||
if(res == 0) {
|
||||
recorder.save_game(gameinfo,label);
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["save_confirm_message"], gui::OK_ONLY);
|
||||
}
|
||||
command = HOTKEY_SAVE_GAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -650,10 +490,183 @@ void play_turn(game_data& gameinfo, game_state& state_of_game,
|
|||
if(command == HOTKEY_NULL)
|
||||
command = check_keys(gui);
|
||||
|
||||
if(command == HOTKEY_RECRUIT) {
|
||||
std::vector<unit> sample_units;
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
std::vector<std::string> item_keys;
|
||||
std::vector<std::string> items;
|
||||
const std::set<std::string>& recruits
|
||||
= current_team.recruits();
|
||||
for(std::set<std::string>::const_iterator it =
|
||||
recruits.begin(); it != recruits.end(); ++it) {
|
||||
item_keys.push_back(*it);
|
||||
const std::map<std::string,unit_type>::const_iterator
|
||||
u_type = gameinfo.unit_types.find(*it);
|
||||
if(u_type == gameinfo.unit_types.end()) {
|
||||
std::cerr << "could not find " << *it << std::endl;
|
||||
assert(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
const unit_type& type = u_type->second;
|
||||
std::stringstream description;
|
||||
|
||||
description << type.language_name() << ","
|
||||
<< type.cost() << " gold";
|
||||
items.push_back(description.str());
|
||||
sample_units.push_back(unit(&type,team_num));
|
||||
}
|
||||
|
||||
const int recruit_res =
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["recruit_unit"] + ":\n",
|
||||
gui::OK_CANCEL,&items,&sample_units);
|
||||
if(recruit_res != -1) {
|
||||
const std::string& name = item_keys[recruit_res];
|
||||
const std::map<std::string,unit_type>::const_iterator
|
||||
u_type = gameinfo.unit_types.find(name);
|
||||
assert(u_type != gameinfo.unit_types.end());
|
||||
|
||||
if(u_type->second.cost() > current_team.gold()) {
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["not_enough_gold_to_recruit"],
|
||||
gui::OK_ONLY);
|
||||
} else {
|
||||
recorder.add_recruit(recruit_res,last_hex);
|
||||
|
||||
//create a unit with traits
|
||||
unit new_unit(&(u_type->second),team_num,true);
|
||||
const std::string& msg =
|
||||
recruit_unit(map,team_num,units,new_unit,
|
||||
last_hex,&gui);
|
||||
if(msg.empty())
|
||||
current_team.spend_gold(u_type->second.cost());
|
||||
else
|
||||
gui::show_dialog(gui,NULL,"",msg,gui::OK_ONLY);
|
||||
|
||||
undo_stack.clear();
|
||||
redo_stack.clear();
|
||||
|
||||
gui.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(command == HOTKEY_RECALL) {
|
||||
//sort the available units into order by value
|
||||
//so that the most valuable units are shown first
|
||||
std::sort(state_of_game.available_units.begin(),
|
||||
state_of_game.available_units.end(),
|
||||
compare_unit_values());
|
||||
|
||||
gui.draw(); //clear the old menu
|
||||
if(state_of_game.available_units.empty()) {
|
||||
gui::show_dialog(gui,NULL,"",string_table["no_recall"]);
|
||||
} else if(current_team.gold() < game_config::recall_cost) {
|
||||
std::stringstream msg;
|
||||
msg << string_table["not_enough_gold_to_recall_1"]
|
||||
<< " " << game_config::recall_cost << " "
|
||||
<< string_table["not_enough_gold_to_recall_2"];
|
||||
gui::show_dialog(gui, NULL,"",msg.str());
|
||||
} else {
|
||||
std::vector<std::string> options;
|
||||
for(std::vector<unit>::const_iterator unit =
|
||||
state_of_game.available_units.begin();
|
||||
unit != state_of_game.available_units.end(); ++unit) {
|
||||
std::stringstream option;
|
||||
option << unit->type().language_name() << ","
|
||||
<< string_table["level"] << ": "
|
||||
<< unit->type().level() << ","
|
||||
<< string_table["xp"] << ": "
|
||||
<< unit->experience() << "/"
|
||||
<< unit->max_experience();
|
||||
options.push_back(option.str());
|
||||
}
|
||||
|
||||
const int res = gui::show_dialog(gui,NULL,"",
|
||||
string_table["select_unit"] + ":\n",
|
||||
gui::OK_CANCEL,&options,
|
||||
&state_of_game.available_units);
|
||||
if(res >= 0) {
|
||||
|
||||
const std::string err = recruit_unit(map,team_num,
|
||||
units,state_of_game.available_units[res],
|
||||
last_hex,&gui);
|
||||
if(!err.empty()) {
|
||||
gui::show_dialog(gui,NULL,"",err,gui::OK_ONLY);
|
||||
} else {
|
||||
current_team.spend_gold(
|
||||
game_config::recall_cost);
|
||||
state_of_game.available_units.erase(
|
||||
state_of_game.available_units.begin()+res);
|
||||
|
||||
recorder.add_recall(res,last_hex);
|
||||
|
||||
undo_stack.clear();
|
||||
redo_stack.clear();
|
||||
|
||||
gui.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(command == HOTKEY_SAVE_GAME) {
|
||||
std::stringstream stream;
|
||||
stream << string_table["scenario"]
|
||||
<< " " << (state_of_game.scenario+1)
|
||||
<< " " << string_table["turn"]
|
||||
<< " " << status.turn();
|
||||
std::string label = stream.str();
|
||||
|
||||
const int res = gui::show_dialog(gui, NULL, "", "",
|
||||
gui::OK_CANCEL,NULL,NULL,
|
||||
string_table["save_game_label"],
|
||||
&label);
|
||||
|
||||
if(res == 0) {
|
||||
recorder.save_game(gameinfo,label);
|
||||
gui::show_dialog(gui,NULL,"",
|
||||
string_table["save_confirm_message"], gui::OK_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
unit_map::const_iterator un = units.find(new_hex);
|
||||
if(un == units.end())
|
||||
un = units.find(selected_hex);
|
||||
|
||||
if(command == HOTKEY_UNIT_DESCRIPTION && un != units.end()) {
|
||||
const std::string description = un->second.type().unit_description()
|
||||
+ "\n\n" + string_table["see_also"];
|
||||
|
||||
std::vector<std::string> options;
|
||||
|
||||
options.push_back(string_table["terrain_info"]);
|
||||
options.push_back(string_table["attack_resistance"]);
|
||||
options.push_back(string_table["close_window"]);
|
||||
|
||||
std::vector<unit> units_list(options.size(),un->second);
|
||||
|
||||
SDL_Surface* const unit_image = gui.getImage(
|
||||
un->second.type().image_profile(), display::UNSCALED);
|
||||
|
||||
const int res = gui::show_dialog(gui,unit_image,
|
||||
un->second.type().language_name(),
|
||||
description,gui::MESSAGE,
|
||||
&options,&units_list);
|
||||
|
||||
//terrain table
|
||||
if(res == 0) {
|
||||
command = HOTKEY_TERRAIN_TABLE;
|
||||
}
|
||||
|
||||
//attack resistance table
|
||||
else if(res == 1) {
|
||||
command = HOTKEY_ATTACK_RESISTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
if(un != units.end() && command == HOTKEY_ATTACK_RESISTANCE) {
|
||||
gui.draw();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue