Half-Life и Adrenaline Gamer форум
http://aghl.ru/forum/

HLSDK (Client) newline hud
http://aghl.ru/forum/viewtopic.php?f=20&t=2584
Страница 1 из 1

Автор:  Gennaro-HL [ 25 окт 2016, 15:14 ]
Заголовок сообщения:  HLSDK (Client) newline hud

Hello, I have a problem with line break
when the string contains color codes the message is moved to the left.

You can remove the color codes without losing the colors in the hud?

Image:

Изображение

As I can get the same effect as this:

Изображение

Код:

   int ypos = max(((ScreenHeight - (m_iLines * LINE_HEIGHT)) / 6) - 40, 30); // shift it up slightly

   char Txt[100] = "Last match won by \n^1G^2G^3G^4G^5G^6G^7G^8G^9G";
   char *sz = Txt;
   char *next_line;
   while (*sz)
   {
      int line_length = 0; // count the length of the current line
      for (next_line = sz; *next_line != '\n' && *next_line != 0; next_line++)
         line_length += gHUD.m_scrinfo.charWidths[*next_line];
      char *top = next_line;
      if (*top == '\n')
         *top = 0;
      else
         top = NULL;

      int xpos = (ScreenWidth - line_length) / 2 - 5; // find where to start drawing the line
      
      gHUD.DrawHudString(xpos, ypos, ScreenWidth, sz, 255, 0, 0);
      
      ypos += LINE_HEIGHT;

      if (top)  // restore
         *top = '\n';
      sz = next_line;
      if (*sz == '\n')
         sz++;

      if (ypos > (ScreenHeight - 20)) // don't let it draw too low
         break;
   }


Автор:  Lev [ 25 окт 2016, 19:52 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

That is probably because it counts chars to align text on the center and it count color codes like they will be printed, but you remove them on output, so text is aligned to the left. You should remove color codes when counting line length (do not count them).

Автор:  Gennaro-HL [ 27 окт 2016, 03:09 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

some example?

this will I have to remove the colored codes
(int line_length = 0;)

Автор:  Gennaro-HL [ 13 ноя 2016, 05:46 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

Can somebody help me
I can not find a solution

:(

Автор:  Lev [ 13 ноя 2016, 10:54 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

Not sure what your problem exactly.
Probably that your colored text isn't aligned well.
If it is, then you need to fix it here:
Код:
      for (next_line = sz; *next_line != '\n' && *next_line != 0; next_line++)
         line_length += gHUD.m_scrinfo.charWidths[*next_line];
Do not count color codes here. Like so:
Код:
      for (next_line = sz; *next_line != '\n' && *next_line != 0; next_line++)
      {
         if (*next_line == '^' && (*(next_line+1) >= '0' && *(next_line+1) <= '9')
         {
            next_line++;
            continue;
         }
         line_length += gHUD.m_scrinfo.charWidths[*next_line];
      }
But it should be the same as your code that outputs text converting color codes into colors.

Автор:  Gennaro-HL [ 14 ноя 2016, 19:13 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

Look
My problem is that text with color does not line up well when you do the line break
example:
DEFAULT CODE
CURRENT CODE:

Did I do something wrong?

Код:
//The effect I want
///////////////////CURRENT CODE (GGGGGGGGGG)
////////////////////////////GGGGGGGGGG
char Txt[200] = "CURRENT CODE (GGGGGGGGGG)\n^1G^2G^3G^4G^5G^6GG^7G^8G^9G";

   int ypos = max(((ScreenHeight - (m_iLines * LINE_HEIGHT)) / 3) - 40, 30);

   char *sz = Txt;
   char *next_line;
   while (*sz)
   {
      int line_length = 0;
      for (next_line = sz; *next_line != '\n' && *next_line != 0; next_line++)
      {
         if (*next_line == '^' && (*(next_line + 1) >= 0 && *(next_line + 1) <= 9))
         {
            next_line++;
            continue;
         }
         line_length += gHUD.m_scrinfo.charWidths[*next_line];
      }
      char *top = next_line;
      if (*top == '\n')
         *top = 0;
      else
         top = NULL;

      int xpos;
      xpos = (ScreenWidth - line_length) / 2;

      gHUD.DrawHudStringColor(xpos, ypos, ScreenWidth, sz, 255, 255, 255);

      ypos += LINE_HEIGHT;

      if (top)  // restore
         *top = '\n';
      sz = next_line;
      if (*sz == '\n')
         sz2++;

      if (ypos > (ScreenHeight - 20))
         break;
   }

Result:

Изображение

Автор:  Lev [ 14 ноя 2016, 23:41 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

Sorry, forgotten quotes
Код:
(*(next_line + 1) >= 0 && *(next_line + 1) <= 9)
Код:
(*(next_line + 1) >= '0' && *(next_line + 1) <= '9')

Автор:  Gennaro-HL [ 15 ноя 2016, 14:10 ]
Заголовок сообщения:  Re: HLSDK (Client) newline hud

thank you

Страница 1 из 1 Часовой пояс: UTC + 5 часов [ Летнее время ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/