Author: fendrin
Date: Sat Mar 12 08:22:52 2011
New Revision: 48857
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48857&view=rev
Log:
Enabled the drawing of village ownership flags in the editor.
Modified:
branches/editor/src/display.cpp
branches/editor/src/display.hpp
branches/editor/src/editor/action.cpp
branches/editor/src/editor/editor_controller.cpp
branches/editor/src/editor/editor_display.cpp
branches/editor/src/editor/editor_display.hpp
branches/editor/src/editor/mouse_action.cpp
branches/editor/src/game_display.cpp
branches/editor/src/game_display.hpp
branches/editor/src/game_events.cpp
Modified: branches/editor/src/display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/display.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/display.cpp (original)
+++ branches/editor/src/display.cpp Sat Mar 12 08:22:52 2011
@@ -1951,6 +1951,29 @@
redraw_observers_.clear();
}
+surface display::get_flag(const map_location& loc)
+{
+ t_translation::t_terrain terrain = get_map().get_terrain(loc);
+
+ if(!get_map().is_village(terrain)) {
+ return surface(NULL);
+ }
+
+ for(size_t i = 0; i != get_teams().size(); ++i) {
+ if(get_teams()[i].owns_village(loc) &&
+ (!fogged(loc) || !get_teams()[playing_team()].is_enemy(i+1)))
+ {
+ flags_[i].update_last_draw_time();
+ const image::locator &image_flag = animate_map_ ?
+ flags_[i].get_current_frame() :
flags_[i].get_first_frame();
+ return image::get_image(image_flag, image::TOD_COLORED);
+ }
+ }
+
+ return surface(NULL);
+}
+
+
void display::draw(bool update,bool force) {
// log_scope("display::draw");
if (screen_.update_locked()) {
@@ -2043,6 +2066,7 @@
invalidated_hexes_ += invalidated_.size();
}
+
void display::draw_hex(const map_location& loc) {
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);
@@ -2055,10 +2079,13 @@
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
get_terrain_images(loc,tod.id, image_type, BACKGROUND));
- drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
+ drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
get_terrain_images(loc,tod.id,image_type, FOREGROUND));
- // Draw the grid, if that's been enabled
+ // village-control flags.
+ drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
get_flag(loc));
+
+ // Draw the grid, if that's been enabled
if(grid_ && on_map && !off_map_tile) {
static const image::locator
grid_top(game_config::images::grid_top);
drawing_buffer_add(LAYER_GRID_TOP, loc, xpos, ypos,
@@ -2066,6 +2093,21 @@
static const image::locator
grid_bottom(game_config::images::grid_bottom);
drawing_buffer_add(LAYER_GRID_BOTTOM, loc, xpos, ypos,
image::get_image(grid_bottom,
image::TOD_COLORED));
+
+ //TODO enable for drawing [item]s
+ /*
+ typedef overlay_map::const_iterator Itor;
+ std::pair<Itor,Itor> overlays =
overlays_.equal_range(loc);
+ for( ; overlays.first != overlays.second;
++overlays.first) {
+ if ((overlays.first->second.team_name == "" ||
+
overlays.first->second.team_name.find(teams_[playing_team()].team_name()) !=
std::string::npos)
+ && !(is_fogged &&
!overlays.first->second.visible_in_fog))
+ {
+ drawing_buffer_add(LAYER_TERRAIN_BG,
loc, xpos, ypos,
+
image::get_image(overlays.first->second.image,image_type));
+ }
+ }
+ */
}
}
@@ -2497,6 +2539,18 @@
}
}
+//TODO sort to the right location
+void display::invalidate_animations_location(const map_location& loc) {
+ if (get_map().is_village(loc)) {
+ const int owner = player_teams::village_owner(loc);
+ if (owner >= 0 && flags_[owner].need_update()
+ && (!fogged(loc) ||
!get_teams()[playing_team()].is_enemy(owner+1))) {
+ invalidate(loc);
+ }
+ }
+}
+
+
void display::add_arrow(arrow& arrow)
{
const arrow_path_t & arrow_path = arrow.get_path();
Modified: branches/editor/src/display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/display.hpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/display.hpp (original)
+++ branches/editor/src/display.hpp Sat Mar 12 08:22:52 2011
@@ -295,11 +295,14 @@
*/
virtual void invalidate_animations();
+ virtual size_t playing_team() const = 0 ;
+
+
/**
* Per-location invalidation called by invalidate_animations()
* defaults to no action, overridden by derived classes
*/
- virtual void invalidate_animations_location(const map_location&
/*loc*/) {}
+ virtual void invalidate_animations_location(const map_location&
/*loc*/);
const gamemap& get_map() const { return *map_; }
@@ -848,6 +851,8 @@
//TODO move to the right place
/** Animated flags for each team */
std::vector<animated<image::locator> > flags_;
+private:
+ surface get_flag(const map_location& loc);
};
#endif
Modified: branches/editor/src/editor/action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/editor/action.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/editor/action.cpp (original)
+++ branches/editor/src/editor/action.cpp Sat Mar 12 08:22:52 2011
@@ -423,6 +423,9 @@
for(std::vector<team>::iterator i = teams.begin(); i != teams.end();
++i) {
i->lose_village(loc_);
}
+ //TODO remove debug output
+ //ERR_ED << teams[0].to_config().debug();
+ ERR_ED << side_number_;
teams[side_number_].get_village(loc_);
}
Modified: branches/editor/src/editor/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/editor/editor_controller.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/editor/editor_controller.cpp (original)
+++ branches/editor/src/editor/editor_controller.cpp Sat Mar 12 08:22:52 2011
@@ -146,6 +146,7 @@
show_menu(default_tool_menu->items(),menu_loc.x+1,menu_loc.y +
menu_loc.h + 1,false);
return;
}
+
}
void editor_controller::init_gui(CVideo& video)
@@ -388,11 +389,23 @@
current_side_index_ = 0;
current_area_index_ = 0;
map_context_refresher mcr(*this, *map_contexts_[index]);
+
+ resources::game_map = &get_map();
+ resources::units = &get_map().get_units();
+// resources::units = &units_;
+ //resources::teams = &teams_;
+ resources::teams = &get_map().get_teams();
+ //resources::state_of_game = &gamestate_;
+ //resources::controller = this;
+ //resources::tod_manager = &tod_manager_;
+ //resources::undo_stack = &undo_stack_;
+ //resources::redo_stack = &redo_stack_;
+ //resources::persist = &persist_;
}
void editor_controller::switch_area(const int index)
{
- //TODO implement undo
+ //TODO think about implementing undo
const map_areas areas = get_map().get_named_areas();
const std::vector<std::string> ids = areas.get_area_ids();
current_area_index_ = index;
@@ -411,7 +424,7 @@
}
//TODO
//get_display().set_team(index , false);
- //get_display().set_playing_team(index );
+ get_display().set_playing_team(index);
current_side_index_ = index;
}
@@ -420,6 +433,17 @@
boost::scoped_ptr<map_context>
del(map_contexts_[current_context_index_]);
map_context_refresher mcr(*this, *new_mc);
map_contexts_[current_context_index_] = new_mc;
+ resources::game_map = &get_map();
+ resources::units = &get_map().get_units();
+ resources::teams = &get_map().get_teams();
+ //resources::units = &units_;
+ //resources::teams = &teams_;
+ //resources::state_of_game = &gamestate_;
+ //resources::controller = this;
+ //resources::tod_manager = &tod_manager_;
+ //resources::undo_stack = &undo_stack_;
+ //resources::redo_stack = &redo_stack_;
+ //resources::persist = &persist_;
}
void editor_controller::editor_settings_dialog()
Modified: branches/editor/src/editor/editor_display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/editor/editor_display.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/editor/editor_display.cpp (original)
+++ branches/editor/src/editor/editor_display.cpp Sat Mar 12 08:22:52 2011
@@ -24,6 +24,7 @@
: display(video, &map, theme_cfg, level)
, brush_locations_()
, toolbar_hint_()
+ , activeTeam_(0)
{
//TODO this gives an undefined reference, no idea why.
//singleton_ = this;
@@ -75,6 +76,8 @@
void editor_display::draw_hex(const map_location& loc)
{
+ //TODO do we need to call the super class method explicitly?
+ display::draw_hex(loc);
int xpos = get_location_x(loc);
int ypos = get_location_y(loc);
display::draw_hex(loc);
@@ -108,10 +111,40 @@
text = str_cast(mouseoverHex_);
refresh_report("position", element);
}
- text = int(get_map().villages().size());
+
+ if (playing_team() == 0)
+ text = int(get_map().villages().size());
+ else {
+ std::ostringstream village_report;
+ //TODO look how it is done in game_display and port that code
to display
+ village_report <<
lexical_cast<std::string>(map().get_teams()[playing_team()
-1].villages().size())
+ << "/" <<
lexical_cast<std::string>(get_map().villages().size());
+ text = village_report.str();
+ }
refresh_report("villages", element);
text = toolbar_hint_;
refresh_report("editor_tool_hint", element);
+
+ //TODO port to new system
+//
+// refresh_report(reports::VILLAGES,
reports::report(village_report.str()));
+//
+// std::ostringstream unit_report;
+//
+// unit_report << lexical_cast<std::string>(side_units(map().get_units(),
viewing_side()))
+// << "/" << lexical_cast<std::string>(map().get_units().size());
+//
+////TODO cleanup.
+//// case NUM_UNITS: {
+//// if (current_side != playing_side)
+//// str << span_color(font::GRAY_COLOUR);
+//// str << side_units(units, current_side);
+//// if (current_side != playing_side)
+//// str << naps;
+//// break;
+// refresh_report(reports::NUM_UNITS, reports::report(unit_report.str()));
+// refresh_report(reports::EDITOR_TOOL_HINT,
reports::report(toolbar_hint_));
+
}
} //end namespace editor
Modified: branches/editor/src/editor/editor_display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/editor/editor_display.hpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/editor/editor_display.hpp (original)
+++ branches/editor/src/editor/editor_display.hpp Sat Mar 12 08:22:52 2011
@@ -40,6 +40,12 @@
/* Inherited from display*/
const std::vector<team>& get_teams() { return map().get_teams(); }
+ void set_playing_team(size_t team) { activeTeam_ = team; }
+
+ /** The playing team is the team active for editing. */
+ size_t playing_team() const { return activeTeam_; }
+ //int playing_side() const { return activeTeam_ + 1; }
+
protected:
void pre_draw();
/**
@@ -47,6 +53,7 @@
*/
image::TYPE get_image_type(const map_location& loc);
+ /* Inherited from display */
void draw_hex(const map_location& loc);
const SDL_Rect& get_clip_rect();
@@ -55,8 +62,11 @@
std::set<map_location> brush_locations_;
std::string toolbar_hint_;
- //TODO that is copied game_display.hpp find a use for it
+ //TODO that is copied from game_display.hpp find a use for it
static editor_display *singleton_;
+
+private:
+ size_t activeTeam_;
};
} //end namespace editor
Modified: branches/editor/src/editor/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/editor/mouse_action.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/editor/mouse_action.cpp (original)
+++ branches/editor/src/editor/mouse_action.cpp Sat Mar 12 08:22:52 2011
@@ -429,8 +429,8 @@
editor_action* mouse_action_village::up_left(editor_display& disp, int x, int
y)
{
map_location hex = disp.hex_clicked_on(x, y);
- //TODO enable
-// return new editor_action_village(hex, disp.playing_team());
+
+ return new editor_action_village(hex, disp.playing_team());
return NULL;
}
Modified: branches/editor/src/game_display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/game_display.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/game_display.cpp (original)
+++ branches/editor/src/game_display.cpp Sat Mar 12 08:22:52 2011
@@ -82,58 +82,61 @@
reach_map_(),
reach_map_old_(),
reach_map_changed_(true),
- game_mode_(RUNNING),
- flags_()
+ game_mode_(RUNNING)
+//TODO
+ //flags_()
{
singleton_ = this;
- // Inits the flag list and the team colors used by ~TC
- flags_.reserve(teams_.size());
-
- std::vector<std::string> side_colors;
- side_colors.reserve(teams_.size());
-
- for(size_t i = 0; i != teams_.size(); ++i) {
- std::string side_color = team::get_side_color_index(i+1);
- side_colors.push_back(side_color);
- std::string flag = teams_[i].flag();
- std::string old_rgb = game_config::flag_rgb;
- std::string new_rgb = side_color;
-
- if(flag.empty()) {
- flag = game_config::images::flag;
- }
-
- LOG_DP << "Adding flag for team " << i << " from animation " <<
flag << "\n";
-
- // Must recolor flag image
- animated<image::locator> temp_anim;
-
- std::vector<std::string> items = utils::split(flag);
- std::vector<std::string>::const_iterator itor = items.begin();
- for(; itor != items.end(); ++itor) {
- const std::vector<std::string>& items =
utils::split(*itor, ':');
- std::string str;
- int time;
-
- if(items.size() > 1) {
- str = items.front();
- time = atoi(items.back().c_str());
- } else {
- str = *itor;
- time = 100;
- }
- std::stringstream temp;
- temp << str << "~RC(" << old_rgb << ">"<< new_rgb <<
")";
- image::locator flag_image(temp.str());
- temp_anim.add_frame(time, flag_image);
- }
- flags_.push_back(temp_anim);
-
-
flags_.back().start_animation(rand()%flags_.back().get_end_time(), true);
- }
- image::set_team_colors(&side_colors);
- clear_screen();
+ load_flags();
+
+// // Inits the flag list and the team colors used by ~TC
+// flags_.reserve(teams_.size());
+//
+// std::vector<std::string> side_colors;
+// side_colors.reserve(teams_.size());
+//
+// for(size_t i = 0; i != teams_.size(); ++i) {
+// std::string side_color = team::get_side_color_index(i+1);
+// side_colors.push_back(side_color);
+// std::string flag = teams_[i].flag();
+// std::string old_rgb = game_config::flag_rgb;
+// std::string new_rgb = side_color;
+//
+// if(flag.empty()) {
+// flag = game_config::images::flag;
+// }
+//
+// LOG_DP << "Adding flag for team " << i << " from animation " <<
flag << "\n";
+//
+// // Must recolor flag image
+// animated<image::locator> temp_anim;
+//
+// std::vector<std::string> items = utils::split(flag);
+// std::vector<std::string>::const_iterator itor = items.begin();
+// for(; itor != items.end(); ++itor) {
+// const std::vector<std::string>& items =
utils::split(*itor, ':');
+// std::string str;
+// int time;
+//
+// if(items.size() > 1) {
+// str = items.front();
+// time = atoi(items.back().c_str());
+// } else {
+// str = *itor;
+// time = 100;
+// }
+// std::stringstream temp;
+// temp << str << "~RC(" << old_rgb << ">"<< new_rgb <<
")";
+// image::locator flag_image(temp.str());
+// temp_anim.add_frame(time, flag_image);
+// }
+// flags_.push_back(temp_anim);
+//
+//
flags_.back().start_animation(rand()%flags_.back().get_end_time(), true);
+// }
+// image::set_team_colors(&side_colors);
+// clear_screen();
}
game_display* game_display::create_dummy_display(CVideo& video)
@@ -529,6 +532,7 @@
height = bar_loc.h;
}
+ //TODO old stuff from before the editor branch: comment or remove
//if(alpha != ftofxp(1.0)) {
// surf.assign(adjust_surface_alpha(surf,alpha));
// if(surf == NULL) {
@@ -886,15 +890,15 @@
return calculate_energy_bar(surf);
}
-void game_display::invalidate_animations_location(const map_location& loc) {
- if (get_map().is_village(loc)) {
- const int owner = player_teams::village_owner(loc);
- if (owner >= 0 && flags_[owner].need_update()
- && (!fogged(loc) || !teams_[currentTeam_].is_enemy(owner+1))) {
- invalidate(loc);
- }
- }
-}
+//void game_display::invalidate_animations_location(const map_location& loc) {
+// if (get_map().is_village(loc)) {
+// const int owner = player_teams::village_owner(loc);
+// if (owner >= 0 && flags_[owner].need_update()
+// && (!fogged(loc) || !teams_[currentTeam_].is_enemy(owner+1))) {
+// invalidate(loc);
+// }
+// }
+//}
void game_display::invalidate_animations()
{
Modified: branches/editor/src/game_display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/game_display.hpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/game_display.hpp (original)
+++ branches/editor/src/game_display.hpp Sat Mar 12 08:22:52 2011
@@ -167,7 +167,7 @@
/**
* Extra game per-location invalidation (village ownership)
*/
- void invalidate_animations_location(const map_location& loc);
+// void invalidate_animations_location(const map_location& loc);
virtual void draw_minimap_units();
@@ -274,6 +274,7 @@
int viewing_side() const { return currentTeam_ + 1; }
/** The playing team is the team whose turn it is. */
+ //TODO this is bullshit
size_t playing_team() const { return activeTeam_; }
int playing_side() const { return activeTeam_ + 1; }
@@ -403,7 +404,7 @@
static std::map<map_location, int> debugHighlights_;
/** Animated flags for each team */
- std::vector<animated<image::locator> > flags_;
+ //std::vector<animated<image::locator> > flags_;
static game_display * singleton_;
};
Modified: branches/editor/src/game_events.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/branches/editor/src/game_events.cpp?rev=48857&r1=48856&r2=48857&view=diff
==============================================================================
--- branches/editor/src/game_events.cpp (original)
+++ branches/editor/src/game_events.cpp Sat Mar 12 08:22:52 2011
@@ -3179,7 +3179,8 @@
const entity_location& loc2,
const config& data)
{
- assert(manager_running);
+ //TODO
+ //assert(manager_running);
if(!events_init())
return;
@@ -3193,7 +3194,8 @@
const entity_location& loc2,
const config& data)
{
- assert(manager_running);
+ if (!manager_running) return true;
+ //assert(manager_running);
raise(event,loc1,loc2,data);
return pump();
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits