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

building fix - small/large buildings and flags using mouse click on map #474

Open
p1plp1 opened this issue Aug 23, 2020 · 0 comments
Open

Comments

@p1plp1
Copy link

p1plp1 commented Aug 23, 2020

add this to viewport.cc:
bool
Viewport::handle_click_right(int lx, int ly) {
set_redraw();
Player *player = interface->get_player();
MapPos clk_pos = map_pos_from_screen_pix(lx, ly);
if (interface->is_building_road()) {
return false;
} else {
if ((map->get_obj(clk_pos) == Map::ObjectFlag) && (map->get_owner(clk_pos) == player->get_index())) {
//flag popup
interface->update_map_cursor_pos(clk_pos);
player->temp_index = map->get_obj_index(clk_pos);
play_sound(Audio::TypeSfxClick);
interface->open_popup(PopupBox::TypeTransportInfo);
interface->update_map_cursor_pos(clk_pos);
return false;
}
}
return true;
}
...
bool
Viewport::handle_dbl_click(int lx, int ly, Event::Button button) {
...
} else {
//build dblclick fix
Log::Info["map:get_obj"] << "object: " << map->get_obj(clk_pos);
switch (interface->get_build_possibility()) {
case Interface::BuildPossibilityFlag:
if ((map->get_obj(clk_pos) == Map::ObjectNone) ||
(map->get_obj(clk_pos) == Map::ObjectFelledPine4) || (map->get_obj(clk_pos) == Map::ObjectFelledTree4) ||
(map->get_obj(clk_pos) >= Map::ObjectStub && map->get_obj(clk_pos) <= Map::ObjectCadaver1)) {
interface->get_game()->build_flag(interface->get_map_cursor_pos(),player);
interface->update_map_cursor_pos(clk_pos);
play_sound(Audio::TypeSfxClick);
return false;
}
break;
case Interface::BuildPossibilityCastle:
if ((map->get_obj(clk_pos) == Map::ObjectNone) ||
(map->get_obj(clk_pos) >= Map::ObjectStub && map->get_obj(clk_pos) <= Map::ObjectSandstone3)) {
interface->get_game()->build_castle(interface->get_map_cursor_pos(),player);
interface->update_map_cursor_pos(clk_pos);
play_sound(Audio::TypeSfxClick);
return false;
}
break;
case Interface::BuildPossibilityMine:
if ((map->get_obj(clk_pos) == Map::ObjectNone) ||
(map->get_obj(clk_pos) >= Map::ObjectSignLargeGold && map->get_obj(clk_pos) <= Map::ObjectSignEmpty)) {
interface->open_popup(PopupBox::TypeMineBuilding);
interface->update_map_cursor_pos(clk_pos);
play_sound(Audio::TypeSfxClick);
return false;
}
break;
case Interface::BuildPossibilitySmall:
if ((map->get_obj(clk_pos) == Map::ObjectNone) ||
(map->get_obj(clk_pos) == Map::ObjectFelledPine4) || (map->get_obj(clk_pos) == Map::ObjectFelledTree4) ||
(map->get_obj(clk_pos) >= Map::ObjectStub && map->get_obj(clk_pos) <= Map::ObjectSandstone3)) {
interface->open_popup(PopupBox::TypeBasicBld);
interface->update_map_cursor_pos(clk_pos);
play_sound(Audio::TypeSfxClick);
return false;
}
break;
case Interface::BuildPossibilityLarge:
if ((map->get_obj(clk_pos) == Map::ObjectNone) ||
(map->get_obj(clk_pos) == Map::ObjectFelledPine4) || (map->get_obj(clk_pos) == Map::ObjectFelledTree4) ||
(map->get_obj(clk_pos) >= Map::ObjectStub && map->get_obj(clk_pos) <= Map::ObjectSandstone3)) {
interface->open_popup(PopupBox::TypeBasicBldFlip);
interface->update_map_cursor_pos(clk_pos);
play_sound(Audio::TypeSfxClick);
return false;
}
break;
default:
break;
}
if (map->get_obj(clk_pos) > Map::ObjectCastle) {
return false;
}

if (map->get_obj(clk_pos) == Map::ObjectFlag) {
  if (map->get_owner(clk_pos) == player->get_index()) {
	interface->build_road_begin();
    //move to 2nd button interface->open_popup(PopupBox::TypeTransportInfo);
  }

  player->temp_index = map->get_obj_index(clk_pos);
} else { /* Building */

...

viewport.h:
...
virtual bool handle_click_right(int x, int y);
...

gui.cc:
case Event::TypeClick:
if (event->button == Event::ButtonLeft) {
result = handle_click_left(event_x, event_y);
}
if (event->button == Event::ButtonRight) {
result = handle_click_right(event_x, event_y);
}
break;

gui.h:
virtual bool handle_click_right(int x, int y) { return false; }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant