1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Text messages drawn inside the viewport */
19 
20 #ifndef INC_C4GameMessage
21 #define INC_C4GameMessage
22 
23 #include "lib/StdColors.h"
24 #include "script/C4Value.h"
25 
26 const int32_t C4GM_MaxText = 256,
27               C4GM_MinDelay = 20;
28 
29 const int32_t C4GM_Global       =  1,
30               C4GM_GlobalPlayer =  2,
31               C4GM_Target       =  3,
32               C4GM_TargetPlayer =  4;
33 
34 const int32_t C4GM_NoBreak = 1<<0,
35               C4GM_Bottom  = 1<<1, // message placed at bottom of screen
36               C4GM_Multiple= 1<<2,
37               C4GM_Top     = 1<<3,
38               C4GM_Left    = 1<<4,
39               C4GM_Right   = 1<<5,
40               C4GM_HCenter = 1<<6,
41               C4GM_VCenter = 1<<7,
42               C4GM_DropSpeech = 1<<8, // cut any text after '$'
43               C4GM_WidthRel = 1<<9,
44               C4GM_XRel     = 1<<10,
45               C4GM_YRel     = 1<<11,
46               C4GM_Zoom     = 1<<12;
47 
48 const int32_t C4GM_PositioningFlags = C4GM_Bottom | C4GM_Top | C4GM_Left | C4GM_Right | C4GM_HCenter | C4GM_VCenter;
49 
50 class C4GameMessage
51 {
52 	friend class C4GameMessageList;
53 public:
54 	void Draw(C4TargetFacet &cgo, int32_t iPlayer);
55 	C4GameMessage();
56 	~C4GameMessage();
57 protected:
58 	int32_t X, Y, Wdt, Hgt;
59 	int32_t Delay;
60 	DWORD ColorDw;
61 	int32_t Player;
62 	int32_t Type;
63 	C4Object *Target;
64 	StdCopyStrBuf Text;
65 	C4GameMessage *Next;
66 	C4ID DecoID;
67 	C4PropList *PictureDef; // can be definition, object or prop list with Source and Name properties
68 	C4Value PictureDefVal; // C4Value holding PictureDef to prevent deletion
69 	C4GUI::FrameDecoration *pFrameDeco{nullptr};
70 	uint32_t dwFlags;
71 protected:
72 	void Init(int32_t iType, const StdStrBuf & Text, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t dwCol, C4ID idDecoID, C4PropList *pSrc, uint32_t dwFlags, int width);
73 	void Append(const char *szText, bool fNoDuplicates = false);
74 	bool Execute();
75 	const char *WordWrap(int32_t iMaxWidth);
76 	void UpdateDef(C4ID idUpdDef);
77 
78 public:
GetPositioningFlags()79 	int32_t GetPositioningFlags() const { return dwFlags & C4GM_PositioningFlags; }
80 };
81 
82 class C4GameMessageList
83 {
84 public:
85 	C4GameMessageList();
86 	~C4GameMessageList();
87 protected:
88 	C4GameMessage *First;
89 public:
90 	void Default();
91 	void Clear();
92 	void Execute();
93 	void Draw(C4TargetFacet &gui_cgo, C4TargetFacet &cgo, int32_t iPlayer);
94 	void ClearPlayers(int32_t iPlayer, int32_t dwPositioningFlags);
95 	void ClearPointers(C4Object *pObj);
96 	void UpdateDef(C4ID idUpdDef); // called after reloaddef
97 	bool New(int32_t iType, const StdStrBuf & Text, C4Object *pTarget, int32_t iPlayer, int32_t iX = -1, int32_t iY = -1, uint32_t dwClr = 0xffFFFFFF, C4ID idDecoID=C4ID::None, C4PropList *pSrc=nullptr, uint32_t dwFlags=0u, int32_t width=0);
98 	bool New(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t dwClr, C4ID idDecoID=C4ID::None, C4PropList *pSrc=nullptr, uint32_t dwFlags=0u, int32_t width=0);
99 	bool Append(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t bCol, bool fNoDuplicates = false);
100 };
101 
102 extern C4GameMessageList Messages;
103 
GameMsgObject(const char * szText,C4Object * pTarget)104 inline void GameMsgObject(const char *szText, C4Object *pTarget)
105 {
106 	::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,C4RGB(0xff, 0xff, 0xff));
107 }
108 
GameMsgObjectPlayer(const char * szText,C4Object * pTarget,int32_t iPlayer)109 inline void GameMsgObjectPlayer(const char *szText, C4Object *pTarget, int32_t iPlayer)
110 {
111 	::Messages.New(C4GM_TargetPlayer,szText,pTarget,iPlayer,0,0, C4RGB(0xff, 0xff, 0xff));
112 }
113 
114 void GameMsgObjectError(const char *szText, C4Object *pTarget, bool Red = true);
115 
GameMsgObjectDw(const char * szText,C4Object * pTarget,uint32_t dwClr)116 inline void GameMsgObjectDw(const char *szText, C4Object *pTarget, uint32_t dwClr)
117 {
118 	::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,dwClr);
119 }
120 #endif
121