Scenario playlist editor.

This commit is contained in:
fendrin 2013-05-19 13:50:16 +02:00
parent 73f8c96778
commit 0f8a287b10
7 changed files with 70 additions and 10 deletions

View File

@ -491,6 +491,16 @@
xanchor=right xanchor=right
yanchor=fixed yanchor=fixed
[/menu] [/menu]
[menu]
id=menu-playlist
items=editor-playlist
image=button_square/button_square_30
overlay=icons/action/editor-tool-soundsource_30
tooltip= _ "Playlist"
rect="=-31,=,+30,+30"
xanchor=right
yanchor=fixed
[/menu]
[menu] [menu]
title= _ "Assign Time Schedule" title= _ "Assign Time Schedule"
id=menu-editor-schedule id=menu-editor-schedule

View File

@ -74,6 +74,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
, help_manager_(NULL) , help_manager_(NULL)
, do_quit_(false) , do_quit_(false)
, quit_mode_(EXIT_ERROR) , quit_mode_(EXIT_ERROR)
, music_tracks_()
{ {
init_gui(); init_gui();
toolkit_.reset(new editor_toolkit(*gui_.get(), key_, game_config_, *context_manager_.get())); toolkit_.reset(new editor_toolkit(*gui_.get(), key_, game_config_, *context_manager_.get()));
@ -140,14 +141,18 @@ void editor_controller::init_tods(const config& game_config)
void editor_controller::init_music(const config& game_config) void editor_controller::init_music(const config& game_config)
{ {
const config &cfg = game_config.child("editor_music"); if (!game_config.has_child("editor_music")) {
if (!cfg) {
ERR_ED << "No editor music defined\n"; ERR_ED << "No editor music defined\n";
return; return;
} }
BOOST_FOREACH(const config &i, cfg.child_range("music")) {
sound::play_music_config(i); BOOST_FOREACH(const config& editor_music, game_config.child_range("editor_music")) {
BOOST_FOREACH(const config& music, editor_music.child_range("music")) {
music_tracks_.push_back(sound::music_track(music));
sound::play_music_config(music);
}
} }
sound::commit_music_changes(); sound::commit_music_changes();
} }
@ -250,6 +255,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case editor::SIDE: case editor::SIDE:
case editor::TIME: case editor::TIME:
case editor::SCHEDULE: case editor::SCHEDULE:
case editor::MUSIC:
return true; return true;
} }
} }
@ -484,6 +490,9 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case editor::TIME: case editor::TIME:
return index == context_manager_->get_map_context().get_time_manager()->turn() -1 return index == context_manager_->get_map_context().get_time_manager()->turn() -1
? ACTION_SELECTED : ACTION_DESELECTED; ? ACTION_SELECTED : ACTION_DESELECTED;
case editor::MUSIC:
return context_manager_->get_map_context().is_in_playlist(music_tracks_[index].id())
? ACTION_ON : ACTION_OFF;
case editor::SCHEDULE: case editor::SCHEDULE:
{ {
tods_map::const_iterator it = tods_.begin(); tods_map::const_iterator it = tods_.begin();
@ -546,6 +555,12 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
image::set_color_adjustment(col.r, col.g, col.b); image::set_color_adjustment(col.r, col.g, col.b);
return true; return true;
} }
case MUSIC:
{
sound::play_music_once(music_tracks_[index].id());
context_manager_->get_map_context().add_to_playlist(music_tracks_[index]);
return true;
}
case SCHEDULE: case SCHEDULE:
{ {
tod_manager* tod = context_manager_->get_map_context().get_time_manager(); tod_manager* tod = context_manager_->get_map_context().get_time_manager();
@ -860,6 +875,13 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
active_menu_ = editor::TIME; active_menu_ = editor::TIME;
context_manager_->expand_time_menu(items); context_manager_->expand_time_menu(items);
} }
if (!items.empty() && items.front() == "editor-playlist") {
active_menu_ = editor::MUSIC;
items.erase(items.begin());
BOOST_FOREACH(const sound::music_track& track, music_tracks_) {
items.push_back(track.id());
}
}
if (!items.empty() && items.front() == "editor-assign-schedule") { if (!items.empty() && items.front() == "editor-assign-schedule") {
active_menu_ = editor::SCHEDULE; active_menu_ = editor::SCHEDULE;

View File

@ -27,6 +27,7 @@
#include "../mouse_handler_base.hpp" #include "../mouse_handler_base.hpp"
#include "../tooltips.hpp" #include "../tooltips.hpp"
#include "sound_music_track.hpp"
class map_generator; class map_generator;
@ -63,7 +64,8 @@ enum menu_type {
AREA, AREA,
SIDE, SIDE,
TIME, TIME,
SCHEDULE SCHEDULE,
MUSIC
}; };
/** /**
@ -252,6 +254,7 @@ class editor_controller : public controller_base,
bool do_quit_; bool do_quit_;
EXIT_STATUS quit_mode_; EXIT_STATUS quit_mode_;
std::vector<sound::music_track> music_tracks_;
}; };
} //end namespace editor } //end namespace editor

View File

@ -57,6 +57,7 @@ map_context::map_context(const editor_map& map, const display& disp)
, teams_() , teams_()
, tod_manager_(new tod_manager) , tod_manager_(new tod_manager)
, state_() , state_()
, music_tracks_()
{ {
} }
@ -80,6 +81,7 @@ map_context::map_context(const config& game_config, const std::string& filename,
, teams_() , teams_()
, tod_manager_(NULL) , tod_manager_(NULL)
, state_() , state_()
, music_tracks_()
{ {
/* /*
* Overview of situations possibly found in the file: * Overview of situations possibly found in the file:
@ -147,6 +149,10 @@ map_context::map_context(const config& game_config, const std::string& filename,
tod_manager_->add_time_area(t); tod_manager_->add_time_area(t);
} }
BOOST_FOREACH(const config& music, level.child_range("music")) {
music_tracks_.insert(std::pair<std::string, sound::music_track>(music["name"], sound::music_track(music)));
}
resources::teams = &teams_; resources::teams = &teams_;
int i = 1; int i = 1;
@ -280,6 +286,10 @@ bool map_context::save()
config wml_data = tod_manager_->to_config(); config wml_data = tod_manager_->to_config();
labels_.write(wml_data); labels_.write(wml_data);
BOOST_FOREACH(const music_map::value_type& track, music_tracks_) {
track.second.write(wml_data, true);
}
//TODO think about saving the map to the wml file //TODO think about saving the map to the wml file
//config& map = cfg.add_child("map"); //config& map = cfg.add_child("map");
//gamemap::write(map); //gamemap::write(map);

View File

@ -16,10 +16,11 @@
#define EDITOR_MAP_CONTEXT_HPP_INCLUDED #define EDITOR_MAP_CONTEXT_HPP_INCLUDED
#include "editor_map.hpp" #include "editor_map.hpp"
#include "map_label.hpp"
#include "unit_map.hpp"
#include "tod_manager.hpp"
#include "gamestatus.hpp" #include "gamestatus.hpp"
#include "map_label.hpp"
#include "sound_music_track.hpp"
#include "tod_manager.hpp"
#include "unit_map.hpp"
#include <boost/utility.hpp> #include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
@ -111,6 +112,17 @@ public:
return active_area_; return active_area_;
} }
bool is_in_playlist(std::string track_id) {
return music_tracks_.find(track_id) != music_tracks_.end();
}
void add_to_playlist(const sound::music_track& track) {
if (music_tracks_.find(track.id()) == music_tracks_.end())
music_tracks_.insert(std::pair<std::string, sound::music_track>(track.id(), track));
else music_tracks_.erase(track.id());
}
/** /**
* Draw a terrain on a single location on the map. * Draw a terrain on a single location on the map.
* Sets the refresh flags accordingly. * Sets the refresh flags accordingly.
@ -357,6 +369,9 @@ private:
boost::scoped_ptr<tod_manager> tod_manager_; boost::scoped_ptr<tod_manager> tod_manager_;
game_state state_; game_state state_;
typedef std::map<std::string, sound::music_track> music_map;
music_map music_tracks_;
}; };

View File

@ -79,7 +79,7 @@ void music_track::resolve()
LOG_AUDIO << "resolved music track '" << id_ << "' into '" << file_path_ << "'\n"; LOG_AUDIO << "resolved music track '" << id_ << "' into '" << file_path_ << "'\n";
} }
void music_track::write(config &parent_node, bool append) void music_track::write(config &parent_node, bool append) const
{ {
config& m = parent_node.add_child("music"); config& m = parent_node.add_child("music");
m["name"] = id_; m["name"] = id_;

View File

@ -31,7 +31,7 @@ public:
music_track(); music_track();
music_track(const config& node); music_track(const config& node);
music_track(const std::string& v_name); music_track(const std::string& v_name);
void write(config& parent_node, bool append); void write(config& parent_node, bool append) const;
bool valid() const { return file_path_.empty() != true; } bool valid() const { return file_path_.empty() != true; }