Improved the new ingame dialogs with portrait.

The code can now show a scrollbar if the text doesn't fit like the normal
dialog. (Note there's a redraw glitch which turns most of the dialog black.)
Also updated the changelog.
This commit is contained in:
Mark de Wever 2008-11-25 19:07:06 +00:00
parent 0abea5549f
commit 2bb2da1e80
13 changed files with 234 additions and 48 deletions

View file

@ -16,6 +16,8 @@ Version 1.5.6+svn:
* Tweaked the algorithm that extends the darkened area below long
story texts so that it gives a more consistent appearance.
* Added a border and blurring to story screens' text blocks.
* Improved wrapping in the new widgets.
* Improved easy close handling.
Version 1.5.6:
* Authoring tools:

View file

@ -94,7 +94,7 @@
)#enddef
[window_definition]
id = "message_test_left"
id = "wml_message_left"
description = "bar"
[resolution]
@ -129,7 +129,7 @@
[/window_definition]
[window_definition]
id = "message_test_right"
id = "wml_message_right"
description = "bar"
[resolution]
@ -227,7 +227,7 @@
window_width = {WIDTH}
window_height = {HEIGHT}
definition = "message_test_left"
definition = "wml_message_left"
automatic_placement = "false"
@ -309,14 +309,14 @@
[window]
id = "message_test_left"
description = "Test dialog to test Jetryl's new message style and Kitty's portraits."
id = "wml_message_left"
description = "Dialog showing a unit portrait on the left side"
[resolution]
window_width = 0
window_height = 0
definition = "message_test_left"
definition = "wml_message_left"
automatic_placement = "false"
@ -362,16 +362,66 @@
[/column]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[grid]
[scroll_label]
id = "message"
definition = "default"
[/scroll_label]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
[/label]
[/column]
[/row]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[scroll_label] # NOTE maybe change the code to use message instead of label as id
id = "label"
definition = "default"
[/scroll_label]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
# This button will be shown or hidden depending on the
# whether or not a scrollbar is needed to show the
# text.
id = "ok"
definition = "default"
label = "close"
[/button]
[/column]
[/row]
[/grid]
[/column]
@ -404,7 +454,7 @@
window_width = {WIDTH}
window_height = {HEIGHT}
definition = "message_test_right"
definition = "wml_message_right"
automatic_placement = "false"
@ -485,7 +535,7 @@
#enddef
[window]
id = "message_test_right"
id = "wml_message_right"
description = "Test dialog to test Jetryl's new message style and Kitty's portraits."
{RESOLUTION_RIGHT 1000 700 250}
{RESOLUTION_RIGHT 0 0 500}

View file

@ -12,6 +12,7 @@ src/gui/dialogs/mp_connect.cpp
src/gui/dialogs/mp_create_game.cpp
src/gui/dialogs/mp_method_selection.cpp
src/gui/dialogs/title_screen.cpp
src/gui/dialogs/wml_message.cpp
src/gui/widgets/button.cpp
src/gui/widgets/canvas.cpp
src/gui/widgets/control.cpp

View file

@ -228,6 +228,7 @@ SET(wesnoth-main_SRC
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp

View file

@ -76,6 +76,7 @@ wesnoth_source = \
gui/dialogs/mp_create_game.cpp \
gui/dialogs/mp_method_selection.cpp \
gui/dialogs/title_screen.cpp \
gui/dialogs/wml_message.cpp \
gui/widgets/button.cpp \
gui/widgets/debug.cpp \
gui/widgets/canvas.cpp \

View file

@ -214,6 +214,7 @@ wesnoth_sources = Split("""
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp
gui/dialogs/title_screen.cpp
gui/dialogs/wml_message.cpp
gui/widgets/button.cpp
gui/widgets/canvas.cpp
gui/widgets/control.cpp

View file

@ -25,8 +25,9 @@
#include "game_events.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/widgets/spacer.hpp"
#include "gui/widgets/window.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/widgets/settings.hpp"
#include "log.hpp"
#include "map.hpp"
#include "map_label.hpp"
#include "map_exception.hpp"
@ -34,6 +35,7 @@
#include "sound.hpp"
#include "terrain_filter.hpp"
#include "unit_display.hpp"
#include "wml_exception.hpp"
#include <boost/scoped_ptr.hpp>
@ -2891,23 +2893,11 @@ namespace {
const tportrait* portrait =
speaker->second.portrait(400, tportrait::LEFT);
if(portrait) {
gui2::twindow window =
gui2::build((screen)->video(), "message_test_left");
const t_string message = cfg["message"];
const std::string image = portrait ? portrait->image : "";
const bool mirror = portrait ? portrait->mirror : false;
window.canvas(1).set_variable("portrait_image", variant(image));
window.canvas(1).set_variable("portrait_mirror", variant(mirror));
gui2::tcontrol* label = dynamic_cast<gui2::tcontrol*>(window.find_widget("message", false));
assert(label);
label->set_label(message);
window.show();
gui2::twml_message_left (
caption,
cfg["message"],
portrait->image,
portrait->mirror).show(screen->video());
return;
}
}

View file

@ -21,11 +21,6 @@
namespace gui2 {
twindow tmessage::build_window(CVideo& video)
{
return build(video, get_id(MESSAGE));
}
void tmessage::pre_show(CVideo& /*video*/, twindow& window)
{
if(!title_.empty()) {
@ -77,6 +72,11 @@ void tmessage::pre_show(CVideo& /*video*/, twindow& window)
}
}
twindow tmessage::build_window(CVideo& video)
{
return build(video, get_id(MESSAGE));
}
/** @todo the caption is ignored. */
void show_message(CVideo& video, const std::string& title,
const std::string& message, const std::string& /*button_caption*/,

View file

@ -44,6 +44,10 @@ public:
void set_message(const std::string& message) { message_ = message; }
protected:
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
private:
/** The title for the dialog. */
std::string title_;
@ -66,9 +70,6 @@ private:
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
};
/**

View file

@ -0,0 +1,41 @@
/* $Id$ */
/*
copyright (c) 2008 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 version 2
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 "gui/dialogs/wml_message.hpp"
#include "gui/widgets/window.hpp"
namespace gui2 {
void twml_message_::pre_show(CVideo& video, twindow& window)
{
// Inherited.
tmessage::pre_show(video, window);
window.canvas(1).set_variable("portrait_image", variant(portrait_));
window.canvas(1).set_variable("portrait_mirror", variant(mirror_));
}
twindow twml_message_left::build_window(CVideo& video)
{
return build(video, get_id(WML_MESSAGE_LEFT));
}
twindow twml_message_right::build_window(CVideo& video)
{
return build(video, get_id(WML_MESSAGE_RIGHT));
}
} // namespace gui2

View file

@ -0,0 +1,88 @@
/* $Id$ */
/*
copyright (c) 2008 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 version 2
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 GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
#define GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
#include "gui/dialogs/message.hpp"
namespace gui2 {
/**
* Base class for the wml generated messages.
*
* We have a separate sub class for left and right images.
*/
class twml_message_ : public tmessage
{
public:
twml_message_(const std::string& title, const std::string& message,
const std::string portrait, const bool mirror)
: tmessage(title, message, true)
, portrait_(portrait)
, mirror_(mirror)
{
}
private:
/** Filename of the portrait. */
std::string portrait_;
/** Mirror the portrait? */
bool mirror_;
/**
* Inherited from tmessage.
*
* The subclasses need to implement the left or right definition.
*/
twindow build_window(CVideo& /*video*/) = 0;
/** Inherited from tmessage. */
void pre_show(CVideo& video, twindow& window);
};
/** Shows a dialog with the portrait on the left side. */
class twml_message_left : public twml_message_
{
public:
twml_message_left(const std::string& title, const std::string& message,
const std::string portrait, const bool mirror)
: twml_message_(title, message, portrait, mirror)
{
}
private:
/** Inherited from twml_message_. */
twindow build_window(CVideo& video);
};
/** Shows a dialog with the portrait on the right side. */
class twml_message_right : public twml_message_
{
public:
twml_message_right(const std::string& title, const std::string& message,
const std::string portrait, const bool mirror)
: twml_message_(title, message, portrait, mirror)
{
}
private:
/** Inherited from twml_message_. */
twindow build_window(CVideo& video);
};
} // namespace gui2
#endif

View file

@ -62,6 +62,8 @@ static void fill_window_types()
{
window_type_list[ADDON_CONNECT] = "addon_connect";
window_type_list[LANGUAGE_SELECTION] = "language_selection";
window_type_list[WML_MESSAGE_LEFT] = "wml_message_left";
window_type_list[WML_MESSAGE_RIGHT] = "wml_message_right";
window_type_list[MESSAGE] = "message";
window_type_list[MP_CONNECT] = "mp_connect";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";

View file

@ -40,23 +40,31 @@ enum twindow_type {
ADDON_CONNECT, /**< The addon server connection dialog. */
LANGUAGE_SELECTION, /**< The language selection dialog. */
MESSAGE, /**< A generic message dialog. */
WML_MESSAGE_LEFT, /**<
* A WML message dialog with the portrait on
* the left side.
*/
WML_MESSAGE_RIGHT, /**<
* A WML message dialog with the portrait on
* the right side.
*/
MP_CONNECT, /**< The mp server connection dialog. */
MP_METHOD_SELECTION, /**<
* The dialog which allows you to choose the kind
* mp game the user wants to play.
*/
*/
MP_SERVER_LIST, /**< The mp server list dialog. */
MP_CREATE_GAME, /**< The mp creation dialog. */
#ifndef DISABLE_EDITOR2
EDITOR_NEW_MAP, /**< New map dialog. */
EDITOR_GENERATE_MAP, /**< Editor random map genarator dialog. */
EDITOR_RESIZE_MAP, /**< Editor resize map dialog. */
EDITOR_SETTINGS, /**< Editor settings dialog. */
EDITOR_RESIZE_MAP, /**< Editor resize map dialog. */
EDITOR_SETTINGS, /**< Editor settings dialog. */
#endif
COUNT /**<
* The last one to hold the number of items and as
* sentinel.
*/
* The last one to hold the number of items and as
* sentinel.
*/
};
const std::string& get_id(const twindow_type window_type);