new hotkeys

This commit is contained in:
John W. C. McNabb 2005-05-18 14:06:30 +00:00
parent 45d98e7c3c
commit aa8caf2760
8 changed files with 136 additions and 4 deletions

View File

@ -1,5 +1,7 @@
CVS HEAD:
* user interface improvements:
* added hotkey for cycle to previous unit (shift-N) (part of #10703)
* added hotkey for hold position (patch 3994)
* made the right Command key on Mac OS X work like the left one
* made the 100 gold minimum for next scenario explicitly mentioned (#12987)
* made menu widgets sortable

View File

@ -161,10 +161,20 @@ default=yes
key=n
[/hotkey]
[hotkey]
command=cycleback
key=n
shift=yes
[/hotkey]
[hotkey]
command=endunitturn
key=" "
[/hotkey]
[hotkey]
command=holdposition
key=" "
shift=yes
[/hotkey]
[hotkey]
command=leader
key=l
[/hotkey]
@ -330,10 +340,20 @@ default=yes
key=n
[/hotkey]
[hotkey]
command=cycleback
key=n
shift=yes
[/hotkey]
[hotkey]
command=endunitturn
key=" "
[/hotkey]
[hotkey]
command=holdposition
key=" "
shift=yes
[/hotkey]
[hotkey]
command=leader
key=l
[/hotkey]

View File

@ -43,6 +43,8 @@ const struct {
bool hidden;
} hotkey_list_[] = {
{ hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next unit"), false },
{ hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous unit"), false },
{ hotkey::HOTKEY_UNIT_HOLD_POSITION, "holdposition", N_("Hold Position"), false},
{ hotkey::HOTKEY_END_UNIT_TURN, "endunitturn", N_("End Unit Turn"), false },
{ hotkey::HOTKEY_LEADER, "leader", N_("Leader"), false },
{ hotkey::HOTKEY_UNDO, "undo", N_("Undo"), false },
@ -411,10 +413,18 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
if(executor)
executor->cycle_units();
break;
case HOTKEY_CYCLE_BACK_UNITS:
if(executor)
executor->cycle_back_units();
break;
case HOTKEY_ENDTURN:
if(executor)
executor->end_turn();
break;
case HOTKEY_UNIT_HOLD_POSITION:
if(executor)
executor->unit_hold_position();
break;
case HOTKEY_END_UNIT_TURN:
if(executor)
executor->end_unit_turn();

View File

@ -28,7 +28,8 @@ class display;
namespace hotkey {
enum HOTKEY_COMMAND {
HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
HOTKEY_CYCLE_UNITS,HOTKEY_CYCLE_BACK_UNITS, HOTKEY_UNIT_HOLD_POSITION,
HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
HOTKEY_UNDO, HOTKEY_REDO,
HOTKEY_ZOOM_IN, HOTKEY_ZOOM_OUT, HOTKEY_ZOOM_DEFAULT,
HOTKEY_FULLSCREEN, HOTKEY_SCREENSHOT, HOTKEY_ACCELERATED,
@ -129,8 +130,10 @@ protected:
public:
virtual void cycle_units() {}
virtual void cycle_back_units() {}
virtual void end_turn() {}
virtual void goto_leader() {}
virtual void unit_hold_position() {}
virtual void end_unit_turn() {}
virtual void undo() {}
virtual void redo() {}

View File

@ -1036,6 +1036,7 @@ bool turn_info::can_execute_command(hotkey::HOTKEY_COMMAND command) const
//commands we can always do
case hotkey::HOTKEY_LEADER:
case hotkey::HOTKEY_CYCLE_UNITS:
case hotkey::HOTKEY_CYCLE_BACK_UNITS:
case hotkey::HOTKEY_ZOOM_IN:
case hotkey::HOTKEY_ZOOM_OUT:
case hotkey::HOTKEY_ZOOM_DEFAULT:
@ -1091,6 +1092,7 @@ bool turn_info::can_execute_command(hotkey::HOTKEY_COMMAND command) const
return !browse_ && !commands_disabled && current_team().auto_shroud_updates() == false;
//commands we can only do if we are actually playing, not just viewing
case hotkey::HOTKEY_UNIT_HOLD_POSITION:
case hotkey::HOTKEY_END_UNIT_TURN:
case hotkey::HOTKEY_RECRUIT:
case hotkey::HOTKEY_REPEAT_RECRUIT:
@ -1203,9 +1205,7 @@ bool turn_info::unit_in_cycle(unit_map::const_iterator it) const
void turn_info::cycle_units()
{
unit_map::const_iterator it = units_.find(next_unit_);
unit_map::const_iterator yellow_it = units_.end();
if(it != units_.end()) {
for(++it; it != units_.end(); ++it) {
if(unit_in_cycle(it)) {
@ -1244,6 +1244,47 @@ void turn_info::cycle_units()
}
}
void turn_info::cycle_back_units()
{
unit_map::const_iterator it = units_.find(next_unit_);
if(it != units_.begin()) {
for(--it; it != units_.begin(); --it) {
if(unit_in_cycle(it)) {
break;
}
}
}
if(it == units_.begin()) {
for(it = units_.end(); it != units_.begin(); --it) {
if(unit_in_cycle(it)) {
break;
}
}
}
if(it != units_.begin() && !gui_.fogged(it->first.x,it->first.y)) {
const bool ignore_zocs = it->second.type().is_skirmisher();
const bool teleport = it->second.type().teleports();
current_paths_ = paths(map_,status_,gameinfo_,units_,it->first,teams_,ignore_zocs,teleport,path_turns_);
gui_.set_paths(&current_paths_);
gui_.scroll_to_tile(it->first.x,it->first.y,display::WARP);
}
if(it != units_.begin()) {
next_unit_ = it->first;
selected_hex_ = next_unit_;
gui_.select_hex(selected_hex_);
gui_.highlight_hex(selected_hex_);
current_route_.steps.clear();
gui_.set_route(NULL);
show_attack_options(it);
} else {
next_unit_ = gamemap::location();
}
}
void turn_info::end_turn()
{
if(browse_)
@ -1312,6 +1353,28 @@ void turn_info::goto_leader()
}
}
void turn_info::unit_hold_position()
{
if(browse_)
return;
const unit_map::iterator un = units_.find(selected_hex_);
if(un != units_.end() && un->second.side() == team_num_ && un->second.movement_left() >= 0) {
un->second.set_hold_position(!un->second.hold_position());
gui_.draw_tile(selected_hex_.x,selected_hex_.y);
gui_.set_route(NULL);
gui_.set_paths(NULL);
current_paths_ = paths();
gui_.draw();
if(un->second.hold_position()) {
un->second.set_user_end_turn(true);
cycle_units();
}
}
}
void turn_info::end_unit_turn()
{
if(browse_)
@ -1320,6 +1383,9 @@ void turn_info::end_unit_turn()
const unit_map::iterator un = units_.find(selected_hex_);
if(un != units_.end() && un->second.side() == team_num_ && un->second.movement_left() >= 0) {
un->second.set_user_end_turn(!un->second.user_end_turn());
if(un->second.hold_position() && !un->second.user_end_turn()){
un->second.set_hold_position(false);
}
gui_.draw_tile(selected_hex_.x,selected_hex_.y);
gui_.set_route(NULL);

View File

@ -136,8 +136,10 @@ private:
//overridden from command_executor
virtual void cycle_units();
virtual void cycle_back_units();
virtual void end_turn();
virtual void goto_leader();
virtual void unit_hold_position();
virtual void end_unit_turn();
virtual void undo();
virtual void redo();

View File

@ -69,7 +69,8 @@ unit::unit(const game_data& data, const config& cfg) :
moves_(0), user_end_turn_(false), facingLeft_(true),
resting_(false),
recruit_(false),
guardian_(false), upkeep_(UPKEEP_FREE)
guardian_(false), upkeep_(UPKEEP_FREE),
hold_position_(false)
{
read(data,cfg);
}
@ -98,6 +99,7 @@ unit::unit(const unit_type* t, int side, bool use_traits, bool dummy_unit, unit_
maxMovement_(type_->movement()),
backupMaxMovement_(type_->movement()),
resting_(false), recruit_(false), attacks_(type_->attacks()),
hold_position_(false),
backupAttacks_(type_->attacks()),
guardian_(false), upkeep_(UPKEEP_FULL_PRICE),
unrenamable_(false)
@ -125,6 +127,7 @@ unit::unit(const unit_type* t, const unit& u) :
experience_(0),
maxExperience_(type_->experience_needed()),
backupMaxExperience_(type_->experience_needed()),
hold_position_(u.hold_position_),
side_(u.side()), moves_(u.moves_),
user_end_turn_(false), facingLeft_(u.facingLeft_),
maxMovement_(type_->movement()),
@ -262,10 +265,22 @@ bool unit::can_attack() const
void unit::set_movement(int moves)
{
hold_position_ = false;
user_end_turn_ = false;
moves_ = moves;
}
//This does not mark the unit's turn as being done even if value is true. To do that, either call void unit_hold_position(), or set_user_end_turn(value).
void unit::set_hold_position(bool value)
{
hold_position_ = value;
}
bool unit::hold_position() const
{
return hold_position_;
}
void unit::set_user_end_turn(bool value)
{
user_end_turn_ = value;
@ -279,6 +294,13 @@ bool unit::user_end_turn() const
void unit::set_attacked()
{
moves_ = ATTACKED;
set_hold_position(false);
}
void unit::unit_hold_position()
{
hold_position_ = true;
user_end_turn_ = true;
}
void unit::end_unit_turn()
@ -300,6 +322,9 @@ void unit::new_turn()
set_flag("nightstalk");
if(stone())
set_attacked();
if (hold_position_) {
user_end_turn_ = true;
}
}
bool unit::move_interrupted() const {

View File

@ -62,11 +62,14 @@ public:
bool can_recruit() const;
int total_movement() const;
int movement_left() const;
void set_hold_position(bool value);
bool hold_position() const;
void set_user_end_turn(bool value=true);
bool user_end_turn() const;
bool can_attack() const;
void set_movement(int moves);
void set_attacked();
void unit_hold_position();
void end_unit_turn();
void new_turn();
void end_turn();
@ -188,6 +191,7 @@ private:
bool facingLeft_;
int maxMovement_, backupMaxMovement_;
bool resting_;
bool hold_position_;
std::string underlying_description_, description_;