| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design) |
| 5 | * Copyright (c) 2017-2020, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* Text messages drawn inside the viewport */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "C4ForwardDeclarations.h" |
| 22 | #include <C4Surface.h> |
| 23 | #include <C4Gui.h> |
| 24 | |
| 25 | #include <memory> |
| 26 | #include <vector> |
| 27 | |
| 28 | const int32_t C4GM_MaxText = 256, |
| 29 | C4GM_MinDelay = 20; |
| 30 | |
| 31 | const int32_t C4GM_Global = 1, |
| 32 | C4GM_GlobalPlayer = 2, |
| 33 | C4GM_Target = 3, |
| 34 | C4GM_TargetPlayer = 4; |
| 35 | |
| 36 | const int32_t C4GM_NoBreak = 1 << 0, |
| 37 | C4GM_Bottom = 1 << 1, // message placed at bottom of screen |
| 38 | C4GM_Multiple = 1 << 2, |
| 39 | C4GM_Top = 1 << 3, |
| 40 | C4GM_Left = 1 << 4, |
| 41 | C4GM_Right = 1 << 5, |
| 42 | C4GM_HCenter = 1 << 6, |
| 43 | C4GM_VCenter = 1 << 7, |
| 44 | C4GM_DropSpeech = 1 << 8, // cut any text after '$' |
| 45 | C4GM_WidthRel = 1 << 9, |
| 46 | C4GM_XRel = 1 << 10, |
| 47 | C4GM_YRel = 1 << 11, |
| 48 | C4GM_ALeft = 1 << 12, |
| 49 | C4GM_ACenter = 1 << 13, |
| 50 | C4GM_ARight = 1 << 14; |
| 51 | |
| 52 | const int32_t C4GM_PositioningFlags = C4GM_Bottom | C4GM_Top | C4GM_Left | C4GM_Right | C4GM_HCenter | C4GM_VCenter; |
| 53 | |
| 54 | class C4GameMessage |
| 55 | { |
| 56 | friend class C4GameMessageList; |
| 57 | |
| 58 | public: |
| 59 | void Draw(C4FacetEx &cgo, int32_t iPlayer); |
| 60 | C4GameMessage(); |
| 61 | ~C4GameMessage(); |
| 62 | |
| 63 | protected: |
| 64 | int32_t X, Y, Wdt; |
| 65 | int32_t Delay; |
| 66 | uint32_t ColorDw; |
| 67 | int32_t Player; |
| 68 | int32_t Type; |
| 69 | C4Object *Target; |
| 70 | StdStrBuf Text; |
| 71 | C4ID DecoID; StdStrBuf PortraitDef; |
| 72 | C4GUI::FrameDecoration *pFrameDeco; |
| 73 | uint32_t dwFlags; |
| 74 | |
| 75 | protected: |
| 76 | void Init(int32_t iType, const StdStrBuf &Text, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint32_t dwCol, C4ID idDecoID, const char *szPortraitDef, uint32_t dwFlags, int width); |
| 77 | void Append(const char *szText, bool fNoDuplicates = false); |
| 78 | bool Execute(); |
| 79 | void UpdateDef(C4ID idUpdDef); |
| 80 | |
| 81 | public: |
| 82 | int32_t GetPositioningFlags() const { return dwFlags & C4GM_PositioningFlags; } |
| 83 | }; |
| 84 | |
| 85 | class C4GameMessageList |
| 86 | { |
| 87 | public: |
| 88 | C4GameMessageList(); |
| 89 | ~C4GameMessageList(); |
| 90 | |
| 91 | protected: |
| 92 | std::vector<std::unique_ptr<C4GameMessage>> Messages; |
| 93 | |
| 94 | public: |
| 95 | void Clear(); |
| 96 | void Execute(); |
| 97 | void Draw(C4FacetEx &cgo, int32_t iPlayer); |
| 98 | void ClearPlayers(int32_t iPlayer, int32_t dwPositioningFlags); |
| 99 | void ClearPointers(C4Object *pObj); |
| 100 | void UpdateDef(C4ID idUpdDef); // called after reloaddef |
| 101 | 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, const char *szPortraitDef = nullptr, uint32_t dwFlags = 0u, int32_t width = 0); |
| 102 | bool New(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint8_t bCol); |
| 103 | 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, const char *szPortraitDef = nullptr, uint32_t dwFlags = 0u, int32_t width = 0); |
| 104 | bool Append(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint8_t bCol, bool fNoDuplicates = false); |
| 105 | }; |
| 106 | |
| 107 | void GameMsgObject(const char *szText, C4Object *pTarget, int32_t iFCol = FWhite); |
| 108 | void GameMsgObjectPlayer(const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iFCol = FWhite); |
| 109 | void GameMsgGlobal(const char *szText, int32_t iFCol = FWhite); |
| 110 | void GameMsgPlayer(const char *szText, int32_t iPlayer, int32_t iFCol = FWhite); |
| 111 | |
| 112 | void GameMsgObjectDw(const char *szText, C4Object *pTarget, uint32_t dwClr); |
| 113 | |