Restructured the Editor UI:
Two terrains may now be selected in the palette, one is used for filling when moving selections and cutting/pasting and will be used when drawing with the right button. The context menu is removed, instead the function of the left button is chosen in the right panel and operations that do not need a location to work is chosen from an additional menu.
This commit is contained in:
parent
bef2a622ed
commit
23d62b4e06
14 changed files with 323 additions and 109 deletions
|
@ -194,6 +194,14 @@ alt=yes
|
|||
shift=no
|
||||
[/hotkey]
|
||||
|
||||
[hotkey]
|
||||
command="editdraw"
|
||||
key="d"
|
||||
ctrl=yes
|
||||
alt=no
|
||||
shift=no
|
||||
[/hotkey]
|
||||
|
||||
[resolution]
|
||||
width=800
|
||||
height=600
|
||||
|
@ -205,7 +213,7 @@ height=600
|
|||
[/main_map]
|
||||
|
||||
[menu]
|
||||
title=main_menu
|
||||
title=edit_main_menu
|
||||
image=lite
|
||||
items=editnewmap,editloadmap,editsaveas,editsavemap,editrevert,undo,redo,preferences,editquit
|
||||
rect=3,1,107,22
|
||||
|
@ -214,10 +222,49 @@ height=600
|
|||
[/menu]
|
||||
|
||||
[menu]
|
||||
is_context_menu=true
|
||||
items=undo,redo,editsetstartpos,editfloodfill,editfillselection,editcut,editcopy,editpaste,editresize,editflip
|
||||
title=edit_operations_menu
|
||||
image=lite
|
||||
items=editcut,editcopy,editselectall,editfillselection,editresize,editflip
|
||||
rect=120,1,107,22
|
||||
[/menu]
|
||||
|
||||
# The toolbar.
|
||||
[menu]
|
||||
title="Draw"
|
||||
image=lite_small
|
||||
items=editdraw
|
||||
rect=900,250,55,22
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/menu]
|
||||
|
||||
[menu]
|
||||
title="Flood"
|
||||
image=lite_small
|
||||
items=editfloodfill
|
||||
rect=960,250,55,22
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/menu]
|
||||
|
||||
[menu]
|
||||
title="Start P"
|
||||
image=lite_small
|
||||
items=editsetstartpos
|
||||
rect=900,270,55,22
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/menu]
|
||||
|
||||
[menu]
|
||||
title="Paste"
|
||||
image=lite_small
|
||||
items=editpaste
|
||||
rect=960,270,55,22
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/menu]
|
||||
|
||||
# top panel
|
||||
[panel]
|
||||
image=misc/top-bg.png
|
||||
|
@ -268,12 +315,20 @@ height=600
|
|||
yanchor=fixed
|
||||
[/position]
|
||||
|
||||
[edit_left_button_function]
|
||||
font_size=12
|
||||
rect=900,300,1024,320
|
||||
xanchor=right
|
||||
yanchor=fixed
|
||||
[/edit_left_button_function]
|
||||
|
||||
[selected_terrain]
|
||||
font_size=12
|
||||
rect=900,736,1024,20
|
||||
rect=900,730,1024,20
|
||||
xanchor=right
|
||||
yanchor=bottom
|
||||
[/selected_terrain]
|
||||
|
||||
[/status]
|
||||
|
||||
[/resolution]
|
||||
|
|
|
@ -513,6 +513,7 @@ action_editrevert="Revert from Disk"
|
|||
action_editresize="Resize Map"
|
||||
action_editflip="Flip Map"
|
||||
action_editselectall="Select All"
|
||||
action_editdraw="Draw Terrain"
|
||||
save_hotkeys_button="Save Hotkeys"
|
||||
change_hotkey_button="Change Hotkey"
|
||||
hotkeys_dialog="Hotkey Settings"
|
||||
|
@ -723,5 +724,9 @@ edit_resize_map_title="Resize Map"
|
|||
edit_x_axis="X-Axis"
|
||||
edit_y_axis="Y-Axis"
|
||||
edit_flip_around="Flip around (this may change the dimensions of the map):"
|
||||
edit_operations_menu="Operations"
|
||||
edit_main_menu="Main Menu"
|
||||
edit_foreground_short="FG"
|
||||
edit_background_short="BG"
|
||||
|
||||
[/language]
|
||||
|
|
BIN
images/buttons/lite_small-active.png
Normal file
BIN
images/buttons/lite_small-active.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 593 B |
BIN
images/buttons/lite_small-pressed.png
Normal file
BIN
images/buttons/lite_small-pressed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 606 B |
BIN
images/buttons/lite_small.png
Normal file
BIN
images/buttons/lite_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 593 B |
|
@ -79,12 +79,13 @@ bool map_editor::first_time_created_ = true;
|
|||
int map_editor::num_operations_since_save_ = 0;
|
||||
config map_editor::prefs_;
|
||||
config map_editor::hotkeys_;
|
||||
map_editor::LEFT_BUTTON_FUNC map_editor::l_button_func_ = DRAW;
|
||||
|
||||
map_editor::map_editor(display &gui, gamemap &map, config &theme, config &game_config)
|
||||
: gui_(gui), map_(map), abort_(DONT_ABORT),
|
||||
theme_(theme), game_config_(game_config), map_dirty_(false),
|
||||
palette_(gui, size_specs_, map), brush_(gui, size_specs_),
|
||||
l_button_func_(NONE), prefs_disp_manager_(&gui_), all_hexes_selected_(false) {
|
||||
l_button_held_func_(NONE), prefs_disp_manager_(&gui_), all_hexes_selected_(false) {
|
||||
|
||||
// Set size specs.
|
||||
adjust_sizes(gui_, size_specs_);
|
||||
|
@ -113,6 +114,9 @@ map_editor::map_editor(display &gui, gamemap &map, config &theme, config &game_c
|
|||
hotkey::add_hotkeys(hotkeys_, true);
|
||||
}
|
||||
recalculate_starting_pos_labels();
|
||||
reports::set_report_content(reports::EDIT_LEFT_BUTTON_FUNCTION,
|
||||
translate_string("action_editdraw"));
|
||||
gui_.invalidate_game_status();
|
||||
gui_.begin_game();
|
||||
gui_.invalidate_all();
|
||||
gui_.draw();
|
||||
|
@ -180,38 +184,13 @@ void map_editor::handle_mouse_button_event(const SDL_MouseButtonEvent &event,
|
|||
if (button == SDL_BUTTON_LEFT) {
|
||||
gamemap::location hex_clicked = gui_.hex_clicked_on(mousex, mousey);
|
||||
if (map_.on_board(hex_clicked)) {
|
||||
if (key_[SDLK_LSHIFT] || key_[SDLK_RSHIFT]) {
|
||||
if (selected_hexes_.find(hex_clicked)
|
||||
== selected_hexes_.end()) {
|
||||
l_button_func_ = ADD_SELECTION;
|
||||
}
|
||||
else {
|
||||
l_button_func_ = REMOVE_SELECTION;
|
||||
}
|
||||
}
|
||||
else if (key_[SDLK_RCTRL] || key_[SDLK_LCTRL]) {
|
||||
const gamemap::TERRAIN terrain = map_.get_terrain(selected_hex_);
|
||||
if(palette_.selected_terrain() != terrain) {
|
||||
palette_.select_terrain(terrain);
|
||||
}
|
||||
l_button_func_ = NONE;
|
||||
}
|
||||
else if (selected_hexes_.find(hex_clicked) != selected_hexes_.end()) {
|
||||
l_button_func_ = MOVE_SELECTION;
|
||||
selection_move_start_ = hex_clicked;
|
||||
}
|
||||
else if (!selected_hexes_.empty()) {
|
||||
// If hexes are selected, clear them and do not draw
|
||||
// anything.
|
||||
selected_hexes_.clear();
|
||||
gui_.clear_highlighted_locs();
|
||||
update_mouse_over_hexes(hex_clicked);
|
||||
}
|
||||
else {
|
||||
l_button_func_ = DRAW_TERRAIN;
|
||||
}
|
||||
left_click(hex_clicked);
|
||||
}
|
||||
else {
|
||||
}
|
||||
if (button == SDL_BUTTON_RIGHT) {
|
||||
gamemap::location hex_clicked = gui_.hex_clicked_on(mousex, mousey);
|
||||
if (map_.on_board(hex_clicked)) {
|
||||
right_click(hex_clicked);
|
||||
}
|
||||
}
|
||||
// Mimic the game's behavior on middle click and mouse wheel
|
||||
|
@ -249,13 +228,59 @@ void map_editor::handle_mouse_button_event(const SDL_MouseButtonEvent &event,
|
|||
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
// If we miss the mouse up event we need to perform the actual
|
||||
// movement if we are in the progress of moving a selection.
|
||||
if (l_button_func_ == MOVE_SELECTION) {
|
||||
if (l_button_held_func_ == MOVE_SELECTION) {
|
||||
perform_selection_move();
|
||||
}
|
||||
l_button_func_ = NONE;
|
||||
l_button_held_func_ = NONE;
|
||||
}
|
||||
}
|
||||
|
||||
void map_editor::left_click(const gamemap::location hex_clicked) {
|
||||
if (key_[SDLK_LSHIFT] || key_[SDLK_RSHIFT]) {
|
||||
if (selected_hexes_.find(hex_clicked)
|
||||
== selected_hexes_.end()) {
|
||||
l_button_held_func_ = ADD_SELECTION;
|
||||
}
|
||||
else {
|
||||
l_button_held_func_ = REMOVE_SELECTION;
|
||||
}
|
||||
}
|
||||
else if (key_[SDLK_RCTRL] || key_[SDLK_LCTRL]) {
|
||||
const gamemap::TERRAIN terrain = map_.get_terrain(selected_hex_);
|
||||
if(palette_.selected_fg_terrain() != terrain) {
|
||||
palette_.select_fg_terrain(terrain);
|
||||
}
|
||||
l_button_held_func_ = NONE;
|
||||
}
|
||||
else if (selected_hexes_.find(hex_clicked) != selected_hexes_.end()) {
|
||||
l_button_held_func_ = MOVE_SELECTION;
|
||||
selection_move_start_ = hex_clicked;
|
||||
}
|
||||
else if (!selected_hexes_.empty()) {
|
||||
// If hexes are selected, clear them and do not draw
|
||||
// anything.
|
||||
selected_hexes_.clear();
|
||||
gui_.clear_highlighted_locs();
|
||||
update_mouse_over_hexes(hex_clicked);
|
||||
}
|
||||
else if (l_button_func_ == DRAW) {
|
||||
l_button_held_func_ = DRAW_TERRAIN;
|
||||
}
|
||||
else if (l_button_func_ == FLOOD_FILL) {
|
||||
perform_flood_fill();
|
||||
}
|
||||
else if (l_button_func_ == SET_STARTING_POSITION) {
|
||||
perform_set_starting_pos();
|
||||
}
|
||||
else if (l_button_func_ == PASTE) {
|
||||
perform_paste();
|
||||
}
|
||||
}
|
||||
|
||||
void map_editor::right_click(const gamemap::location /* hex_clicked */) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void map_editor::edit_save_as() {
|
||||
const std::string default_dir =
|
||||
|
@ -283,7 +308,7 @@ void map_editor::edit_save_as() {
|
|||
}
|
||||
}
|
||||
|
||||
void map_editor::edit_set_start_pos() {
|
||||
void map_editor::perform_set_starting_pos() {
|
||||
std::vector<std::string> players;
|
||||
for (int i = 0; i < num_players; i++) {
|
||||
std::stringstream str;
|
||||
|
@ -298,20 +323,30 @@ void map_editor::edit_set_start_pos() {
|
|||
}
|
||||
}
|
||||
|
||||
void map_editor::edit_flood_fill() {
|
||||
void map_editor::edit_set_start_pos() {
|
||||
l_button_func_ = SET_STARTING_POSITION;
|
||||
left_button_func_changed("action_editsetstartpos");
|
||||
}
|
||||
|
||||
void map_editor::perform_flood_fill() {
|
||||
terrain_log log;
|
||||
flood_fill(map_, selected_hex_, palette_.selected_terrain(), &log);
|
||||
flood_fill(map_, selected_hex_, palette_.selected_fg_terrain(), &log);
|
||||
std::vector<gamemap::location> to_invalidate;
|
||||
map_undo_action action;
|
||||
for (terrain_log::iterator it = log.begin(); it != log.end(); it++) {
|
||||
to_invalidate.push_back((*it).first);
|
||||
action.add_terrain((*it).second, palette_.selected_terrain(),
|
||||
action.add_terrain((*it).second, palette_.selected_fg_terrain(),
|
||||
(*it).first);
|
||||
}
|
||||
terrain_changed(to_invalidate, action);
|
||||
save_undo_action(action);
|
||||
}
|
||||
|
||||
void map_editor::edit_flood_fill() {
|
||||
l_button_func_ = FLOOD_FILL;
|
||||
left_button_func_changed("action_editfloodfill");
|
||||
}
|
||||
|
||||
void map_editor::edit_save_map() {
|
||||
save_map("", true);
|
||||
}
|
||||
|
@ -321,7 +356,7 @@ void map_editor::edit_quit() {
|
|||
}
|
||||
|
||||
void map_editor::edit_new_map() {
|
||||
const std::string map = new_map_dialog(gui_, palette_.selected_terrain(),
|
||||
const std::string map = new_map_dialog(gui_, palette_.selected_bg_terrain(),
|
||||
changed_since_save(), game_config_);
|
||||
if (map != "") {
|
||||
num_operations_since_save_ = 0;
|
||||
|
@ -361,8 +396,8 @@ void map_editor::edit_fill_selection() {
|
|||
for (std::set<gamemap::location>::const_iterator it = selected_hexes_.begin();
|
||||
it != selected_hexes_.end(); it++) {
|
||||
if (map_.on_board(*it)) {
|
||||
undo_action.add_terrain(map_.get_terrain(*it), palette_.selected_terrain(), *it);
|
||||
map_.set_terrain(*it, palette_.selected_terrain());
|
||||
undo_action.add_terrain(map_.get_terrain(*it), palette_.selected_bg_terrain(), *it);
|
||||
map_.set_terrain(*it, palette_.selected_bg_terrain());
|
||||
}
|
||||
}
|
||||
terrain_changed(selected_hexes_, undo_action);
|
||||
|
@ -380,7 +415,7 @@ void map_editor::edit_copy() {
|
|||
insert_selection_in_clipboard();
|
||||
}
|
||||
|
||||
void map_editor::edit_paste() {
|
||||
void map_editor::perform_paste() {
|
||||
map_undo_action undo_action;
|
||||
std::set<gamemap::location> filled;
|
||||
gamemap::location start_hex = selected_hex_;
|
||||
|
@ -411,6 +446,11 @@ void map_editor::edit_paste() {
|
|||
save_undo_action(undo_action);
|
||||
}
|
||||
|
||||
void map_editor::edit_paste() {
|
||||
l_button_func_ = PASTE;
|
||||
left_button_func_changed("action_editpaste");
|
||||
}
|
||||
|
||||
void map_editor::edit_revert() {
|
||||
std::string new_map;
|
||||
try {
|
||||
|
@ -435,7 +475,7 @@ void map_editor::edit_resize() {
|
|||
resize_dialog(gui_, map_.x(), map_.y());
|
||||
if (new_size.first != 0) {
|
||||
const std::string resized_map =
|
||||
resize_map(map_, new_size.first, new_size.second, palette_.selected_terrain());
|
||||
resize_map(map_, new_size.first, new_size.second, palette_.selected_bg_terrain());
|
||||
if (resized_map != "") {
|
||||
map_undo_action action;
|
||||
action.set_map_data(map_.write(), resized_map);
|
||||
|
@ -472,6 +512,11 @@ void map_editor::edit_select_all() {
|
|||
highlight_selected_hexes();
|
||||
}
|
||||
|
||||
void map_editor::edit_draw() {
|
||||
l_button_func_ = DRAW;
|
||||
left_button_func_changed("action_editdraw");
|
||||
}
|
||||
|
||||
std::string map_editor::load_map(const std::string filename) {
|
||||
bool load_successful = true;
|
||||
std::string msg;
|
||||
|
@ -554,6 +599,7 @@ bool map_editor::can_execute_command(hotkey::HOTKEY_COMMAND command) const {
|
|||
case hotkey::HOTKEY_EDIT_RESIZE:
|
||||
case hotkey::HOTKEY_EDIT_FLIP:
|
||||
case hotkey::HOTKEY_EDIT_SELECT_ALL:
|
||||
case hotkey::HOTKEY_EDIT_DRAW:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
|
@ -714,7 +760,7 @@ void map_editor::left_button_down(const int mousex, const int mousey) {
|
|||
selected = get_component(map_, selected_hex_);
|
||||
for (std::set<gamemap::location>::const_iterator it = selected.begin();
|
||||
it != selected.end(); it++) {
|
||||
if (l_button_func_ == ADD_SELECTION) {
|
||||
if (l_button_held_func_ == ADD_SELECTION) {
|
||||
gui_.add_highlighted_loc(*it);
|
||||
selected_hexes_.insert(*it);
|
||||
}
|
||||
|
@ -731,7 +777,7 @@ void map_editor::left_button_down(const int mousex, const int mousey) {
|
|||
selected = get_tiles(map_, hex, brush_.selected_brush_size());
|
||||
for (std::vector<gamemap::location>::const_iterator it = selected.begin();
|
||||
it != selected.end(); it++) {
|
||||
if (l_button_func_ == ADD_SELECTION) {
|
||||
if (l_button_held_func_ == ADD_SELECTION) {
|
||||
gui_.add_highlighted_loc(*it);
|
||||
selected_hexes_.insert(*it);
|
||||
}
|
||||
|
@ -745,34 +791,10 @@ void map_editor::left_button_down(const int mousex, const int mousey) {
|
|||
}
|
||||
// If the left mouse button is down and we beforhand have registred
|
||||
// a mouse down event, draw terrain at the current location.
|
||||
else if (l_button_func_ == DRAW_TERRAIN) {
|
||||
if(map_.on_board(hex)) {
|
||||
const gamemap::TERRAIN terrain = map_[hex.x][hex.y];
|
||||
// optimize for common case
|
||||
if(brush_.selected_brush_size() == 1) {
|
||||
if(palette_.selected_terrain() != terrain) {
|
||||
draw_terrain(palette_.selected_terrain(), hex);
|
||||
}
|
||||
}
|
||||
std::vector<gamemap::location> locs =
|
||||
get_tiles(map_, hex, brush_.selected_brush_size());
|
||||
map_undo_action action;
|
||||
std::vector<gamemap::location> to_invalidate;
|
||||
for(std::vector<gamemap::location>::const_iterator it = locs.begin();
|
||||
it != locs.end(); ++it) {
|
||||
if(palette_.selected_terrain() != map_[it->x][it->y]) {
|
||||
to_invalidate.push_back(*it);
|
||||
action.add_terrain(map_[it->x][it->y], palette_.selected_terrain(), *it);
|
||||
map_.set_terrain(*it, palette_.selected_terrain());
|
||||
}
|
||||
}
|
||||
if (!to_invalidate.empty()) {
|
||||
terrain_changed(to_invalidate, action);
|
||||
save_undo_action(action);
|
||||
}
|
||||
}
|
||||
else if (l_button_held_func_ == DRAW_TERRAIN) {
|
||||
draw_on_mouseover_hexes(palette_.selected_fg_terrain());
|
||||
}
|
||||
else if (l_button_func_ == MOVE_SELECTION) {
|
||||
else if (l_button_held_func_ == MOVE_SELECTION) {
|
||||
const int x_diff = hex.x - selection_move_start_.x;
|
||||
const int y_diff = hex.y - selection_move_start_.y;
|
||||
// No other selections should be active when doing this.
|
||||
|
@ -788,6 +810,35 @@ void map_editor::left_button_down(const int mousex, const int mousey) {
|
|||
}
|
||||
}
|
||||
|
||||
void map_editor::draw_on_mouseover_hexes(const gamemap::TERRAIN terrain) {
|
||||
const gamemap::location hex = selected_hex_;
|
||||
if(map_.on_board(hex)) {
|
||||
const gamemap::TERRAIN old_terrain = map_[hex.x][hex.y];
|
||||
// optimize for common case
|
||||
if(brush_.selected_brush_size() == 1) {
|
||||
if(terrain != old_terrain) {
|
||||
draw_terrain(terrain, hex);
|
||||
}
|
||||
}
|
||||
std::vector<gamemap::location> locs =
|
||||
get_tiles(map_, hex, brush_.selected_brush_size());
|
||||
map_undo_action action;
|
||||
std::vector<gamemap::location> to_invalidate;
|
||||
for(std::vector<gamemap::location>::const_iterator it = locs.begin();
|
||||
it != locs.end(); ++it) {
|
||||
if(terrain != map_[it->x][it->y]) {
|
||||
to_invalidate.push_back(*it);
|
||||
action.add_terrain(map_.get_terrain(*it), terrain, *it);
|
||||
map_.set_terrain(*it, terrain);
|
||||
}
|
||||
}
|
||||
if (!to_invalidate.empty()) {
|
||||
terrain_changed(to_invalidate, action);
|
||||
save_undo_action(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void map_editor::perform_selection_move() {
|
||||
map_undo_action undo_action;
|
||||
const int x_diff = selected_hex_.x - selection_move_start_.x;
|
||||
|
@ -816,8 +867,8 @@ void map_editor::perform_selection_move() {
|
|||
// Fill the selection with the selected terrain.
|
||||
for (it = selected_hexes_.begin(); it != selected_hexes_.end(); it++) {
|
||||
if (map_.on_board(*it) && new_selection.find(*it) == new_selection.end()) {
|
||||
undo_action.add_terrain(map_.get_terrain(*it), palette_.selected_terrain(), *it);
|
||||
map_.set_terrain(*it, palette_.selected_terrain());
|
||||
undo_action.add_terrain(map_.get_terrain(*it), palette_.selected_bg_terrain(), *it);
|
||||
map_.set_terrain(*it, palette_.selected_bg_terrain());
|
||||
}
|
||||
}
|
||||
undo_action.set_selection(selected_hexes_, new_selection);
|
||||
|
@ -906,9 +957,13 @@ void map_editor::invalidate_all_and_adjacent(const std::set<gamemap::location> &
|
|||
invalidate_all_and_adjacent(v);
|
||||
}
|
||||
|
||||
void map_editor::right_button_down(const int /*mousex*/, const int /*mousey*/) {
|
||||
void map_editor::right_button_down(const int mousex, const int mousey) {
|
||||
// Draw with the bacground terrain on rightclick, no matter what
|
||||
// operations are wanted with the left button.
|
||||
// TODO evaluate if this is what is the smartest thing to do.
|
||||
draw_on_mouseover_hexes(palette_.selected_bg_terrain());
|
||||
}
|
||||
|
||||
|
||||
void map_editor::middle_button_down(const int mousex, const int mousey) {
|
||||
const gamemap::location& minimap_loc = gui_.minimap_location_on(mousex,mousey);
|
||||
const gamemap::location hex = gui_.hex_clicked_on(mousex, mousey);
|
||||
|
@ -1050,6 +1105,15 @@ void map_editor::update_mouse_over_hexes(const gamemap::location mouse_over_hex)
|
|||
selected_hex_ = mouse_over_hex;
|
||||
}
|
||||
|
||||
void map_editor::left_button_func_changed(const std::string &new_function) {
|
||||
reports::set_report_content(reports::EDIT_LEFT_BUTTON_FUNCTION,
|
||||
translate_string(new_function));
|
||||
//palette_.set_dirty();
|
||||
//brush_.set_dirty();
|
||||
|
||||
gui_.invalidate_game_status();
|
||||
}
|
||||
|
||||
void map_editor::main_loop() {
|
||||
unsigned int last_brush_size = brush_.selected_brush_size();
|
||||
while (abort_ == DONT_ABORT) {
|
||||
|
@ -1096,7 +1160,7 @@ void map_editor::main_loop() {
|
|||
left_button_down(mousex, mousey);
|
||||
}
|
||||
else {
|
||||
if (l_button_func_ == MOVE_SELECTION) {
|
||||
if (l_button_held_func_ == MOVE_SELECTION) {
|
||||
// When it is detected that the mouse is no longer down
|
||||
// and we are in the progress of moving a selection,
|
||||
// perform the movement.
|
||||
|
@ -1117,7 +1181,7 @@ void map_editor::main_loop() {
|
|||
// not held down and then update the minimap and the starting
|
||||
// position labels.
|
||||
if (map_dirty_) {
|
||||
if (!l_button_down) {
|
||||
if (!l_button_down && !r_button_down) {
|
||||
map_dirty_ = false;
|
||||
// XXX Currently this rebuilds all terrain, so we only want to do it once.
|
||||
gui_.rebuild_terrain(gamemap::location(1,1));
|
||||
|
|
|
@ -113,6 +113,11 @@ public:
|
|||
/// Either select or deselect all hexes on the map depending on if
|
||||
/// this operations has been invoked before or not.
|
||||
virtual void edit_select_all();
|
||||
virtual void edit_draw();
|
||||
|
||||
void perform_flood_fill();
|
||||
void perform_paste();
|
||||
void perform_set_starting_pos();
|
||||
|
||||
virtual bool can_execute_command(hotkey::HOTKEY_COMMAND command) const;
|
||||
|
||||
|
@ -128,10 +133,16 @@ private:
|
|||
/// Called in every iteration when the left mouse button is held
|
||||
/// down. Note that this differs from a click.
|
||||
void left_button_down(const int mousex, const int mousey);
|
||||
|
||||
/// Handle a left click on the location.
|
||||
void left_click(const gamemap::location loc);
|
||||
|
||||
/// Called in every iteration when the right mouse button is held
|
||||
/// down. Note that this differs from a click.
|
||||
void right_button_down(const int mousex, const int mousey);
|
||||
|
||||
/// Handle a right click on the location.
|
||||
void right_click(const gamemap::location loc);
|
||||
|
||||
/// Called in every iteration when the middle mouse button is held
|
||||
/// down. Note that this differs from a click.
|
||||
|
@ -223,6 +234,15 @@ private:
|
|||
/// number done since save.
|
||||
void save_undo_action(const map_undo_action &action);
|
||||
|
||||
/// Call when the left mouse button function has changed. Updated
|
||||
/// the report indicating what will be performed. New_function is
|
||||
/// the hotkey-string describing the action.
|
||||
void left_button_func_changed(const std::string &new_function);
|
||||
|
||||
/// Draw the terrain on the hexes the mouse is over, taking account
|
||||
/// for brush size.
|
||||
void draw_on_mouseover_hexes(const gamemap::TERRAIN t);
|
||||
|
||||
/// An item in the clipboard. Consists of the copied terrain and an
|
||||
/// offset. When pasting stuff, the offset is used to calculate
|
||||
/// where to put the pasted hex when calculating from the one
|
||||
|
@ -237,8 +257,12 @@ private:
|
|||
};
|
||||
|
||||
/// What to perform while the left button is held down.
|
||||
enum LEFT_BUTTON_FUNC {DRAW_TERRAIN, ADD_SELECTION, REMOVE_SELECTION,
|
||||
MOVE_SELECTION, NONE};
|
||||
enum LEFT_BUTTON_HELD_FUNC {DRAW_TERRAIN, ADD_SELECTION, REMOVE_SELECTION,
|
||||
MOVE_SELECTION, NONE};
|
||||
|
||||
/// What to perform on a left button click.
|
||||
enum LEFT_BUTTON_FUNC {DRAW, SELECT_HEXES, FLOOD_FILL,
|
||||
SET_STARTING_POSITION, PASTE};
|
||||
|
||||
display &gui_;
|
||||
gamemap &map_;
|
||||
|
@ -264,7 +288,7 @@ private:
|
|||
std::set<gamemap::location> selected_hexes_;
|
||||
std::vector<clipboard_item> clipboard_;
|
||||
gamemap::location clipboard_offset_loc_;
|
||||
LEFT_BUTTON_FUNC l_button_func_;
|
||||
LEFT_BUTTON_HELD_FUNC l_button_held_func_;
|
||||
gamemap::location selection_move_start_;
|
||||
// mouse_moved_ will be true if the mouse have moved between two
|
||||
// cycles.
|
||||
|
@ -273,6 +297,7 @@ private:
|
|||
static config prefs_;
|
||||
static config hotkeys_;
|
||||
static bool first_time_created_;
|
||||
static LEFT_BUTTON_FUNC l_button_func_;
|
||||
bool all_hexes_selected_;
|
||||
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ void adjust_sizes(const display &disp, size_specs &sizes) {
|
|||
sizes.brush_x = disp.mapx() + 33;
|
||||
sizes.brush_y = 190;
|
||||
sizes.palette_x = disp.mapx() + 40;
|
||||
sizes.palette_y = sizes.brush_y + 30 + 10;
|
||||
sizes.palette_y = sizes.brush_y + 160 + 10;
|
||||
sizes.palette_w = sizes.terrain_space * 2;
|
||||
sizes.palette_h = disp.y() - sizes.palette_y - 60;
|
||||
}
|
||||
|
|
|
@ -42,10 +42,10 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
|
|||
std::cerr << "No terrain found.\n";
|
||||
}
|
||||
else {
|
||||
selected_terrain_ = terrains_[0];
|
||||
selected_fg_terrain_ = terrains_[0];
|
||||
selected_bg_terrain_ = terrains_[0];
|
||||
}
|
||||
reports::set_report_content(reports::SELECTED_TERRAIN,
|
||||
get_terrain_string(selected_terrain()));
|
||||
update_report();
|
||||
adjust_size();
|
||||
}
|
||||
|
||||
|
@ -110,14 +110,25 @@ void terrain_palette::scroll_bottom() {
|
|||
}
|
||||
}
|
||||
|
||||
gamemap::TERRAIN terrain_palette::selected_terrain() const {
|
||||
return selected_terrain_;
|
||||
gamemap::TERRAIN terrain_palette::selected_fg_terrain() const {
|
||||
return selected_fg_terrain_;
|
||||
}
|
||||
|
||||
void terrain_palette::select_terrain(gamemap::TERRAIN terrain) {
|
||||
if (selected_terrain_ != terrain) {
|
||||
gamemap::TERRAIN terrain_palette::selected_bg_terrain() const {
|
||||
return selected_bg_terrain_;
|
||||
}
|
||||
|
||||
void terrain_palette::select_fg_terrain(gamemap::TERRAIN terrain) {
|
||||
if (selected_fg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
selected_terrain_ = terrain;
|
||||
selected_fg_terrain_ = terrain;
|
||||
}
|
||||
}
|
||||
|
||||
void terrain_palette::select_bg_terrain(gamemap::TERRAIN terrain) {
|
||||
if (selected_bg_terrain_ != terrain) {
|
||||
set_dirty();
|
||||
selected_bg_terrain_ = terrain;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,9 +155,17 @@ std::string terrain_palette::get_terrain_string(const gamemap::TERRAIN t) {
|
|||
void terrain_palette::left_mouse_click(const int mousex, const int mousey) {
|
||||
int tselect = tile_selected(mousex, mousey);
|
||||
if(tselect >= 0) {
|
||||
select_terrain(terrains_[tstart_+tselect]);
|
||||
reports::set_report_content(reports::SELECTED_TERRAIN,
|
||||
get_terrain_string(selected_terrain()));
|
||||
select_fg_terrain(terrains_[tstart_+tselect]);
|
||||
update_report();
|
||||
gui_.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
|
||||
void terrain_palette::right_mouse_click(const int mousex, const int mousey) {
|
||||
int tselect = tile_selected(mousex, mousey);
|
||||
if(tselect >= 0) {
|
||||
select_bg_terrain(terrains_[tstart_+tselect]);
|
||||
update_report();
|
||||
gui_.invalidate_game_status();
|
||||
}
|
||||
}
|
||||
|
@ -184,6 +203,9 @@ void terrain_palette::handle_event(const SDL_Event& event) {
|
|||
if (mouse_button_event.button == SDL_BUTTON_LEFT) {
|
||||
left_mouse_click(mousex, mousey);
|
||||
}
|
||||
if (mouse_button_event.button == SDL_BUTTON_RIGHT) {
|
||||
right_mouse_click(mousex, mousey);
|
||||
}
|
||||
if (mouse_button_event.button == SDL_BUTTON_WHEELUP) {
|
||||
scroll_up();
|
||||
}
|
||||
|
@ -237,9 +259,18 @@ void terrain_palette::draw(bool force) {
|
|||
dstrect.h = image->h;
|
||||
|
||||
SDL_BlitSurface(image, NULL, screen, &dstrect);
|
||||
gui::draw_rectangle(dstrect.x, dstrect.y, image->w, image->h,
|
||||
terrain == selected_terrain() ? 0xF000:0 , screen);
|
||||
|
||||
if (terrain == selected_bg_terrain() && terrain == selected_fg_terrain()) {
|
||||
gui::draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, 0x0F00, screen);
|
||||
}
|
||||
else if (terrain == selected_bg_terrain()) {
|
||||
gui::draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, 0x00F0, screen);
|
||||
}
|
||||
else if (terrain == selected_fg_terrain()) {
|
||||
gui::draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, 0xF000, screen);
|
||||
}
|
||||
else {
|
||||
gui::draw_rectangle(dstrect.x, dstrect.y, image->w, image->h, 0, screen);
|
||||
}
|
||||
if (counter_from_zero % 2 != 0)
|
||||
y += size_specs_.terrain_space;
|
||||
}
|
||||
|
@ -261,6 +292,13 @@ int terrain_palette::tile_selected(const int x, const int y) const {
|
|||
return -1;
|
||||
}
|
||||
|
||||
void terrain_palette::update_report() {
|
||||
const std::string msg = translate_string("edit_foreground_short") + ": "
|
||||
+ get_terrain_string(selected_fg_terrain()) + "\n"
|
||||
+ translate_string("edit_background_short") +
|
||||
": " + get_terrain_string(selected_bg_terrain());
|
||||
reports::set_report_content(reports::SELECTED_TERRAIN, msg);
|
||||
}
|
||||
|
||||
brush_bar::brush_bar(display &gui, const size_specs &sizes)
|
||||
: gui::widget(gui), size_specs_(sizes), gui_(gui), selected_(0), total_brush_(3),
|
||||
|
|
|
@ -43,11 +43,15 @@ public:
|
|||
/// Scroll the terrain palette to the bottom.
|
||||
void scroll_bottom();
|
||||
|
||||
/// Return the currently selected terrain.
|
||||
gamemap::TERRAIN selected_terrain() const;
|
||||
/// Return the currently selected foreground terrain.
|
||||
gamemap::TERRAIN selected_fg_terrain() const;
|
||||
/// Return the currently selected background terrain.
|
||||
gamemap::TERRAIN selected_bg_terrain() const;
|
||||
|
||||
/// Select a terrain.
|
||||
void select_terrain(gamemap::TERRAIN);
|
||||
|
||||
/// Select a foreground terrain.
|
||||
void select_fg_terrain(gamemap::TERRAIN);
|
||||
void select_bg_terrain(gamemap::TERRAIN);
|
||||
|
||||
// Draw the palette. If force is true everything will be redrawn
|
||||
// even though it is not invalidated.
|
||||
|
@ -69,6 +73,8 @@ private:
|
|||
/// is a terrain that may be chosen, select the terrain if that is
|
||||
/// the case.
|
||||
void left_mouse_click(const int mousex, const int mousey);
|
||||
void right_mouse_click(const int mousex, const int mousey);
|
||||
|
||||
|
||||
/// Return the number of the tile that is at coordinates (x, y) in the
|
||||
/// panel.
|
||||
|
@ -77,11 +83,14 @@ private:
|
|||
/// Return a string represeting the terrain and the underlying ones.
|
||||
std::string get_terrain_string(const gamemap::TERRAIN);
|
||||
|
||||
/// Update the report with the currently selected terrains.
|
||||
void update_report();
|
||||
|
||||
const size_specs &size_specs_;
|
||||
display &gui_;
|
||||
unsigned int tstart_;
|
||||
std::vector<gamemap::TERRAIN> terrains_;
|
||||
gamemap::TERRAIN selected_terrain_;
|
||||
gamemap::TERRAIN selected_fg_terrain_, selected_bg_terrain_;
|
||||
const gamemap &map_;
|
||||
gui::button top_button_, bot_button_;
|
||||
size_t button_x_, top_button_y_, bot_button_y_;
|
||||
|
|
|
@ -82,6 +82,7 @@ HOTKEY_COMMAND string_to_command(const std::string& str)
|
|||
m.insert(val("editresize",HOTKEY_EDIT_RESIZE));
|
||||
m.insert(val("editflip",HOTKEY_EDIT_FLIP));
|
||||
m.insert(val("editselectall",HOTKEY_EDIT_SELECT_ALL));
|
||||
m.insert(val("editdraw",HOTKEY_EDIT_DRAW));
|
||||
m.insert(val("delayshroud",HOTKEY_DELAY_SHROUD));
|
||||
m.insert(val("updateshroud",HOTKEY_UPDATE_SHROUD));
|
||||
m.insert(val("continue",HOTKEY_CONTINUE_MOVE));
|
||||
|
@ -513,6 +514,10 @@ void execute_command(display& disp, HOTKEY_COMMAND command, command_executor* ex
|
|||
if(executor)
|
||||
executor->edit_select_all();
|
||||
break;
|
||||
case HOTKEY_EDIT_DRAW:
|
||||
if(executor)
|
||||
executor->edit_draw();
|
||||
break;
|
||||
default:
|
||||
std::cerr << "command_executor: unknown command number " << command << ", ignoring.\n";
|
||||
break;
|
||||
|
|
|
@ -44,7 +44,7 @@ enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER,
|
|||
HOTKEY_EDIT_NEW_MAP, HOTKEY_EDIT_LOAD_MAP, HOTKEY_EDIT_FLOOD_FILL,
|
||||
HOTKEY_EDIT_FILL_SELECTION, HOTKEY_EDIT_CUT, HOTKEY_EDIT_COPY,
|
||||
HOTKEY_EDIT_PASTE, HOTKEY_EDIT_REVERT, HOTKEY_EDIT_RESIZE,
|
||||
HOTKEY_EDIT_FLIP, HOTKEY_EDIT_SELECT_ALL,
|
||||
HOTKEY_EDIT_FLIP, HOTKEY_EDIT_SELECT_ALL, HOTKEY_EDIT_DRAW,
|
||||
HOTKEY_NULL };
|
||||
|
||||
struct hotkey_item {
|
||||
|
@ -136,6 +136,7 @@ public:
|
|||
virtual void edit_resize() {}
|
||||
virtual void edit_flip() {}
|
||||
virtual void edit_select_all() {}
|
||||
virtual void edit_draw() {}
|
||||
|
||||
//Gets the action's image (if any). Displayed left of the action text in menus.
|
||||
virtual std::string get_action_image(hotkey::HOTKEY_COMMAND command) const { return ""; }
|
||||
|
|
|
@ -14,7 +14,8 @@ namespace {
|
|||
"unit_traits","unit_status","unit_alignment","unit_abilities","unit_hp","unit_xp",
|
||||
"unit_moves","unit_weapons","unit_image","unit_profile","time_of_day",
|
||||
"turn","gold","villages","num_units","upkeep", "expenses",
|
||||
"income", "terrain", "position", "side_playing", "observers", "selected_terrain"};
|
||||
"income", "terrain", "position", "side_playing", "observers", "selected_terrain",
|
||||
"edit_left_button_function"};
|
||||
std::map<reports::TYPE, std::string> report_contents;
|
||||
}
|
||||
|
||||
|
@ -374,6 +375,16 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
|
|||
return report();
|
||||
}
|
||||
}
|
||||
case EDIT_LEFT_BUTTON_FUNCTION: {
|
||||
std::map<TYPE, std::string>::const_iterator it =
|
||||
report_contents.find(EDIT_LEFT_BUTTON_FUNCTION);
|
||||
if (it != report_contents.end()) {
|
||||
return report(it->second);
|
||||
}
|
||||
else {
|
||||
return report();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return report(str.str());
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace reports {
|
|||
UNIT_ALIGNMENT, UNIT_ABILITIES, UNIT_HP, UNIT_XP, UNIT_MOVES, UNIT_WEAPONS,
|
||||
UNIT_IMAGE, UNIT_PROFILE, TIME_OF_DAY,
|
||||
TURN, GOLD, VILLAGES, NUM_UNITS, UPKEEP, EXPENSES, INCOME, TERRAIN, POSITION,
|
||||
SIDE_PLAYING, OBSERVERS, SELECTED_TERRAIN, NUM_REPORTS};
|
||||
SIDE_PLAYING, OBSERVERS, SELECTED_TERRAIN, EDIT_LEFT_BUTTON_FUNCTION,
|
||||
NUM_REPORTS};
|
||||
|
||||
enum { UNIT_REPORTS_BEGIN=UNIT_DESCRIPTION, UNIT_REPORTS_END=UNIT_PROFILE+1 };
|
||||
enum { STATUS_REPORTS_BEGIN=TIME_OF_DAY, STATUS_REPORTS_END=NUM_REPORTS};
|
||||
|
@ -68,7 +69,7 @@ namespace reports {
|
|||
// which_report. Note that this only works for some reports,
|
||||
// i.e. reports that can not be deducted from the supplied arguments
|
||||
// to generate_report.
|
||||
// Currently: SELECTED_TERRAIN
|
||||
// Currently: SELECTED_TERRAIN, EDIT_LEFT_BUTTON_FUNCTION
|
||||
void set_report_content(const TYPE which_report, const std::string &content);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue