Revert 2010-12-14T07:50:26Z!guillaume.melquiond@gmail.com.
This commit is contained in:
parent
f97da238a5
commit
228efb74c3
20 changed files with 358 additions and 8 deletions
|
@ -488,6 +488,7 @@ set(wesnoth-main_SRC
|
|||
playmp_controller.cpp
|
||||
playsingle_controller.cpp
|
||||
playturn.cpp
|
||||
portrait.cpp
|
||||
replay.cpp
|
||||
replay_controller.cpp
|
||||
resources.cpp
|
||||
|
|
|
@ -261,6 +261,7 @@ wesnoth_source = \
|
|||
playmp_controller.cpp \
|
||||
playsingle_controller.cpp \
|
||||
playturn.cpp \
|
||||
portrait.cpp \
|
||||
replay.cpp \
|
||||
replay_controller.cpp \
|
||||
resources.cpp \
|
||||
|
|
|
@ -237,6 +237,7 @@ wesnoth_sources = Split("""
|
|||
playmp_controller.cpp
|
||||
playsingle_controller.cpp
|
||||
playturn.cpp
|
||||
portrait.cpp
|
||||
replay.cpp
|
||||
replay_controller.cpp
|
||||
resources.cpp
|
||||
|
|
|
@ -735,6 +735,32 @@ void tdistributor::remove_tooltip()
|
|||
do_remove_tooltip();
|
||||
}
|
||||
|
||||
void tdistributor::show_help_popup(const t_string& message, const unsigned timeout)
|
||||
{
|
||||
DBG_GUI_E << "Event: show help popup.\n";
|
||||
|
||||
if(help_popup_) {
|
||||
DBG_GUI_E << "Help is already there, bailing out.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if(tooltip_) {
|
||||
remove_tooltip();
|
||||
}
|
||||
|
||||
// Kill hover events FIXME not documented.
|
||||
had_hover_ = true;
|
||||
hover_pending_ = false;
|
||||
|
||||
help_popup_ = mouse_focus_;
|
||||
|
||||
do_show_help_popup(tpoint(mouse_x_, mouse_y_), message);
|
||||
|
||||
if(timeout) {
|
||||
SDL_AddTimer(timeout, popup_callback, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void tdistributor::remove_help_popup()
|
||||
{
|
||||
if(!help_popup_) {
|
||||
|
|
|
@ -300,6 +300,18 @@ public:
|
|||
/** Removes the currently shown tooltip. */
|
||||
void remove_tooltip();
|
||||
|
||||
/**
|
||||
* Shows a help message.
|
||||
*
|
||||
* A help message is like a tooltip, but in general contains more info and
|
||||
* the user needs to trigger it (most of the time with the F1 button).
|
||||
*
|
||||
* @param message The message to show.
|
||||
* @param timeout The time the help message is shown, 0 means
|
||||
* forever.
|
||||
*/
|
||||
void show_help_popup(const t_string& message, const unsigned timeout);
|
||||
|
||||
/** Removes the currently show tooltip. */
|
||||
void remove_help_popup();
|
||||
|
||||
|
@ -358,6 +370,16 @@ private:
|
|||
/** Function to do the real removal of the tooltip. */
|
||||
virtual void do_remove_tooltip() = 0;
|
||||
|
||||
/**
|
||||
* The function to do the real job of showing the help popup.
|
||||
*
|
||||
* @param location The location in the window where to show the
|
||||
* help popup.
|
||||
* @param help_popup The message to show.
|
||||
*/
|
||||
virtual void do_show_help_popup(
|
||||
const tpoint& location, const t_string& help_popup) = 0;
|
||||
|
||||
/** Function to do the real removal of the help popup. */
|
||||
virtual void do_remove_help_popup() = 0;
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
|
||||
#define GETTEXT_DOMAIN "wesnoth-lib"
|
||||
|
||||
#include "gui/auxiliary/window_builder_private.hpp"
|
||||
|
||||
#include "asserts.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "gettext.hpp"
|
||||
|
@ -472,6 +474,14 @@ tbuilder_grid::tbuilder_grid(const config& cfg) :
|
|||
<< rows << " rows and " << cols << " columns.\n";
|
||||
}
|
||||
|
||||
tbuilder_gridcell::tbuilder_gridcell(const config& cfg) :
|
||||
tbuilder_widget(cfg),
|
||||
flags(implementation::read_flags(cfg)),
|
||||
border_size(cfg["border_size"]),
|
||||
widget(create_builder_widget(cfg))
|
||||
{
|
||||
}
|
||||
|
||||
twidget* tbuilder_grid::build() const
|
||||
{
|
||||
return build(new tgrid());
|
||||
|
|
57
src/gui/auxiliary/window_builder_private.hpp
Normal file
57
src/gui/auxiliary/window_builder_private.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2010 by Mark de Wever <koraq@xs4all.nl>
|
||||
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
|
||||
* This file contains all classes used privately in window_builder.cpp and
|
||||
* should only be included by window_builder.cpp.
|
||||
*/
|
||||
|
||||
#ifndef GUI_AUXILIARY_WINDOW_BUILDER_PRIVATE_HPP_INCLUDED
|
||||
#define GUI_AUXILIARY_WINDOW_BUILDER_PRIVATE_HPP_INCLUDED
|
||||
|
||||
#include "gui/auxiliary/window_builder.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
/**
|
||||
* A temporary helper class.
|
||||
*
|
||||
* @todo refactor with the grid builder.
|
||||
*/
|
||||
struct tbuilder_gridcell
|
||||
: public tbuilder_widget
|
||||
{
|
||||
explicit tbuilder_gridcell(const config& cfg);
|
||||
|
||||
/** The flags for the cell. */
|
||||
unsigned flags;
|
||||
|
||||
/** The bordersize for the cell. */
|
||||
unsigned border_size;
|
||||
|
||||
/** The widgets for the cell. */
|
||||
tbuilder_widget_ptr widget;
|
||||
|
||||
/** We're a dummy the building is done on construction. */
|
||||
twidget* build () const { return NULL; }
|
||||
};
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
@ -1030,6 +1030,17 @@ void tgrid_implementation::cell_request_reduce_width(
|
|||
maximum_width - child.border_space().x);
|
||||
}
|
||||
|
||||
void set_single_child(tgrid& grid, twidget* widget)
|
||||
{
|
||||
grid.set_rows_cols(1, 1);
|
||||
grid.set_child(widget
|
||||
, 0
|
||||
, 0
|
||||
, tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
| tgrid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
, 0);
|
||||
}
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
|
||||
|
|
|
@ -427,6 +427,17 @@ private:
|
|||
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the single child in a grid.
|
||||
*
|
||||
* The function initializes the grid to 1 x 1 and adds the widget with the grow
|
||||
* to client flags.
|
||||
*
|
||||
* @param grid The grid to add the child to.
|
||||
* @param widget The widget to add as child to the grid.
|
||||
*/
|
||||
void set_single_child(tgrid& grid, twidget* widget);
|
||||
|
||||
} // namespace gui2
|
||||
|
||||
#endif
|
||||
|
|
|
@ -343,16 +343,15 @@ void tlist::init()
|
|||
{
|
||||
init_grid(cast<tlistbox_definition::tresolution>(config()).grid);
|
||||
|
||||
tgrid *g = find_widget<tgrid>(&grid(), "_list_grid", false, true);
|
||||
g->set_rows_cols(1, 1);
|
||||
g->set_child(generator_, 0, 0, tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT |
|
||||
tgrid::VERTICAL_GROW_SEND_TO_CLIENT, 0);
|
||||
set_single_child(
|
||||
find_widget<tgrid>(&grid(), "_list_grid", false)
|
||||
, generator_);
|
||||
|
||||
/*
|
||||
* These items should be managed by the new listbox class.
|
||||
* So make them invisible for now.
|
||||
*/
|
||||
g = find_widget<tgrid>(&grid(), "_header_grid", false, false);
|
||||
tgrid* g = find_widget<tgrid>(&grid(), "_header_grid", false, false);
|
||||
if(g) g->set_visible(twidget::INVISIBLE);
|
||||
|
||||
g = find_widget<tgrid>(&grid(), "_footer_grid", false, false);
|
||||
|
|
|
@ -234,6 +234,25 @@ void tlistbox::list_item_clicked(twidget* caller)
|
|||
assert(false);
|
||||
}
|
||||
|
||||
bool tlistbox::update_content_size()
|
||||
{
|
||||
if(get_visible() == twidget::INVISIBLE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if(get_size() == tpoint(0, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(content_resize_request(true)) {
|
||||
content_grid_->set_visible_area(content_visible_area());
|
||||
set_dirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void tlistbox::place(const tpoint& origin, const tpoint& size)
|
||||
{
|
||||
// Inherited.
|
||||
|
|
|
@ -179,6 +179,22 @@ public:
|
|||
// { state_ = active ? ENABLED : DISABLED; }
|
||||
//
|
||||
|
||||
/**
|
||||
* Request to update the size of the content after changing the content.
|
||||
*
|
||||
* When a resize is required the container first can try to handle it
|
||||
* itself. If it can't honour the request the function will call @ref
|
||||
* twindow::invalidate_layout().
|
||||
*
|
||||
* @note Calling this function on a widget with size == (0, 0) results
|
||||
* false but doesn't call invalidate_layout, the engine expects to be in
|
||||
* build up phase with the layout already invalidated.
|
||||
*
|
||||
* @returns True if the resizing succeeded, false
|
||||
* otherwise.
|
||||
*/
|
||||
bool update_content_size();
|
||||
|
||||
/***** ***** ***** ***** inherited ***** ***** ****** *****/
|
||||
|
||||
/** Inherited from tscrollbar_container. */
|
||||
|
|
|
@ -1021,6 +1021,49 @@ void twindow::do_remove_tooltip()
|
|||
tooltip_.set_visible(twidget::HIDDEN);
|
||||
}
|
||||
|
||||
void twindow::do_show_help_popup(const tpoint& location, const t_string& help_popup)
|
||||
{
|
||||
// Note copy past of twindow::do_show_tooltip except that the help may be empty.
|
||||
DBG_GUI_G << LOG_HEADER << " message: '" << help_popup << "'.\n";
|
||||
|
||||
if(help_popup.empty()) {
|
||||
return;
|
||||
}
|
||||
twidget* widget = find_at(location, true);
|
||||
assert(widget);
|
||||
|
||||
const SDL_Rect widget_rect = widget->get_rect();
|
||||
const SDL_Rect client_rect = get_client_rect();
|
||||
|
||||
help_popup_.set_label(help_popup);
|
||||
const tpoint size = help_popup_.get_best_size();
|
||||
|
||||
SDL_Rect help_popup_rect = ::create_rect(0, 0, size.x, size.y);
|
||||
|
||||
// Find the best position to place the widget
|
||||
if(widget_rect.y - size.y > 0) {
|
||||
// put above
|
||||
help_popup_rect.y = widget_rect.y - size.y;
|
||||
} else {
|
||||
//put below no test
|
||||
help_popup_rect.y = widget_rect.y + widget_rect.h;
|
||||
}
|
||||
|
||||
if(widget_rect.x + size.x < client_rect.w) {
|
||||
// Directly above the mouse
|
||||
help_popup_rect.x = widget_rect.x;
|
||||
} else {
|
||||
// shift left, no test
|
||||
help_popup_rect.x = client_rect.w - size.x;
|
||||
}
|
||||
|
||||
help_popup_.place(
|
||||
tpoint(help_popup_rect.w, help_popup_rect.h),
|
||||
tpoint(help_popup_rect.x, help_popup_rect.y));
|
||||
|
||||
help_popup_.set_visible(twidget::VISIBLE);
|
||||
}
|
||||
|
||||
bool twindow::click_dismiss()
|
||||
{
|
||||
if(does_click_dismiss()) {
|
||||
|
|
|
@ -531,8 +531,11 @@ public:
|
|||
|
||||
/** Inherited from tevent_handler. */
|
||||
void do_remove_tooltip();
|
||||
|
||||
private:
|
||||
|
||||
/** Inherited from tevent_handler. */
|
||||
void do_show_help_popup(const tpoint& location, const t_string& help_popup);
|
||||
|
||||
/** Inherited from tevent_handler. */
|
||||
void do_remove_help_popup()
|
||||
{ help_popup_.set_visible(twidget::HIDDEN); }
|
||||
|
|
50
src/portrait.cpp
Normal file
50
src/portrait.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2010 by mark de wever <koraq@xs4all.nl>
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "portrait.hpp"
|
||||
|
||||
#include "config.hpp"
|
||||
#include "log.hpp"
|
||||
#include "serialization/string_utils.hpp"
|
||||
#include "util.hpp"
|
||||
#include "wml_exception.hpp"
|
||||
|
||||
static lg::log_domain log_config("config");
|
||||
#define WRN_CF LOG_STREAM(warn, log_config)
|
||||
|
||||
static tportrait::tside get_side(const std::string& side)
|
||||
{
|
||||
if(side == "both") {
|
||||
return tportrait::BOTH;
|
||||
} else if(side == "right") {
|
||||
return tportrait::RIGHT;
|
||||
} else if(side == "left") {
|
||||
return tportrait::LEFT;
|
||||
} else {
|
||||
WRN_CF << "Unknown portrait side '" << side << "' defaulting to left.\n";
|
||||
return tportrait::LEFT;
|
||||
}
|
||||
}
|
||||
|
||||
tportrait::tportrait(const config& cfg) :
|
||||
image(cfg["image"]),
|
||||
side(get_side(cfg["side"])),
|
||||
size(lexical_cast_default<unsigned>(cfg["size"])),
|
||||
mirror(utils::string_bool(cfg["mirror"]))
|
||||
{
|
||||
VALIDATE(!image.empty(), missing_mandatory_wml_key("portrait", "image"));
|
||||
VALIDATE(size != 0, missing_mandatory_wml_key("portrait", "size"));
|
||||
}
|
||||
|
42
src/portrait.hpp
Normal file
42
src/portrait.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 - 2010 by mark de wever <koraq@xs4all.nl>
|
||||
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 PORTRAIT_HPP_INCLUDED
|
||||
#define PORTRAIT_HPP_INCLUDED
|
||||
|
||||
class config;
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @todo this is a proof-of-concept version and undocumented. It should be
|
||||
* documented later and also allow WML to modify the portraits. This all
|
||||
* starts to make sense when the new dialogs become mainline.
|
||||
*/
|
||||
|
||||
/** Contains the definition of a portrait for a unit(type). */
|
||||
struct tportrait {
|
||||
|
||||
tportrait(const config& cfg);
|
||||
|
||||
enum tside { LEFT, RIGHT, BOTH };
|
||||
|
||||
std::string image;
|
||||
tside side;
|
||||
unsigned size;
|
||||
bool mirror;
|
||||
};
|
||||
|
||||
#endif
|
14
src/unit.cpp
14
src/unit.cpp
|
@ -2879,6 +2879,20 @@ std::string unit::image_mods() const{
|
|||
return modifier.str();
|
||||
}
|
||||
|
||||
const tportrait* unit::portrait(
|
||||
const unsigned size, const tportrait::tside side) const
|
||||
{
|
||||
foreach(const tportrait& portrait, (type()->portraits())) {
|
||||
if(portrait.size == size
|
||||
&& (side == portrait.side || portrait.side == tportrait::BOTH)) {
|
||||
|
||||
return &portrait;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void unit::remove_attacks_ai()
|
||||
{
|
||||
if (attacks_left_ == max_attacks_) {
|
||||
|
|
12
src/unit.hpp
12
src/unit.hpp
|
@ -321,6 +321,18 @@ public:
|
|||
std::string TC_image_mods() const;
|
||||
std::string image_mods() const;
|
||||
|
||||
/**
|
||||
* Gets the portrait for a unit.
|
||||
*
|
||||
* @param size The size of the portrait.
|
||||
* @param side The side the portrait is shown on.
|
||||
*
|
||||
* @returns The portrait with the wanted size.
|
||||
* @retval NULL The wanted portrait doesn't exist.
|
||||
*/
|
||||
const tportrait* portrait(
|
||||
const unsigned size, const tportrait::tside side) const;
|
||||
|
||||
private:
|
||||
void advance_to(const config &old_cfg, const unit_type *t,
|
||||
bool use_traits, game_state *state);
|
||||
|
|
|
@ -584,7 +584,8 @@ unit_type::unit_type(const unit_type& o) :
|
|||
possibleTraits_(o.possibleTraits_),
|
||||
genders_(o.genders_),
|
||||
animations_(o.animations_),
|
||||
build_status_(o.build_status_)
|
||||
build_status_(o.build_status_),
|
||||
portraits_(o.portraits_)
|
||||
{
|
||||
gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL;
|
||||
gender_types_[1] = o.gender_types_[1] != NULL ? new unit_type(*o.gender_types_[1]) : NULL;
|
||||
|
@ -629,7 +630,8 @@ unit_type::unit_type(config &cfg) :
|
|||
possibleTraits_(),
|
||||
genders_(),
|
||||
animations_(),
|
||||
build_status_(NOT_BUILT)
|
||||
build_status_(NOT_BUILT),
|
||||
portraits_()
|
||||
{
|
||||
gender_types_[0] = NULL;
|
||||
gender_types_[1] = NULL;
|
||||
|
@ -737,6 +739,10 @@ void unit_type::build_full(const movement_type_map &mv_types,
|
|||
game_config::add_color_info(cfg);
|
||||
|
||||
|
||||
foreach (const config &portrait, cfg_.child_range("portrait")) {
|
||||
portraits_.push_back(tportrait(portrait));
|
||||
}
|
||||
|
||||
// Deprecation messages, only seen when unit is parsed for the first time.
|
||||
|
||||
build_status_ = FULL;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define UNIT_TYPES_H_INCLUDED
|
||||
|
||||
#include "unit_animation.hpp"
|
||||
#include "portrait.hpp"
|
||||
#include "race.hpp"
|
||||
|
||||
class gamemap;
|
||||
|
@ -283,6 +284,8 @@ public:
|
|||
|
||||
BUILD_STATUS build_status() const { return build_status_; }
|
||||
|
||||
const std::vector<tportrait>& portraits() const { return portraits_; }
|
||||
|
||||
const config &get_cfg() const { return cfg_; }
|
||||
|
||||
private:
|
||||
|
@ -338,6 +341,9 @@ private:
|
|||
mutable std::vector<unit_animation> animations_;
|
||||
|
||||
BUILD_STATUS build_status_;
|
||||
|
||||
/** List with the portraits available for the unit. */
|
||||
std::vector<tportrait> portraits_;
|
||||
};
|
||||
|
||||
class unit_type_data
|
||||
|
|
Loading…
Add table
Reference in a new issue