Time and Schedule selection in the editor.

This commit is contained in:
fendrin 2013-05-14 18:07:54 +02:00
parent b9f83399cd
commit 25f5d44d70
15 changed files with 193 additions and 77 deletions

View file

@ -2,8 +2,8 @@
# Editor time-of-day (lighting settings) presets
[editor_times]
name= _ "Old"
id=old
name= _ "Test"
id=test
{DAWN}
{MORNING}
{DUSK}
@ -35,13 +35,9 @@
{DEEP_UNDERGROUND}
[/editor_times]
{campaigns/Under_the_Burning_Suns/utils/time.cfg}
[editor_times]
name= _ "After the Fall"
id=after_the_fall
{DAWN}
{MORNING}
{DUSK}
{FIRST_WATCH}
{UNDERGROUND}
{DEEP_UNDERGROUND}
{TWO_SUNS_DEFAULT_SCHEDULE}
[/editor_times]

View file

@ -65,7 +65,7 @@
#image=lite_small
#image=lite
font_size=9
items=statustable,editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,editor-multiplayer-save,editor-multiplayer-save-as,preferences,editor-settings,help,editor-close-map,quit-editor,editor-quit-to-desktop
items=statustable,editor-map-new,editor-map-load,editor-map-revert,editor-map-save,editor-map-save-as,preferences,editor-settings,help,editor-close-map,quit-editor,editor-quit-to-desktop
ref=top-panel
rect="=+1,=+1,+100,+20"
#rect="=+3,=+1,+55,=-4"
@ -89,11 +89,17 @@
title= _ "Map"
image=menu_buttons/menu_button_copper_H20
#image=lite
items=editor-map-resize,editor-map-rotate,editor-map-generate, editor-map-apply-mask,editor-map-create-mask-to, editor-refresh,editor-update-transitions,editor-auto-update-transitions,editor-partial-update-transitions,editor-no-update-transitions,editor-refresh-image-cache, editor-draw-coordinates,editor-draw-terrain-codes
items=editor-map-resize,editor-map-rotate,editor-map-generate, editor-map-apply-mask,editor-map-create-mask-to,menu-editor-transitions,editor-refresh,editor-refresh-image-cache,togglegrid,editor-draw-coordinates,editor-draw-terrain-codes
rect="+1,=,+100,="
xanchor=fixed
yanchor=fixed
[/menu]
[menu]
title= _ "Transition update"
button=false
id=menu-editor-transitions
items=editor-update-transitions,editor-auto-update-transitions,editor-partial-update-transitions,editor-no-update-transitions
[/menu]
[menu]
id=menu-editor-window
title= _ "Window"
@ -475,7 +481,24 @@
xanchor=right
yanchor=fixed
[/action]
[menu]
id=switch_time
items=editor-switch-time, menu-editor-schedule
#editor-assign-schedule
#type=checkbox
image=button_square/button_square_30
overlay=icons/action/editor-switch-time_30
tooltip_name_prepend=yes
rect="=-31,=,+30,+30"
xanchor=right
yanchor=fixed
[/menu]
[menu]
title= _ "Assign Time Schedule"
id=menu-editor-schedule
button=false
items=editor-assign-schedule
[/menu]
####### Game Map
[panel]
id=border-top

View file

@ -848,6 +848,9 @@ void display::create_buttons()
DBG_DP << "creating menu buttons...\n";
const std::vector<theme::menu>& buttons = theme_.menus();
for(std::vector<theme::menu>::const_iterator i = buttons.begin(); i != buttons.end(); ++i) {
if (!i->is_button()) continue;
gui::button b(screen_, i->title(), gui::button::TYPE_TURBO, i->image(),
gui::button::DEFAULT_SPACE, true, i->overlay());
DBG_DP << "drawing button " << i->get_id() << "\n";
@ -1649,7 +1652,7 @@ const theme::menu* display::menu_pressed()
assert(false);
return NULL;
}
return &theme_.menus()[index];
return theme_.get_menu_item(i->id());
}
}

View file

@ -89,13 +89,6 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
gui().redraw_everything();
events::raise_draw_event();
/* TODO enable if you can say what the purpose of the code is.
if (default_tool_menu != NULL) {
const SDL_Rect& menu_loc = default_tool_menu->location(get_display().screen_area());
show_menu(default_tool_menu->items(),menu_loc.x+1,menu_loc.y + menu_loc.h + 1,false);
return;
}
*/
}
void editor_controller::init_gui()
@ -117,6 +110,7 @@ void editor_controller::init_tods(const config& game_config)
BOOST_FOREACH(const config &schedule, game_config.child_range("editor_times")) {
const std::string& schedule_id = schedule["id"];
const std::string& schedule_name = schedule["name"];
if (schedule_id.empty()) {
ERR_ED << "Missing ID attribute in a TOD Schedule.\n";
continue;
@ -125,8 +119,8 @@ void editor_controller::init_tods(const config& game_config)
tods_map::iterator times = tods_.find(schedule_id);
if (times == tods_.end()) {
std::pair<tods_map::iterator, bool> new_times =
tods_.insert(std::pair<std::string, std::vector<time_of_day> >
(schedule_id, std::vector<time_of_day>()));
tods_.insert( std::pair<std::string, std::pair<std::string, std::vector<time_of_day> > >
(schedule_id, std::pair<std::string, std::vector<time_of_day> >(schedule_name, std::vector<time_of_day>())) );
times = new_times.first;
} else {
ERR_ED << "Duplicate TOD Schedule ids.\n";
@ -134,7 +128,7 @@ void editor_controller::init_tods(const config& game_config)
}
BOOST_FOREACH(const config &time, schedule.child_range("time")) {
times->second.push_back(time_of_day(time));
times->second.second.push_back(time_of_day(time));
}
}
@ -224,7 +218,7 @@ void editor_controller::editor_settings_dialog()
}
image::color_adjustment_resetter adjust_resetter;
if(!gui2::teditor_settings::execute(&(gui()), tods_["default"], gui().video())) {
if(!gui2::teditor_settings::execute(&(gui()), tods_["test"].second, gui().video())) {
adjust_resetter.reset();
}
context_manager_->refresh_all();
@ -254,6 +248,8 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case editor::PALETTE:
case editor::AREA:
case editor::SIDE:
case editor::TIME:
case editor::SCHEDULE:
return true;
}
}
@ -283,6 +279,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_STATUS_TABLE:
case HOTKEY_EDITOR_SWITCH_TIME:
return true;
// unit tool related
@ -350,8 +347,6 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_TOOL_VILLAGE:
return !context_manager_->get_map_context().get_teams().empty();
//TODO
// case HOTKEY_EDITOR_EXPORT_SELECTION_COORDS:
case HOTKEY_EDITOR_AREA_DEFINE:
case HOTKEY_EDITOR_CUT:
case HOTKEY_EDITOR_COPY:
@ -481,6 +476,12 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case editor::SIDE:
return static_cast<size_t>(index) == gui_->playing_team()
? ACTION_SELECTED : ACTION_DESELECTED;
case editor::TIME:
return index == context_manager_->get_map_context().get_time_manager()->turn() -1
? ACTION_SELECTED : ACTION_DESELECTED;
case editor::SCHEDULE:
//TODO
return ACTION_STATELESS;
}
return ACTION_ON;
default:
@ -513,8 +514,7 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case SIDE:
gui_->set_team(index, true);
gui_->set_playing_team(index);
//TODO
// toolkit_->get_palette_manager()->draw();
toolkit_->get_palette_manager()->draw_contents();
return true;
case AREA:
//TODO store the selection for the state setting.
@ -526,6 +526,22 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
gui_->scroll_to_tiles(locs.begin(), locs.end());
return true;
}
case TIME:
{
tod_manager* tod = context_manager_->get_map_context().get_time_manager();
tod->set_turn(index +1, true);
tod_color col = tod->times()[index].color;
image::set_color_adjustment(col.r, col.g, col.b);
return true;
}
case SCHEDULE:
{
tod_manager* tod = context_manager_->get_map_context().get_time_manager();
tods_map::iterator iter = tods_.begin();
std::advance(iter, index);
tod->replace_schedule(iter->second.second);
return true;
}
}
return true;
@ -553,6 +569,8 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
// gui2::teditor_select_palette_group::execute(selected, blah_items, gui_->video());
}
return true;
case HOTKEY_EDITOR_SWITCH_TIME:
return true;
case HOTKEY_EDITOR_PALETTE_UPSCROLL:
toolkit_->get_palette_manager()->scroll_up();
gui_->draw(true,false);
@ -782,11 +800,14 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
std::vector<std::string> items;
std::vector<std::string>::const_iterator i = items_arg.begin();
while(i != items_arg.end()) {
while(i != items_arg.end())
{
hotkey::HOTKEY_COMMAND command = hotkey::get_id(*i);
if (!(!can_execute_command(command)
|| (context_menu && !in_context_menu(command)))) {
if ( ( can_execute_command(command)
&& (!context_menu || in_context_menu(command)) )
|| command == hotkey::HOTKEY_NULL) {
items.push_back(*i);
}
++i;
@ -795,7 +816,6 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
active_menu_ = editor::MAP;
context_manager_->expand_open_maps_menu(items);
}
//TODO
if (!items.empty() && items.front() == "editor-palette-groups") {
active_menu_ = editor::PALETTE;
toolkit_->get_palette_manager()->active_palette().expand_palette_groups_menu(items);
@ -808,6 +828,20 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
active_menu_ = editor::AREA;
context_manager_->expand_areas_menu(items);
}
if (!items.empty() && items.front() == "editor-switch-time") {
active_menu_ = editor::TIME;
context_manager_->expand_time_menu(items);
}
if (!items.empty() && items.front() == "editor-assign-schedule") {
active_menu_ = editor::SCHEDULE;
items.erase(items.begin());
for (tods_map::iterator iter = tods_.begin();
iter != tods_.end(); ++iter) {
items.push_back(iter->second.first);
}
}
command_executor::show_menu(items, xloc, yloc, context_menu, gui());
}
@ -856,11 +890,8 @@ void editor_controller::change_unit_id()
if(un != units.end()) {
std::string id = un->id();
if(gui2::tedit_text::execute(title, label, id, gui_->video())) {
//TODO we may not want a translated name here.
if (gui2::tedit_text::execute(title, label, id, gui_->video())) {
un->set_id(id);
//TODO
//gui_->invalidate_unit();
}
}
}
@ -879,8 +910,6 @@ void editor_controller::rename_unit()
if(gui2::tedit_text::execute(title, label, name, gui_->video())) {
//TODO we may not want a translated name here.
un->set_name(name);
//TODO
//gui_->invalidate_unit();
}
}
}

View file

@ -61,7 +61,9 @@ enum menu_type {
MAP,
PALETTE,
AREA,
SIDE
SIDE,
TIME,
SCHEDULE
};
/**
@ -111,6 +113,11 @@ class editor_controller : public controller_base,
/** command_executor override */
bool execute_command(hotkey::HOTKEY_COMMAND command, int index = -1);
/** command_executor override */
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& /*gui*/) {
show_menu(items_arg, xloc, yloc, context_menu);
}
/** controller_base override */
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
@ -224,7 +231,7 @@ class editor_controller : public controller_base,
boost::scoped_ptr<editor_display> gui_;
/** Pre-defined time of day lighting settings for the settings dialog */
typedef std::map<std::string, std::vector<time_of_day> > tods_map;
typedef std::map<std::string, std::pair<std::string ,std::vector<time_of_day> > > tods_map;
tods_map tods_;
/* managers */

View file

@ -38,8 +38,7 @@ EXIT_STATUS start(const config& game_conf, CVideo& video, const std::string& fil
editor_controller editor(game_conf, video);
if (!filename.empty()) {
if (is_directory(filename)) {
//TODO
//editor.set_default_dir(filename);
editor.context_manager_->set_default_dir(filename);
editor.context_manager_->load_map_dialog(true);
} else {
editor.context_manager_->load_map(filename, false);

View file

@ -37,6 +37,8 @@
#include "terrain_translation.hpp"
#include "wml_separators.hpp"
namespace {
static std::vector<std::string> saved_windows_;
}
@ -271,6 +273,36 @@ void context_manager::expand_sides_menu(std::vector<std::string>& items)
}
}
void context_manager::expand_time_menu(std::vector<std::string>& items)
{
for (unsigned int i = 0; i < items.size(); ++i) {
if (items[i] == "editor-switch-time") {
items.erase(items.begin() + i);
std::vector<std::string> contexts;
tod_manager* tod_m = get_map_context().get_time_manager();
BOOST_FOREACH(const time_of_day& time, tod_m->times()) {
//for (size_t mci = 0; mci < tod_m->times().size(); ++mci) {
//const time_of_day& time = tod_m->times()[mci];
std::stringstream label;
// label << "[" << mci+1 << "] ";
if (!time.image.empty())
label << IMAGE_PREFIX << time.image << IMG_TEXT_SEPARATOR;
//<< COLUMN_SEPARATOR;
label << time.name;
//label << (time.name.empty() ? _("(New Side)") : time.name);
contexts.push_back(label.str());
}
items.insert(items.begin() + i, contexts.begin(), contexts.end());
break;
}
}
}
void context_manager::apply_mask_dialog()
{
std::string fn = get_map_context().get_filename();

View file

@ -121,6 +121,9 @@ public:
/** Menu expanding for the map's defined areas */
void expand_areas_menu(std::vector<std::string>& items);
/** Menu expanding for the map's defined areas */
void expand_time_menu(std::vector<std::string>& items);
/** Display a load map dialog and process user input. */
void load_map_dialog(bool force_same_context = false);
@ -145,11 +148,11 @@ public:
return *map_contexts_[current_context_index_];
}
private:
/** Set the default dir (where the filebrowser is pointing at when there is no map file opened) */
void set_default_dir(const std::string& str);
private:
/**
* Replace the current map context and refresh accordingly
*/

View file

@ -162,6 +162,7 @@ const hotkey_command hotkey_list_[] = {
{ hotkey::HOTKEY_EDITOR_PALETTE_UPSCROLL, "editor-palette-upscroll", N_("Scroll Palette Left"), false, hotkey::SCOPE_EDITOR, NULL },
{ hotkey::HOTKEY_EDITOR_PALETTE_DOWNSCROLL, "editor-palette-downscroll", N_("Scroll Palette Right"), false, hotkey::SCOPE_EDITOR, NULL },
{ hotkey::HOTKEY_EDITOR_SWITCH_TIME, "editor-switch-time", N_("Switch Time of Day"), false, hotkey::SCOPE_EDITOR, NULL },
{ hotkey::HOTKEY_EDITOR_TOOL_NEXT, "editor-tool-next", N_("Next Tool"), false, hotkey::SCOPE_EDITOR, NULL },
@ -1289,33 +1290,24 @@ void command_executor::set_button_state(display& disp) {
void command_executor::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool /*context_menu*/, display& gui)
{
std::vector<std::string> items = items_arg;
if (items.empty()) {
return;
}
//TODO this does not make sense anymore
if (can_execute_command(hotkey::get_id(items.front()), 0)) {
// If just one item is passed in, that means we should execute that item.
/*
if (!context_menu && items.size() == 1 && items_arg.size() == 1) {
hotkey::execute_command(gui,hotkey::get_id(items.front()), this);
set_button_state(gui);
return;
}
*/
if (items.empty()) return;
std::vector<std::string> menu = get_menu_images(gui, items);
int res = 0;
{
gui::dialog mmenu = gui::dialog(gui,"","",
gui::MESSAGE, gui::dialog::hotkeys_style);
mmenu.set_menu(menu);
res = mmenu.show(xloc, yloc);
} // This will kill the dialog.
if (res < 0 || size_t(res) >= items.size()) {
return;
}
std::vector<std::string> menu = get_menu_images(gui, items);
int res = 0;
{
gui::dialog mmenu = gui::dialog(gui,"","",
gui::MESSAGE, gui::dialog::hotkeys_style);
mmenu.set_menu(menu);
res = mmenu.show(xloc, yloc);
} // This will kill the dialog.
if (res < 0 || size_t(res) >= items.size()) return;
const theme::menu* submenu = gui.get_theme().get_menu_item(items[res]);
if (submenu) {
int y,x;
SDL_GetMouseState(&x,&y);
this->show_menu(submenu->items(), x, y, submenu->is_context(), gui);
} else {
const hotkey::HOTKEY_COMMAND cmd = hotkey::get_id(items[res]);
hotkey::execute_command(gui,cmd,this,res);
set_button_state(gui);
@ -1341,7 +1333,7 @@ void command_executor::execute_action(const std::vector<std::string>& items_arg,
}
}
std::string command_executor::get_menu_image(const std::string& command, int index) const {
std::string command_executor::get_menu_image(display& disp, const std::string& command, int index) const {
const std::string base_image_name = "icons/action/" + command + "_25.png";
const std::string pressed_image_name = "icons/action/" + command + "_25-pressed.png";
@ -1349,6 +1341,11 @@ std::string command_executor::get_menu_image(const std::string& command, int ind
const hotkey::HOTKEY_COMMAND hk = hotkey::get_id(command);
const hotkey::ACTION_STATE state = get_action_state(hk, index);
const theme::menu* menu = disp.get_theme().get_menu_item(command);
if (menu)
return "buttons/fold-arrow.png";
//if (hk == hotkey::HOTKEY_NULL)
if (file_exists(game_config::path + "/images/" + base_image_name)) {
switch (state) {
case ACTION_ON:
@ -1382,14 +1379,18 @@ std::vector<std::string> command_executor::get_menu_images(display& disp, const
std::stringstream str;
//see if this menu item has an associated image
std::string img(get_menu_image(item, i));
std::string img(get_menu_image(disp, item, i));
if (img.empty() == false) {
has_image = true;
str << IMAGE_PREFIX << img << COLUMN_SEPARATOR;
}
if (hk == hotkey::HOTKEY_NULL) {
str << item.substr(0, item.find_last_not_of(' ') + 1) << COLUMN_SEPARATOR;
const theme::menu* menu = disp.get_theme().get_menu_item(item);
if (menu)
str << menu->title();
else
str << item.substr(0, item.find_last_not_of(' ') + 1) << COLUMN_SEPARATOR;
} else {
std::string desc = hotkey::get_description(item);
if (hk == HOTKEY_ENDTURN) {

View file

@ -94,6 +94,9 @@ enum HOTKEY_COMMAND {
HOTKEY_EDITOR_PALETTE_ITEM_SWAP,
HOTKEY_EDITOR_PALETTE_GROUPS, HOTKEY_EDITOR_PALETTE_UPSCROLL, HOTKEY_EDITOR_PALETTE_DOWNSCROLL,
HOTKEY_EDITOR_TOOL_NEXT,
HOTKEY_EDITOR_SWITCH_TIME,
HOTKEY_EDITOR_TOOL_PAINT, HOTKEY_EDITOR_TOOL_FILL,
HOTKEY_EDITOR_TOOL_SELECT, HOTKEY_EDITOR_TOOL_STARTING_POSITION, HOTKEY_EDITOR_TOOL_LABEL,
HOTKEY_EDITOR_TOOL_UNIT, HOTKEY_EDITOR_TOOL_VILLAGE, HOTKEY_EDITOR_TOOL_ITEM, HOTKEY_EDITOR_TOOL_SOUNDSOURCE,
@ -393,11 +396,11 @@ public:
// Does the action control a toggle switch? If so, return the state of the action (on or off).
virtual ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND /*command*/, int /*index*/) const { return ACTION_STATELESS; }
// Returns the appropriate menu image. Checkable items will get a checked/unchecked image.
std::string get_menu_image(const std::string& command, int index=-1) const;
std::string get_menu_image(display& disp, const std::string& command, int index=-1) const;
// Returns a vector of images for a given menu.
std::vector<std::string> get_menu_images(display &, const std::vector<std::string>& items_arg);
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
virtual void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
void execute_action(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu, display& gui);
/**

View file

@ -514,6 +514,7 @@ theme::slider::slider(const config &cfg):
theme::menu::menu() :
object(),
button_(true),
context_(false),
title_(),
tooltip_(),
@ -523,7 +524,9 @@ theme::menu::menu() :
{}
theme::menu::menu(const config &cfg):
object(cfg), context_(cfg["is_context_menu"].to_bool()),
object(cfg),
button_(cfg["button"].to_bool(true)),
context_(cfg["is_context_menu"].to_bool(false)),
title_(cfg["title"].str() + cfg["title_literal"].str()),
tooltip_(cfg["tooltip"]), image_(cfg["image"]), overlay_(cfg["overlay"]),
items_(utils::split(cfg["items"]))

View file

@ -221,6 +221,8 @@ public:
using object::location;
bool is_button() const { return button_; }
bool is_context() const { return context_; }
const std::string& title() const { return title_; }
@ -235,6 +237,7 @@ public:
void set_title(const std::string& new_title) { title_ = new_title; }
private:
bool button_;
bool context_;
std::string title_, tooltip_, image_, overlay_;
std::vector<std::string> items_;

View file

@ -68,8 +68,7 @@ void time_of_day::parse_times(const config& cfg, std::vector<time_of_day>& norma
if(normal_times.empty())
{
// Make sure we have at least default time
config dummy_cfg;
normal_times.push_back(time_of_day(dummy_cfg));
normal_times.push_back(time_of_day());
}
}

View file

@ -199,6 +199,19 @@ void tod_manager::replace_schedule(const config& time_cfg)
currentTime_ = 0;
}
void tod_manager::replace_schedule(const std::vector<time_of_day>& schedule)
{
times_.clear();
BOOST_FOREACH(const time_of_day& time, schedule) {
config cfg;
time.write(cfg);
times_.push_back(time_of_day(cfg));
}
currentTime_ = 0;
}
std::vector<std::string> tod_manager::get_area_ids() const
{
std::vector<std::string> areas;
@ -309,7 +322,8 @@ void tod_manager::set_turn(const int num, const bool increase_limit_if_needed)
set_number_of_turns(new_turn);
}
turn_ = new_turn;
resources::gamedata->get_variable("turn_number") = new_turn;
if (resources::gamedata)
resources::gamedata->get_variable("turn_number") = new_turn;
}
void tod_manager::set_new_current_times(const int new_current_turn_number)

View file

@ -65,6 +65,7 @@ class tod_manager : public savegame::savegame_config
* Replace the time of day schedule
*/
void replace_schedule(const config& time_cfg);
void replace_schedule(const std::vector<time_of_day>& schedule);
/**
* @returns the [time_area]s' ids.