Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

215 linhas
5.3KB

  1. /* ---------------------------------------------------------------------------|
  2. *
  3. * Distributed under the CC0 public domain license.
  4. * By Alison G. Watson. Attribution is encouraged, though not required.
  5. * See licenses/cc0.txt for more information.
  6. *
  7. * ---------------------------------------------------------------------------|
  8. *
  9. * Log UI and logging functions.
  10. *
  11. * ---------------------------------------------------------------------------|
  12. */
  13. #include "common.h"
  14. #include "p_log.h"
  15. #include "p_player.h"
  16. #include "m_list.h"
  17. #include "p_hudid.h"
  18. #include "w_world.h"
  19. /* Static Functions -------------------------------------------------------- */
  20. static void LogV(i32 levl) {
  21. ACS_BeginPrint();
  22. if(levl) {
  23. for(i32 i = 0; i < levl; i++) ACS_PrintChar('>');
  24. ACS_PrintChar(' ');
  25. }
  26. }
  27. static void LogPop(struct player *p) {
  28. p->log.hudC--;
  29. fastmemmove(&p->log.hudV[0], &p->log.hudV[1], sizeof p->log.hudV[0] * p->log.hudC);
  30. }
  31. static void LogH(struct player *p, struct logdat *ld) {
  32. ld->ftim = 5;
  33. ld->time = 140 - p->log.curtime;
  34. p->log.curtime = 140;
  35. if(p->log.hudC >= countof(p->log.hudV)) LogPop(p);
  36. p->log.hudV[p->log.hudC++] = *ld;
  37. }
  38. static void LogF(struct player *p, struct logfdt *lf) {
  39. Vec_GrowN(p->log.curmap->data, 1, 8, _tag_logs);
  40. Vec_Next(p->log.curmap->data) = *lf;
  41. }
  42. /* Extern Functions -------------------------------------------------------- */
  43. void P_Log_Both(struct player *p, i32 levl, cstr fmt, ...) {
  44. struct logdat ld = {};
  45. LogV(levl);
  46. va_list vl;
  47. va_start(vl, fmt);
  48. __vnprintf(fmt, vl);
  49. va_end(vl);
  50. ld.inf = ACS_EndStrParam();
  51. LogF(p, &ld.fdta);
  52. LogH(p, &ld);
  53. }
  54. void P_Log_HUDs(struct player *p, i32 levl, cstr fmt, ...) {
  55. struct logdat ld = {};
  56. LogV(levl);
  57. va_list vl;
  58. va_start(vl, fmt);
  59. __vnprintf(fmt, vl);
  60. va_end(vl);
  61. ld.inf = ACS_EndStrParam();
  62. LogH(p, &ld);
  63. }
  64. void P_Log_Full(struct player *p, cstr fmt, ...) {
  65. struct logfdt lf = {};
  66. ACS_BeginPrint();
  67. va_list vl;
  68. va_start(vl, fmt);
  69. __vnprintf(fmt, vl);
  70. va_end(vl);
  71. lf.inf = ACS_EndStrParam();
  72. LogF(p, &lf);
  73. }
  74. void P_Log_Entry(struct player *p) {
  75. struct logmap *lm = nil;
  76. i32 lnum = MapNum;
  77. for(i32 i = 0; i < p->log.mapsC; i++)
  78. if(p->log.mapsV[i].lnum == lnum) {lm = &p->log.mapsV[i]; break;}
  79. if(!lm)
  80. {
  81. Vec_GrowN(p->log.maps, 1, 32, _tag_logs);
  82. lm = &Vec_Next(p->log.maps);
  83. lm->name = (ACS_BeginPrint(), ACS_PrintName(PRINTNAME_LEVELNAME), ACS_EndStrParam());
  84. lm->lnum = lnum;
  85. }
  86. p->log.curmap = lm;
  87. p->logF(LC(LANG "ENTER_FMT"), lm->name, CanonTime(ct_full, ticks));
  88. }
  89. script void P_Log_PTick(struct player *p) {
  90. if(p->log.curtime == 0) {
  91. if(p->log.hudC) {
  92. LogPop(p);
  93. p->log.curtime = p->log.hudV[p->log.hudC - 1].time;
  94. }
  95. } else {
  96. p->log.curtime--;
  97. }
  98. for(i32 i = 0; i < p->log.hudC; i++) {
  99. if(p->log.hudV[i].ftim) {
  100. p->log.hudV[i].ftim--;
  101. }
  102. }
  103. }
  104. void P_CBI_TabLog(struct gui_state *g, struct player *p) {
  105. static i32 const ht = 10;
  106. if(G_Button(g, .x = 25, 38, Pre(btnprev)))
  107. if(--CBIState(g)->logsel < 0) CBIState(g)->logsel = p->log.mapsC - 1;
  108. if(G_Button(g, .x = 25 + gui_p.btnprev.w, 38, Pre(btnnext)))
  109. if(++CBIState(g)->logsel >= p->log.mapsC) CBIState(g)->logsel = 0;
  110. struct logmap *lm = &p->log.mapsV[CBIState(g)->logsel];
  111. PrintText_str(lm->name, s_lmidfont, g->defcr, 28+gui_p.btnprev.w+gui_p.btnnext.w,1, 40,1);
  112. G_ScrBeg(g, &CBIState(g)->logscr, 15, 50, 280, 175, lm->dataC * ht);
  113. for(i32 i = 0; i < lm->dataC; i++) {
  114. i32 const y = ht * i;
  115. if(G_ScrOcc(g, &CBIState(g)->logscr, y, ht)) continue;
  116. PrintSprite(sp_UI_LogList, g->ox,1, y + g->oy,1);
  117. PrintText_str(lm->dataV[i].inf, s_smallfnt, CR_GREEN, g->ox + 2,1, y + g->oy + 1,1);
  118. }
  119. G_ScrEnd(g, &CBIState(g)->logscr);
  120. }
  121. script void HUD_Log(struct player *p, i32 cr, i32 x, i32 yy) {
  122. if(p->getCVarI(sc_hud_showlog)) {
  123. k32 scale = p->getCVarK(sc_hud_logsize);
  124. i32 yo = 200 / scale;
  125. i32 xs = 320 / scale;
  126. i32 ys = 240 / scale;
  127. SetSize(xs, ys);
  128. SetClipW(0, 0, xs, ys, xs);
  129. i32 i = 0;
  130. for(i32 i = 0; i < p->log.hudC; i++) {
  131. struct logdat const *const ld = &p->log.hudV[i];
  132. i32 y = 10 * i;
  133. i32 ya;
  134. if(p->getCVarI(sc_hud_logfromtop)) {ya = 1; y = 20 + y;}
  135. else {ya = 2; y = (yo - y) + yy;}
  136. PrintText_str(ld->inf, s_lmidfont, cr, x,1, y,ya);
  137. if(ld->ftim) SetFade(fid_logadS + i, 1, 8);
  138. if(CheckFade(fid_logadS + i)) {
  139. cstr s = RemoveTextColors_str(ld->inf, ACS_StrLen(ld->inf));
  140. PrintTextChS(s);
  141. PrintTextFX(s_lmidfont, CR_WHITE, x,1, y,ya, fid_logadS + i, ptf_add);
  142. }
  143. }
  144. SetSize(320, 240);
  145. }
  146. }
  147. /* Scripts ----------------------------------------------------------------- */
  148. script_str ext("ACS") addr(OBJ "LogS")
  149. void Sc_Log(i32 levl, i32 type) {
  150. str name = ServCallS(sm_GetLogName);
  151. if(name[0] == '_') name = Language(LANG "LOG%S", name);
  152. with_player(LocalPlayer) switch(type) {
  153. case msg_ammo: if(p->getCVarI(sc_player_ammolog))
  154. case msg_huds: p->logH(levl, "%S", name); break;
  155. case msg_full: p->logF( "%S", name); break;
  156. case msg_both: p->logB(levl, "%S", name); break;
  157. }
  158. }
  159. /* EOF */