editor2: random map generate dialog stub, refresh image cache option

This commit is contained in:
Tomasz Śniatowski 2008-08-04 13:36:59 +01:00
parent 2a3f64a738
commit a9362872b3
14 changed files with 224 additions and 3 deletions

View File

@ -24,6 +24,7 @@
[textdomain]
name="wesnoth-editor"
[/textdomain]
{multiplayer/scenarios/Random_Scenario.cfg}
#endif
{campaigns/}
{scenario-test.cfg}

View File

@ -0,0 +1,75 @@
###
### Definition of the window to create a new map in editor2.
###
[window]
id = "editor_generate_map"
description = "Generate random map dialog."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Generate Random Map"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "settings"
definition = "default"
size_text = _ "Settings"
label = _ "Settings"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "generate"
definition = "default"
label = _ "Generate"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View File

@ -140,7 +140,7 @@
id=menu-editor-map
title= _ "Map"
image=lite
items=editor-map-resize,editor-map-rotate,editor-map-flip-x,editor-map-flip-y,editor-map-generate,editor-refresh,editor-update-transitions,editor-auto-update-transitions
items=editor-map-resize,editor-map-rotate,editor-map-flip-x,editor-map-flip-y,editor-map-generate,editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-refresh-image-cache
rect="+2,=,+100,="
xanchor=fixed
yanchor=fixed

View File

@ -308,6 +308,7 @@ SET(wesnoth-main_SRC
IF(ENABLE_EDITOR2)
SET(wesnoth-editor2_SRC
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_new_map.cpp
editor2/action.cpp
editor2/brush.cpp

View File

@ -153,6 +153,7 @@ wesnoth_source = \
# used with editor2 option in the wesnoth target
wesnoth_editor2_SOURCES = \
gui/dialogs/editor_generate_map.cpp \
gui/dialogs/editor_new_map.cpp \
editor2/action.cpp \
editor2/brush.cpp \

View File

@ -245,6 +245,7 @@ wesnoth_sources.extend(python_env.Object(Split("""
# used with editor2 option in the wesnoth target
wesnoth_editor2_sources = Split("""
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_new_map.cpp
editor2/action.cpp
editor2/brush.cpp

View File

@ -20,6 +20,7 @@
#include "mouse_action.hpp"
#include "gui/dialogs/editor_new_map.hpp"
#include "gui/dialogs/editor_generate_map.hpp"
#include "gui/widgets/button.hpp"
#include "../config_adapter.hpp"
@ -31,6 +32,8 @@
#include "../foreach.hpp"
#include "../gettext.hpp"
#include "../hotkeys.hpp"
#include "../map_create.hpp"
#include "../mapgen.hpp"
#include "../preferences.hpp"
#include "../wml_exception.hpp"
@ -42,7 +45,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
: controller_base(SDL_GetTicks(), game_config, video)
, mouse_handler_base(get_map())
, map_context_(editor_map(game_config, 44, 33, t_translation::GRASS_LAND))
, gui_(NULL), do_quit_(false), quit_mode_(EXIT_ERROR)
, gui_(NULL), map_generator_(NULL), do_quit_(false), quit_mode_(EXIT_ERROR)
, auto_update_transitions_(true)
{
init(video);
@ -78,6 +81,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
palette_->adjust_size();
refresh_all();
gui_->draw();
palette_->draw(true);
events::raise_draw_event();
}
@ -96,6 +100,7 @@ editor_controller::~editor_controller()
delete palette_;
delete size_specs_;
delete floating_label_manager_;
delete map_generator_;
delete gui_;
typedef std::pair<hotkey::HOTKEY_COMMAND, mouse_action*> apr;
foreach (apr a, mouse_actions_) {
@ -152,7 +157,7 @@ void editor_controller::load_map_dialog()
void editor_controller::new_map_dialog()
{
if (!confirm_discard()) return;
gui2::teditor_new_map dialog;;
gui2::teditor_new_map dialog;
dialog.set_map_width(get_map().total_width());
dialog.set_map_height(get_map().total_height());
@ -196,6 +201,30 @@ void editor_controller::save_map_as_dialog()
save_map_as(input_name);
}
void editor_controller::generate_map_dialog()
{
if (map_generator_ == NULL) {
// Initialize the map generator if it has not been used before
const config* const toplevel_cfg = game_config_.find_child("multiplayer","id","multiplayer_Random_Map");
const config* const cfg = toplevel_cfg == NULL ? NULL : toplevel_cfg->child("generator");
if (cfg == NULL) {
WRN_ED << "No random map generator\n";
return;
}
else {
map_generator_ = create_map_generator("", cfg);
}
}
if (!confirm_discard()) return;
if (!confirm_discard()) return;
gui2::teditor_generate_map dialog;
dialog.show(gui().video());
if (map_generator_->allow_user_config()) {
map_generator_->user_config(gui());
}
}
bool editor_controller::save_map_as(const std::string& filename)
{
std::string old_filename = get_map_context().get_filename();
@ -339,6 +368,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_REFRESH:
case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
case HOTKEY_EDITOR_REFRESH_IMAGE_CACHE:
return true;
default:
return false;
@ -432,6 +462,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_MAP_SAVE_AS:
save_map_as_dialog();
return true;
case HOTKEY_EDITOR_MAP_GENERATE:
generate_map_dialog();
return true;
case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
auto_update_transitions_ = !auto_update_transitions_;
if (!auto_update_transitions_) {
@ -445,6 +478,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
reload_map();
return true;
break;
case HOTKEY_EDITOR_REFRESH_IMAGE_CACHE:
refresh_image_cache();
return true;
default:
return controller_base::execute_command(command, index);
}
@ -582,6 +618,10 @@ mouse_action* editor_controller::get_mouse_action()
return mouse_action_;
}
void editor_controller::refresh_image_cache() {
image::flush_cache();
refresh_all();
}
void editor_controller::refresh_after_action(bool drag_part)
{

View File

@ -33,6 +33,7 @@
#include <boost/utility.hpp>
class config;
class map_generator;
namespace tooltips {
class manager;
@ -69,6 +70,7 @@ class editor_controller : public controller_base,
void load_map_dialog();
void new_map_dialog();
void save_map_as_dialog();
void generate_map_dialog();
bool save_map(bool display_confirmation = false);
bool save_map_as(const std::string& filename);
void new_map(int width, int height, t_translation::t_terrain fill);
@ -111,6 +113,8 @@ class editor_controller : public controller_base,
/** init the display object and general set-up */
void init(CVideo& video);
void refresh_image_cache();
void refresh_after_action(bool drag_part = false);
void refresh_all();
@ -131,6 +135,8 @@ class editor_controller : public controller_base,
/** The display object used and owned by the editor. */
editor_display* gui_;
map_generator* map_generator_;
size_specs* size_specs_;
terrain_palette* palette_;
brush_bar* brush_bar_;

View File

@ -0,0 +1,50 @@
/* $Id$ */
/*
copyright (c) 2008 by mark de wever <koraq@xs4all.nl>
part of the battle for wesnoth project http://www.wesnoth.org/
this program is free software; you can redistribute it and/or modify
it under the terms of the gnu general public license version 2
or at your option any later version.
this program is distributed in the hope that it will be useful,
but without any warranty.
see the copying file for more details.
*/
#include "gui/dialogs/editor_generate_map.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/window_builder.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/text_box.hpp"
#include "log.hpp"
#include "wml_exception.hpp"
#define DBG_GUI LOG_STREAM_INDENT(debug, widget)
#define LOG_GUI LOG_STREAM_INDENT(info, widget)
#define WRN_GUI LOG_STREAM_INDENT(warn, widget)
#define ERR_GUI LOG_STREAM_INDENT(err, widget)
namespace gui2 {
teditor_generate_map::teditor_generate_map()
{
}
twindow teditor_generate_map::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_GENERATE_MAP));
}
void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& window)
{
}
void teditor_generate_map::post_show(twindow& window)
{
}
} // namespace gui2

View File

@ -0,0 +1,40 @@
/* $Id$ */
/*
copyright (c) 2008 by mark de wever <koraq@xs4all.nl>
part of the battle for wesnoth project http://www.wesnoth.org/
this program is free software; you can redistribute it and/or modify
it under the terms of the gnu general public license version 2
or at your option any later version.
this program is distributed in the hope that it will be useful,
but without any warranty.
see the copying file for more details.
*/
#ifndef GUI_DIALOGS_EDITOR_GENERATE_MAP_HPP_INCLUDED
#define GUI_DIALOGS_EDITOR_GENERATE_MAP_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
namespace gui2 {
class teditor_generate_map : public tdialog
{
public:
teditor_generate_map();
private:
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
};
} // namespace gui2
#endif

View File

@ -90,6 +90,7 @@ static void fill_window_types()
window_type_list[MP_CREATE_GAME] = "mp_create_game";
#ifdef USE_EDITOR2
window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";
#endif
}

View File

@ -43,6 +43,7 @@ enum twindow_type {
MP_CREATE_GAME, /**< The mp creation dialog. */
#ifdef USE_EDITOR2
EDITOR_NEW_MAP, //<! New map dialog
EDITOR_GENERATE_MAP, /** Editor random map genarator dialog */
#endif
DUMMY //<! Dummy always the last one.
};

View File

@ -178,6 +178,9 @@ const struct {
N_("Update Terrain Tranistions"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS, "editor-auto-update-transitions",
N_("Auto-update Terrain Transitions"), false, hotkey::SCOPE_EDITOR },
{ hotkey::HOTKEY_EDITOR_REFRESH_IMAGE_CACHE, "editor-refresh-image-cache",
N_("Refresh Image Cache"), false, hotkey::SCOPE_EDITOR },
#endif
{ hotkey::HOTKEY_DELAY_SHROUD, "delayshroud", N_("Delay Shroud Updates"), false, hotkey::SCOPE_GAME },

View File

@ -87,6 +87,7 @@ enum HOTKEY_COMMAND {
HOTKEY_EDITOR_MAP_GENERATE,
HOTKEY_EDITOR_REFRESH, HOTKEY_EDITOR_UPDATE_TRANSITIONS,
HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS,
HOTKEY_EDITOR_REFRESH_IMAGE_CACHE,
#endif
//misc.