/src/gui/C4GameMessage.h

https://bitbucket.org/randrian/openclonk2 · C Header · 130 lines · 93 code · 16 blank · 21 comment · 0 complexity · fb888524b96e1c73e2fde4bdc3787ff3 MD5 · raw file

  1. /*
  2. * OpenClonk, http://www.openclonk.org
  3. *
  4. * Copyright (c) 1998-2000 Matthes Bender
  5. * Copyright (c) 2001, 2005, 2008 Sven Eberhardt
  6. * Copyright (c) 2001 Michael K?ser
  7. * Copyright (c) 2004 G?nther Brammer
  8. * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
  9. *
  10. * Portions might be copyrighted by other authors who have contributed
  11. * to OpenClonk.
  12. *
  13. * Permission to use, copy, modify, and/or distribute this software for any
  14. * purpose with or without fee is hereby granted, provided that the above
  15. * copyright notice and this permission notice appear in all copies.
  16. * See isc_license.txt for full license and disclaimer.
  17. *
  18. * "Clonk" is a registered trademark of Matthes Bender.
  19. * See clonk_trademark_license.txt for full license.
  20. */
  21. /* Text messages drawn inside the viewport */
  22. #ifndef INC_C4GameMessage
  23. #define INC_C4GameMessage
  24. #include <C4Surface.h>
  25. #include <C4Gui.h>
  26. const int32_t C4GM_MaxText = 256,
  27. C4GM_MinDelay = 20;
  28. const int32_t C4GM_Global = 1,
  29. C4GM_GlobalPlayer = 2,
  30. C4GM_Target = 3,
  31. C4GM_TargetPlayer = 4;
  32. const int32_t C4GM_NoBreak = 1<<0,
  33. C4GM_Bottom = 1<<1, // message placed at bottom of screen
  34. C4GM_Multiple= 1<<2,
  35. C4GM_Top = 1<<3,
  36. C4GM_Left = 1<<4,
  37. C4GM_Right = 1<<5,
  38. C4GM_HCenter = 1<<6,
  39. C4GM_VCenter = 1<<7,
  40. C4GM_DropSpeech = 1<<8, // cut any text after '$'
  41. C4GM_WidthRel = 1<<9,
  42. C4GM_XRel = 1<<10,
  43. C4GM_YRel = 1<<11;
  44. const int32_t C4GM_PositioningFlags = C4GM_Bottom | C4GM_Top | C4GM_Left | C4GM_Right | C4GM_HCenter | C4GM_VCenter;
  45. class C4GameMessage
  46. {
  47. friend class C4GameMessageList;
  48. public:
  49. void Draw(C4TargetFacet &cgo, int32_t iPlayer, float Zoom);
  50. C4GameMessage();
  51. ~C4GameMessage();
  52. protected:
  53. int32_t X,Y,Wdt;
  54. int32_t Delay;
  55. DWORD ColorDw;
  56. int32_t Player;
  57. int32_t Type;
  58. C4Object *Target;
  59. StdCopyStrBuf Text;
  60. C4GameMessage *Next;
  61. C4ID DecoID; StdStrBuf PortraitDef;
  62. C4GUI::FrameDecoration *pFrameDeco;
  63. uint32_t dwFlags;
  64. protected:
  65. 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);
  66. void Append(const char *szText, bool fNoDuplicates = false);
  67. bool Execute();
  68. const char *WordWrap(int32_t iMaxWidth);
  69. void UpdateDef(C4ID idUpdDef);
  70. public:
  71. int32_t GetPositioningFlags() const { return dwFlags & C4GM_PositioningFlags; }
  72. };
  73. class C4GameMessageList
  74. {
  75. public:
  76. C4GameMessageList();
  77. ~C4GameMessageList();
  78. protected:
  79. C4GameMessage *First;
  80. public:
  81. void Default();
  82. void Clear();
  83. void Execute();
  84. void Draw(C4TargetFacet &cgo, int32_t iPlayer, float Zoom);
  85. void ClearPlayers(int32_t iPlayer, int32_t dwPositioningFlags);
  86. void ClearPointers(C4Object *pObj);
  87. void UpdateDef(C4ID idUpdDef); // called after reloaddef
  88. 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=NULL, uint32_t dwFlags=0u, int32_t width=0);
  89. bool New(int32_t iType, const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iX, int32_t iY, uint8_t bCol);
  90. 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=NULL, uint32_t dwFlags=0u, int32_t width=0);
  91. 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);
  92. };
  93. extern C4GameMessageList Messages;
  94. inline void GameMsgObject(const char *szText, C4Object *pTarget, int32_t iFCol=FWhite)
  95. {
  96. ::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,(uint8_t) iFCol);
  97. }
  98. inline void GameMsgObjectPlayer(const char *szText, C4Object *pTarget, int32_t iPlayer, int32_t iFCol=FWhite)
  99. {
  100. ::Messages.New(C4GM_TargetPlayer,szText,pTarget,iPlayer,0,0,(uint8_t) iFCol);
  101. }
  102. inline void GameMsgGlobal(const char *szText, int32_t iFCol=FWhite)
  103. {
  104. ::Messages.New(C4GM_Global,szText,NULL,ANY_OWNER,0,0,(uint8_t) iFCol);
  105. }
  106. inline void GameMsgPlayer(const char *szText, int32_t iPlayer, int32_t iFCol=FWhite)
  107. {
  108. ::Messages.New(C4GM_GlobalPlayer,szText,NULL,iPlayer,0,0,(uint8_t) iFCol);
  109. }
  110. inline void GameMsgObjectDw(const char *szText, C4Object *pTarget, uint32_t dwClr)
  111. {
  112. ::Messages.New(C4GM_Target,szText,pTarget,NO_OWNER,0,0,dwClr);
  113. }
  114. #endif