OpenClonk
C4MessageBoard Class Reference

#include <C4MessageBoard.h>

Collaboration diagram for C4MessageBoard:
[legend]

Public Member Functions

 C4MessageBoard ()
 
 ~C4MessageBoard ()
 
void Init (C4Facet &cgo, bool fStartup)
 
void Execute ()
 
void Draw (C4Facet &cgo)
 
void AddLog (const char *szMessage)
 
void ClearLog ()
 
void LogNotify ()
 
void EnsureLastMessage ()
 
bool ControlScrollUp ()
 
bool ControlScrollDown ()
 
C4PlayerGetMessagePlayer (const char *szMessage)
 

Public Attributes

C4Facet Output
 

Friends

class C4MessageInput
 

Detailed Description

Definition at line 29 of file C4MessageBoard.h.

Constructor & Destructor Documentation

◆ C4MessageBoard()

C4MessageBoard::C4MessageBoard ( )

Definition at line 37 of file C4MessageBoard.cpp.

37  : LogBuffer(C4LogSize, C4LogMaxLines, 0, " ", false)
38 {
39  Delay = -1;
40  Fader = 0;
41  Speed = 2;
42  Output.Default();
43  Startup = false;
44  ScreenFader = 0;
45  iBackScroll = -1;
46  ScrollUpBinding = nullptr;
47  ScrollDownBinding = nullptr;
48  iLineHgt = 1; // Prevent unitialized access with USE_CONSOLE
49 }
const int C4LogSize
const int C4LogMaxLines
void Default()
Definition: C4Facet.cpp:31

References C4Facet::Default(), and Output.

Here is the call graph for this function:

◆ ~C4MessageBoard()

C4MessageBoard::~C4MessageBoard ( )

Definition at line 51 of file C4MessageBoard.cpp.

52 {
53  LogBuffer.Clear();
54  LogBuffer.SetLBWidth(0);
55 }
void Clear()
Definition: C4LogBuf.cpp:308
void SetLBWidth(int iToWidth)
Definition: C4LogBuf.cpp:314

References C4LogBuffer::Clear(), and C4LogBuffer::SetLBWidth().

Here is the call graph for this function:

Member Function Documentation

◆ AddLog()

void C4MessageBoard::AddLog ( const char *  szMessage)

Definition at line 198 of file C4MessageBoard.cpp.

199 {
200  // safety
201  if (!szMessage || !*szMessage) return;
202  // make sure new message will be drawn
203  ++iBackScroll;
204  // register message in standard messageboard font
205  LogBuffer.AppendLines(szMessage, &::GraphicsResource.FontRegular, 0, nullptr);
206 }
C4GraphicsResource GraphicsResource
void AppendLines(const char *szLine, CStdFont *pFont, DWORD dwClr, CStdFont *pFirstLineFont=nullptr)
Definition: C4LogBuf.cpp:170

References C4LogBuffer::AppendLines(), C4GraphicsResource::FontRegular, and GraphicsResource.

Here is the call graph for this function:

◆ ClearLog()

void C4MessageBoard::ClearLog ( )

Definition at line 208 of file C4MessageBoard.cpp.

209 {
210  LogBuffer.Clear();
211 }

References C4LogBuffer::Clear().

Here is the call graph for this function:

◆ ControlScrollDown()

bool C4MessageBoard::ControlScrollDown ( )

Definition at line 253 of file C4MessageBoard.cpp.

254 {
255  Delay=-1; Fader=0;
256  if (iBackScroll > -1) iBackScroll--;
257  return true;
258 }

Referenced by Init().

Here is the caller graph for this function:

◆ ControlScrollUp()

bool C4MessageBoard::ControlScrollUp ( )

Definition at line 246 of file C4MessageBoard.cpp.

247 {
248  Delay=-1; Fader=0;
249  iBackScroll++;
250  return true;
251 }

Referenced by Init().

Here is the caller graph for this function:

◆ Draw()

void C4MessageBoard::Draw ( C4Facet cgo)

Definition at line 131 of file C4MessageBoard.cpp.

132 {
133  if (!Application.Active) return;
134 
135  // Startup: draw Loader
136  if (Startup)
137  {
139  ::GraphicsSystem.pLoaderScreen->Draw(cgo, C4LoaderScreen::Flag::ALL, Game.InitProgress, &LogBuffer);
140  else
141  // loader not yet loaded: black BG
142  pDraw->DrawBoxDw(cgo.Surface, 0,0, cgo.Wdt, cgo.Hgt, 0x00000000);
143  return;
144  }
145 
146  // Game running: message fader
147 
148  // draw messages
149  // how many "extra" messages should be shown?
150  int iMsgFader = C4MSGB_MaxMsgFading;
151  // check screenfader range
152  if (ScreenFader >= 1.0f)
153  {
154  return;
155  }
157  // show msgs
158  for (int iMsg = -iMsgFader; iMsg < 0; iMsg++)
159  {
160  // get message at pos
161  if (iMsg-iBackScroll >= 0) break;
162  const char *Message = LogBuffer.GetLine(iMsg-iBackScroll, nullptr, nullptr, nullptr);
163  if (!Message || !*Message) continue;
164  // calc target position (y)
165  int iMsgY = cgo.Y + cgo.Hgt + iMsg * iLineHgt + Fader;
166 
167  // player message color?
168  C4Player *pPlr = GetMessagePlayer(Message);
169 
170  DWORD dwColor;
171  if (pPlr)
172  dwColor = PlrClr2TxtClr(pPlr->ColorDw) & 0xffffff;
173  else
174  dwColor = 0xffffff;
175  // fade out (msg fade)
176  float fade = std::max(ScreenFader, 0.0f) + ((iMsg + 2.0f + float(Fader) / iLineHgt) / std::min(2-iMsgFader, -1));
177  DWORD dwFade = (0xff - Clamp(int(fade * 0xff), 0, 0xff)) << 24;
178  dwColor |= dwFade;
179  // Draw
180  pDraw->StringOut(Message,::GraphicsResource.FontRegular,1.0,cgo.Surface,cgo.X,iMsgY,dwColor);
181  }
182 }
C4Draw * pDraw
Definition: C4Draw.cpp:42
C4Game Game
Definition: C4Globals.cpp:52
C4Application Application
Definition: C4Globals.cpp:44
C4GraphicsSystem GraphicsSystem
Definition: C4Globals.cpp:51
const int C4MSGB_MaxMsgFading
uint32_t DWORD
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
DWORD PlrClr2TxtClr(DWORD dwClr)
Definition: StdColors.h:104
bool Active
Definition: C4App.h:63
bool StringOut(const char *szText, CStdFont &rFont, float fZoom, C4Surface *sfcDest, float iTx, float iTy, DWORD dwFCol=0xffffffff, BYTE byForm=ALeft, bool fDoMarkup=true)
Definition: C4Draw.cpp:570
void DrawBoxDw(C4Surface *sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr)
Definition: C4Draw.cpp:840
C4Surface * Surface
Definition: C4Facet.h:117
float Hgt
Definition: C4Facet.h:118
float Wdt
Definition: C4Facet.h:118
float Y
Definition: C4Facet.h:118
float X
Definition: C4Facet.h:118
int32_t InitProgress
Definition: C4Game.h:134
C4LoaderScreen * pLoaderScreen
void Draw(C4Facet &cgo, Flag options=Flag::ALL, int iProgress=0, class C4LogBuffer *pLog=nullptr, int Process=0)
const char * GetLine(int iLineIndex, CStdFont **ppFont, DWORD *pdwClr, bool *pNewParagraph) const
Definition: C4LogBuf.cpp:280
C4Player * GetMessagePlayer(const char *szMessage)
uint32_t ColorDw
Definition: C4Player.h:89

References C4AbstractApp::Active, Application, C4MSGB_MaxMsgFading, Clamp(), C4Player::ColorDw, C4LoaderScreen::Draw(), C4Draw::DrawBoxDw(), C4GraphicsResource::FontRegular, Game, C4LogBuffer::GetLine(), GetMessagePlayer(), GraphicsResource, GraphicsSystem, C4Facet::Hgt, C4Game::InitProgress, C4GraphicsSystem::OverwriteBg(), pDraw, C4GraphicsSystem::pLoaderScreen, PlrClr2TxtClr(), C4Draw::StringOut(), C4Facet::Surface, C4Facet::Wdt, C4Facet::X, and C4Facet::Y.

Referenced by Execute(), and LogNotify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EnsureLastMessage()

void C4MessageBoard::EnsureLastMessage ( )

Definition at line 184 of file C4MessageBoard.cpp.

185 {
186  // Ingore if startup or typein
187  if (Startup) return;
188  // scroll until end of log
189  for (int i = 0; i < 100; i++)
190  {
192  Execute();
193  if (iBackScroll < 0) break;
194  Delay=0;
195  }
196 }

References C4GraphicsSystem::Execute(), Execute(), and GraphicsSystem.

Here is the call graph for this function:

◆ Execute()

void C4MessageBoard::Execute ( )

Definition at line 57 of file C4MessageBoard.cpp.

58 {
59  // Startup? draw only
60  if (Startup) { Draw(Output); return; }
61 
62  // typein or messages waiting? fade in
63  if (::MessageInput.IsTypeIn() || iBackScroll >= 0)
64  ScreenFader = std::max(ScreenFader - 0.20f, -1.0f);
65 
66  // no curr msg?
67  if (iBackScroll<0)
68  {
69  // draw anyway
70  Draw(Output);
71  if (!::MessageInput.IsTypeIn())
72  ScreenFader = std::min(ScreenFader + 0.05f, 1.0f);
73  return;
74  }
75 
76  // recalc fade/delay speed
77  Speed = std::max(1, iBackScroll / 5);
78  // fade msg in?
79  if (Fader > 0)
80  Fader = std::max(Fader - Speed, 0);
81  // hold curr msg? (delay)
82  if (Fader <= 0)
83  {
84  // no delay set yet?
85  if (Delay == -1)
86  {
87  // set delay based on msg length
88  const char *szCurrMsg = LogBuffer.GetLine(std::min(-iBackScroll, -1), nullptr, nullptr, nullptr);
89  if (szCurrMsg) Delay = strlen(szCurrMsg); else Delay = 0;
90  }
91  // wait...
92  if (Delay > 0) Delay = std::max(Delay - Speed, 0);
93  // end of delay
94  if (Delay == 0)
95  {
96  // set cursor to next msg (or at end of log)
97  iBackScroll = std::max(iBackScroll - 1, -1);
98  // reset fade
99  Fader = iLineHgt;
100  Delay = -1;
101  }
102  }
103 
104  // Draw
105  Draw(Output);
106 }
C4MessageInput MessageInput
void Draw(C4Facet &cgo)

References Draw(), C4LogBuffer::GetLine(), C4MessageInput::IsTypeIn(), MessageInput, and Output.

Referenced by EnsureLastMessage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetMessagePlayer()

C4Player * C4MessageBoard::GetMessagePlayer ( const char *  szMessage)

Definition at line 228 of file C4MessageBoard.cpp.

229 {
230  // Scan message text for heading player name
231  if (SEqual2(szMessage, "* "))
232  {
233  StdStrBuf str;
234  str.CopyUntil(szMessage + 2,' ');
236  }
237  if (SCharCount(':',szMessage))
238  {
239  StdStrBuf str;
240  str.CopyUntil(szMessage + 2,':');
242  }
243  return nullptr;
244 }
C4PlayerList Players
unsigned int SCharCount(char cTarget, const char *szInStr, const char *cpUntil)
Definition: Standard.cpp:326
bool SEqual2(const char *szStr1, const char *szStr2)
Definition: Standard.cpp:204
C4Player * GetByName(const char *szName, int iExcluding=NO_OWNER) const
void CopyUntil(const char *szString, char cUntil)
Definition: StdBuf.h:613
const char * getData() const
Definition: StdBuf.h:442

References StdStrBuf::CopyUntil(), C4PlayerList::GetByName(), StdStrBuf::getData(), Players, SCharCount(), and SEqual2().

Referenced by Draw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void C4MessageBoard::Init ( C4Facet cgo,
bool  fStartup 
)

Definition at line 108 of file C4MessageBoard.cpp.

109 {
110  Output=cgo;
111  Startup=fStartup;
113  LogBuffer.SetLBWidth(Output.Wdt);
114 
115  if (!Startup)
116  {
117  // set cursor to end of log
118  iBackScroll = -1;
119  Fader = 0;
120  Speed = 2;
121  ScreenFader = 1.0f; // msgs faded out
122 
123  LogBuffer.SetLBWidth(Output.Wdt);
124  }
125 
126  // messageboard
127  ScrollUpBinding = std::make_unique<C4KeyBinding>(C4KeyCodeEx(K_UP, KEYS_Shift), "MsgBoardScrollUp", KEYSCOPE_Fullscreen, new C4KeyCB <C4MessageBoard>(*GraphicsSystem.MessageBoard, &C4MessageBoard::ControlScrollUp));
128  ScrollDownBinding = std::make_unique<C4KeyBinding>(C4KeyCodeEx(K_DOWN, KEYS_Shift), "MsgBoardScrollDown", KEYSCOPE_Fullscreen, new C4KeyCB <C4MessageBoard>(*GraphicsSystem.MessageBoard, &C4MessageBoard::ControlScrollDown));
129 }
@ KEYSCOPE_Fullscreen
@ KEYS_Shift
std::unique_ptr< C4MessageBoard > MessageBoard
int GetLineHeight() const
Definition: C4FontLoader.h:125

References ControlScrollDown(), ControlScrollUp(), C4GraphicsResource::FontRegular, CStdFont::GetLineHeight(), GraphicsResource, GraphicsSystem, KEYS_Shift, KEYSCOPE_Fullscreen, C4GraphicsSystem::MessageBoard, Output, C4LogBuffer::SetLBWidth(), and C4Facet::Wdt.

Here is the call graph for this function:

◆ LogNotify()

void C4MessageBoard::LogNotify ( )

Definition at line 213 of file C4MessageBoard.cpp.

214 {
215  // do not show startup board if GUI is active
216  if (::pGUI->IsActive()) return;
217  // Reset
218  iBackScroll=0;
219  // Draw
220  if (pDraw)
221  {
222  Draw(Output);
223  // startup: Draw message board only and do page flip
224  if (Startup) FullScreen.pSurface->PageFlip();
225  }
226 }
C4FullScreen FullScreen
Definition: C4Globals.cpp:46
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1191
bool IsActive()
Definition: C4Gui.h:2633
bool PageFlip(C4Rect *pSrcRt=nullptr, C4Rect *pDstRt=nullptr)
Definition: C4Surface.cpp:310
C4Surface * pSurface
Definition: C4Window.h:275

References Draw(), FullScreen, C4GUI::Screen::IsActive(), Output, C4Surface::PageFlip(), pDraw, pGUI, and C4Window::pSurface.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ C4MessageInput

friend class C4MessageInput
friend

Definition at line 62 of file C4MessageBoard.h.

Member Data Documentation

◆ Output

C4Facet C4MessageBoard::Output

Definition at line 35 of file C4MessageBoard.h.

Referenced by C4MessageBoard(), Execute(), Init(), and LogNotify().


The documentation for this class was generated from the following files: