Enabled the side menu in the editor.
It allows side creation and switching for now.
This commit is contained in:
parent
f23e15aa25
commit
6da230921a
9 changed files with 126 additions and 8 deletions
|
@ -37,6 +37,7 @@
|
|||
#include "arrow.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "whiteboard/manager.hpp"
|
||||
|
||||
#include "SDL_image.h"
|
||||
|
||||
|
@ -182,6 +183,31 @@ struct is_energy_color {
|
|||
(color&0x000000FF) < 0x00000010; }
|
||||
};
|
||||
|
||||
void display::set_team(size_t teamindex, bool show_everything)
|
||||
{
|
||||
assert(teamindex < teams_->size());
|
||||
currentTeam_ = teamindex;
|
||||
if (!show_everything)
|
||||
{
|
||||
labels().set_team(&(*teams_)[teamindex]);
|
||||
viewpoint_ = &(*teams_)[teamindex];
|
||||
}
|
||||
else
|
||||
{
|
||||
labels().set_team(NULL);
|
||||
viewpoint_ = NULL;
|
||||
}
|
||||
labels().recalculate_labels();
|
||||
if(resources::whiteboard)
|
||||
resources::whiteboard->on_viewer_change(teamindex);
|
||||
}
|
||||
|
||||
void display::set_playing_team(size_t teamindex)
|
||||
{
|
||||
assert(teamindex < teams_->size());
|
||||
activeTeam_ = teamindex;
|
||||
invalidate_game_status();
|
||||
}
|
||||
|
||||
const SDL_Rect& display::calculate_energy_bar(surface surf)
|
||||
{
|
||||
|
|
|
@ -63,8 +63,6 @@ public:
|
|||
virtual ~display();
|
||||
static display* get_singleton() { return singleton_ ;}
|
||||
|
||||
//TODO sort
|
||||
|
||||
bool show_everything() const { return !viewpoint_; }
|
||||
|
||||
const std::vector<team>& get_teams() {return *teams_;}
|
||||
|
@ -78,6 +76,18 @@ public:
|
|||
size_t viewing_team() const { return currentTeam_; }
|
||||
int viewing_side() const { return currentTeam_ + 1; }
|
||||
|
||||
/**
|
||||
* Sets the team controlled by the player using the computer.
|
||||
* Data from this team will be displayed in the game status.
|
||||
*/
|
||||
void set_team(size_t team, bool observe=false);
|
||||
|
||||
/**
|
||||
* set_playing_team sets the team whose turn it currently is
|
||||
*/
|
||||
void set_playing_team(size_t team);
|
||||
|
||||
|
||||
/**
|
||||
* Cancels all the exclusive draw requests.
|
||||
*/
|
||||
|
|
|
@ -102,6 +102,12 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
|
||||
void editor_controller::init_gui()
|
||||
{
|
||||
//TODO duplicate code, see the map_context_refresher
|
||||
resources::game_map = &context_manager_->get_map();
|
||||
resources::units = &context_manager_->get_map().get_units();
|
||||
resources::tod_manager = &context_manager_->get_map().get_time_manager();
|
||||
resources::teams = &context_manager_->get_map().get_teams();
|
||||
|
||||
gui_->change_map(&context_manager_->get_map());
|
||||
gui_->change_units(&context_manager_->get_map().get_units());
|
||||
gui_->change_teams(&context_manager_->get_map().get_teams());
|
||||
|
@ -262,6 +268,8 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
|
|||
case HOTKEY_EDITOR_QUIT_TO_DESKTOP:
|
||||
case HOTKEY_EDITOR_SETTINGS:
|
||||
case HOTKEY_EDITOR_MAP_NEW:
|
||||
case HOTKEY_EDITOR_SIDE_NEW:
|
||||
case HOTKEY_EDITOR_SIDE_SWITCH:
|
||||
case HOTKEY_EDITOR_MAP_LOAD:
|
||||
case HOTKEY_EDITOR_MAP_SAVE_AS:
|
||||
case HOTKEY_EDITOR_BRUSH_NEXT:
|
||||
|
@ -344,7 +352,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
|
|||
return ACTION_STATELESS;
|
||||
case editor::AREA:
|
||||
case editor::SIDE:
|
||||
return ACTION_ON;
|
||||
return (size_t)index == gui_->playing_team() ? ACTION_ON : ACTION_OFF;
|
||||
}
|
||||
return ACTION_ON;
|
||||
default:
|
||||
|
@ -372,7 +380,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
toolkit_->get_palette_manager()->set_group(index);
|
||||
return true;
|
||||
case SIDE:
|
||||
//TODO
|
||||
gui_->set_team(index, true);
|
||||
gui_->set_playing_team(index);
|
||||
return true;
|
||||
case AREA:
|
||||
//TODO
|
||||
return true;
|
||||
|
@ -463,7 +473,6 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
context_manager_->perform_refresh(editor_action_select_none());
|
||||
return true;
|
||||
case HOTKEY_EDITOR_SELECTION_FILL:
|
||||
//TODO
|
||||
context_manager_->fill_selection();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_SELECTION_RANDOMIZE:
|
||||
|
@ -482,6 +491,9 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
case HOTKEY_EDITOR_MAP_NEW:
|
||||
context_manager_->new_map_dialog();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_SIDE_NEW:
|
||||
context_manager_->get_map().new_side();
|
||||
return true;
|
||||
case HOTKEY_EDITOR_MAP_SAVE:
|
||||
save_map();
|
||||
return true;
|
||||
|
@ -531,8 +543,6 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void editor_controller::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu)
|
||||
{
|
||||
if (context_menu) {
|
||||
|
@ -577,6 +587,12 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
|
|||
toolkit_->get_palette_manager()->active_palette().expand_palette_groups_menu(items);
|
||||
context_menu = true; //FIXME hack to display a one-item menu
|
||||
}
|
||||
if (!items.empty() && items.front() == "editor-side-switch") {
|
||||
active_menu_ = editor::SIDE;
|
||||
context_manager_->expand_sides_menu(items);
|
||||
context_menu = true; //FIXME hack to display a one-item menu
|
||||
}
|
||||
|
||||
command_executor::show_menu(items, xloc, yloc, context_menu, gui());
|
||||
}
|
||||
|
||||
|
|
|
@ -203,6 +203,27 @@ void context_manager::expand_open_maps_menu(std::vector<std::string>& items)
|
|||
}
|
||||
}
|
||||
|
||||
void context_manager::expand_sides_menu(std::vector<std::string>& items)
|
||||
{
|
||||
for (unsigned int i = 0; i < items.size(); ++i) {
|
||||
if (items[i] == "editor-side-switch") {
|
||||
items.erase(items.begin() + i);
|
||||
std::vector<std::string> contexts;
|
||||
for (size_t mci = 0; mci < get_map().get_teams().size(); ++mci) {
|
||||
std::string name = get_map().get_teams()[mci].name();
|
||||
if (name.empty()) {
|
||||
name = _("(New Side)");
|
||||
}
|
||||
std::string label = "[" + lexical_cast<std::string>(mci) + "] "
|
||||
+ name;
|
||||
contexts.push_back(label);
|
||||
}
|
||||
items.insert(items.begin() + i, contexts.begin(), contexts.end());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void context_manager::apply_mask_dialog()
|
||||
{
|
||||
std::string fn = get_map_context().get_filename();
|
||||
|
|
|
@ -111,6 +111,9 @@ public:
|
|||
/** Menu expanding for open maps list */
|
||||
void expand_open_maps_menu(std::vector<std::string>& items);
|
||||
|
||||
/** Menu expanding for the map's player sides */
|
||||
void expand_sides_menu(std::vector<std::string>& items);
|
||||
|
||||
/** Display a load map dialog and process user input. */
|
||||
void load_map_dialog(bool force_same_context = false);
|
||||
|
||||
|
|
|
@ -63,12 +63,14 @@ editor_map::editor_map(const config& terrain_cfg, const config& level, const dis
|
|||
{
|
||||
labels_.read(level);
|
||||
|
||||
resources::teams = &teams_;
|
||||
|
||||
BOOST_FOREACH(const config& side, level.child_range("side"))
|
||||
{
|
||||
team t;
|
||||
t.build(side, *this, 100);
|
||||
//this is done because we don't count as observer is there is a human controller
|
||||
t.change_controller("null");
|
||||
//t.change_controller("null");
|
||||
//TODO alternative? : gamestatus::teambuilder
|
||||
|
||||
teams_.push_back(t);
|
||||
|
@ -447,6 +449,37 @@ void editor_map::write(config& cfg) const {
|
|||
config& map = cfg.add_child("map");
|
||||
gamemap::write(map);
|
||||
labels_.write(cfg);
|
||||
|
||||
std::stringstream buf;
|
||||
|
||||
for(std::vector<team>::const_iterator t = teams_.begin(); t != teams_.end(); ++t) {
|
||||
int side_num = t - teams_.begin() + 1;
|
||||
|
||||
config& side = cfg.add_child("side");
|
||||
t->write(side);
|
||||
// TODO make this customizable via gui
|
||||
side["no_leader"] = "no";
|
||||
side["allow_player"] = "yes";
|
||||
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");
|
||||
buf.str(std::string());
|
||||
buf << side_num;
|
||||
side["side"] = buf.str();
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} //end namespace editor
|
||||
|
|
|
@ -76,6 +76,11 @@ class editor_map : public gamemap
|
|||
{
|
||||
public:
|
||||
|
||||
/** Adds a new side to the map */
|
||||
void new_side() {
|
||||
teams_.push_back(team());
|
||||
}
|
||||
|
||||
/** Get the team from the current map context object */
|
||||
std::vector<team>& get_teams() {
|
||||
return teams_;
|
||||
|
|
|
@ -138,6 +138,8 @@ const struct {
|
|||
{ hotkey::HOTKEY_EDITOR_MAP_SAVE_ALL, "editor-map-save-all", N_("Save All Maps"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_REVERT, "editor-map-revert", N_("Revert All Changes"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_MAP_INFO, "editor-map-info", N_("Map Information"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_SIDE_NEW, "editor-side-new", N_("Add new Side"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_SIDE_SWITCH, "editor-side-switch", N_("Switch Side"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_PALETTE_ITEM_SWAP, "editor-terrain-palette-swap",
|
||||
N_("Swap Foreground/Background Terrains"), false, hotkey::SCOPE_EDITOR },
|
||||
{ hotkey::HOTKEY_EDITOR_PALETTE_GROUPS, "editor-palette-groups", N_("Change Palette Group"), false, hotkey::SCOPE_EDITOR },
|
||||
|
|
|
@ -71,6 +71,7 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_WB_BUMP_DOWN_ACTION,
|
||||
HOTKEY_WB_SUPPOSE_DEAD,
|
||||
|
||||
// Editor commands
|
||||
HOTKEY_EDITOR_QUIT_TO_DESKTOP,
|
||||
HOTKEY_EDITOR_CLOSE_MAP, HOTKEY_EDITOR_SWITCH_MAP,
|
||||
HOTKEY_EDITOR_SETTINGS,
|
||||
|
@ -101,6 +102,7 @@ enum HOTKEY_COMMAND {
|
|||
HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS,
|
||||
HOTKEY_EDITOR_REFRESH_IMAGE_CACHE,
|
||||
HOTKEY_EDITOR_DRAW_COORDINATES, HOTKEY_EDITOR_DRAW_TERRAIN_CODES,
|
||||
HOTKEY_EDITOR_SIDE_NEW, HOTKEY_EDITOR_SIDE_SWITCH,
|
||||
|
||||
//misc.
|
||||
HOTKEY_USER_CMD,
|
||||
|
|
Loading…
Add table
Reference in a new issue