infrastructure for clicking on unit image
This commit is contained in:
parent
5824d6b2c4
commit
7f68096bbd
5 changed files with 39 additions and 3 deletions
|
@ -214,6 +214,11 @@ const SDL_Rect& display::minimap_area() const
|
|||
return theme_.mini_map_location(screen_area());
|
||||
}
|
||||
|
||||
const SDL_Rect& display::unit_image_area() const
|
||||
{
|
||||
return theme_.unit_image_location(screen_area());
|
||||
}
|
||||
|
||||
SDL_Rect display::screen_area() const
|
||||
{
|
||||
const SDL_Rect res = {0,0,x(),y()};
|
||||
|
@ -400,6 +405,14 @@ gamemap::location display::minimap_location_on(int x, int y)
|
|||
return gamemap::location(int((x - rect.x)/xdiv),int((y-rect.y)/ydiv));
|
||||
}
|
||||
|
||||
bool display::unit_image_on(int x, int y)
|
||||
{
|
||||
const SDL_Rect rect = unit_image_area();
|
||||
|
||||
return (x >= rect.x && y >= rect.y &&
|
||||
x < rect.x + rect.w && y < rect.y + rect.h);
|
||||
}
|
||||
|
||||
void display::scroll(int xmove, int ymove)
|
||||
{
|
||||
const int orig_x = xpos_;
|
||||
|
|
|
@ -129,6 +129,7 @@ public:
|
|||
|
||||
const SDL_Rect& map_area() const;
|
||||
const SDL_Rect& minimap_area() const;
|
||||
const SDL_Rect& unit_image_area() const;
|
||||
|
||||
SDL_Rect screen_area() const;
|
||||
|
||||
|
@ -158,6 +159,10 @@ public:
|
|||
//location if the mouse isn't over the minimap.
|
||||
gamemap::location minimap_location_on(int x, int y);
|
||||
|
||||
// given x,y co-ordinates of the mouse, returns whether the
|
||||
// mouse is over the unit image or not
|
||||
bool unit_image_on(int x, int y);
|
||||
|
||||
//sets the paths that are currently displayed as available for the unit
|
||||
//to move along. All other paths will be greyed out. If NULL, no paths
|
||||
//will be displayed as selected.
|
||||
|
|
|
@ -801,6 +801,12 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
return;
|
||||
}
|
||||
|
||||
// clicked on unit image? then move highlight to unit
|
||||
if (gui_.unit_image_on(event.x,event.y)) {
|
||||
// FIXME: actually do something here
|
||||
return;
|
||||
}
|
||||
|
||||
gamemap::location::DIRECTION nearest_hex, second_nearest_hex;
|
||||
gamemap::location hex = gui_.hex_clicked_on(event.x,event.y,&nearest_hex,&second_nearest_hex);
|
||||
|
||||
|
@ -817,7 +823,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
route = enemy_paths_ ? current_paths_.routes.end() :
|
||||
current_paths_.routes.find(hex);
|
||||
|
||||
unit_map::iterator enemy = find_unit(hex);
|
||||
const unit_map::iterator enemy = find_unit(hex);
|
||||
|
||||
const gamemap::location src = selected_hex_;
|
||||
paths orig_paths = current_paths_;
|
||||
|
@ -828,7 +834,7 @@ void turn_info::left_click(const SDL_MouseButtonEvent& event)
|
|||
if(attack_from.valid()) {
|
||||
if(move_unit_along_current_route(false)) { //move the unit without updating shroud
|
||||
u = find_unit(attack_from);
|
||||
enemy = find_unit(hex);
|
||||
// enemy = find_unit(hex);
|
||||
if(u != units_.end() && u->second.side() == team_num_ &&
|
||||
enemy != units_.end() && current_team().is_enemy(enemy->second.side()) && !enemy->second.stone()) {
|
||||
if(attack_enemy(u,enemy) == false) {
|
||||
|
|
|
@ -506,6 +506,12 @@ bool theme::set_resolution(const SDL_Rect& screen)
|
|||
status_.insert(std::pair<std::string,status_item>(i->first,status_item(**j)));
|
||||
}
|
||||
}
|
||||
const config* const unit_image_cfg = status_cfg->child("unit_image");
|
||||
if (unit_image_cfg != NULL) {
|
||||
unit_image_ = object(*unit_image_cfg);
|
||||
} else {
|
||||
unit_image_ = object();
|
||||
}
|
||||
}
|
||||
|
||||
const config::child_list& panel_list = cfg.get_children("panel");
|
||||
|
@ -572,6 +578,11 @@ const SDL_Rect& theme::mini_map_location(const SDL_Rect& screen) const
|
|||
return mini_map_.location(screen);
|
||||
}
|
||||
|
||||
const SDL_Rect& theme::unit_image_location(const SDL_Rect& screen) const
|
||||
{
|
||||
return unit_image_.location(screen);
|
||||
}
|
||||
|
||||
std::map<std::string, config> theme::known_themes;
|
||||
void theme::set_known_themes(const config* cfg){
|
||||
known_themes.clear();
|
||||
|
|
|
@ -147,6 +147,7 @@ public:
|
|||
|
||||
const SDL_Rect& main_map_location(const SDL_Rect& screen) const;
|
||||
const SDL_Rect& mini_map_location(const SDL_Rect& screen) const;
|
||||
const SDL_Rect& unit_image_location(const SDL_Rect& screen) const;
|
||||
|
||||
static void set_known_themes(const config* cfg);
|
||||
static std::vector<std::string> get_known_themes();
|
||||
|
@ -163,7 +164,7 @@ private:
|
|||
|
||||
std::map<std::string,status_item> status_;
|
||||
|
||||
object main_map_, mini_map_;
|
||||
object main_map_, mini_map_, unit_image_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue