From d48e70deea1b12aaea9d0543dfe5f1bac9787177 Mon Sep 17 00:00:00 2001 From: fgsfds Date: Sun, 11 Aug 2019 03:02:47 +0300 Subject: [PATCH] GUI: MOTD field now has automatic height --- src/game/g_basic.pas | 11 +++++++++++ src/game/g_netmaster.pas | 32 +++++++++++++++++--------------- src/mastersrv/master.c | 4 +++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/game/g_basic.pas b/src/game/g_basic.pas index e5ef3d9..bd3f50e 100644 --- a/src/game/g_basic.pas +++ b/src/game/g_basic.pas @@ -90,6 +90,7 @@ procedure SortSArray(var S: SSArray); function b_Text_Format(S: string): string; function b_Text_Unformat(S: string): string; function b_Text_Wrap(S: string; LineLen: Integer): string; +function b_Text_LineCount(S: string): Integer; var gmon_dbg_los_enabled: Boolean = true; @@ -1180,4 +1181,14 @@ begin Result := WrapText(S, ''#10, [#10, ' ', '-'], LineLen); end; +function b_Text_LineCount(S: string): Integer; +var + I: Integer; +begin + Result := IfThen(S = '', 0, 1); + for I := 1 to High(S) do + if S[I] = #10 then + Inc(Result); +end; + end. diff --git a/src/game/g_netmaster.pas b/src/game/g_netmaster.pas index b413486..e8a80d6 100644 --- a/src/game/g_netmaster.pas +++ b/src/game/g_netmaster.pas @@ -530,7 +530,7 @@ end; procedure g_Serverlist_Draw(var SL: TNetServerList; var ST: TNetServerTable); var Srv: TNetServer; - sy, i, y, mw, mx, l: Integer; + sy, i, y, mw, mx, l, motdh: Integer; cw: Byte = 0; ch: Byte = 0; ww: Word = 0; @@ -548,23 +548,25 @@ begin ip := _lc[I_NET_SLIST_HELP]; mw := (Length(ip) * cw) div 2; - e_DrawFillQuad(16, 64, gScreenWidth-16, gScreenHeight-84, 64, 64, 64, 110); - e_DrawQuad(16, 64, gScreenWidth-16, gScreenHeight-84, 255, 127, 0); + motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD); + + e_DrawFillQuad(16, 64, gScreenWidth-16, motdh, 64, 64, 64, 110); + e_DrawQuad(16, 64, gScreenWidth-16, motdh, 255, 127, 0); e_TextureFontPrintEx(gScreenWidth div 2 - mw, gScreenHeight-24, ip, gStdFont, 225, 225, 225, 1); // MOTD if slMOTD <> '' then begin - e_DrawFillQuad(16, gScreenHeight-84, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 110); - e_DrawQuad(16, gScreenHeight-84, gScreenWidth-16, gScreenHeight-44, 255, 127, 0); - e_TextureFontPrintFmt(20, gScreenHeight-81, slMOTD, gStdFont, False, True); + e_DrawFillQuad(16, motdh, gScreenWidth-16, gScreenHeight-44, 64, 64, 64, 110); + e_DrawQuad(16, motdh, gScreenWidth-16, gScreenHeight-44, 255, 127, 0); + e_TextureFontPrintFmt(20, motdh + 3, slMOTD, gStdFont, False, True); end; // Urgent message if not slReadUrgent and (slUrgent <> '') then begin - e_DrawFillQuad(17, 65, gScreenWidth-17, gScreenHeight-85, 64, 64, 64, 128); + e_DrawFillQuad(17, 65, gScreenWidth-17, motdh-1, 64, 64, 64, 128); e_DrawFillQuad(gScreenWidth div 2 - 256, gScreenHeight div 2 - 60, gScreenWidth div 2 + 256, gScreenHeight div 2 + 60, 64, 64, 64, 128); e_DrawQuad(gScreenWidth div 2 - 256, gScreenHeight div 2 - 60, @@ -588,7 +590,7 @@ begin if SL = nil then begin l := Length(slWaitStr) div 2; - e_DrawFillQuad(17, 65, gScreenWidth-17, gScreenHeight-85, 64, 64, 64, 128); + e_DrawFillQuad(17, 65, gScreenWidth-17, motdh-1, 64, 64, 64, 128); e_DrawQuad(gScreenWidth div 2 - 192, gScreenHeight div 2 - 10, gScreenWidth div 2 + 192, gScreenHeight div 2 + 11, 255, 127, 0); e_TextureFontPrint(gScreenWidth div 2 - cw * l, gScreenHeight div 2 - ch div 2, @@ -619,12 +621,12 @@ begin e_DrawLine(1, 16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255); e_DrawLine(1, 16, 85, gScreenWidth - 16, 85, 255, 127, 0); - e_DrawLine(1, 16, gScreenHeight-104, gScreenWidth-16, gScreenHeight-104, 255, 127, 0); + e_DrawLine(1, 16, motdh-20, gScreenWidth-16, motdh-20, 255, 127, 0); - e_DrawLine(1, mx - 70, 64, mx - 70, gScreenHeight-84, 255, 127, 0); - e_DrawLine(1, mx, 64, mx, gScreenHeight-104, 255, 127, 0); - e_DrawLine(1, mx + 52, 64, mx + 52, gScreenHeight-104, 255, 127, 0); - e_DrawLine(1, mx + 104, 64, mx + 104, gScreenHeight-104, 255, 127, 0); + e_DrawLine(1, mx - 70, 64, mx - 70, motdh, 255, 127, 0); + e_DrawLine(1, mx, 64, mx, motdh-20, 255, 127, 0); + e_DrawLine(1, mx + 52, 64, mx + 52, motdh-20, 255, 127, 0); + e_DrawLine(1, mx + 104, 64, mx + 104, motdh-20, 255, 127, 0); e_TextureFontPrintEx(18, 68, 'NAME/MAP', gStdFont, 255, 127, 0, 1); e_TextureFontPrintEx(mx - 68, 68, 'PING', gStdFont, 255, 127, 0, 1); @@ -665,10 +667,10 @@ begin y := y + 42; end; - e_TextureFontPrintEx(20, gScreenHeight-101, ip, gStdFont, 205, 205, 205, 1); + e_TextureFontPrintEx(20, motdh-20+3, ip, gStdFont, 205, 205, 205, 1); ip := IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS]; e_TextureFontPrintEx(gScreenWidth - 48 - (Length(ip) + 1)*cw, - gScreenHeight-101, ip, gStdFont, 205, 205, 205, 1); + motdh-20+3, ip, gStdFont, 205, 205, 205, 1); end; procedure g_Serverlist_GenerateTable(SL: TNetServerList; var ST: TNetServerTable); diff --git a/src/mastersrv/master.c b/src/mastersrv/master.c index 9745694..ce98cfc 100644 --- a/src/mastersrv/master.c +++ b/src/mastersrv/master.c @@ -142,7 +142,9 @@ void d_getargs (int argc, char *argv[]) { int d_readtextfile (const char *fname, char *buf, size_t max) { FILE *f = fopen(fname, "r"); if (f) { - fgets(buf, max, f); + char line[256] = { 0 }; + while(fgets(buffer, sizeof(line), (FILE*) fp)) + printf("%s\n", buffer); fclose(f); return 0; } -- 2.29.2