editor2: make editor2 use the palette, also what seems to fix one crash

This commit is contained in:
Tomasz Śniatowski 2008-07-25 22:52:29 +01:00
parent 3a0b701718
commit 4381208291
3 changed files with 35 additions and 17 deletions

View File

@ -47,8 +47,8 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
init(video);
size_specs_ = new size_specs();
adjust_sizes(gui(), *size_specs_);
palette_ = new terrain_palette(gui(), *size_specs_, map_, game_config);
// foreground_terrain(), background_terrain());
palette_ = new terrain_palette(gui(), *size_specs_, map_, game_config,
foreground_terrain(), background_terrain());
//brush_bar_ = new brush_bar(gui(), *size_specs_);
brushes_.push_back(brush());
@ -68,6 +68,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
cursor::set(cursor::NORMAL);
gui_->invalidate_game_status();
palette_->adjust_size();
refresh_all();
gui_->draw();
events::raise_draw_event();
@ -85,6 +86,8 @@ void editor_controller::init(CVideo& video)
editor_controller::~editor_controller()
{
delete palette_;
delete size_specs_;
delete gui_;
typedef std::pair<hotkey::HOTKEY_COMMAND, mouse_action*> apr;
foreach (apr a, mouse_actions_) {
@ -444,7 +447,6 @@ void editor_controller::refresh_after_action(const editor_action& /*action*/)
void editor_controller::refresh_all()
{
adjust_sizes(gui(), *size_specs_);
palette_->adjust_size();
//brush_bar_->adjust_size();
palette_->draw(true);
//brush_bar_->draw(true);

View File

@ -23,6 +23,7 @@
#include "../config.hpp"
#include "../sdl_utils.hpp"
#include "../serialization/string_utils.hpp"
#include "../foreach.hpp"
#include "../image.hpp"
#include "../reports.hpp"
#include "../gettext.hpp"
@ -45,11 +46,14 @@ terrain_group::terrain_group(const config& cfg, display& gui):
}
terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map, const config& cfg)
const gamemap &map, const config& cfg,
t_translation::t_terrain& fore,
t_translation::t_terrain& back)
: gui::widget(gui.video()), size_specs_(sizes), gui_(gui), tstart_(0),
checked_group_btn_(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"),
selected_fg_terrain_(fore), selected_bg_terrain_(back)
{
// Get the available terrains temporary in terrains_
@ -84,6 +88,7 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
// add the terrain to the requested groups
const std::vector<std::string>& key =
utils::split(t_info.editor_group());
std::cerr << t_info.editor_group() << "\n";
for(std::vector<std::string>::const_iterator k_itor = key.begin();
k_itor != key.end(); ++k_itor)
@ -94,6 +99,10 @@ terrain_palette::terrain_palette(display &gui, const size_specs &sizes,
// Add the terrain to the default group
terrain_map_["all"].push_back(*t_itor);
}
typedef std::pair<std::string, t_translation::t_list> map_pair;
foreach (map_pair mp, terrain_map_) {
std::cerr << mp.first << mp.second.size() << "\n";
}
// Set the default group
terrains_ = terrain_map_["all"];
@ -344,25 +353,29 @@ void terrain_palette::handle_event(const SDL_Event& event) {
}
void terrain_palette::draw(bool force) {
if (top_button_.pressed()) {
scroll_up();
}
if (bot_button_.pressed()) {
scroll_down();
}
for(size_t i = 0; i < terrain_groups_.size(); ++i) {
if(terrain_groups_[i].button.pressed()) {
if(&terrain_groups_[i].button == checked_group_btn_) {
checked_group_btn_->set_check(true);
} else {
checked_group_btn_->set_check(false);
checked_group_btn_ = &terrain_groups_[i].button;
set_group(terrain_groups_[i].id);
}
foreach (terrain_group& g, terrain_groups_) {
if (g.button.pressed()) {
checked_group_btn_ = &g.button;
set_group(g.id);
break;
}
}
foreach (terrain_group& g, terrain_groups_) {
if (&g.button == checked_group_btn_) {
g.button.set_check(true);
} else {
g.button.set_check(false);
}
}
if (!dirty() && !force) {
return;
}

View File

@ -49,7 +49,9 @@ struct terrain_group
class terrain_palette : public gui::widget {
public:
terrain_palette(display &gui, const size_specs &sizes,
const gamemap &map, const config& cfg);
const gamemap &map, const config& cfg,
t_translation::t_terrain& fore,
t_translation::t_terrain& back);
//! Scroll the terrain-palette up one step if possible.
void scroll_up();
@ -139,11 +141,12 @@ private:
//! otherwise things will fail. Thus should be set in constructor.
gui::button *checked_group_btn_;
t_translation::t_terrain selected_fg_terrain_, selected_bg_terrain_;
const gamemap &map_;
gui::button top_button_, bot_button_;
size_t button_x_, top_button_y_, bot_button_y_;
size_t nterrains_, terrain_start_;
t_translation::t_terrain& selected_fg_terrain_;
t_translation::t_terrain& selected_bg_terrain_;
};
//! A bar where the brush is drawn