move editor preferences to a separate file
This commit is contained in:
parent
6a940e6d8d
commit
439618fe56
9 changed files with 207 additions and 88 deletions
|
@ -3208,6 +3208,34 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\editor\editor_preferences.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\Editor\"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\Editor\"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Debug (fast)|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
ObjectFile="$(IntDir)\Editor\"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\editor\map_context.cpp"
|
||||
>
|
||||
|
@ -5335,6 +5363,10 @@
|
|||
RelativePath="..\..\src\editor\editor_palettes.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\editor\editor_preferences.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\src\editor\map_context.hpp"
|
||||
>
|
||||
|
|
|
@ -427,6 +427,7 @@ SET(wesnoth-editor_SRC
|
|||
editor/editor_layout.cpp
|
||||
editor/editor_map.cpp
|
||||
editor/editor_palettes.cpp
|
||||
editor/editor_preferences.cpp
|
||||
editor/map_context.cpp
|
||||
editor/map_fragment.cpp
|
||||
editor/mouse_action.cpp
|
||||
|
|
|
@ -249,6 +249,7 @@ wesnoth_editor_SOURCES = \
|
|||
editor/editor_layout.cpp \
|
||||
editor/editor_map.cpp \
|
||||
editor/editor_palettes.cpp \
|
||||
editor/editor_preferences.cpp \
|
||||
editor/map_context.cpp \
|
||||
editor/map_fragment.cpp \
|
||||
editor/mouse_action.cpp
|
||||
|
|
|
@ -349,6 +349,7 @@ wesnoth_editor_sources = Split("""
|
|||
editor/editor_layout.cpp
|
||||
editor/editor_map.cpp
|
||||
editor/editor_palettes.cpp
|
||||
editor/editor_preferences.cpp
|
||||
editor/map_context.cpp
|
||||
editor/map_fragment.cpp
|
||||
editor/mouse_action.cpp
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "action.hpp"
|
||||
#include "editor_controller.hpp"
|
||||
#include "editor_palettes.hpp"
|
||||
#include "editor_preferences.hpp"
|
||||
#include "mouse_action.hpp"
|
||||
|
||||
#include "gui/dialogs/editor_new_map.hpp"
|
||||
|
@ -41,19 +42,6 @@
|
|||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace {
|
||||
const char* prefkey_default_dir = "editor_default_dir";
|
||||
const char* prefkey_auto_update_transitions = "editor_auto_update_transitions";
|
||||
const char* prefkey_use_mdi = "editor_use_mdi";
|
||||
|
||||
namespace TransitionUpdateMode {
|
||||
const int off = 0;
|
||||
const int on = 1;
|
||||
const int partial = 2;
|
||||
const int count = 3;
|
||||
}
|
||||
}
|
||||
|
||||
namespace editor {
|
||||
|
||||
/**
|
||||
|
@ -107,10 +95,9 @@ editor_controller::editor_controller(const config &game_config, CVideo& video, m
|
|||
, foreground_terrain_(t_translation::MOUNTAIN)
|
||||
, background_terrain_(t_translation::GRASS_LAND)
|
||||
, clipboard_()
|
||||
, auto_update_transitions_(lexical_cast_default<int>(
|
||||
preferences::get(prefkey_auto_update_transitions), TransitionUpdateMode::partial))
|
||||
, use_mdi_(utils::string_bool(preferences::get(prefkey_use_mdi), true))
|
||||
, default_dir_(preferences::get(prefkey_default_dir))
|
||||
, auto_update_transitions_(preferences::editor::auto_update_transitions())
|
||||
, use_mdi_(preferences::editor::use_mdi())
|
||||
, default_dir_(preferences::editor::default_dir())
|
||||
{
|
||||
if (init_map_context == NULL) {
|
||||
create_default_context();
|
||||
|
@ -133,7 +120,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video, m
|
|||
hotkey::get_hotkey(hotkey::HOTKEY_QUIT_GAME).set_description(_("Quit Editor"));
|
||||
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());
|
||||
image::set_colour_adjustment(preferences::editor::tod_r(), preferences::editor::tod_g(), preferences::editor::tod_b());
|
||||
theme& theme = gui().get_theme();
|
||||
const theme::menu* default_tool_menu = NULL;
|
||||
foreach (const theme::menu& m, theme.menus()) {
|
||||
|
@ -385,7 +372,7 @@ void editor_controller::editor_settings_dialog()
|
|||
|
||||
gui2::teditor_settings dialog;
|
||||
dialog.set_tods(tods_);
|
||||
dialog.set_current_adjustment(preferences::editor_r(), preferences::editor_g(), preferences::editor_b());
|
||||
dialog.set_current_adjustment(preferences::editor::tod_r(), preferences::editor::tod_g(), preferences::editor::tod_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.set_use_mdi(use_mdi_);
|
||||
|
@ -394,11 +381,11 @@ void editor_controller::editor_settings_dialog()
|
|||
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());
|
||||
preferences::editor::set_tod_r(dialog.get_red());
|
||||
preferences::editor::set_tod_g(dialog.get_green());
|
||||
preferences::editor::set_tod_b(dialog.get_blue());
|
||||
use_mdi_ = dialog.get_use_mdi();
|
||||
preferences::set(prefkey_use_mdi, lexical_cast<std::string>(use_mdi_));
|
||||
preferences::editor::set_use_mdi(use_mdi_);
|
||||
} else {
|
||||
adjust_resetter.reset();
|
||||
}
|
||||
|
@ -766,8 +753,8 @@ void editor_controller::refresh_after_action(bool drag_part)
|
|||
return;
|
||||
} else {
|
||||
if (get_map_context().needs_terrain_rebuild()) {
|
||||
if ((auto_update_transitions_ == TransitionUpdateMode::on)
|
||||
|| ((auto_update_transitions_ == TransitionUpdateMode::partial)
|
||||
if ((auto_update_transitions_ == preferences::editor::TransitionUpdateMode::on)
|
||||
|| ((auto_update_transitions_ == preferences::editor::TransitionUpdateMode::partial)
|
||||
&& (!drag_part || get_map_context().everything_changed()))) {
|
||||
gui().rebuild_all();
|
||||
get_map_context().set_needs_terrain_rebuild(false);
|
||||
|
@ -1028,9 +1015,10 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
resize_map_dialog();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS:
|
||||
auto_update_transitions_ = (auto_update_transitions_ + 1) % TransitionUpdateMode::count;
|
||||
preferences::set(prefkey_auto_update_transitions, lexical_cast<std::string>(auto_update_transitions_));
|
||||
if (auto_update_transitions_ != TransitionUpdateMode::on) {
|
||||
auto_update_transitions_ = (auto_update_transitions_ + 1)
|
||||
% preferences::editor::TransitionUpdateMode::count;
|
||||
preferences::editor::set_auto_update_transitions(auto_update_transitions_);
|
||||
if (auto_update_transitions_ != preferences::editor::TransitionUpdateMode::on) {
|
||||
return true;
|
||||
} // else intentionally fall through
|
||||
case HOTKEY_EDITOR_UPDATE_TRANSITIONS:
|
||||
|
@ -1107,13 +1095,13 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
|
|||
}
|
||||
} else if (command == hotkey::HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS) {
|
||||
switch (auto_update_transitions_) {
|
||||
case TransitionUpdateMode::on:
|
||||
case preferences::editor::TransitionUpdateMode::on:
|
||||
hotkey::get_hotkey(*i).set_description(_("Auto-update Terrain Transitions: Yes"));
|
||||
break;
|
||||
case TransitionUpdateMode::partial:
|
||||
case preferences::editor::TransitionUpdateMode::partial:
|
||||
hotkey::get_hotkey(*i).set_description(_("Auto-update Terrain Transitions: Partial"));
|
||||
break;
|
||||
case TransitionUpdateMode::off:
|
||||
case preferences::editor::TransitionUpdateMode::off:
|
||||
default:
|
||||
hotkey::get_hotkey(*i).set_description(_("Auto-update Terrain Transitions: No"));
|
||||
}
|
||||
|
|
94
src/editor/editor_preferences.cpp
Normal file
94
src/editor/editor_preferences.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 by Tomasz Sniatowski <kailoran@gmail.com>
|
||||
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 "editor/editor_preferences.hpp"
|
||||
#include "game_preferences.hpp"
|
||||
|
||||
namespace preferences {
|
||||
|
||||
namespace editor {
|
||||
|
||||
int auto_update_transitions() {
|
||||
return lexical_cast_default<int>(preferences::get("editor_auto_update_transitions"), TransitionUpdateMode::partial);
|
||||
}
|
||||
|
||||
void set_auto_update_transitions(int value) {
|
||||
preferences::set("editor_auto_update_transitions", lexical_cast<std::string>(value));
|
||||
}
|
||||
|
||||
bool use_mdi() {
|
||||
return utils::string_bool(preferences::get("editor_use_mdi"), true);
|
||||
}
|
||||
|
||||
void set_use_mdi(bool value) {
|
||||
preferences::set("editor_use_mdi", value ? "yes" : "no");
|
||||
}
|
||||
|
||||
std::string default_dir() {
|
||||
return preferences::get("editor_default_dir");
|
||||
}
|
||||
|
||||
void set_default_dir(const std::string& value) {
|
||||
preferences::set("editor_default_dir", value);
|
||||
}
|
||||
|
||||
namespace {
|
||||
void normalize_editor_rgb(int rval)
|
||||
{
|
||||
if (rval < -255) {
|
||||
rval = -255;
|
||||
}
|
||||
else if (rval > 255) {
|
||||
rval = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_tod_r(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
preferences::set("editor_r",lexical_cast<std::string>(value));
|
||||
}
|
||||
|
||||
void set_tod_g(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
preferences::set("editor_g",lexical_cast<std::string>(value));
|
||||
}
|
||||
|
||||
void set_tod_b(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
preferences::set("editor_b",lexical_cast<std::string>(value));
|
||||
}
|
||||
|
||||
int tod_r()
|
||||
{
|
||||
return lexical_cast_in_range<int>(preferences::get("editor_r"), 0, -255, 255);
|
||||
}
|
||||
|
||||
int tod_g()
|
||||
{
|
||||
return lexical_cast_in_range<int>(preferences::get("editor_g"), 0, -255, 255);
|
||||
}
|
||||
|
||||
int tod_b()
|
||||
{
|
||||
return lexical_cast_in_range<int>(preferences::get("editor_b"), 0, -255, 255);
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
||||
} //end namespace preferences
|
||||
|
59
src/editor/editor_preferences.hpp
Normal file
59
src/editor/editor_preferences.hpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2009 by Tomasz Sniatowski <kailoran@gmail.com>
|
||||
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 EDITOR_PREFERENCES_HPP_INCLUDED
|
||||
#define EDITOR_PREFERENCES_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace preferences {
|
||||
|
||||
namespace editor {
|
||||
|
||||
namespace TransitionUpdateMode {
|
||||
const int off = 0;
|
||||
const int on = 1;
|
||||
const int partial = 2;
|
||||
const int count = 3;
|
||||
}
|
||||
|
||||
int auto_update_transitions();
|
||||
void set_auto_update_transitions(int value);
|
||||
|
||||
bool use_mdi();
|
||||
void set_use_mdi(bool value);
|
||||
|
||||
std::string default_dir();
|
||||
void set_default_dir(const std::string& dir);
|
||||
|
||||
/** Set editor red tint level. */
|
||||
void set_tod_r(int value);
|
||||
/** Set editor green tint level. */
|
||||
void set_tod_g(int value);
|
||||
/** Set editor blue tint level. */
|
||||
void set_tod_b(int value);
|
||||
|
||||
/** Get editor red tint level. */
|
||||
int tod_r();
|
||||
/** Get editor green tint level. */
|
||||
int tod_g();
|
||||
/** Get editor blue tint level. */
|
||||
int tod_b();
|
||||
|
||||
} //end namespace editor
|
||||
|
||||
} //end namespace preferences
|
||||
|
||||
|
||||
#endif
|
|
@ -472,49 +472,6 @@ bool set_music(bool ison) {
|
|||
|
||||
namespace {
|
||||
double scroll = 0.2;
|
||||
|
||||
void normalize_editor_rgb(int rval)
|
||||
{
|
||||
if (rval < -255) {
|
||||
rval = -255;
|
||||
}
|
||||
else if (rval > 255) {
|
||||
rval = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_editor_r(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
prefs["editor_r"] = lexical_cast<std::string>(value);
|
||||
}
|
||||
|
||||
void set_editor_g(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
prefs["editor_g"] = lexical_cast<std::string>(value);
|
||||
}
|
||||
|
||||
void set_editor_b(int value)
|
||||
{
|
||||
normalize_editor_rgb(value);
|
||||
prefs["editor_b"] = lexical_cast<std::string>(value);
|
||||
}
|
||||
|
||||
int editor_r()
|
||||
{
|
||||
return lexical_cast_in_range<int>(get("editor_r"), 0, -255, 255);
|
||||
}
|
||||
|
||||
int editor_g()
|
||||
{
|
||||
return lexical_cast_in_range<int>(get("editor_g"), 0, -255, 255);
|
||||
}
|
||||
|
||||
int editor_b()
|
||||
{
|
||||
return lexical_cast_in_range<int>(get("editor_b"), 0, -255, 255);
|
||||
}
|
||||
|
||||
int scroll_speed()
|
||||
|
|
|
@ -136,20 +136,6 @@ namespace preferences {
|
|||
*/
|
||||
int mouse_scroll_threshold();
|
||||
|
||||
/** Set editor red tint level. */
|
||||
void set_editor_r(int value);
|
||||
/** Set editor green tint level. */
|
||||
void set_editor_g(int value);
|
||||
/** Set editor blue tint level. */
|
||||
void set_editor_b(int value);
|
||||
|
||||
/** Get editor red tint level. */
|
||||
int editor_r();
|
||||
/** Get editor green tint level. */
|
||||
int editor_g();
|
||||
/** Get editor blue tint level. */
|
||||
int editor_b();
|
||||
|
||||
int draw_delay();
|
||||
void set_draw_delay(int value);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue