editor2: allow resizing the map in any direction,

...the dialog needs some more work (use icons instead of text in the
descriptions). Also use the map sizes sans the border in dialogs.
This commit is contained in:
Tomasz Śniatowski 2008-08-09 17:32:45 +01:00
parent 5dd7f5c3e5
commit f2aea15b1f
7 changed files with 232 additions and 21 deletions

View file

@ -134,6 +134,115 @@
[/grid]
[/column]
[/row]
[row]
[column]
[label]
definition = "default"
label = _ "Expand / shrink direction"
[/label]
[/column]
[/row]
[row]
[column]
[grid]
[row]
grow_factor = 1
[column]
grow_factor = 0
[toggle_button]
id = "expand0"
definition = "default"
label = "Bottom / right"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand1"
definition = "default"
label = "Bottom / center"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand2"
definition = "default"
label = "Bottom / left"
[/toggle_button]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 0
[toggle_button]
id = "expand3"
definition = "default"
label = "Center / right"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand4"
definition = "default"
label = "Center"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand5"
definition = "default"
label = "Center / left"
[/toggle_button]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 0
[toggle_button]
id = "expand6"
definition = "default"
label = "Top / right"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand7"
definition = "default"
label = "Top / center"
[/toggle_button]
[/column]
[column]
grow_factor = 0
[toggle_button]
id = "expand8"
definition = "default"
label = "Top / left"
[/toggle_button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
horizontal_alignment = "right"
[toggle_button]
id = "copy_edge_terrain"
definition = "default"
label = _ "Copy edge terrain"
[/toggle_button]
[/column]
[/row]
[row]
grow_factor = 0
[column]

View file

@ -248,7 +248,7 @@ void editor_action_select_inverse::perform_without_undo(map_context& mc) const
void editor_action_resize_map::perform_without_undo(map_context& mc) const
{
mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_);
mc.get_map().resize(x_size_, y_size_, x_offset_, y_offset_, fill_);
mc.set_needs_reload();
}

View file

@ -233,8 +233,9 @@ class editor_action_select_inverse : public editor_action
class editor_action_resize_map : public editor_action
{
public:
editor_action_resize_map(int x_size, int y_size, int x_offset, int y_offset)
: x_size_(x_size), y_size_(y_size), x_offset_(x_offset), y_offset_(y_offset)
editor_action_resize_map(int x_size, int y_size, int x_offset, int y_offset,
t_translation::t_terrain fill = t_translation::NONE_TERRAIN)
: x_size_(x_size), y_size_(y_size), x_offset_(x_offset), y_offset_(y_offset), fill_(fill)
{
}
void perform_without_undo(map_context& mc) const;
@ -243,6 +244,7 @@ class editor_action_resize_map : public editor_action
int y_size_;
int x_offset_;
int y_offset_;
t_translation::t_terrain fill_;
};
//basic rotations. angle is multiplied by 90 degrees so 2 does a 180 turn

View file

@ -68,6 +68,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
WRN_ED << "No brushes defined!";
}
brush_ = &brushes_[0];
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_PAINT,
new mouse_action_paint(foreground_terrain_, &brush_, key_)));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_FILL,
@ -79,6 +80,9 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
new mouse_action_paste(clipboard_)));
hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);
background_terrain_ = t_translation::GRASS_LAND;
foreground_terrain_ = t_translation::MOUNTAIN;
get_map_context().set_starting_position_labels(gui());
cursor::set(cursor::NORMAL);
gui_->invalidate_game_status();
@ -162,8 +166,8 @@ void editor_controller::new_map_dialog()
{
if (!confirm_discard()) return;
gui2::teditor_new_map dialog;
dialog.set_map_width(get_map().total_width());
dialog.set_map_height(get_map().total_height());
dialog.set_map_width(get_map().w());
dialog.set_map_height(get_map().h());
dialog.show(gui().video());
int res = dialog.get_retval();
@ -230,20 +234,64 @@ void editor_controller::generate_map_dialog()
void editor_controller::resize_map_dialog()
{
gui2::teditor_resize_map dialog;
dialog.set_map_width(get_map().total_width());
dialog.set_map_height(get_map().total_height());
dialog.set_old_map_width(get_map().total_width());
dialog.set_old_map_height(get_map().total_height());
dialog.set_map_width(get_map().w());
dialog.set_map_height(get_map().h());
dialog.set_old_map_width(get_map().w());
dialog.set_old_map_height(get_map().h());
dialog.show(gui().video());
int res = dialog.get_retval();
if(res == gui2::twindow::OK) {
int w = dialog.map_width();
int h = dialog.map_height();
t_translation::t_terrain fill = t_translation::GRASS_LAND;
editor_action_resize_map a(w, h, 0, 0);
get_map_context().perform_action(a);
refresh_after_action();
if (w != get_map().w() || h != get_map().h()) {
t_translation::t_terrain fill = background_terrain_;
if (dialog.copy_edge_terrain()) {
fill = t_translation::NONE_TERRAIN;
}
int x_offset = get_map().w() - w;
int y_offset = get_map().h() - h;
switch (dialog.expand_direction()) {
case gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
case gui2::teditor_resize_map::EXPAND_BOTTOM:
case gui2::teditor_resize_map::EXPAND_BOTTOM_LEFT:
y_offset = 0;
break;
case gui2::teditor_resize_map::EXPAND_RIGHT:
case gui2::teditor_resize_map::EXPAND_CENTER:
case gui2::teditor_resize_map::EXPAND_LEFT:
y_offset /= 2;
break;
case gui2::teditor_resize_map::EXPAND_TOP_RIGHT:
case gui2::teditor_resize_map::EXPAND_TOP:
case gui2::teditor_resize_map::EXPAND_TOP_LEFT:
break;
default:
y_offset = 0;
WRN_ED << "Unknown resize expand direction\n";
}
switch (dialog.expand_direction()) {
case gui2::teditor_resize_map::EXPAND_BOTTOM_RIGHT:
case gui2::teditor_resize_map::EXPAND_RIGHT:
case gui2::teditor_resize_map::EXPAND_TOP_RIGHT:
x_offset = 0;
break;
case gui2::teditor_resize_map::EXPAND_BOTTOM:
case gui2::teditor_resize_map::EXPAND_CENTER:
case gui2::teditor_resize_map::EXPAND_TOP:
x_offset /= 2;
break;
case gui2::teditor_resize_map::EXPAND_BOTTOM_LEFT:
case gui2::teditor_resize_map::EXPAND_LEFT:
case gui2::teditor_resize_map::EXPAND_TOP_LEFT:
break;
default:
x_offset = 0;
}
editor_action_resize_map a(w, h, x_offset, y_offset, fill);
get_map_context().perform_action(a);
refresh_after_action();
}
}
}

View file

@ -35,7 +35,7 @@ editor_map::editor_map(const config& terrain_cfg, const std::string& data)
editor_map::editor_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler)
: gamemap(terrain_cfg, gamemap::default_map_header + t_translation::write_game_map(
t_translation::t_map(width, t_translation::t_list(height, filler))))
t_translation::t_map(width + 2, t_translation::t_list(height + 2, filler))))
{
sanity_check();
}
@ -159,8 +159,8 @@ bool editor_map::everything_selected() const
void editor_map::resize(int width, int height, int x_offset, int y_offset,
t_translation::t_terrain filler)
{
int old_w = total_width();
int old_h = total_height();
int old_w = w();
int old_h = h();
if (old_w == width && old_h == height && x_offset == 0 && y_offset == 0) {
return;
}

View file

@ -21,6 +21,7 @@
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/slider.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/window_builder.hpp"
@ -37,9 +38,20 @@
namespace gui2 {
static void callback_expand_direction_changed(twidget* caller)
{
teditor_resize_map* dialog = dynamic_cast<teditor_resize_map*>(caller->dialog());
assert(dialog);
twindow* window = dynamic_cast<twindow*>(caller->get_window());
assert(window);
dialog->update_expand_direction(*window);
}
teditor_resize_map::teditor_resize_map() :
map_width_(register_integer("width", false)),
map_height_(register_integer("height", false))
map_height_(register_integer("height", false)),
copy_edge_terrain_(register_bool("copy_edge_terrain", false)),
expand_direction_(EXPAND_BOTTOM_RIGHT)
{
}
@ -73,6 +85,11 @@ void teditor_resize_map::set_old_map_height(int value)
old_height_ = value;
}
bool teditor_resize_map::copy_edge_terrain() const
{
return copy_edge_terrain_->get_value();
}
twindow teditor_resize_map::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_RESIZE_MAP));
@ -86,7 +103,34 @@ void teditor_resize_map::pre_show(CVideo& /*video*/, twindow& window)
VALIDATE(old_height, missing_widget("old_height"));
old_width->set_label(lexical_cast<std::string>(old_width_));
old_height->set_label(lexical_cast<std::string>(old_height_));
std::string name_prefix = "expand";
for (int i = 0; i < 9; ++i) {
std::string name = name_prefix + lexical_cast<std::string>(i);
direction_buttons_[i] = dynamic_cast<ttoggle_button*>(window.find_widget(name, false));
VALIDATE(direction_buttons_[i], missing_widget(name));
direction_buttons_[i]->set_callback_state_change(callback_expand_direction_changed);
}
window.recalculate_size();
}
void teditor_resize_map::update_expand_direction(twindow& window)
{
std::string name_prefix = "expand";
for (int i = 0; i < 9; ++i) {
if (direction_buttons_[i]->get_value() && static_cast<int>(expand_direction_) != i) {
expand_direction_ = static_cast<EXPAND_DIRECTION>(i);
break;
}
}
for (int i = 0; i < static_cast<int>(expand_direction_); ++i) {
direction_buttons_[i]->set_value(false);
}
direction_buttons_[expand_direction_]->set_value(true);
for (int i = expand_direction_ + 1; i < 9; ++i) {
direction_buttons_[i]->set_value(false);
}
}
} // namespace gui2

View file

@ -19,6 +19,8 @@
namespace gui2 {
class ttoggle_button;
class teditor_resize_map : public tdialog
{
public:
@ -29,9 +31,9 @@ public:
void set_map_height(int value);
int map_height() const;
void set_old_map_width(int value);
int old_map_width() const;
void set_old_map_height(int value);
int old_map_height() const;
bool copy_edge_terrain() const;
enum EXPAND_DIRECTION {
EXPAND_BOTTOM_RIGHT,
EXPAND_BOTTOM,
@ -43,8 +45,10 @@ public:
EXPAND_TOP,
EXPAND_TOP_LEFT
};
EXPAND_DIRECTION expand_direction() { return expand_direction_; }
void set_expand_direction(EXPAND_DIRECTION direction) { expand_direction_ = direction; }
EXPAND_DIRECTION expand_direction() { return EXPAND_BOTTOM_RIGHT; }
void update_expand_direction(twindow& window);
private:
/**
@ -53,14 +57,18 @@ private:
*/
tfield_integer* map_width_;
tfield_integer* map_height_;
tfield_bool* copy_edge_terrain_;
ttoggle_button* direction_buttons_[9];
int old_width_;
int old_height_;
EXPAND_DIRECTION expand_direction_;
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
void pre_show(CVideo& video, twindow& window);
};
} // namespace gui2