Added the framework for the editor groups and added some test cases,

if some of the terrain artists want to define the groups please do so.

And please replace the abomination which should be buttons.

The name in editor_group also should be marked for translation once
the groups are properly determined.
This commit is contained in:
Mark de Wever 2007-02-10 22:13:13 +00:00
parent 5a637075a3
commit e936ff3dbe
25 changed files with 217 additions and 16 deletions

View file

@ -25,6 +25,7 @@ Version 1.3-svn:
* flipping a map over the Y axis no longer resizes the map
* flipping a map over the X axis uses slightly different filler rules
* added the paste option to the edit menu
* added the option to split the terrains is groups
* graphics
* improved layering system for terrain graphics
* fixed terrain selection probabilites (patch #617)

38
data/editor-groups.cfg Normal file
View file

@ -0,0 +1,38 @@
# This file defines the goups which are shown in the editor
# all editor_group entries in terrain.cfg should have a corresponding id here
# name is shown in the tooltip in the editor
# icon is the button icon name
#NOTE: the name is a translatable string the translation marker is omitted
# due to the fact the names are not determined yet
#The all entry shows all terrains and must be available
[editor_group]
id=all
name="the whole bunch"
icon="group_all"
[/editor_group]
[editor_group]
id=bridge
name="bridge"
icon="group_bridge"
[/editor_group]
[editor_group]
id=water
name="water"
icon="group_water"
[/editor_group]
[editor_group]
id=village
name="village"
icon="group_village"
[/editor_group]
[editor_group]
id=ice
name=_ "ice"
icon="group_ice"
[/editor_group]

View file

@ -28,6 +28,8 @@
{campaigns}
{editor-groups.cfg}
[advanced_preference]
field=compress_saves
name=_"Binary Saves"

View file

@ -39,6 +39,7 @@ string=Ai
char=i
unit_height_adjust=-2
aliasof=Aa
editor_group=ice
[/terrain]
[terrain]
@ -47,6 +48,7 @@ id=tundra
name= _ "Snow"
string=Aa
char=S
editor_group=ice
[/terrain]
#
@ -61,6 +63,7 @@ name= _ "Bridge"
char=|
string=Bww|
aliasof=Gg, Ww
editor_group=bridge
[/terrain]
[terrain]
@ -70,6 +73,7 @@ name= _ "Bridge"
char=/
string=Bww/
aliasof=Gg, Ww
editor_group=bridge
[/terrain]
[terrain]
@ -79,6 +83,7 @@ name= _ "Bridge"
char=\
string=Bww\
aliasof=Gg, Ww
editor_group=bridge
[/terrain]
# Deep Water Bridge
@ -89,6 +94,7 @@ name= _ "Bridge"
#char=|
string=Bwo|
aliasof=Gg, Wo
editor_group=bridge
[/terrain]
[terrain]
@ -98,6 +104,7 @@ name= _ "Bridge"
#char=/
string=Bwo/
aliasof=Gg, Wo
editor_group=bridge, water
[/terrain]
[terrain]
@ -107,6 +114,7 @@ name= _ "Bridge"
#char=\
string=Bwo\
aliasof=Gg, Wo
editor_group=bridge, water
[/terrain]
# Swamp Water Bridge
@ -117,6 +125,7 @@ name= _ "Bridge"
#char=|
string=Bss|
aliasof=Gg, Ss
editor_group=bridge, water
[/terrain]
[terrain]
@ -126,6 +135,7 @@ name= _ "Bridge"
#char=/
string=Bss/
aliasof=Gg, Ss
editor_group=bridge, water
[/terrain]
[terrain]
@ -135,6 +145,7 @@ name= _ "Bridge"
#char=\
string=Bss\
aliasof=Gg, Ss
editor_group=bridge, water
[/terrain]
#
# Castles
@ -616,6 +627,7 @@ char=B
aliasof=Vhg, Dd
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -627,6 +639,7 @@ char=U
aliasof=Vhq, Dd
heals=8
gives_income=true
editor_group=village
[/terrain]
# Elven
@ -640,6 +653,7 @@ char=e
aliasof=Vhg
heals=8
gives_income=true
editor_group=village
[/terrain]
@ -652,6 +666,7 @@ string=Veg
aliasof=Vhg
heals=8
gives_income=true
editor_group=village
[/terrain]
@ -666,6 +681,7 @@ char=V
aliasof=Vhg
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -676,6 +692,7 @@ char=v
string=Vhg
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -687,6 +704,7 @@ char=a
aliasof=Vhg, Hh
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -698,6 +716,7 @@ char=A
aliasof=Vhg, Hh
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -709,6 +728,7 @@ char=b
aliasof=Vhg, Mm
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -720,6 +740,7 @@ char=L
aliasof=Vhg
heals=8
gives_income=true
editor_group=village
[/terrain]
# Underground
@ -733,6 +754,7 @@ char=D
aliasof=Vhg, Uu
heals=8
gives_income=true
editor_group=village
[/terrain]
[terrain]
@ -744,6 +766,7 @@ char=p
aliasof=Vhg, Uu
heals=8
gives_income=true
editor_group=village
[/terrain]
# Water
@ -759,6 +782,7 @@ submerge=0.4
unit_height_adjust=-4
heals=8
gives_income=true
editor_group=water, village
[/terrain]
# Swamp
@ -772,6 +796,7 @@ char=Y
aliasof=Vhg, Ss
heals=8
gives_income=true
editor_group=water
[/terrain]
#
@ -786,6 +811,7 @@ string=Wo
char=s
submerge=0.5
unit_height_adjust=-3
editor_group=water
[/terrain]
[terrain]
@ -796,6 +822,7 @@ char=c
string=Ww
submerge=0.4
unit_height_adjust=-4
editor_group=water
[/terrain]
@ -808,6 +835,7 @@ char=k
aliasof=Gg, Wwf
submerge=0.3
unit_height_adjust=-4
editor_group=water
[/terrain]
#

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 553 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 781 B

View file

@ -40,6 +40,9 @@ Version 1.3-svn:
* Flipping a map over the Y axis no longer resizes the map.
* Flipping a map over the X axis uses slightly different filler rules.
* Added the paste option to the edit menu.
* The terrains are now split in groups to the list of terrains per group
is a more friendly list. (NOTE this needs to be finished before
a release Mordante's graphics suck ;) )
* Multiplayer
* Maps

View file

@ -163,7 +163,7 @@ int map_editor::old_brush_size_;
map_editor::map_editor(display &gui, editormap &map, config &theme, config &game_config)
: gui_(gui), map_(map), abort_(DONT_ABORT),
theme_(theme), game_config_(game_config), map_dirty_(false), l_button_palette_dirty_(true),
everything_dirty_(false), palette_(gui, size_specs_, map), brush_(gui, size_specs_),
everything_dirty_(false), palette_(gui, size_specs_, map, game_config), brush_(gui, size_specs_),
l_button_held_func_(NONE), tooltip_manager_(gui_.video()), floating_label_manager_(),
mouse_moved_(false),
highlighted_locs_cleared_(false), prefs_disp_manager_(&gui_), all_hexes_selected_(false) {
@ -218,9 +218,9 @@ void map_editor::load_tooltips()
// Add tooltips to all buttons
const theme &t = gui_.get_theme();
const std::vector<theme::menu> &menus = t.menus();
std::vector<theme::menu>::const_iterator it;
for (it = menus.begin(); it != menus.end(); it++) {
const std::vector<theme::menu> &menus = t.menus();
std::vector<theme::menu>::const_iterator it;
for (it = menus.begin(); it != menus.end(); it++) {
// Get the button's screen location
SDL_Rect screen;
@ -257,7 +257,10 @@ void map_editor::load_tooltips()
if(text != "")
tooltips::add_tooltip(tooltip_rect, text);
}
}
// tooltips for the groups
palette_.load_tooltips();
}
map_editor::~map_editor() {

View file

@ -15,10 +15,13 @@
#include "editor_palettes.hpp"
#include "editor_layout.hpp"
#include "../config.hpp"
#include "../sdl_utils.hpp"
#include "../serialization/string_utils.hpp"
#include "../image.hpp"
#include "../reports.hpp"
#include "../gettext.hpp"
#include "../tooltips.hpp"
#include "../util.hpp"
#include "../video.hpp"
#include "../wassert.hpp"
@ -30,14 +33,51 @@ bool is_invalid_terrain(t_translation::t_letter c) {
c == t_translation::OBSOLETE_KEEP);
}
terrain_group::terrain_group(const config& cfg, display& gui):
id(cfg["id"]), name(cfg["name"]),
button(gui.video(), "", gui::button::TYPE_PRESS, cfg["icon"])
{
}
terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map)
const gamemap &map, const config& cfg)
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0), map_(map),
top_button_(gui.video(), "", gui::button::TYPE_PRESS, "uparrow-button"),
bot_button_(gui.video(), "", gui::button::TYPE_PRESS, "downarrow-button") {
bot_button_(gui.video(), "", gui::button::TYPE_PRESS, "downarrow-button")
{
// get the available terrains temporary in terrains_
terrains_ = map_.get_terrain_list();
terrains_.erase(std::remove_if(terrains_.begin(), terrains_.end(), is_invalid_terrain),
terrains_.end());
// get the available groups and add them to the structure
const config::child_list& groups = cfg.get_children("editor_group");
config::child_list::const_iterator g_itor = groups.begin();
for(; g_itor != groups.end(); ++ g_itor) {
terrain_groups_.push_back(terrain_group(**g_itor, gui));
}
// add the groups for all terrains to the map
t_translation::t_list::const_iterator t_itor = terrains_.begin();
for(; t_itor != terrains_.end(); ++t_itor) {
// add the terrain to the requested groups
const std::vector<std::string>& key =
utils::split(map_.get_terrain_info(*t_itor).editor_group());
for(std::vector<std::string>::const_iterator k_itor = key.begin();
k_itor != key.end(); ++k_itor)
{
terrain_map_[*k_itor].push_back(*t_itor);
}
// add the terrain to the default group
terrain_map_["all"].push_back(*t_itor);
}
// set the default group
terrains_ = terrain_map_["all"];
if(terrains_.empty()) {
std::cerr << "No terrain found.\n";
}
@ -55,12 +95,19 @@ void terrain_palette::adjust_size() {
const size_t button_height = 24;
const size_t button_palette_padding = 8;
//determine number of theme button rows
size_t theme_rows = terrain_groups_.size() / 4;
if(terrain_groups_.size() % 4 != 0) {
++theme_rows;
}
const size_t theme_height = theme_rows * (button_height + button_palette_padding);
SDL_Rect rect = { size_specs_.palette_x, size_specs_.palette_y, size_specs_.palette_w, size_specs_.palette_h };
set_location(rect);
top_button_y_ = size_specs_.palette_y;
top_button_y_ = size_specs_.palette_y + theme_height ;
button_x_ = size_specs_.palette_x + size_specs_.palette_w/2 - button_height/2;
terrain_start_ = top_button_y_ + button_height + button_palette_padding;
const size_t space_for_terrains = size_specs_.palette_h - (button_height + button_palette_padding) * 2;
const size_t space_for_terrains = size_specs_.palette_h - (button_height + button_palette_padding) * 2 - theme_height;
rect.y = terrain_start_;
rect.h = space_for_terrains;
bg_register(rect);
@ -68,11 +115,22 @@ void terrain_palette::adjust_size() {
const unsigned total_terrains = num_terrains();
nterrains_ = minimum<int>(terrains_fitting, total_terrains);
bot_button_y_ = size_specs_.palette_y + (nterrains_ / size_specs_.terrain_width) * size_specs_.terrain_space + \
button_palette_padding * size_specs_.terrain_width + button_height;
button_palette_padding * size_specs_.terrain_width + button_height + theme_height;
top_button_.set_location(button_x_, top_button_y_);
bot_button_.set_location(button_x_, bot_button_y_);
top_button_.set_dirty();
bot_button_.set_dirty();
size_t top = size_specs_.palette_y;
size_t left = size_specs_.palette_x;
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
terrain_groups_[i].button.set_location(left, top);
if(i % 4 == 3) {
left = size_specs_.palette_x;
top += button_height + button_palette_padding;
} else {
left += button_height + button_palette_padding;
}
}
set_dirty();
}
@ -81,6 +139,9 @@ void terrain_palette::set_dirty(bool dirty) {
if (dirty) {
top_button_.set_dirty();
bot_button_.set_dirty();
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
terrain_groups_[i].button.set_dirty();
}
}
}
@ -123,6 +184,15 @@ void terrain_palette::scroll_bottom() {
}
}
void terrain_palette::set_group(const std::string& id)
{
terrains_ = terrain_map_[id];
if(terrains_.empty()) {
std::cerr << "No terrain found.\n";
}
scroll_top();
}
t_translation::t_letter terrain_palette::selected_fg_terrain() const
{
return selected_fg_terrain_;
@ -254,6 +324,12 @@ void terrain_palette::draw(bool force) {
if (bot_button_.pressed()) {
scroll_down();
}
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
if(terrain_groups_[i].button.pressed()) {
set_group(terrain_groups_[i].id);
break;
}
}
if (!dirty() && !force) {
return;
}
@ -330,6 +406,17 @@ void terrain_palette::update_report() {
reports::set_report_content(reports::SELECTED_TERRAIN, msg);
}
void terrain_palette::load_tooltips()
{
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
const std::string& text = terrain_groups_[i].name;
if(text !="") {
const SDL_Rect tooltip_rect = terrain_groups_[i].button.location();
tooltips::add_tooltip(tooltip_rect, text);
}
}
}
// void terrain_palette::bg_backup() {
// restorer_ = surface_restorer(&gui_.video(), get_rect());
// }

View file

@ -25,13 +25,27 @@
#include <vector>
class config;
namespace map_editor {
// a helper struct which for some reason can't be moved to
// the cpp file. Stores the info about the data in
// editor-groups.cfg in a nice format
struct terrain_group
{
terrain_group(const config& cfg, display& gui);
std::string id;
t_string name;
gui::button button;
};
/// A palette where the terrain to be drawn can be selected.
class terrain_palette : public gui::widget {
public:
terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map);
const gamemap &map, const config& cfg);
/// Scroll the terrain palette up one step if possible.
void scroll_up();
@ -45,12 +59,16 @@ public:
/// Scroll the terrain palette to the bottom.
void scroll_bottom();
/// sets a group active id == terrain_map_->first
//the selected terrains remain the same, this can
//result in no visible selected items
void set_group(const std::string& id);
/// Return the currently selected foreground terrain.
t_translation::t_letter selected_fg_terrain() const;
/// Return the currently selected background terrain.
t_translation::t_letter selected_bg_terrain() const;
/// Select a foreground terrain.
void select_fg_terrain(t_translation::t_letter);
void select_bg_terrain(t_translation::t_letter);
@ -65,7 +83,6 @@ public:
virtual void handle_event(const SDL_Event& event);
void set_dirty(bool dirty=true);
/// Return the number of terrains in the palette.
size_t num_terrains() const;
@ -73,6 +90,9 @@ public:
/// changed.
void adjust_size();
/// sets the tooltips used in the palette
void load_tooltips();
private:
void draw_old(bool);
/// To be called when a mouse click occurs. Check if the coordinates
@ -95,7 +115,20 @@ private:
const size_specs &size_specs_;
display &gui_;
unsigned int tstart_;
t_translation::t_list terrains_;
//this map contains all editor_group as defined in terrain.cfg and
//associate with the group there. The group all is added automatically
//and all terrains are also automatically stored in this group
std::map<std::string, t_translation::t_list> terrain_map_;
// a copy from the terrain_map_->second for the current active group
t_translation::t_list terrains_;
//the editor_groups as defined in editor-groups.cfg, note the
//user must make sure the id's here are the same as the
//editor_group in terrain.cfg
std::vector<terrain_group> terrain_groups_;
t_translation::t_letter selected_fg_terrain_, selected_bg_terrain_;
const gamemap &map_;
gui::button top_button_, bot_button_;

View file

@ -129,6 +129,8 @@ terrain_type::terrain_type(const config& cfg)
income_description_own_ = _("Owned village");
}
}
editor_group_ = cfg["editor_group"];
}
void create_terrain_maps(const std::vector<config*>& cfgs,

View file

@ -59,6 +59,8 @@ public:
const t_string& income_description_enemy() const { return income_description_enemy_; }
const t_string& income_description_own() const { return income_description_own_; }
const std::string& editor_group() const { return editor_group_; }
private:
std::string symbol_image_;
std::string id_;
@ -85,6 +87,8 @@ private:
t_string income_description_ally_;
t_string income_description_enemy_;
t_string income_description_own_;
std::string editor_group_;
};
void create_terrain_maps(const std::vector<config*>& cfgs,