Implemented the editor item tool.

This commit is contained in:
fendrin 2013-05-22 08:51:01 +02:00
parent e40af6407e
commit db9a469310
22 changed files with 1110 additions and 99 deletions

View file

@ -12,6 +12,7 @@
{core/editor/terrain-groups.cfg}
{core/editor/time-of-day.cfg}
{core/editor/tool-hints.cfg}
{core/editor/items.cfg}
#endif

138
data/core/editor/items.cfg Normal file
View file

@ -0,0 +1,138 @@
[item_group]
id=items
icon=items/box.png
name= _ "Items"
[item]
id=altar_evil
image=items/altar-evil.png
name= _ "Evil Altar"
[/item]
[item]
id=altar
image=items/altar.png
name= _ "Altar"
[/item]
[item]
id=anvil
image=items/anvil.png
name= _ "Anvil"
[/item]
[item]
id=cage
image=items/cage.png
name= _ "Cage"
[/item]
[item]
id=box
image=items/box.png
name= _ "Box"
[/item]
[item]
id=axe
image=items/axe.png
name= _ "Axe"
[/item]
[item]
id=bomb
image=items/bomb.png
name= _ "Bomb"
[/item]
[item]
id=bones
image=items/bones.png
name= _ "Bones"
[/item]
[item]
id=bow
image=items/bow.png
name= _ "Bow"
[/item]
[item]
id=bow-elven
image=items/bow-elven.png
name= _ "Elven Bow"
[/item]
[item]
id=bow-crystal
image=items/bow-crystal.png
name= _ "Crystal Bow"
[/item]
[item]
id=archery-target
image=items/archery-target-right.png
name= _ "Archery Target"
[/item]
[item]
id=armor
image=items/armor.png
name= _ "Armor"
[/item]
[item]
id=key
image=items/key.png
name= _ "Key"
[/item]
[item]
id=sword
image=items/sword.png
name= _ "Sword"
[/item]
[item]
id=chest
image=items/chest.png
name= _ "Chest"
[/item]
[item]
id=buckler
image=items/buckler.png
name= _ "Buckler"
[/item]
[/item_group]
[item_group]
id=scenery
name= _ "Scenery"
[item]
id=signpost
name= _ "Signpost"
image=scenery/signpost.png
[/item]
[item]
id=whirlpool
name= _ "Whirlpool"
image=scenery/whirlpool.png
[/item]
[item]
id=well
name= _ "Well"
image=scenery/well.png
[/item]
[item]
id=lighthouse
name= _ "Lighthouse"
image=scenery/lighthouse.png
[/item]
[/item_group]

View file

@ -225,10 +225,12 @@ wesnoth_sources = Split("""
editor/action/action_unit.cpp
editor/action/action_label.cpp
editor/action/action_village.cpp
editor/action/action_item.cpp
editor/action/mouse/mouse_action.cpp
editor/action/mouse/mouse_action_map_label.cpp
editor/action/mouse/mouse_action_unit.cpp
editor/action/mouse/mouse_action_village.cpp
editor/action/mouse/mouse_action_item.cpp
editor/map/editor_map.cpp
editor/map/map_context.cpp
editor/map/map_fragment.cpp
@ -237,6 +239,7 @@ wesnoth_sources = Split("""
editor/palette/terrain_palettes.cpp
editor/palette/tristate_button.cpp
editor/palette/unit_palette.cpp
editor/palette/item_palette.cpp
editor/palette/palette_manager.cpp
editor/editor_controller.cpp
editor/editor_display.cpp

View file

@ -38,6 +38,7 @@
#include "tod_manager.hpp"
#include "resources.hpp"
#include "whiteboard/manager.hpp"
#include "overlay.hpp"
#include "SDL_image.h"
@ -75,6 +76,50 @@ namespace {
int display::last_zoom_ = SmallZoom;
void display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo,const std::string& team_name, bool visible_under_fog)
{
const int halo_handle = halo::add(get_location_x(loc) + hex_size() / 2,
get_location_y(loc) + hex_size() / 2, halo, loc);
const overlay item(img, halo, halo_handle, team_name, visible_under_fog);
overlays_.insert(overlay_map::value_type(loc,item));
}
void display::remove_overlay(const map_location& loc)
{
typedef overlay_map::const_iterator Itor;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
while(itors.first != itors.second) {
halo::remove(itors.first->second.halo_handle);
++itors.first;
}
overlays_.erase(loc);
}
void display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
{
//Iterate through the values with key of loc
typedef overlay_map::iterator Itor;
overlay_map::iterator iteratorCopy;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
while(itors.first != itors.second) {
//If image or halo of overlay struct matches toDelete, remove the overlay
if(itors.first->second.image == toDelete || itors.first->second.halo == toDelete) {
iteratorCopy = itors.first;
++itors.first;
halo::remove(iteratorCopy->second.halo_handle);
overlays_.erase(iteratorCopy);
}
else {
++itors.first;
}
}
}
display::display(unit_map* units, CVideo& video, const gamemap* map, const std::vector<team>* t,const config& theme_cfg, const config& level) :
units_(units),
exclusive_unit_draw_requests_(),
@ -2449,6 +2494,20 @@ void display::draw_hex(const map_location& loc) {
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos, get_flag(loc));
}
if(!shrouded(loc)) {
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)
&& !(fogged(loc) && !overlays.first->second.visible_in_fog))
{
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
image::get_image(overlays.first->second.image,image_type));
}
}
}
// Draw the time-of-day mask on top of the terrain in the hex.
// tod may differ from tod if hex is illuminated.
const std::string& tod_hex_mask = tod.image_mask;

View file

@ -48,10 +48,13 @@ class arrow;
#include "widgets/button.hpp"
#include "widgets/slider.hpp"
#include "overlay.hpp"
#include <list>
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <map>
class gamemap;
@ -115,6 +118,21 @@ public:
const SDL_Color& col, fixed_t alpha);
/**
* Functions to add and remove overlays from locations.
*
* An overlay is an image that is displayed on top of the tile.
* One tile may have multiple overlays.
*/
void add_overlay(const map_location& loc, const std::string& image,
const std::string& halo="", const std::string& team_name="",
bool visible_under_fog = true);
/** remove_overlay will remove all overlays on a tile. */
void remove_overlay(const map_location& loc);
/** remove_single_overlay will remove a single overlay from a tile */
void remove_single_overlay(const map_location& loc, const std::string& toDelete);
@ -978,6 +996,11 @@ public: //operations for the arrow framework
void update_arrow(arrow & a);
private:
typedef std::multimap<map_location, overlay> overlay_map;
overlay_map overlays_;
/** Handle for the label which displays frames per second. */
int fps_handle_;
/** Count work done for the debug info displayed under fps */

View file

@ -0,0 +1,145 @@
/*
Copyright (C) 2008 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* Editor item action class
*/
//TODO is a textdomain needed?
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "editor/action/action_item.hpp"
#include "editor/map/map_context.hpp"
#include <boost/scoped_ptr.hpp>
namespace editor {
editor_action_item* editor_action_item::clone() const
{
return new editor_action_item(*this);
}
editor_action* editor_action_item::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo(new editor_action_item_delete(loc_));
perform_without_undo(mc);
return undo.release();
}
void editor_action_item::perform_without_undo(map_context& /*mc*/) const
{
//
// mc.get_items().add(loc_,u_);
// mc.get_items().find(loc_)->set_location(loc_);
// mc.add_changed_location(loc_);
}
editor_action_item_delete* editor_action_item_delete::clone() const
{
return new editor_action_item_delete(*this);
}
editor_action* editor_action_item_delete::perform(map_context& /*mc*/) const
{
// item_map& items = mc.get_items();
// item_map::const_item_iterator item_it = items.find(loc_);
//
// std::auto_ptr<editor_action> undo;
// if (item_it != items.end()) {
// undo.reset(new editor_action_item(loc_, *item_it));
// perform_without_undo(mc);
// return undo.release();
// }
return NULL;
}
void editor_action_item_delete::perform_without_undo(map_context& /*mc*/) const
{
// item_map& items = mc.get_items();
// if (!items.erase(loc_)) {
// ERR_ED << "Could not delete item on " << loc_.x << "/" << loc_.y << "\n";
// } else {
// mc.add_changed_location(loc_);
// }
}
editor_action_item_replace* editor_action_item_replace::clone() const
{
return new editor_action_item_replace(*this);
}
editor_action* editor_action_item_replace::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo(new editor_action_item_replace(new_loc_, loc_));
perform_without_undo(mc);
return undo.release();
}
void editor_action_item_replace::perform_without_undo(map_context& /*mc*/) const
{
// item_map& items = mc.get_items();
// items.move(loc_, new_loc_);
// item::clear_status_caches();
//
// item& u = *items.find(new_loc_);
// //TODO do we still need set_standing?
// u.set_standing();
//
// mc.add_changed_location(loc_);
// mc.add_changed_location(new_loc_);
//
// /* @todo
// if (mc.get_map().is_village(new_loc_)) {
// (*(resources::teams))[u.side()].get_village(new_loc_);
// }
// */
//
////TODO check if that is useful
//// resources::screen->invalidate_item_after_move(loc_, new_loc_);
//// resources::screen->draw();
}
editor_action_item_facing* editor_action_item_facing::clone() const
{
return new editor_action_item_facing(*this);
}
editor_action* editor_action_item_facing::perform(map_context& mc) const
{
std::auto_ptr<editor_action> undo(new editor_action_item_facing(loc_, old_direction_, new_direction_));
perform_without_undo(mc);
return undo.release();
}
void editor_action_item_facing::perform_without_undo(map_context& /*mc*/) const
{
// item_map& items = mc.get_items();
// item_map::item_iterator item_it = items.find(loc_);
//
// if (item_it != items.end()) {
// item_it->set_facing(new_direction_);
// item_it->set_standing();
// }
}
} //end namespace editor

View file

@ -0,0 +1,108 @@
/*
Copyright (C) 2008 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* @file
* Editor action classes. Some important points:
* - This is a polymorphic hierarchy of classes, so actions are usually passed around
* as editor_action pointers
* - The pointers can, in general, be null. Always check for null before doing anything.
* The helper functions perform_ that take a pointer do that.
* - The perform() functions can throw when an error occurs. Use smart pointers if you
* need to ensure the pointer is deleted.
*/
#ifndef EDITOR_ACTION_ITEM_HPP
#define EDITOR_ACTION_ITEM_HPP
#include "editor/action/action.hpp"
#include "overlay.hpp"
//#include "../../item_types.hpp"
//#include "../../item.hpp"
namespace editor {
/**
* place a new item on the map
*/
class editor_action_item : public editor_action_location
{
public:
editor_action_item(map_location loc,
const overlay& item)
: editor_action_location(loc), item_(item)
{
}
editor_action_item* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "item"; }
protected:
overlay item_;
};
/**
* Remove a item from the map.
*/
class editor_action_item_delete : public editor_action_location
{
public:
editor_action_item_delete(map_location loc)
: editor_action_location(loc)
{
}
editor_action_item_delete* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "item_delete"; }
};
class editor_action_item_replace : public editor_action_location
{
public:
editor_action_item_replace(map_location loc, map_location new_loc)
: editor_action_location(loc), new_loc_(new_loc)
{
}
editor_action_item_replace* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "item_replace"; }
protected:
map_location new_loc_;
};
class editor_action_item_facing : public editor_action_location
{
public:
editor_action_item_facing(map_location loc, map_location::DIRECTION new_direction, map_location::DIRECTION old_direction)
: editor_action_location(loc), new_direction_(new_direction), old_direction_(old_direction)
{
}
editor_action_item_facing* clone() const;
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "item_facing"; }
protected:
map_location::DIRECTION new_direction_;
map_location::DIRECTION old_direction_;
};
} //end namespace editor
#endif

View file

@ -0,0 +1,252 @@
/*
Copyright (C) 2008 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "mouse_action_item.hpp"
#include "../action_item.hpp"
#include "../../editor_display.hpp"
//#include "gui/dialogs/item_create.hpp"
#include "tooltips.hpp"
#include "gettext.hpp"
#include "map_location.hpp"
namespace editor {
void mouse_action_item::move(editor_display& disp, const map_location& hex)
{
if (hex != previous_move_hex_) {
update_brush_highlights(disp, hex);
std::set<map_location> adjacent_set;
map_location adjacent[6];
get_adjacent_tiles(previous_move_hex_, adjacent);
for (int i = 0; i < 6; i++)
adjacent_set.insert(adjacent[i]);
disp.invalidate(adjacent_set);
previous_move_hex_ = hex;
// const item_map& items = disp.get_items();
// const item_map::const_item_iterator item_it = items.find(hex);
// if (item_it != items.end()) {
//
// disp.set_mouseover_hex_overlay(NULL);
//
// SDL_Rect rect;
// rect.x = disp.get_location_x(hex);
// rect.y = disp.get_location_y(hex);
// rect.h = disp.hex_size();
// rect.w = disp.hex_size();
// std::stringstream str;
// str << N_("ID: ") << item_it->id() << "\n"
// << N_("Name: ") << item_it->name() << "\n"
// << N_("Type: ") << item_it->type_name();
// tooltips::clear_tooltips();
// tooltips::add_tooltip(rect, str.str());
// }
// else {
// set_mouse_overlay(disp);
// }
}
}
editor_action* mouse_action_item::click_left(editor_display& disp, int x, int y)
{
start_hex_ = disp.hex_clicked_on(x, y);
if (!disp.get_map().on_board(start_hex_)) {
return NULL;
}
const overlay& item = item_palette_.selected_fg_item();
disp.add_overlay(start_hex_, item.image, "", "", true);
// const item_map::const_item_iterator item_it = items.find(start_hex_);
// if (item_it != items.end())
// set_item_mouse_overlay(disp, item_it->type());
click_ = true;
return NULL;
}
editor_action* mouse_action_item::drag_left(editor_display& disp, int x, int y, bool& /*partial*/, editor_action* /*last_undo*/)
{
map_location hex = disp.hex_clicked_on(x, y);
click_ = (hex == start_hex_);
return NULL;
}
editor_action* mouse_action_item::up_left(editor_display& disp, int x, int y)
{
if (!click_) return NULL;
click_ = false;
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.get_map().on_board(hex)) {
return NULL;
}
// item_type type = item_palette_.selected_fg_item();
//
// // Does this serve a purpose other than making sure the type is built?
// // (Calling item_types.build_item_type(type) would now accomplish that
// // with less overhead.)
// const std::string& type_id = type.id();
// const item_type *new_item_type = item_types.find(type_id);
// if (!new_item_type) {
// //TODO rewrite the error message.
// ERR_ED << "create item dialog returned inexistent or unusable item_type id '" << type_id << "'\n";
// return NULL;
// }
//
// const item_type &ut = *new_item_type;
// item_race::GENDER gender = ut.genders().front();
//
// item new_item(ut, disp.viewing_side(), true, gender);
// editor_action* action = new editor_action_item(hex, new_item);
// return action;
return NULL;
}
editor_action* mouse_action_item::drag_end_left(editor_display& disp, int x, int y)
{
if (click_) return NULL;
editor_action* action = NULL;
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.get_map().on_board(hex))
return NULL;
// const item_map& items = disp.get_items();
// const item_map::const_item_iterator item_it = items.find(start_hex_);
// if (item_it == items.end())
// return NULL;
action = new editor_action_item_replace(start_hex_, hex);
return action;
}
/*
editor_action* mouse_action_item::click_right(editor_display& disp, int x, int y)
{
map_location hex = disp.hex_clicked_on(x, y);
start_hex_ = hex;
previous_move_hex_ = hex;
const item_map& items = disp.get_items();
const item_map::const_item_iterator item_it = items.find(start_hex_);
if (item_it != items.end()) {
old_direction_ = item_it->facing();
}
click_ = true;
return NULL;
}
*/
//editor_action* mouse_action_item::drag_right(editor_display& disp, int x, int y, bool& /*partial*/, editor_action* /*last_undo*/)
//{
// map_location hex = disp.hex_clicked_on(x, y);
// if (previous_move_hex_ == hex)
// return NULL;
//
// click_ = (start_hex_ == hex);
// previous_move_hex_ = hex;
//
// const item_map& items = disp.get_items();
//
// const item_map::const_item_iterator item_it = items.find(start_hex_);
// if (item_it != items.end()) {
// for (map_location::DIRECTION new_direction = map_location::NORTH;
// new_direction <= map_location::NORTH_WEST;
// new_direction = map_location::DIRECTION(new_direction +1)){
// if (item_it->get_location().get_direction(new_direction, 1) == hex) {
// return new editor_action_item_facing(start_hex_, new_direction, old_direction_);
// }
// }
// }
//
// return NULL;
//}
//editor_action* mouse_action_item::up_right(editor_display& disp, int /*x*/, int /*y*/)
//{
// if (!click_) return NULL;
// click_ = false;
//
// const item_map& items = disp.get_items();
// const item_map::const_item_iterator item_it = items.find(start_hex_);
// if (item_it != items.end()) {
// return new editor_action_item_delete(start_hex_);
// }
//
// return NULL;
//}
//editor_action* mouse_action_item::drag_end_right(editor_display& disp, int x, int y)
//{
// if (click_) return NULL;
//
// map_location hex = disp.hex_clicked_on(x, y);
// if (!disp.get_map().on_board(hex))
// return NULL;
//
// if(new_direction_ != old_direction_) {
//
// const item_map& items = disp.get_items();
// const item_map::const_item_iterator item_it = items.find(start_hex_);
// if (item_it != items.end()) {
// return new editor_action_item_facing(start_hex_, new_direction_, old_direction_);
// }
// }
//
// return NULL;
//}
void mouse_action_item::set_mouse_overlay(editor_display& disp)
{
const overlay& item = item_palette_.selected_fg_item();
set_item_mouse_overlay(disp, item);
}
void mouse_action_item::set_item_mouse_overlay(editor_display& disp, const overlay& u)
{
std::stringstream filename;
filename << u.image; // << "~RC(" << u.flag_rgb() << '>'
// << team::get_side_color_index(disp.viewing_side()) << ')';
surface image(image::get_image(filename.str()));
Uint8 alpha = 196;
//TODO don't hardcode
int size = 72;
//int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}
} //end namespace editor

View file

@ -0,0 +1,84 @@
/*
Copyright (C) 2008 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef EDITOR_MOUSE_ACTION_ITEM_HPP
#define EDITOR_MOUSE_ACTION_ITEM_HPP
#include "editor/action/mouse/mouse_action.hpp"
#include "editor/palette/item_palette.hpp"
class CKey;
namespace editor {
/**
* item placement action class
*/
class mouse_action_item : public mouse_action
{
public:
mouse_action_item(const CKey& key, item_palette& palette)
: mouse_action(palette, key)
, click_(false)
, start_hex_()
, old_direction_(map_location::NORTH)
, new_direction_(map_location::NORTH)
, item_palette_(palette)
{
}
bool has_context_menu() const {
return true;
}
void move(editor_display& disp, const map_location& hex);
/**
* TODO
*/
editor_action* click_left(editor_display& disp, int x, int y);
/**
* TODO
*/
editor_action* up_left(editor_display& disp, int x, int y);
editor_action* drag_left(editor_display& disp, int x, int y, bool& partial, editor_action* last_undo);
/**
* Drag end replaces the item when clicked left, or adjusts
* the facing when clicked right.
*/
editor_action* drag_end_left(editor_display& disp, int x, int y);
editor_action* click_right(editor_display& /*disp*/, int /*x*/, int /*y*/) {
return NULL;
}
virtual void set_mouse_overlay(editor_display& disp);
void set_item_mouse_overlay(editor_display& disp, const overlay& u);
private:
bool click_;
map_location start_hex_;
map_location::DIRECTION old_direction_;
map_location::DIRECTION new_direction_;
item_palette& item_palette_;
};
} //end namespace editor
#endif

View file

@ -357,6 +357,7 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
case HOTKEY_EDITOR_TOOL_SELECT:
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
case HOTKEY_EDITOR_TOOL_LABEL:
case HOTKEY_EDITOR_TOOL_ITEM:
return true;
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_VILLAGE:
@ -473,6 +474,7 @@ hotkey::ACTION_STATE editor_controller::get_action_state(hotkey::HOTKEY_COMMAND
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_VILLAGE:
case HOTKEY_EDITOR_TOOL_ITEM:
return toolkit_->is_mouse_action_set(command) ? ACTION_ON : ACTION_OFF;
case HOTKEY_EDITOR_DRAW_COORDINATES:
return gui_->get_draw_coordinates() ? ACTION_ON : ACTION_OFF;
@ -656,6 +658,7 @@ bool editor_controller::execute_command(hotkey::HOTKEY_COMMAND command, int inde
case HOTKEY_EDITOR_TOOL_LABEL:
case HOTKEY_EDITOR_TOOL_UNIT:
case HOTKEY_EDITOR_TOOL_VILLAGE:
case HOTKEY_EDITOR_TOOL_ITEM:
toolkit_->hotkey_set_mouse_action(command);
return true;

View file

@ -31,6 +31,8 @@ namespace editor {
int auto_update_transitions();
void set_auto_update_transitions(int value);
//std::vector<std::string>* get_editor_history();
std::string default_dir();
bool draw_terrain_codes();

View file

@ -21,6 +21,7 @@
#include "sound_music_track.hpp"
#include "tod_manager.hpp"
#include "unit_map.hpp"
#include "overlay.hpp"
#include <boost/utility.hpp>
#include <boost/scoped_ptr.hpp>
@ -372,6 +373,9 @@ private:
typedef std::map<std::string, sound::music_track> music_map;
music_map music_tracks_;
typedef std::map<map_location, std::vector<overlay> > overlay_map;
overlay_map overlays_;
};

View file

@ -19,6 +19,7 @@
#include "gettext.hpp"
#include "marked-up_text.hpp"
#include "tooltips.hpp"
#include "overlay.hpp"
#include "editor/action/mouse/mouse_action.hpp"
@ -39,6 +40,7 @@ handler_vector editor_palette<Item>::handler_members()
}
template handler_vector editor_palette<t_translation::t_terrain>::handler_members();
template handler_vector editor_palette<unit_type>::handler_members();
template handler_vector editor_palette<overlay>::handler_members();
template<class Item>
void editor_palette<Item>::expand_palette_groups_menu(std::vector<std::string>& items)
@ -72,6 +74,7 @@ void editor_palette<Item>::expand_palette_groups_menu(std::vector<std::string>&
}
template void editor_palette<t_translation::t_terrain>::expand_palette_groups_menu(std::vector<std::string>& items);
template void editor_palette<unit_type>::expand_palette_groups_menu(std::vector<std::string>& items);
template void editor_palette<overlay>::expand_palette_groups_menu(std::vector<std::string>& items);
template<class Item>
bool editor_palette<Item>::scroll_up()
@ -89,6 +92,7 @@ bool editor_palette<Item>::scroll_up()
}
template bool editor_palette<t_translation::t_terrain>::scroll_up();
template bool editor_palette<unit_type>::scroll_up();
template bool editor_palette<overlay>::scroll_up();
template<class Item>
void editor_palette<Item>::expand_palette_groups_menu(std::vector< std::pair< std::string, std::string> >& items)
@ -106,7 +110,7 @@ void editor_palette<Item>::expand_palette_groups_menu(std::vector< std::pair< st
}
template void editor_palette<t_translation::t_terrain>::expand_palette_groups_menu(std::vector< std::pair< std::string, std::string> >& items);
template void editor_palette<unit_type>::expand_palette_groups_menu(std::vector< std::pair< std::string, std::string> >& items);
template void editor_palette<overlay>::expand_palette_groups_menu(std::vector< std::pair< std::string, std::string> >& items);
template<class Item>
bool editor_palette<Item>::can_scroll_up()
@ -115,6 +119,7 @@ bool editor_palette<Item>::can_scroll_up()
}
template bool editor_palette<t_translation::t_terrain>::can_scroll_up();
template bool editor_palette<unit_type>::can_scroll_up();
template bool editor_palette<overlay>::can_scroll_up();
template<class Item>
bool editor_palette<Item>::can_scroll_down()
@ -123,6 +128,7 @@ bool editor_palette<Item>::can_scroll_down()
}
template bool editor_palette<t_translation::t_terrain>::can_scroll_down();
template bool editor_palette<unit_type>::can_scroll_down();
template bool editor_palette<overlay>::can_scroll_down();
template<class Item>
bool editor_palette<Item>::scroll_down()
@ -145,6 +151,7 @@ bool editor_palette<Item>::scroll_down()
}
template bool editor_palette<t_translation::t_terrain>::scroll_down();
template bool editor_palette<unit_type>::scroll_down();
template bool editor_palette<overlay>::scroll_down();
template<class Item>
void editor_palette<Item>::set_group(const std::string& id)
@ -175,6 +182,7 @@ void editor_palette<Item>::set_group(const std::string& id)
}
template void editor_palette<t_translation::t_terrain>::set_group(const std::string& id);
template void editor_palette<unit_type>::set_group(const std::string& id);
template void editor_palette<overlay>::set_group(const std::string& id);
template<class Item>
void editor_palette<Item>::set_group(size_t index)
@ -184,6 +192,7 @@ void editor_palette<Item>::set_group(size_t index)
}
template void editor_palette<t_translation::t_terrain>::set_group(size_t index);
template void editor_palette<unit_type>::set_group(size_t index);
template void editor_palette<overlay>::set_group(size_t index);
template<class Item>
size_t editor_palette<Item>::active_group_index()
@ -199,6 +208,7 @@ size_t editor_palette<Item>::active_group_index()
}
template size_t editor_palette<t_translation::t_terrain>::active_group_index();
template size_t editor_palette<unit_type>::active_group_index();
template size_t editor_palette<overlay>::active_group_index();
template<class Item>
const config editor_palette<Item>::active_group_report()
@ -216,6 +226,7 @@ const config editor_palette<Item>::active_group_report()
}
template const config editor_palette<t_translation::t_terrain>::active_group_report();
template const config editor_palette<unit_type>::active_group_report();
template const config editor_palette<overlay>::active_group_report();
template<class Item>
void editor_palette<Item>::adjust_size(const SDL_Rect& target)
@ -235,6 +246,7 @@ void editor_palette<Item>::adjust_size(const SDL_Rect& target)
}
template void editor_palette<t_translation::t_terrain>::adjust_size(const SDL_Rect& target);
template void editor_palette<unit_type>::adjust_size(const SDL_Rect& target);
template void editor_palette<overlay>::adjust_size(const SDL_Rect& target);
template<class Item>
void editor_palette<Item>::select_fg_item(const std::string& item_id)
@ -248,6 +260,7 @@ void editor_palette<Item>::select_fg_item(const std::string& item_id)
}
template void editor_palette<t_translation::t_terrain>::select_fg_item(const std::string& terrain_id);
template void editor_palette<unit_type>::select_fg_item(const std::string& unit_id);
template void editor_palette<overlay>::select_fg_item(const std::string& unit_id);
template<class Item>
void editor_palette<Item>::select_bg_item(const std::string& item_id)
@ -261,6 +274,7 @@ void editor_palette<Item>::select_bg_item(const std::string& item_id)
}
template void editor_palette<t_translation::t_terrain>::select_bg_item(const std::string& terrain_id);
template void editor_palette<unit_type>::select_bg_item(const std::string& unit_id);
template void editor_palette<overlay>::select_bg_item(const std::string& unit_id);
template<class Item>
void editor_palette<Item>::swap()
@ -272,6 +286,7 @@ void editor_palette<Item>::swap()
}
template void editor_palette<t_translation::t_terrain>::swap();
template void editor_palette<unit_type>::swap();
template void editor_palette<overlay>::swap();
template<class Item>
size_t editor_palette<Item>::num_items()
@ -281,6 +296,7 @@ size_t editor_palette<Item>::num_items()
}
template size_t editor_palette<t_translation::t_terrain>::num_items();
template size_t editor_palette<unit_type>::num_items();
template size_t editor_palette<overlay>::num_items();
template<class Item>
void editor_palette<Item>::draw_contents()
@ -326,8 +342,8 @@ void editor_palette<Item>::draw_contents()
if (i >= ending) continue;
const std::string item_id = active_group()[counter];
typedef std::map<std::string, Item> item_map_wurscht;
typename item_map_wurscht::iterator item = item_map_.find(item_id);
//typedef std::map<std::string, Item> item_map_wurscht;
typename item_map::iterator item = item_map_.find(item_id);
surface item_image(NULL);
std::stringstream tooltip_text;
@ -378,6 +394,7 @@ void editor_palette<Item>::draw_contents()
}
template void editor_palette<t_translation::t_terrain>::draw_contents();
template void editor_palette<unit_type>::draw_contents();
template void editor_palette<overlay>::draw_contents();
} // end namespace editor

View file

@ -172,7 +172,8 @@ private:
protected:
std::map<std::string, std::vector<std::string> > group_map_;
std::map<std::string, Item> item_map_;
typedef std::map<std::string, Item> item_map;
item_map item_map_;
size_t nitems_, nmax_items_, items_start_;
std::set<std::string> non_core_items_;

View file

@ -0,0 +1,135 @@
/*
Copyright (C) 2012 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Manage the item-palette in the editor.
*/
#define GETTEXT_DOMAIN "wesnoth-editor"
#include "item_palette.hpp"
#include "../../gettext.hpp"
//#include "../../item_types.hpp"
#include <boost/foreach.hpp>
#include "config.h"
#include <string>
namespace editor {
std::string item_palette::get_help_string() {
return selected_fg_item().name;
}
void item_palette::setup(const config& cfg)
{
BOOST_FOREACH(const config& group, cfg.child_range("item_group")) {
groups_.push_back(item_group(group));
BOOST_FOREACH(const config& item, group.child_range("item")) {
item_map_.insert(std::pair<std::string, overlay>(item["id"], overlay(item)));
group_map_[group["id"]].push_back(item["id"]);
}
nmax_items_ = std::max(nmax_items_, group_map_[group["id"]].size());
}
// BOOST_FOREACH(const item_type_data::item_type_map::value_type &i, item_types.types())
// {
// item_map_.insert(std::pair<std::string, item_type>(i.second.id(), i.second));
// group_map_[i.second.race_id()].push_back(i.second.id());
// nmax_items_ = std::max(nmax_items_, group_map_[i.second.race_id()].size());
// //TODO
// bool core = true;
// if (core) {
// // Add the item to the default group
// group_map_["all"].push_back(i.second.id());
// nmax_items_ = std::max(nmax_items_, group_map_["all"].size());
// } else {
// non_core_items_.insert(i.second.id());
// }
// }
//
// BOOST_FOREACH(const race_map::value_type &i, item_types.races())
// {
// config cfg;
// cfg["id"] = i.second.id();
// cfg["name"] = i.second.plural_name();
// cfg["icon"] = "icons/item-groups/race_" + i.second.id();
// cfg["core"] = "yes";
// groups_.push_back(item_group(cfg));
// }
//
// //TODO
// //move "invalid" items to the end
// //std::stable_partition(items.begin(), items.end(), is_valid_terrain);
//
select_fg_item("anvil");
select_bg_item("altar");
//
// // Set the default group
set_group("items");
//
// if(active_group().empty()) {
// ERR_ED << "No items found.\n";
// }
}
void item_palette::draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text) {
surface screen = gui_.video().getSurface();
std::stringstream filename;
filename << item.image; // << "~RC(" << u.flag_rgb() << '>'
// << team::get_side_color_index(gui_.viewing_side()) << ')';
image = surface(image::get_image(filename.str()));
if(image == NULL) {
tooltip_text << "IMAGE NOT FOUND\n";
ERR_ED << "image for item type: '" << filename.str() << "' not found\n";
image = image::get_image(game_config::images::missing);
if (image == NULL) {
ERR_ED << "Placeholder image not found\n";
return;
}
}
if(image->w != item_size_ || image->h != item_size_) {
image.assign(scale_surface(image,
item_size_, item_size_));
}
tooltip_text << item.name;
}
item_palette::item_palette(editor_display &gui, const config& cfg,
mouse_action** active_mouse_action)
//TODO avoid magic numbers
: editor_palette<overlay>(gui, cfg, 36, 4, active_mouse_action)
{
}
const std::string& item_palette::get_id(const overlay& item)
{
return item.id;
}
}

View file

@ -0,0 +1,50 @@
/*
Copyright (C) 2012 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* Manage the item-palette in the editor.
*/
#ifndef ITEM_PALETTES_H_INCLUDED
#define ITEM_PALETTES_H_INCLUDED
#include "editor_palettes.hpp"
#include "overlay.hpp"
namespace editor {
//std::string get_selected_terrain();
/** Palette where the terrain to be drawn can be selected. */
class item_palette : public editor_palette<overlay> {
public:
item_palette(editor_display &gui,
const config& cfg,
mouse_action** active_mouse_action);
virtual void setup(const config& cfg);
virtual std::string get_help_string();
private:
virtual const std::string& get_id(const overlay& item);
virtual void draw_item(const overlay& item, surface& image, std::stringstream& tooltip_text);
};
}
#endif

View file

@ -31,10 +31,12 @@ palette_manager::palette_manager(editor_display& gui, const config& cfg
mouse_action_(active_mouse_action),
terrain_palette_(new terrain_palette(gui, cfg, active_mouse_action)),
unit_palette_(new unit_palette(gui, cfg, active_mouse_action)),
empty_palette_(new empty_palette(gui))
empty_palette_(new empty_palette(gui)),
item_palette_(new item_palette(gui, cfg, active_mouse_action))
{
unit_palette_->setup(cfg);
terrain_palette_->setup(cfg);
item_palette_->setup(cfg);
}
void palette_manager::set_group(size_t index)

View file

@ -24,6 +24,7 @@
#include "empty_palette.hpp"
#include "terrain_palettes.hpp"
#include "unit_palette.hpp"
#include "item_palette.hpp"
namespace editor {
@ -80,7 +81,7 @@ public:
boost::scoped_ptr<terrain_palette> terrain_palette_;
boost::scoped_ptr<unit_palette> unit_palette_;
boost::scoped_ptr<empty_palette> empty_palette_;
boost::scoped_ptr<item_palette> item_palette_;
};
}

View file

@ -19,6 +19,7 @@
#include "editor/action/mouse/mouse_action_map_label.hpp"
#include "editor/action/mouse/mouse_action_unit.hpp"
#include "editor/action/mouse/mouse_action_village.hpp"
#include "editor/action/mouse/mouse_action_item.hpp"
#include <boost/foreach.hpp>
@ -85,6 +86,8 @@ void editor_toolkit::init_mouse_actions(const config& game_config, context_manag
new mouse_action_village(key_, *palette_manager_->empty_palette_.get())));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_PASTE,
new mouse_action_paste(cmanager.get_clipboard(), key_, *palette_manager_->empty_palette_.get())));
mouse_actions_.insert(std::make_pair(hotkey::HOTKEY_EDITOR_TOOL_ITEM,
new mouse_action_item(key_, *palette_manager_->item_palette_.get())));
BOOST_FOREACH(const theme::menu& menu, gui_.get_theme().menus()) {
if (menu.items().size() == 1) {

View file

@ -70,7 +70,7 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
tod_manager_(tod),
level_(level),
displayedUnitHex_(),
overlays_(),
// overlays_(),
sidebarScaling_(1.0),
first_turn_(true),
in_game_(false),
@ -264,11 +264,11 @@ void game_display::draw_hex(const map_location& loc)
{
const bool on_map = get_map().on_board(loc);
const bool is_shrouded = shrouded(loc);
const bool is_fogged = fogged(loc);
// const bool is_fogged = fogged(loc);
const int xpos = get_location_x(loc);
const int ypos = get_location_y(loc);
image::TYPE image_type = get_image_type(loc);
// image::TYPE image_type = get_image_type(loc);
display::draw_hex(loc);
@ -283,19 +283,7 @@ void game_display::draw_hex(const map_location& loc)
loc, xpos, ypos, image::get_image("misc/hover-hex-bottom.png", image::SCALED_TO_HEX));
}
if(!is_shrouded) {
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));
}
}
}
// Draw reach_map information.
// We remove the reachability mask of the unit
@ -775,60 +763,21 @@ void game_display::clear_attack_indicator()
set_attack_indicator(map_location::null_location, map_location::null_location);
}
void game_display::add_overlay(const map_location& loc, const std::string& img, const std::string& halo,const std::string& team_name, bool visible_under_fog)
{
const int halo_handle = halo::add(get_location_x(loc) + hex_size() / 2,
get_location_y(loc) + hex_size() / 2, halo, loc);
const overlay item(img, halo, halo_handle, team_name, visible_under_fog);
overlays_.insert(overlay_map::value_type(loc,item));
}
void game_display::remove_overlay(const map_location& loc)
{
typedef overlay_map::const_iterator Itor;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
while(itors.first != itors.second) {
halo::remove(itors.first->second.halo_handle);
++itors.first;
}
overlays_.erase(loc);
}
void game_display::remove_single_overlay(const map_location& loc, const std::string& toDelete)
{
//Iterate through the values with key of loc
typedef overlay_map::iterator Itor;
overlay_map::iterator iteratorCopy;
std::pair<Itor,Itor> itors = overlays_.equal_range(loc);
while(itors.first != itors.second) {
//If image or halo of overlay struct matches toDelete, remove the overlay
if(itors.first->second.image == toDelete || itors.first->second.halo == toDelete) {
iteratorCopy = itors.first;
++itors.first;
halo::remove(iteratorCopy->second.halo_handle);
overlays_.erase(iteratorCopy);
}
else {
++itors.first;
}
}
}
void game_display::parse_team_overlays()
{
const team& curr_team = (*teams_)[playing_team()];
const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1];
BOOST_FOREACH(const game_display::overlay_map::value_type i, overlays_) {
const overlay& ov = i.second;
if (!ov.team_name.empty() &&
((ov.team_name.find(curr_team.team_name()) + 1) != 0) !=
((ov.team_name.find(prev_team.team_name()) + 1) != 0))
{
invalidate(i.first);
}
}
// const team& curr_team = (*teams_)[playing_team()];
// const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1];
// BOOST_FOREACH(const game_display::overlay_map::value_type i, overlays_) {
// const overlay& ov = i.second;
// if (!ov.team_name.empty() &&
// ((ov.team_name.find(curr_team.team_name()) + 1) != 0) !=
// ((ov.team_name.find(prev_team.team_name()) + 1) != 0))
// {
// invalidate(i.first);
// }
// }
}
std::string game_display::current_team_name() const

View file

@ -222,21 +222,6 @@ public:
attack_indicator_src_.get_relative_dir(attack_indicator_dst_));
}
/**
* Functions to add and remove overlays from locations.
*
* An overlay is an image that is displayed on top of the tile.
* One tile may have multiple overlays.
*/
void add_overlay(const map_location& loc, const std::string& image,
const std::string& halo="", const std::string& team_name="",
bool visible_under_fog = true);
/** remove_overlay will remove all overlays on a tile. */
void remove_overlay(const map_location& loc);
/** remove_single_overlay will remove a single overlay from a tile */
void remove_single_overlay(const map_location& loc, const std::string& toDelete);
/**
* Check the overlay_map for proper team-specific overlays to be
@ -331,20 +316,20 @@ private:
map_location displayedUnitHex_;
struct overlay {
overlay(const std::string& img, const std::string& halo_img,
int handle, const std::string& overlay_team_name, const bool fogged) : image(img), halo(halo_img),
team_name(overlay_team_name), halo_handle(handle) , visible_in_fog(fogged){}
std::string image;
std::string halo;
std::string team_name;
int halo_handle;
bool visible_in_fog;
};
// struct overlay {
// overlay(const std::string& img, const std::string& halo_img,
// int handle, const std::string& overlay_team_name, const bool fogged) : image(img), halo(halo_img),
// team_name(overlay_team_name), halo_handle(handle) , visible_in_fog(fogged){}
// std::string image;
// std::string halo;
// std::string team_name;
// int halo_handle;
// bool visible_in_fog;
// };
typedef std::multimap<map_location,overlay> overlay_map;
// typedef std::multimap<map_location,overlay> overlay_map;
overlay_map overlays_;
// overlay_map overlays_;

46
src/overlay.hpp Normal file
View file

@ -0,0 +1,46 @@
/*
Copyright (C) 2003 - 2013 by Fabian Mueller <fabianmueller5@gmx.de>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef OVERLAY_INCLUDED
#define OVERLAY_INCLUDED
struct overlay
{
overlay(const std::string& img, const std::string& halo_img,
int handle, const std::string& overlay_team_name, const bool fogged) : image(img), halo(halo_img),
team_name(overlay_team_name), halo_handle(handle) , visible_in_fog(fogged)
{}
overlay(const config& cfg) :
image(cfg["image"]), halo(cfg["halo"]), team_name(cfg["team_name"]),
name(cfg["name"].t_str()), id(cfg["id"]),
halo_handle(-1), visible_in_fog(cfg["visible_in_fog"].to_int())
{
}
std::string image;
std::string halo;
std::string team_name;
t_string name;
std::string id;
int halo_handle;
bool visible_in_fog;
};
#endif