editor2: settings dialog

currently only does lightning settings by having presets and custom
sliders. Functional but still WIP, may have some subtle bugs. Changing
slider values refreshes the underlying map, in a possibly inefficient
way (flicker), but working reasonably. This fills fr#11408
This commit is contained in:
Tomasz Śniatowski 2008-09-17 17:45:10 +01:00
parent 4a368e22bd
commit a806efa0a8
14 changed files with 577 additions and 1 deletions

View file

@ -1,4 +1,10 @@
Version 1.5.4+svn:
* Editor2:
* Added editor-specific settings dialog
* Lightning setting similar to that of old editor, with presets from a
(hardcoded) list of time_of_days. Can change the settings and see the
effects without having to close the settings dialog. The preferences
are shared with the old editor.
* Graphics:
* New or updated unit frames: Walking Corpse swimmer, Soulless swimmer
* Language and i18n:

View file

@ -25,6 +25,7 @@
{core/editor-groups.cfg}
{core/editor2-brushes.cfg}
{core/editor2-hotkeys.cfg}
{core/editor2-tods.cfg}
{core/editor2-tool-hints.cfg}
#endif
#endif

View file

@ -0,0 +1,8 @@
#textdomain wesnoth-editor
[editor_times]
{DAWN}
{MORNING}
{DUSK}
{FIRST_WATCH}
[/editor_times]

View file

@ -0,0 +1,222 @@
###
### Definition of the window to create a new map in editor2.
###
#define ONE_ROW_GRID
[grid]
[row]
grow_factor = 0
#enddef
#define ONE_ROW_GRID_END
[/row]
[/grid]
#enddef
[window]
id = "editor_settings"
description = "Editor settings 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 = _ "Editor Settings"
[/label]
[/column]
[/row]
[row]
[column]
[label]
definition = "default"
label = _ "Time of day lightning preset"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
grow_factor = 1
horizontal_grow = "true"
[grid]
[row]
grow_factor = 0
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "current_tod"
definition = "default"
[/label]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "next_tod"
definition = "default"
size_text = _ "Next"
label = _ "Next"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[row]
grow_factor = 0
[column]
[label]
id = "current_tod_image"
definition = "default"
[/label]
[/column]
[/row]
[row]
grow_factor = 0
[column]
[toggle_button]
id = "custom_tod_toggle"
definition = "default"
label = _ "Custom lightning setting"
[/toggle_button]
[/column]
[/row]
[row]
[column]
[grid]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Red:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[slider]
id = "custom_tod_red"
definition = "default"
best_slider_length = 511
minimum_value = -255
maximum_value = 255
step_size = 1
[/slider]
[/column]
[/row]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Green:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[slider]
id = "custom_tod_green"
definition = "default"
best_slider_length = 511
minimum_value = -255
maximum_value = 255
step_size = 1
[/slider]
[/column]
[/row]
[row]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Blue:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_alignment = "left"
[slider]
id = "custom_tod_blue"
definition = "default"
best_slider_length = 511
minimum_value = -255
maximum_value = 255
step_size = 1
[/slider]
[/column]
[/row]
[/grid]
[/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 = "ok"
definition = "default"
label = _ "OK"
[/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]
#undef ONE_ROW_GRID
#undef ONE_ROW_GRID_END

View file

@ -3,8 +3,13 @@ changes may be omitted). For a complete list of changes, see the main
changelog: http://svn.gna.org/viewcvs/*checkout*/wesnoth/trunk/changelog
Version 1.5.4+svn:
* Editor2
* Allow changing the display time of day from a preset list or to custom
values via sliders, available in the new editor settings dialog.
* Language and translations
* updated translations: Finnish, Slovak.
* Unit changes and balancing
* Made units with the healthy trait take a quarter less damage from poison.

View file

@ -318,8 +318,9 @@ IF(ENABLE_EDITOR2)
SET(wesnoth-editor2_SRC
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_resize_map.cpp
gui/dialogs/editor_new_map.cpp
gui/dialogs/editor_resize_map.cpp
gui/dialogs/editor_settings.cpp
editor2/action.cpp
editor2/brush.cpp
editor2/editor_main.cpp

View file

@ -161,6 +161,7 @@ wesnoth_editor2_SOURCES = \
gui/dialogs/editor_generate_map.cpp \
gui/dialogs/editor_new_map.cpp \
gui/dialogs/editor_resize_map.cpp \
gui/dialogs/editor_settings.cpp \
editor2/action.cpp \
editor2/brush.cpp \
editor2/editor_main.cpp \

View file

@ -255,6 +255,7 @@ wesnoth_editor2_sources = Split("""
gui/dialogs/editor_generate_map.cpp
gui/dialogs/editor_new_map.cpp
gui/dialogs/editor_resize_map.cpp
gui/dialogs/editor_settings.cpp
editor2/action.cpp
editor2/brush.cpp
editor2/editor_main.cpp

View file

@ -22,6 +22,7 @@
#include "gui/dialogs/editor_new_map.hpp"
#include "gui/dialogs/editor_generate_map.hpp"
#include "gui/dialogs/editor_resize_map.hpp"
#include "gui/dialogs/editor_settings.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/window.hpp"
@ -93,11 +94,13 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
init_mouse_actions(game_config);
hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);
init_map_generators(game_config);
init_tods(game_config);
hotkey::get_hotkey(hotkey::HOTKEY_QUIT_GAME).set_description(_("Quit Editor"));
background_terrain_ = t_translation::GRASS_LAND;
foreground_terrain_ = t_translation::MOUNTAIN;
get_map_context().set_starting_position_labels(gui());
cursor::set(cursor::NORMAL);
image::set_colour_adjustment(preferences::editor_r(), preferences::editor_g(), preferences::editor_b());
gui_->invalidate_game_status();
refresh_all();
events::raise_draw_event();
@ -169,6 +172,19 @@ void editor_controller::init_map_generators(const config& game_config)
}
}
void editor_controller::init_tods(const config& game_config)
{
const config* cfg = game_config.child("editor_times");
if (cfg == NULL) {
ERR_ED << "No editor time-of-day defined\n";
return;
}
foreach (const config* i, cfg->get_children("time")) {
tods_.push_back(time_of_day(*i));
}
}
void editor_controller::load_tooltips()
{
// Tooltips for the groups
@ -220,6 +236,38 @@ void editor_controller::quit_confirm(EXIT_STATUS mode)
}
}
void editor_controller::editor_settings_dialog()
{
if (tods_.empty()) {
gui::message_dialog(gui(), _("Error"), _("No editor time-of-day found")).show();
return;
}
gui2::teditor_settings dialog;
dialog.set_tods(tods_);
dialog.set_current_adjustment(preferences::editor_r(), preferences::editor_g(), preferences::editor_b());
dialog.set_redraw_callback(boost::bind(&editor_controller::editor_settings_dialog_redraw_callback, this, _1, _2, _3));
image::colour_adjustment_resetter adjust_resetter;
dialog.show(gui().video());
int res = dialog.get_retval();
if(res == gui2::twindow::OK) {
image::set_colour_adjustment(dialog.get_red(), dialog.get_green(), dialog.get_blue());
preferences::set_editor_r(dialog.get_red());
preferences::set_editor_g(dialog.get_green());
preferences::set_editor_b(dialog.get_blue());
} else {
adjust_resetter.reset();
}
refresh_all();
}
void editor_controller::editor_settings_dialog_redraw_callback(int r, int g, int b)
{
image::set_colour_adjustment(r, g, b);
refresh_all();
}
bool editor_controller::confirm_discard()
{
if (get_map_context().modified()) {
@ -492,6 +540,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_PARTIAL_UNDO:
return true;
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
case HOTKEY_EDITOR_SETTINGS:
case HOTKEY_EDITOR_MAP_NEW:
case HOTKEY_EDITOR_MAP_LOAD:
case HOTKEY_EDITOR_MAP_SAVE_AS:
@ -568,6 +617,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
quit_confirm(EXIT_QUIT_TO_DESKTOP);
return true;
case HOTKEY_EDITOR_SETTINGS:
editor_settings_dialog();
return true;
case HOTKEY_EDITOR_TERRAIN_PALETTE_SWAP:
palette_->swap();
if (get_mouse_action()->uses_terrains()) set_mouseover_overlay();

View file

@ -80,6 +80,8 @@ class editor_controller : public controller_base,
*/
void quit_confirm(EXIT_STATUS status);
void editor_settings_dialog();
/**
* Shows an are-you-sure dialog if the map was modified.
* @return true if the user confirmed or the map was not modified, false otherwise
@ -233,6 +235,7 @@ class editor_controller : public controller_base,
*/
void perform_refresh(const editor_action& action, bool drag_part = false);
void editor_settings_dialog_redraw_callback(int r, int g, int b);
private:
/** init the display object and general set-up */
void init(CVideo& video);
@ -246,6 +249,8 @@ class editor_controller : public controller_base,
/** init available random map generators */
void init_map_generators(const config& game_config);
void init_tods(const config& game_config);
/**
* Load editor-specific tooltips
*/
@ -294,6 +299,12 @@ class editor_controller : public controller_base,
std::vector<map_generator*> map_generators_;
int current_map_generator_index_;
std::vector<time_of_day> tods_;
int current_tod_index_;
/** Legacy object required by the legacy terrain palette and brush bar */
size_specs* size_specs_;

View file

@ -0,0 +1,171 @@
/* $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_settings.hpp"
#include "gui/dialogs/field.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/label.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/slider.hpp"
#include "gui/widgets/text_box.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gettext.hpp"
#include "image.hpp"
#include "log.hpp"
#include "wml_exception.hpp"
#define DBG_GUI LOG_STREAM_INDENT(debug, gui)
#define LOG_GUI LOG_STREAM_INDENT(info, gui)
#define WRN_GUI LOG_STREAM_INDENT(warn, gui)
#define ERR_GUI LOG_STREAM_INDENT(err, gui)
#define ERR_ED LOG_STREAM_INDENT(err, editor)
namespace gui2 {
teditor_settings::teditor_settings()
: redraw_callback_(),
tods_(), current_tod_(0),
current_tod_label_(NULL), current_tod_image_(NULL),
custom_tod_toggle_(NULL),
custom_tod_toggle_field_(register_bool("custom_tod_toggle", false)),
custom_tod_red_(NULL), custom_tod_green_(NULL), custom_tod_blue_(NULL),
custom_tod_red_field_(register_integer("custom_tod_red", false)),
custom_tod_green_field_(register_integer("custom_tod_green", false)),
custom_tod_blue_field_(register_integer("custom_tod_blue", false))
{
}
void teditor_settings::do_next_tod(twindow& window)
{
current_tod_++;
current_tod_ %= tods_.size();
custom_tod_toggle_->set_value(false);
update_selected_tod_info(window);
}
const time_of_day& teditor_settings::get_selected_tod() const
{
assert(static_cast<size_t>(current_tod_) < tods_.size());
return tods_[current_tod_];
}
int teditor_settings::get_red() const
{
std::cerr << "get red " << custom_tod_red_field_->get_cache_value() << "\n";
return custom_tod_red_field_->get_cache_value();
}
int teditor_settings::get_green() const
{
std::cerr << "get green " << custom_tod_green_field_->get_cache_value() << "\n";
return custom_tod_green_field_->get_cache_value();
}
int teditor_settings::get_blue() const
{
std::cerr << "get blue" << custom_tod_blue_field_->get_cache_value() << "\n";
return custom_tod_blue_field_->get_cache_value();
}
void teditor_settings::update_tod_display(twindow& window)
{
redraw_callback_(custom_tod_red_->get_value(),
custom_tod_green_->get_value(),
custom_tod_blue_->get_value());
}
void teditor_settings::set_current_adjustment(int r, int g, int b)
{
for (size_t i = 0; i < tods_.size(); ++i) {
time_of_day& tod = tods_[i];
if (tod.red == r && tod.green == g && tod.blue == b) {
current_tod_ = i;
custom_tod_toggle_field_->set_cache_value(false);
return;
}
}
/* custom tod */
std::cerr << "adj set b\n";
custom_tod_red_field_->set_cache_value(r);
custom_tod_green_field_->set_cache_value(g);
custom_tod_blue_field_->set_cache_value(b);
custom_tod_toggle_field_->set_cache_value(true);
std::cerr << "adj set " << r << " " << g << " " << b << "\n";
}
void teditor_settings::update_selected_tod_info(twindow& window)
{
std::cerr << "update_selected_tod_info begin\n";
bool custom = custom_tod_toggle_->get_value();
if (custom) {
current_tod_label_->set_label(_("Custom setting"));
} else {
std::stringstream ss;
ss << (current_tod_ + 1);
ss << "/" << tods_.size();
ss << ": " << get_selected_tod().name;
current_tod_label_->set_label(ss.str());
//current_tod_image_->set_icon_name(get_selected_tod().image);
custom_tod_red_->set_value(get_selected_tod().red);
custom_tod_green_->set_value(get_selected_tod().green);
custom_tod_blue_->set_value(get_selected_tod().blue);
custom_tod_red_field_->set_cache_value(get_selected_tod().red);
custom_tod_green_field_->set_cache_value(get_selected_tod().green);
custom_tod_blue_field_->set_cache_value(get_selected_tod().blue);
}
custom_tod_red_->set_active(custom);
custom_tod_green_->set_active(custom);
custom_tod_blue_->set_active(custom);
current_tod_label_->set_active(!custom);
update_tod_display(window);
window.invalidate_layout();
std::cerr << "update_selected_tod_info end\n";
}
twindow teditor_settings::build_window(CVideo& video)
{
return build(video, get_id(EDITOR_SETTINGS));
}
void teditor_settings::pre_show(CVideo& /*video*/, twindow& window)
{
assert(!tods_.empty());
current_tod_label_ = &window.get_widget<tlabel>("current_tod", false);
current_tod_image_ = &window.get_widget<tlabel>("current_tod_image", false);
custom_tod_toggle_ = &window.get_widget<ttoggle_button>("custom_tod_toggle", false);
custom_tod_red_ = &window.get_widget<tslider>("custom_tod_red", false);
custom_tod_green_ = &window.get_widget<tslider>("custom_tod_green", false);
custom_tod_blue_ = &window.get_widget<tslider>("custom_tod_blue", false);
tbutton& next_tod_button = window.get_widget<tbutton>("next_tod", false);
next_tod_button.set_callback_mouse_left_click(
dialog_callback<teditor_settings, &teditor_settings::do_next_tod>);
custom_tod_toggle_->set_callback_state_change(
dialog_callback<teditor_settings, &teditor_settings::update_selected_tod_info>);
custom_tod_red_->set_callback_positioner_move(
dialog_callback<teditor_settings, &teditor_settings::update_tod_display>);
custom_tod_green_->set_callback_positioner_move(
dialog_callback<teditor_settings, &teditor_settings::update_tod_display>);
custom_tod_blue_->set_callback_positioner_move(
dialog_callback<teditor_settings, &teditor_settings::update_tod_display>);
update_selected_tod_info(window);
}
void teditor_settings::post_show(twindow& /*window*/)
{
}
} // namespace gui2

View file

@ -0,0 +1,95 @@
/* $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_SETTINGS_HPP_INCLUDED
#define GUI_DIALOGS_EDITOR_SETTINGS_HPP_INCLUDED
#include "time_of_day.hpp"
#include "gui/dialogs/dialog.hpp"
#include <vector>
#include <boost/function.hpp>
namespace gui2 {
class tlabel;
class ttoggle_button;
class tslider;
class teditor_settings : public tdialog
{
public:
teditor_settings();
void set_redraw_callback(boost::function<void (int, int, int)> callback) { redraw_callback_ = callback; }
/** Callback for the next tod button */
void do_next_tod(twindow& window);
void update_tod_display(twindow& window);
void set_tods(const std::vector<time_of_day>& tods) { tods_ = tods; }
const std::vector<time_of_day>& get_tods() const { return tods_; }
void set_current_adjustment(int r, int g, int b);
void set_selected_tod(time_of_day tod);
const time_of_day& get_selected_tod() const;
int get_red() const;
int get_green() const;
int get_blue() const;
void update_selected_tod_info(twindow& window);
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);
boost::function<void (int, int, int)> redraw_callback_;
/** Available time_of_days */
std::vector<time_of_day> tods_;
/** Current map generator index */
int current_tod_;
/** Label for the current tod */
tlabel* current_tod_label_;
/** Label for the current tod image*/
tlabel* current_tod_image_;
ttoggle_button* custom_tod_toggle_;
tfield_bool* custom_tod_toggle_field_;
tslider* custom_tod_red_;
tslider* custom_tod_green_;
tslider* custom_tod_blue_;
tfield_integer* custom_tod_red_field_;
tfield_integer* custom_tod_green_field_;
tfield_integer* custom_tod_blue_field_;
};
} // namespace gui2
#endif

View file

@ -94,6 +94,7 @@ static void fill_window_types()
window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";
window_type_list[EDITOR_RESIZE_MAP] = "editor_resize_map";
window_type_list[EDITOR_SETTINGS] = "editor_settings";
#endif
}

View file

@ -46,6 +46,7 @@ enum twindow_type {
EDITOR_NEW_MAP, //<! New map dialog
EDITOR_GENERATE_MAP, /** Editor random map genarator dialog */
EDITOR_RESIZE_MAP, /** Editor resize map dialog */
EDITOR_SETTINGS, /** Editor settings dialog */
#endif
DUMMY //<! Dummy always the last one.
};