Improved the time of day schedule menu.
Change the save state of the scenario when times are adjusted. Load the default schedule into new maps.
This commit is contained in:
parent
904383ea4f
commit
2abb7cb8f1
4 changed files with 101 additions and 49 deletions
|
@ -502,7 +502,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
|
|||
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
|
||||
return index == context_manager_->get_map_context().get_time_manager()->get_current_time()
|
||||
? ACTION_SELECTED : ACTION_DESELECTED;
|
||||
case editor::MUSIC:
|
||||
return context_manager_->get_map_context().is_in_playlist(music_tracks_[index].id())
|
||||
|
@ -561,9 +561,8 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
}
|
||||
case TIME:
|
||||
{
|
||||
//TODO mark the map as changed
|
||||
tod_manager* tod = context_manager_->get_map_context().get_time_manager();
|
||||
tod->set_turn(index +1, true);
|
||||
context_manager_->get_map_context().set_starting_time(index);
|
||||
const tod_manager* tod = context_manager_->get_map_context().get_time_manager();
|
||||
tod_color col = tod->times()[index].color;
|
||||
image::set_color_adjustment(col.r, col.g, col.b);
|
||||
return true;
|
||||
|
@ -581,12 +580,10 @@ bool editor_controller::execute_command(const hotkey::hotkey_command& cmd, int i
|
|||
}
|
||||
case SCHEDULE:
|
||||
{
|
||||
//TODO mark the map as changed
|
||||
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);
|
||||
tod->set_turn(1, true);
|
||||
context_manager_->get_map_context().replace_schedule(iter->second.second);
|
||||
const tod_manager* tod = context_manager_->get_map_context().get_time_manager();
|
||||
tod_color col = tod->times()[0].color;
|
||||
image::set_color_adjustment(col.r, col.g, col.b);
|
||||
return true;
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
*/
|
||||
#define GETTEXT_DOMAIN "wesnoth-editor"
|
||||
|
||||
#include "team.hpp"
|
||||
|
||||
#include "context_manager.hpp"
|
||||
#include "display.hpp"
|
||||
#include "filesystem.hpp"
|
||||
|
@ -187,10 +189,10 @@ void context_manager::edit_side_dialog(int side)
|
|||
team& t = get_map_context().get_teams()[side];
|
||||
|
||||
//TODO
|
||||
//t.controller();
|
||||
//t.hidden();
|
||||
//t.support()
|
||||
|
||||
team::CONTROLLER controller = t.controller();
|
||||
|
||||
std::string id = t.save_id();
|
||||
std::string name = t.name();
|
||||
|
||||
|
@ -199,6 +201,7 @@ void context_manager::edit_side_dialog(int side)
|
|||
int village_gold = t.village_gold();
|
||||
int village_support = t.village_support();
|
||||
|
||||
bool hidden = t.hidden();
|
||||
bool share_view = t.share_view();
|
||||
bool share_maps = t.share_maps();
|
||||
bool fog = t.uses_fog();
|
||||
|
@ -206,13 +209,13 @@ void context_manager::edit_side_dialog(int side)
|
|||
|
||||
bool ok = gui2::teditor_edit_side::execute(id, name,
|
||||
gold, income,
|
||||
fog, share_view, shroud, share_maps,
|
||||
fog, share_view, shroud, share_maps, controller,
|
||||
gui_.video());
|
||||
|
||||
if (ok) {
|
||||
get_map_context().set_side_setup(id, name,
|
||||
get_map_context().set_side_setup(side, id, name,
|
||||
gold, income, village_gold, village_support,
|
||||
fog, share_view, shroud, share_maps);
|
||||
fog, share_view, shroud, share_maps, controller, hidden);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -650,8 +653,8 @@ void context_manager::create_default_context()
|
|||
|
||||
t_translation::t_terrain default_terrain =
|
||||
t_translation::read_terrain_code(game_config::default_terrain);
|
||||
|
||||
map_context* mc = new map_context(editor_map(game_config_, 44, 33, default_terrain), gui_, true);
|
||||
const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
|
||||
map_context* mc = new map_context(editor_map(game_config_, 44, 33, default_terrain), gui_, true, default_schedule);
|
||||
add_map_context(mc);
|
||||
} else {
|
||||
BOOST_FOREACH(const std::string& filename, saved_windows_) {
|
||||
|
@ -867,23 +870,25 @@ void context_manager::revert_map()
|
|||
|
||||
void context_manager::new_map(int width, int height, const t_translation::t_terrain & fill, bool new_context)
|
||||
{
|
||||
const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
|
||||
editor_map m(game_config_, width, height, fill);
|
||||
if (new_context) {
|
||||
int new_id = add_map_context(new map_context(m, gui_, true));
|
||||
int new_id = add_map_context(new map_context(m, gui_, true, default_schedule));
|
||||
switch_context(new_id);
|
||||
} else {
|
||||
replace_map_context(new map_context(m, gui_, true));
|
||||
replace_map_context(new map_context(m, gui_, true, default_schedule));
|
||||
}
|
||||
}
|
||||
|
||||
void context_manager::new_scenario(int width, int height, const t_translation::t_terrain & fill, bool new_context)
|
||||
{
|
||||
const config& default_schedule = game_config_.find_child("editor_times", "id", "default");
|
||||
editor_map m(game_config_, width, height, fill);
|
||||
if (new_context) {
|
||||
int new_id = add_map_context(new map_context(m, gui_, false));
|
||||
int new_id = add_map_context(new map_context(m, gui_, false, default_schedule));
|
||||
switch_context(new_id);
|
||||
} else {
|
||||
replace_map_context(new map_context(m, gui_, false));
|
||||
replace_map_context(new map_context(m, gui_, false, default_schedule));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace editor {
|
|||
|
||||
const size_t map_context::max_action_stack_size_ = 100;
|
||||
|
||||
map_context::map_context(const editor_map& map, const display& disp, bool pure_map)
|
||||
map_context::map_context(const editor_map& map, const display& disp, bool pure_map, const config& schedule)
|
||||
: filename_()
|
||||
, map_data_key_()
|
||||
, embedded_(false)
|
||||
|
@ -62,7 +62,7 @@ map_context::map_context(const editor_map& map, const display& disp, bool pure_m
|
|||
, labels_(disp, NULL)
|
||||
, units_()
|
||||
, teams_()
|
||||
, tod_manager_(new tod_manager)
|
||||
, tod_manager_(new tod_manager(schedule))
|
||||
, state_()
|
||||
, music_tracks_()
|
||||
{
|
||||
|
@ -164,19 +164,26 @@ map_context::map_context(const config& game_config, const std::string& filename,
|
|||
|
||||
}
|
||||
|
||||
void map_context::set_side_setup(const std::string& /*id*/, const std::string& /*name*/,
|
||||
int gold, int income, int village_gold, int village_support , bool fog, bool share_view, bool shroud, bool share_maps)
|
||||
void map_context::set_side_setup(int side, const std::string& id, const std::string& name,
|
||||
int gold, int income, int village_gold, int village_support,
|
||||
bool fog, bool share_view, bool shroud, bool share_maps,
|
||||
team::CONTROLLER controller, bool hidden)
|
||||
{
|
||||
team& t = teams_[0];
|
||||
assert(teams_.size() > static_cast<u_int>(side));
|
||||
team& t = teams_[side];
|
||||
t.set_save_id(id);
|
||||
t.set_name(name);
|
||||
t.change_controller(controller);
|
||||
t.set_gold(gold);
|
||||
t.set_base_income(income);
|
||||
//t.set_hidden(hidden);
|
||||
t.set_hidden(hidden);
|
||||
t.set_fog(fog);
|
||||
t.set_share_maps(share_maps);
|
||||
t.set_shroud(shroud);
|
||||
t.set_share_view(share_view);
|
||||
t.set_village_gold(village_gold);
|
||||
t.set_village_support(village_support);
|
||||
actions_since_save_++;
|
||||
}
|
||||
|
||||
void map_context::set_scenario_setup(const std::string& id, const std::string& name, const std::string& description,
|
||||
|
@ -189,8 +196,22 @@ void map_context::set_scenario_setup(const std::string& id, const std::string& n
|
|||
victory_defeated_ = victory_defeated;
|
||||
tod_manager_->set_number_of_turns(turns);
|
||||
xp_mod_ = xp_mod;
|
||||
actions_since_save_++;
|
||||
}
|
||||
|
||||
void map_context::set_starting_time(int time)
|
||||
{
|
||||
tod_manager_->set_current_time(time);
|
||||
if (!pure_map_)
|
||||
actions_since_save_++;
|
||||
}
|
||||
|
||||
void map_context::replace_schedule(const std::vector<time_of_day>& schedule)
|
||||
{
|
||||
tod_manager_->replace_schedule(schedule);
|
||||
if (!pure_map_)
|
||||
actions_since_save_++;
|
||||
}
|
||||
|
||||
void map_context::load_scenario(const config& game_config)
|
||||
{
|
||||
|
@ -201,11 +222,16 @@ void map_context::load_scenario(const config& game_config)
|
|||
scenario_name_ = scenario["name"].str();
|
||||
scenario_description_ = scenario["description"].str();
|
||||
|
||||
xp_mod_ = scenario["experience_modifier"].to_int();
|
||||
|
||||
victory_defeated_ = scenario["victory_when_enemies_defeated"].to_bool(true);
|
||||
random_time_ = scenario["random_start_time"].to_bool(false);
|
||||
|
||||
map_ = editor_map::from_string(game_config, scenario["map_data"]); //throws on error
|
||||
|
||||
labels_.read(scenario);
|
||||
|
||||
tod_manager_.reset(new tod_manager(scenario));
|
||||
tod_manager_.reset(new tod_manager(scenario, scenario["turns"].to_int(-1)));
|
||||
BOOST_FOREACH(const config &t, scenario.child_range("time_area")) {
|
||||
tod_manager_->add_time_area(t);
|
||||
}
|
||||
|
@ -341,15 +367,22 @@ void map_context::reset_starting_position_labels(display& disp)
|
|||
config map_context::to_config()
|
||||
{
|
||||
config scenario;
|
||||
scenario["id"] = scenario_id_;
|
||||
scenario["name"] = scenario_name_;
|
||||
scenario["description"] = scenario_description_;
|
||||
scenario.append(tod_manager_->to_config());
|
||||
scenario["map_data"] = map_.write();
|
||||
labels_.write(scenario);
|
||||
|
||||
scenario["id"] = scenario_id_;
|
||||
scenario["name"] = t_string(scenario_name_);
|
||||
scenario["description"] = scenario_description_;
|
||||
|
||||
scenario["experience_modifier"] = xp_mod_;
|
||||
scenario["victory_when_enemies_defeated"] = victory_defeated_;
|
||||
scenario["random_starting_time"] = random_time_;
|
||||
|
||||
scenario.append(tod_manager_->to_config());
|
||||
scenario.remove_attribute("turn_at");
|
||||
|
||||
scenario["map_data"] = map_.write();
|
||||
|
||||
labels_.write(scenario);
|
||||
|
||||
BOOST_FOREACH(const music_map::value_type& track, music_tracks_) {
|
||||
track.second.write(scenario, true);
|
||||
}
|
||||
|
@ -358,27 +391,31 @@ config map_context::to_config()
|
|||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = scenario.add_child("side");
|
||||
//t->write(side);
|
||||
// TODO make this customizable via gui and clean up
|
||||
|
||||
side["side"] = side_num;
|
||||
side["hidden"] = t->hidden();
|
||||
|
||||
side["controller"] = t->controller_string();
|
||||
// TODO make this customizable via gui
|
||||
side["no_leader"] = "yes";
|
||||
side["allow_player"] = "yes";
|
||||
|
||||
//side.clear_children("ai");
|
||||
side["fog"] = t->uses_fog();
|
||||
side["share_view"] = t->share_view();
|
||||
side["shroud"] = t->uses_shroud();
|
||||
side["share_maps"] = t->share_maps();
|
||||
|
||||
//side.remove_attribute("color");
|
||||
//side.remove_attribute("recruit");
|
||||
//side.remove_attribute("recall_cost");
|
||||
//side.remove_attribute("gold");
|
||||
//side.remove_attribute("start_gold");
|
||||
//side.remove_attribute("hidden");
|
||||
side["side"] = side_num;
|
||||
side["gold"] = t->gold();
|
||||
side["income"] = t->base_income();
|
||||
|
||||
//current visible units
|
||||
for(unit_map::const_iterator i = units_.begin(); i != units_.end(); ++i) {
|
||||
if(i->side() == side_num) {
|
||||
config& u = side.add_child("unit");
|
||||
i->get_location().write(u); // TODO: Needed?
|
||||
i->write(u);
|
||||
i->get_location().write(u);
|
||||
u["type"] = i->type_id();
|
||||
u["canrecruit"] = i->can_recruit();
|
||||
u["unrenamable"] = i->unrenamable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,6 +425,12 @@ config map_context::to_config()
|
|||
bool map_context::save_scenario()
|
||||
{
|
||||
assert(!is_embedded());
|
||||
|
||||
if (scenario_id_.empty())
|
||||
scenario_id_ = file_name(filename_);
|
||||
if (scenario_name_.empty())
|
||||
scenario_name_ = scenario_id_;
|
||||
|
||||
try {
|
||||
std::stringstream wml_stream;
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
* empty, indicating a new map.
|
||||
* Marked "explicit" to avoid automatic conversions.
|
||||
*/
|
||||
explicit map_context(const editor_map& map, const display& disp, bool pure_map);
|
||||
explicit map_context(const editor_map& map, const display& disp, bool pure_map, const config& schedule);
|
||||
|
||||
/**
|
||||
* Create map_context from a map file. If the map cannot be loaded, an
|
||||
|
@ -81,6 +81,7 @@ public:
|
|||
team t;
|
||||
t.set_hidden(false);
|
||||
teams_.push_back(t);
|
||||
actions_since_save_++;
|
||||
}
|
||||
|
||||
/** Get the team from the current map context object */
|
||||
|
@ -101,6 +102,10 @@ public:
|
|||
return units_;
|
||||
}
|
||||
|
||||
void replace_schedule(const std::vector<time_of_day>& schedule);
|
||||
|
||||
void set_starting_time(int time);
|
||||
|
||||
tod_manager* get_time_manager() {
|
||||
return tod_manager_.get();
|
||||
}
|
||||
|
@ -174,8 +179,10 @@ public:
|
|||
/**
|
||||
* TODO
|
||||
*/
|
||||
void set_side_setup(const std::string& /*id*/, const std::string& /*name*/,
|
||||
int gold, int income, int village_gold, int village_support , bool fog, bool share_view, bool shroud, bool share_maps);
|
||||
void set_side_setup(int side, const std::string& id, const std::string& name,
|
||||
int gold, int income, int village_gold, int village_support,
|
||||
bool fog, bool share_view, bool shroud, bool share_maps,
|
||||
team::CONTROLLER controller, bool hidden);
|
||||
|
||||
/**
|
||||
* Getter for the labels reset flag. Set when the labels need to be refreshed.
|
||||
|
@ -209,8 +216,8 @@ public:
|
|||
const std::string& get_map_data_key() const { return map_data_key_; }
|
||||
|
||||
const std::string& get_id() const { return scenario_id_; }
|
||||
const std::string& get_description() const { return scenario_id_; }
|
||||
const std::string& get_name() const { return scenario_id_; }
|
||||
const std::string& get_description() const { return scenario_description_; }
|
||||
const std::string& get_name() const { return scenario_name_; }
|
||||
|
||||
int get_xp_mod() const { return xp_mod_; }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue