1 /*-------------------------------------------------------------------------------
2 
3 	BARONY
4 	File: messages.hpp
5 	Desc: defines stuff for messages that draw onto the screen and then
6 	fade away after a while.
7 
8 	Copyright 2013-2016 (c) Turning Wheel LLC, all rights reserved.
9 	See LICENSE for details.
10 
11 -------------------------------------------------------------------------------*/
12 
13 #pragma once
14 
15 //#include "SDL.h"
16 
17 #include "main.hpp"
18 #include "interface/interface.hpp"
19 
20 //Time in seconds before the message starts fading.
21 #define MESSAGE_PREFADE_TIME 3600
22 //How fast the alpha value de-increments
23 #define MESSAGE_FADE_RATE 10
24 /*
25  * Maximum number of messages displayed on screen at once before the oldest message is automatically deleted.
26  * Currently calculated as the maximum number of messages from the top of the screen to the status panel.
27  */
28 #define MESSAGE_FONT ttf16
29 #define MESSAGE_FONT_SIZE TTF_FontHeight(MESSAGE_FONT)
30 #define MESSAGE_MAX_TOTAL_LINES ((yres - (status_bmp->h * uiscale_chatlog)) / MESSAGE_FONT_SIZE)
31 //Number of pixels from the left edge of the screen the messages are.
32 #define MESSAGE_X_OFFSET 5
33 //The location the newest message is displayed (in other words, the bottom of the message list -- they're drawn from oldest to newest, top down).
34 #define MESSAGE_Y_OFFSET (yres-(status_bmp->h * uiscale_chatlog)-MESSAGE_FONT_SIZE-20-(60 * uiscale_playerbars * uiscale_playerbars))
35 static const int ADD_MESSAGE_BUFFER_LENGTH = 256;
36 /*
37  * Right, so this is how it's going to work:
38  * This is a "class" to emulate a virtual console -- minecraft style. I mean, message log, not console.
39  * It draws messages up above the main bar and stuff. It...ya. Minecraft messages pop up, dissapear, you know?
40  * This is what that does.
41  */
42 
43 typedef struct Message
44 {
45 	string_t* text; //Same size as the message in draw.c. Make sure not to overrun it.
46 
47 	//Its location (durr).
48 	int x, y;
49 
50 	//The time it's been displayed so far.
51 	int time_displayed;
52 
53 	//The alpha of the message (SDL > 1.1.5, or whatever version it was, has 255 as SDL_ALPHA_OPAQUE and 0 as ASL_ALPHA_TRANSPARENT).
54 	/*
55 	 * Building on that last point, we could probably:
56 		if (SDL_ALPHA_TRANSPARENT < SDL_ALPHA_OPAQUE)
57 		{
58 			alpha--;
59 		}
60 		else
61 		{
62 			alpha++;
63 		}
64 	 * To ensure everything always works right. I guess. Maybe not necessary. Whatever. There are much bigger problems to worry about.
65 	 */
66 	Sint16 alpha;
67 } Message;
68 
69 /*
70  * Adds a message to the list of messages.
71  */
72 void addMessage(Uint32 color, char* content, ...);
73 
74 /*
75  * Updates all the messages; fades them & removes them.
76  */
77 void updateMessages();
78 
79 /*
80  * Draw all the messages.
81  */
82 void drawMessages();
83 
84 
85 /*
86  * Used on program deinitialization.
87  */
88 void deleteAllNotificationMessages();
89 
90 /*
91 * Remove single % from message strings.
92 */
93 std::string messageSanitizePercentSign(std::string src, int* percentSignsFound);
94