1 /***************************************************************************
2  *   Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com>          *
3  *                                                                         *
4  *   Part of the Free Heroes2 Engine:                                      *
5  *   http://sourceforge.net/projects/fheroes2                              *
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or modify  *
8  *   it under the terms of the GNU General Public License as published by  *
9  *   the Free Software Foundation; either version 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program is distributed in the hope that it will be useful,       *
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15  *   GNU General Public License for more details.                          *
16  *                                                                         *
17  *   You should have received a copy of the GNU General Public License     *
18  *   along with this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 
23 #include "agg_image.h"
24 #include "cursor.h"
25 #include "dialog.h"
26 #include "difficulty.h"
27 #include "game.h"
28 #include "game_over.h"
29 #include "icn.h"
30 #include "localevent.h"
31 #include "maps.h"
32 #include "player_info.h"
33 #include "settings.h"
34 #include "translations.h"
35 #include "ui_button.h"
36 #include "ui_text.h"
37 
GameInfo(void)38 void Dialog::GameInfo( void )
39 {
40     fheroes2::Display & display = fheroes2::Display::instance();
41     Settings & conf = Settings::Get();
42 
43     // setup cursor
44     const CursorRestorer cursorRestorer( true, Cursor::POINTER );
45 
46     const fheroes2::Sprite & box = fheroes2::AGG::GetICN( ICN::SCENIBKG, 0 );
47 
48     // This is a shadow offset from the original ICN::SCENIBKG image.
49     const fheroes2::Point shadowOffset( -16, 4 );
50 
51     fheroes2::Point pt( ( display.width() - box.width() + shadowOffset.x ) / 2, ( ( display.height() - box.height() + shadowOffset.y ) / 2 ) );
52     fheroes2::ImageRestorer back( display, pt.x, pt.y, box.width(), box.height() );
53     fheroes2::Blit( box, display, pt.x, pt.y );
54 
55     fheroes2::Text text;
56 
57     text.set( conf.MapsName(), { fheroes2::FontSize::NORMAL, fheroes2::FontColor::WHITE } );
58     text.draw( pt.x + 52, pt.y + 32, 350, display );
59 
60     text.set( _( "Map\nDifficulty" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
61     text.draw( pt.x + 50, pt.y + 56, 80, display );
62 
63     text.set( _( "Game\nDifficulty" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
64     text.draw( pt.x + 140, pt.y + 56, 80, display );
65 
66     text.set( _( "Rating" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
67     text.draw( pt.x + 230, pt.y + 78 - text.height( 80 ), 80, display );
68 
69     text.set( _( "Map Size" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
70     text.draw( pt.x + 322, pt.y + 78 - text.height( 80 ), 80, display );
71 
72     text.set( Difficulty::String( conf.MapsDifficulty() ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
73     text.draw( pt.x + 50, pt.y + 84, 80, display );
74 
75     text.set( Difficulty::String( Game::getDifficulty() ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
76     text.draw( pt.x + 140, pt.y + 84, 80, display );
77 
78     text.set( std::to_string( Game::GetRating() ) + " %", { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
79     text.draw( pt.x + 230, pt.y + 84, 80, display );
80 
81     text.set( Maps::SizeString( conf.MapsSize().width ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
82     text.draw( pt.x + 322, pt.y + 84, 80, display );
83 
84     text.set( conf.MapsDescription(), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
85     text.draw( pt.x + 52, pt.y + 107, 350, display );
86 
87     text.set( _( "Opponents" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
88     text.draw( pt.x + 52, pt.y + 152, 350, display );
89 
90     text.set( _( "Class" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
91     text.draw( pt.x + 52, pt.y + 227, 350, display );
92 
93     Interface::PlayersInfo playersInfo( true, true, false );
94 
95     playersInfo.UpdateInfo( conf.GetPlayers(), fheroes2::Point( pt.x + 40, pt.y + 165 ), fheroes2::Point( pt.x + 40, pt.y + 240 ) );
96     playersInfo.RedrawInfo( true );
97 
98     text.set( _( "Victory\nConditions" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
99     text.draw( pt.x + 40, pt.y + 347, 80, display );
100 
101     text.set( GameOver::GetActualDescription( conf.ConditionWins() ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
102     text.draw( pt.x + 130, pt.y + 350, 272, display );
103 
104     text.set( _( "Loss\nConditions" ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
105     text.draw( pt.x + 40, pt.y + 392, 80, display );
106 
107     text.set( GameOver::GetActualDescription( conf.ConditionLoss() ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::WHITE } );
108     text.draw( pt.x + 130, pt.y + 398, 272, display );
109 
110     text.set( _( "Score: " ) + std::to_string( Game::GetGameOverScores() ), { fheroes2::FontSize::SMALL, fheroes2::FontColor::YELLOW } );
111     text.draw( pt.x + 385 - text.width(), pt.y + 436, 80, display );
112 
113     fheroes2::Button buttonOk( pt.x + 178, pt.y + 426, ICN::REQUESTS, 1, 2 );
114     fheroes2::ButtonSprite buttonCfg
115         = fheroes2::makeButtonWithShadow( pt.x + 50, pt.y + 426, fheroes2::AGG::GetICN( ICN::BTNCONFIG, 0 ), fheroes2::AGG::GetICN( ICN::BTNCONFIG, 1 ), display );
116 
117     buttonOk.draw();
118     buttonCfg.draw();
119 
120     display.render();
121 
122     LocalEvent & le = LocalEvent::Get();
123 
124     // message loop
125     while ( le.HandleEvents() ) {
126         le.MousePressLeft( buttonOk.area() ) ? buttonOk.drawOnPress() : buttonOk.drawOnRelease();
127         le.MousePressLeft( buttonCfg.area() ) ? buttonCfg.drawOnPress() : buttonCfg.drawOnRelease();
128 
129         if ( le.MouseClickLeft( buttonOk.area() ) || HotKeyCloseWindow )
130             break;
131 
132         if ( le.MouseClickLeft( buttonCfg.area() ) ) {
133             Dialog::ExtSettings( true );
134             display.render();
135         }
136     }
137 }
138