Add a new title screen.

Now that all 'stable' --new-widgets code has been moved to the default way
starting with --new-widgets is no longer needed unless you want to develop for
it. So the new proof-of-concept title screen can be committed. Only has the
basic buttons which work, but needs some cleanup up, both in looks and code
working.
This commit is contained in:
Mark de Wever 2008-08-24 19:27:53 +00:00
parent 71a66eaf11
commit a5abf58f2c
12 changed files with 329 additions and 6 deletions

View file

@ -0,0 +1,120 @@
###
### Definition of the main screen for Wesnoth.
###
[window_definition]
id = "title_screen"
description = "The window definition for the title screen."
[resolution]
[background]
[draw]
[image]
x = 0
y = 0
w = "(width)"
h = "(height)"
name = "(background_image)"
[/image]
[text]
x = 0
y = "(height - text_height)"
w = "(text_width)"
h = "(text_height)"
font_size = 16
font_colour = "255, 255, 255, 128"
text = "(revision_number)"
[/text]
[/draw]
[/background]
[foreground]
[draw]
[/draw]
[/foreground]
[/resolution]
[/window_definition]
#define GUI_TIP_SECTION
#enddef
#define GUI_BUTTON ID CAPTION
[row]
[column]
border = "all"
border_size = 5
horizontal_alignment = "left"
[button]
id = {ID}
definition = "default"
label = {CAPTION}
[/button]
[/column]
[/row]
#enddef
#define MENU_SECTION
[grid]
{GUI_BUTTON "tutorial" _"Tutorial"}
{GUI_BUTTON "campaign" _"Campaign"}
{GUI_BUTTON "multiplayer" _"Multiplayer"}
{GUI_BUTTON "load" _"Load"}
{GUI_BUTTON "addons" _"Add-ons"}
{GUI_BUTTON "editor" _"Editor"}
{GUI_BUTTON "language" _"Language"}
{GUI_BUTTON "preferences" _"Preferences"}
{GUI_BUTTON "credits" _"Credits"}
{GUI_BUTTON "quit" _"Quit"}
[/grid]
#enddef
[window]
id = "title_screen"
description = "MP create game dialog."
[resolution]
definition = "title_screen"
automatic_placement = "false"
x = 0
y = 0
width = "(screen_width)"
height = "(screen_height)"
[grid]
[row]
[column]
{MENU_SECTION}
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef GUI_TIP_SECTION
#undef MENU_SECTION
#undef GUI_BUTTON

View file

@ -11,6 +11,7 @@ src/gui/dialogs/language_selection.cpp
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/widgets/button.cpp
src/gui/widgets/canvas.cpp
src/gui/widgets/control.cpp

View file

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

View file

@ -78,6 +78,7 @@ wesnoth_source = \
gui/dialogs/mp_connect.cpp \
gui/dialogs/mp_create_game.cpp \
gui/dialogs/mp_method_selection.cpp \
gui/dialogs/title_screen.cpp \
gui/widgets/button.cpp \
gui/widgets/canvas.cpp \
gui/widgets/control.cpp \

View file

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

View file

@ -34,6 +34,7 @@
#include "gui/dialogs/addon_connect.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/dialogs/mp_method_selection.hpp"
#include "gui/dialogs/title_screen.hpp"
#include "gui/widgets/window.hpp"
#include "help.hpp"
#include "hotkeys.hpp"
@ -2158,11 +2159,20 @@ static int play_game(int argc, char** argv)
gui::TITLE_RESULT res = game.is_loading() ? gui::LOAD_GAME : gui::NOTHING;
while(res == gui::NOTHING) {
res = gui::show_title(game.disp(),tips_of_day);
if (res == gui::REDRAW_BACKGROUND) {
gui::set_background_dirty();
res = gui::NOTHING;
if(gui2::new_widgets) {
cursor::set(cursor::NORMAL); // does a window need a cursor manager as well???
gui2::ttitle_screen dlg;
dlg.show(game.disp().video());
res = static_cast<gui::TITLE_RESULT>(dlg.get_retval());
} else {
while(res == gui::NOTHING) {
res = gui::show_title(game.disp(),tips_of_day);
if (res == gui::REDRAW_BACKGROUND) {
gui::set_background_dirty();
res = gui::NOTHING;
}
}
}

View file

@ -0,0 +1,100 @@
/* $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/title_screen.hpp"
#include "game_config.hpp"
#include "gettext.hpp"
#include "gui/dialogs/addon_connect.hpp"
#include "gui/dialogs/language_selection.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/widget.hpp"
#include "gui/widgets/window.hpp"
#include "gui/widgets/window_builder.hpp"
#include "gui/widgets/settings.hpp"
#include "log.hpp"
#include "wml_exception.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)
#define ERR_CONFIG LOG_STREAM(err, config)
namespace gui2 {
namespace {
template<class D>
void show_dialog(twidget* caller)
{
ttitle_screen *dialog = dynamic_cast<ttitle_screen*>(caller->dialog());
assert(dialog);
D dlg;
dlg.show(*(dialog->video()));
}
} // namespace
/*WIKI
* @page = GUIWindowWML
* @order = 2_title_screen
*
* == Title screen ==
*
* This shows the title screen.
*/
twindow ttitle_screen::build_window(CVideo& video)
{
return build(video, get_id(TITLE_SCREEN));
}
void ttitle_screen::pre_show(CVideo& video, twindow& window)
{
assert(!video_);
video_ = &video;
set_restore(false);
// Note changing the language doesn't upate the title screen...
window.get_widget<tbutton>("language", false).
set_callback_mouse_left_click( show_dialog<gui2::tlanguage_selection>);
window.get_widget<tbutton>("addons", false).
set_callback_mouse_left_click( show_dialog<gui2::taddon_connect>);
window.canvas()[0].set_variable("revision_number",
variant(_("Version") + std::string(" ") + game_config::revision));
/*Select a random game_title*/
std::vector<std::string> game_title_list =
utils::split(game_config::game_title, ',', utils::STRIP_SPACES | utils::REMOVE_EMPTY);
if(game_title_list.empty()) {
ERR_CONFIG << "No title image defined\n";
} else {
window.canvas()[0].set_variable("background_image",
variant(game_title_list[rand()%game_title_list.size()]));
}
}
void ttitle_screen::post_show(twindow& /*window*/)
{
video_ = NULL;
}
} // namespace gui2

View file

@ -0,0 +1,48 @@
/* $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_TITLE_SCREEN_HPP_INCLUDED
#define GUI_DIALOGS_TITLE_SCREEN_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
namespace gui2 {
class ttitle_screen : public tdialog
{
public:
ttitle_screen() :
video_(NULL)
{
}
CVideo* video() { return video_; }
private:
/** Used in show in order to show child windows. */
CVideo* video_;
/** Inherited from tdialog. */
twindow build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
};
} // namespace gui2
#endif

View file

@ -89,6 +89,7 @@ static void fill_window_types()
window_type_list[MP_METHOD_SELECTION] = "mp_method_selection";
window_type_list[MP_SERVER_LIST] = "mp_server_list";
window_type_list[MP_CREATE_GAME] = "mp_create_game";
window_type_list[TITLE_SCREEN] = "title_screen";
#ifdef USE_EDITOR2
window_type_list[EDITOR_NEW_MAP] = "editor_new_map";
window_type_list[EDITOR_GENERATE_MAP] = "editor_generate_map";

View file

@ -34,6 +34,7 @@ namespace gui2 {
extern bool new_widgets;
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.
MP_CONNECT, //<! The mp server connection dialog.

View file

@ -22,6 +22,7 @@
#include "cursor.hpp"
#include "font.hpp"
#include "log.hpp"
#include "titlescreen.hpp"
#include "tstring.hpp"
#include "video.hpp"
@ -160,6 +161,42 @@ twindow::tretval twindow::get_retval_by_id(const std::string& id)
return OK;
} else if(id == "cancel") {
return CANCEL;
/**
* The ones for the title screen.
*
* This is a kind of hack, but the values are hardcoded in the titlescreen
* and don't want to change them at the moment. It would be a good idea to
* add some namespaces to avoid names clashing.
*/
} else if(id == "tutorial") {
return static_cast<tretval>(gui::TUTORIAL);
#ifdef USE_EDITOR2
} else if(id == "editor") {
return static_cast<tretval>(gui::START_MAP_EDITOR);
#endif
} else if(id == "credits") {
return static_cast<tretval>(gui::SHOW_ABOUT);
} else if(id == "quit") {
return static_cast<tretval>(gui::QUIT_GAME);
/**
* The hacks which are here so the old engine can handle the event. The new
* engine can't handle all dialogs yet, so it needs to fall back to the old
* engine to make certain things happen.
*/
} else if(id == "campaign") {
return static_cast<tretval>(gui::NEW_CAMPAIGN);
} else if(id == "multiplayer") {
return static_cast<tretval>(gui::MULTIPLAYER);
} else if(id == "load") {
return static_cast<tretval>(gui::LOAD_GAME);
} else if(id == "addons") {
return static_cast<tretval>(gui::GET_ADDONS);
} else if(id == "preferences") {
return static_cast<tretval>(gui::EDIT_PREFERENCES);
// default if nothing matched
} else {
return NONE;
}

View file

@ -24,8 +24,10 @@ namespace gui {
* Values for the menu-items of the main menu.
*
* The code assumes TUTORIAL is the first item.
* The values are also used as the button retour values, where 0 means no
* automatic value so we need to avoid 0.
*/
enum TITLE_RESULT { TUTORIAL = 0, /**< Start special campaign 'tutorial' */
enum TITLE_RESULT { TUTORIAL = 1, /**< Start special campaign 'tutorial' */
NEW_CAMPAIGN, /**< Let user select a campaign to play */
MULTIPLAYER, /**< Play single scenario against humans or AI */
LOAD_GAME, GET_ADDONS,