Add a new proof-of-concept generic widget.

This widget will need some more changes to be able to replace the current
dialogs shown to the user. Only replaced one place where widgets are used in
order to test the dialog.
This commit is contained in:
Mark de Wever 2008-09-21 11:22:24 +00:00
parent cef0564be8
commit af362c7832
10 changed files with 212 additions and 1 deletions

View file

@ -316,3 +316,69 @@
[/window]
#undef RESOLUTION_RIGHT
[window]
id = "message"
description = "Message dialog with 1 ok button for now."
[resolution]
definition = "default"
[grid]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "title"
definition = "title"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[scroll_label]
id = "label"
definition = "default"
[/scroll_label]
[/column]
[/row]
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "center"
[button]
id = "ok"
definition = "default"
label = "close"
[/button]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -8,6 +8,7 @@ src/game_preferences_display.cpp
src/gui/dialogs/addon_connect.cpp
src/gui/dialogs/dialog.cpp
src/gui/dialogs/language_selection.cpp
src/gui/dialogs/message.cpp
src/gui/dialogs/mp_connect.cpp
src/gui/dialogs/mp_create_game.cpp
src/gui/dialogs/mp_method_selection.cpp

View file

@ -232,6 +232,7 @@ SET(wesnoth-main_SRC
gui/dialogs/addon_connect.cpp
gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/message.cpp
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp

View file

@ -75,6 +75,7 @@ wesnoth_source = \
gui/dialogs/addon_connect.cpp \
gui/dialogs/dialog.cpp \
gui/dialogs/language_selection.cpp \
gui/dialogs/message.cpp \
gui/dialogs/mp_connect.cpp \
gui/dialogs/mp_create_game.cpp \
gui/dialogs/mp_method_selection.cpp \

View file

@ -208,6 +208,7 @@ wesnoth_sources = Split("""
gui/dialogs/addon_connect.cpp
gui/dialogs/dialog.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/message.cpp
gui/dialogs/mp_connect.cpp
gui/dialogs/mp_create_game.cpp
gui/dialogs/mp_method_selection.cpp

View file

@ -27,6 +27,7 @@
#include "gettext.hpp"
#include "gui/dialogs/addon_connect.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/mp_method_selection.hpp"
#include "gui/widgets/window.hpp"
#include "log.hpp"
@ -1092,7 +1093,9 @@ namespace {
prepare_addons_list_for_display(addons, addon_dirs, parentdir);
if (addons.empty()) {
gui::show_error_message(disp, _("You have no add-ons installed."));
/** @todo should use a dialog which always shows the close button. */
gui2::show_message(disp.video(), _("Error"),
_("You have no add-ons installed."));
return;
}

View file

@ -0,0 +1,60 @@
/* $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/message.hpp"
#include "gui/widgets/label.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/window_builder.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/scroll_label.hpp"
#include "log.hpp"
#define DBG_GUI LOG_STREAM_INDENT(debug, gui)
#define LOG_GUI LOG_STREAM_INDENT(info, gui)
#define WRN_GUI LOG_STREAM_INDENT(warn, gui)
#define ERR_GUI LOG_STREAM_INDENT(err, gui)
namespace gui2 {
twindow tmessage::build_window(CVideo& video)
{
return build(video, get_id(MESSAGE));
}
void tmessage::pre_show(CVideo& /*video*/, twindow& window)
{
tlabel* title =
dynamic_cast<tlabel*>(window.find_widget("title", false));
VALIDATE(title, missing_widget("title"));
title->set_label(title_);
tcontrol* label =
dynamic_cast<tcontrol*>(window.find_widget("label", false));
VALIDATE(label, missing_widget("label"));
label->set_label(message_);
}
/** @todo the caption is ignored. */
void show_message(CVideo& video, const std::string& title,
const std::string& message, const std::string& /*button_caption*/)
{
tmessage(title, message).show(video);
}
} // namespace gui2

View file

@ -0,0 +1,76 @@
/* $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_MESSAGE_HPP_INCLUDED
#define GUI_DIALOGS_MESSAGE_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
namespace gui2 {
/**
* Main class to show messages to the user.
*
* It can be used to show a message or ask a result from the user. For the most
* common usage cases there are helper functions defined.
*/
class tmessage : public tdialog
{
public:
tmessage(const std::string& title, const std::string& message)
: title_(title)
, message_(message)
{}
/***** ***** ***** setters / getters for members ***** ****** *****/
void set_title(const std::string& title) { title_ = title; }
void set_message(const std::string& message) { message_ = message; }
private:
/** The title for the dialog. */
std::string title_;
/** The message to show to the user. */
std::string message_;
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
};
/**
* Shows a message to the user.
*
* Normally the dialog won't have a button only when the text doesn't fit in
* the dialog and a scrollbar is used the button will be shown.
*
* @todo Since the click close function isn't implemented yet a button is
* always shown.
*
* @param video The video which contains the surface to draw upon.
* @param title The title of the dialog.
* @param message The message to show in the dialog.
* @param button_caption The caption of the close button.
*/
void show_message(CVideo& video, const std::string& title,
const std::string& message, const std::string& button_caption = "");
} // namespace gui2
#endif

View file

@ -89,6 +89,7 @@ static void fill_window_types()
{
window_type_list[ADDON_CONNECT] = "addon_connect";
window_type_list[LANGUAGE_SELECTION] = "language_selection";
window_type_list[MESSAGE] = "message";
window_type_list[MP_CONNECT] = "mp_connect";
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
window_type_list[MP_SERVER_LIST] = "mp_server_list";

View file

@ -39,6 +39,7 @@ enum twindow_type {
TITLE_SCREEN, /**< The main title screen of the game. */
ADDON_CONNECT, /**< The addon server connection dialog. */
LANGUAGE_SELECTION, /**< The language selection dialog. */
MESSAGE, /**< A generic message dialog. */
MP_CONNECT, /**< The mp server connection dialog. */
MP_METHOD_SELECTION, /**<
* The dialog which allows you to choose the kind