editor2: context menu, starting location labels (defunct atm)

This commit is contained in:
Tomasz Śniatowski 2008-07-26 21:05:57 +01:00
parent a5c09d3e19
commit ba26373baf
10 changed files with 58 additions and 12 deletions

View file

@ -169,14 +169,9 @@
[menu]
id=menu-editor-selection
is_context_menu=true
items=editor-cut,editor-copy,editor-paste,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
items=menu-editor-starting-position,undo,redo,editor-cut,editor-copy,editor-paste,editor-selection-rotate,editor-selection-flip,editor-selection-generate,editor-selection-randomize
[/menu]
[menu]
is_context_menu=true
items=wml,undo,redo,describeunit,renameunit,createunit,changeside,labelteamterrain,labelterrain,clearlabels,speak,continue,recruit,recall,delayshroud,updateshroud,cycle,endturn
[/menu]
[mini_map]
id=mini-map
ref=top-right-panel

View file

@ -77,6 +77,9 @@ void controller_base::handle_event(const SDL_Event& event)
case SDL_MOUSEBUTTONUP:
get_mouse_handler_base().mouse_press(event.button, browse_);
post_mouse_press(event);
if (get_mouse_handler_base().get_show_menu()){
show_menu(get_display().get_theme().context_menu()->items(),event.button.x,event.button.y,true);
}
break;
case SDL_ACTIVEEVENT:
if (event.active.type == SDL_APPMOUSEFOCUS && event.active.gain == 0) {

View file

@ -30,6 +30,8 @@
#define ERR_ED LOG_STREAM_INDENT(err, editor)
#define SCOPE_ED log_scope2(editor, __FUNCTION__)
class display;
class gamemap;
namespace editor2 {

View file

@ -67,6 +67,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_SELECT, new mouse_action_select(*this)));
hotkey_set_mouse_action(hotkey::HOTKEY_EDITOR_TOOL_PAINT);
map_.set_starting_position_labels(gui());
cursor::set(cursor::NORMAL);
gui_->invalidate_game_status();
palette_->adjust_size();
@ -241,8 +242,10 @@ void editor_controller::new_map(int width, int height, t_translation::t_terrain
void editor_controller::set_map(const editor_map& map)
{
map_.clear_starting_position_labels(gui());
map_ = map;
gui().reload_map();
map_.set_starting_position_labels(gui());
refresh_all();
}
@ -363,6 +366,25 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
}
}
void editor_controller::expand_starting_position_menu(std::vector<std::string>& items)
{
for (unsigned int i = 0; i < items.size(); ++i) {
if (items[i] == "editor-STARTING-POSITION") {
items.erase(items.begin() + i);
std::vector<std::string> newitems;
std::vector<std::string> newsaves;
for (int player_i = 0; player_i < gamemap::MAX_PLAYERS; ++player_i) {
//TODO gettext format
std::string name = "Set starting position for player " + lexical_cast<std::string>(player_i);
newitems.push_back(name);
}
items.insert(items.begin()+i, newitems.begin(), newitems.end());
break;
}
}
}
void editor_controller::show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu)
{
std::vector<std::string> items = items_arg;
@ -385,6 +407,7 @@ void editor_controller::show_menu(const std::vector<std::string>& items_arg, int
}
++i;
}
expand_starting_position_menu(items);
controller_base::show_menu(items, xloc, yloc, context_menu);
}
@ -541,6 +564,4 @@ void editor_controller::left_drag_end(int x, int y, const bool browse)
}
}
} //end namespace editor2

View file

@ -62,6 +62,7 @@ class editor_controller : public controller_base,
bool can_execute_command(hotkey::HOTKEY_COMMAND, int index = -1) const;
hotkey::ACTION_STATE get_action_state(hotkey::HOTKEY_COMMAND command) const;
bool execute_command(hotkey::HOTKEY_COMMAND command, int index = -1);
void expand_starting_position_menu(std::vector<std::string>& items);
void show_menu(const std::vector<std::string>& items_arg, int xloc, int yloc, bool context_menu);
void cycle_brush();
void preferences();

View file

@ -15,8 +15,10 @@
#include "action_base.hpp"
#include "editor_map.hpp"
#include "../display.hpp"
#include "../filesystem.hpp"
#include "../foreach.hpp"
#include "../gettext.hpp"
#include "../pathutils.hpp"
#include <cassert>
@ -68,6 +70,26 @@ std::set<gamemap::location> editor_map::get_contigious_terrain_tiles(const gamem
return result;
}
void editor_map::clear_starting_position_labels(display& disp) const
{
foreach (const gamemap::location& loc, startingPositions_) {
if (loc.valid()) {
disp.labels().set_label(loc, "");
}
}
}
void editor_map::set_starting_position_labels(display& disp) const
{
std::string label = _("Player");
label += " ";
for (int i = 1; i <= gamemap::MAX_PLAYERS; i++) {
if (startingPositions_[i].valid()) {
disp.labels().set_label(startingPositions_[i], label + lexical_cast<std::string>(i));
}
}
}
bool editor_map::save()
{
std::string data = write();

View file

@ -44,6 +44,10 @@ public:
*/
std::set<gamemap::location> get_contigious_terrain_tiles(const gamemap::location& start) const;
void clear_starting_position_labels(display& disp) const;
void set_starting_position_labels(display& disp) const;
/**
* @return true when the location is part of the selection, false otherwise
*/

View file

@ -45,7 +45,6 @@ public:
const gamemap::location& get_last_hex() const { return last_hex_; }
gamemap::location get_selected_hex() const { return selected_hex_; }
bool get_undo() const { return undo_; }
bool get_show_menu() const { return show_menu_; }
void set_path_turns(const int path_turns) { path_turns_ = path_turns; }
void set_current_paths(paths new_paths);
void set_selected_hex(gamemap::location hex) { selected_hex_ = hex; }

View file

@ -51,6 +51,8 @@ public:
bool is_dragging() { return dragging_; }
bool get_show_menu() const { return show_menu_; }
/**
* This handles minimap scrolling and click-drag.
* @returns true when the caller should not process the mouse motion

View file

@ -730,9 +730,6 @@ void play_controller::post_mouse_press(const SDL_Event& event) {
mouse_handler_.set_undo(false);
menu_handler_.undo(player_number_);
}
if (mouse_handler_.get_show_menu()){
show_menu(gui_->get_theme().context_menu()->items(),event.button.x,event.button.y,true);
}
}
static void trim_items(std::vector<std::string>& newitems) {