X-Git-Url: https://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fcommon%2Fnet_notice.qc;h=1d10cf94fb8249a9fbaef77fb57e8c25feb004f4;hp=317eec1094ebafa189b35575bab5d693f18779fa;hb=e0012447bfce1b551df3dc01b043655aa93dafad;hpb=b683bf23a495d3b1b3f6df3bda75bfe0f069ab05 diff --git a/qcsrc/common/net_notice.qc b/qcsrc/common/net_notice.qc index 317eec1094..1d10cf94fb 100644 --- a/qcsrc/common/net_notice.qc +++ b/qcsrc/common/net_notice.qc @@ -1,36 +1,27 @@ #include "net_notice.qh" +REGISTER_NET_TEMP(TE_CSQC_SVNOTICE) + #ifdef SVQC -void sv_notice_join_think() -{SELFPARAM(); - //NextLevel(); - float argc = tokenizebyseparator(autocvar_sv_join_notices, "|"); - if(argc > 0) - { - float i; - for(i = argc - 1; i >= 0; --i) - sv_notice_to(self.owner, argv(i), autocvar_sv_join_notices_time, false); - } - remove(self); +void sv_notice_join_think(entity this) +{ + int argc = tokenizebyseparator(autocvar_sv_join_notices, "|"); + if (argc <= 0) return; + for (int i = 0; i < argc; ++i) + sv_notice_to(this, argv(i), autocvar_sv_join_notices_time, false); } -void sv_notice_join() -{SELFPARAM(); +void sv_notice_join(entity _to) +{ // to-do: make sv_join_notices support per-entry times - if(autocvar_sv_join_notices == "") - return; - - entity n = spawn(); - n.owner = self; - n.think = sv_notice_join_think; - n.nextthink = time + 1; + if (autocvar_sv_join_notices == "") return; + defer(_to, 1, sv_notice_join_think); } void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) { msg_entity = _to; - WriteByte(MSG_ONE, SVC_TEMPENTITY); - WriteByte(MSG_ONE, TE_CSQC_SVNOTICE); + WriteHeader(MSG_ONE, TE_CSQC_SVNOTICE); WriteString(MSG_ONE, _notice); WriteLong(MSG_ONE, _howlong); WriteByte(MSG_ONE, _modal); @@ -38,77 +29,76 @@ void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) void sv_notice_toall(string _notice, float _howlong, float _modal) { - entity _head; - FOR_EACH_REALCLIENT(_head) - sv_notice_to(_head, _notice, _howlong, _modal); - + FOREACH_CLIENT(IS_REAL_CLIENT(it), sv_notice_to(it, _notice, _howlong, _modal)); } #endif // SVQC #ifdef CSQC +NET_HANDLE(TE_CSQC_SVNOTICE, bool isNew) +{ + cl_notice_read(); + return true; +} +entity cl_notices; void cl_notice_read() { - //float _done; - //float _modal; - entity _notice = new(sv_notice); + entity _notice = new_pure(sv_notice); _notice.netname = strzone(ReadString()); _notice.alpha = ReadLong() + time; _notice.skin = ReadByte(); + if(!cl_notices) + cl_notices = LL_NEW(); + LL_PUSH(cl_notices, _notice); } -float cl_notice_run() +void cl_notice_run() { - entity _notes; - string _notice; - float m = false; - - _notes = findchain(classname, "sv_notice"); - if(!_notes) - return false; - #define M1 30 - #define M2 10 - - vector v1, v2 = '0 0 0', v3; - v1 = '1 1 0' * M1; - v2_x = vid_conwidth - (2 * M1); - v2_y = vid_conheight - (2 * M1); - + if (!cl_notices) + return; + + bool flag = false; + LL_EACH(cl_notices, it.alpha > time, { flag = true; break; }); + if (!flag) + { + LL_DELETE(cl_notices); + return; + } + + const int M1 = 30; + const int M2 = 10; + + vector v1 = '1 1 0' * M1; + vector v2 = '0 0 0'; + v2.x = vid_conwidth - (2 * M1); + v2.y = vid_conheight - (2 * M1); drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL); + v1 = '1 1 0' * (M1 + M2); - v2_x = vid_conwidth - (2 * (M1 + M2)); - v2_y = vid_conheight - (2 * (M1 + M2)); + v2.x = vid_conwidth - (2 * (M1 + M2)); + v2.y = vid_conheight - (2 * (M1 + M2)); drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL); - v3 = v1 + '10 10 0'; - #define OUT(s,z) drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3_y += z + 4 + vector v3 = v1 + '10 10 0'; + #define OUT(s, z) MACRO_BEGIN \ + drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); \ + v3.y += z + 4; \ + MACRO_END + float cur_time = 0; + float time_width = 48; OUT(_("^1Server notices:"), 32); - - //drawcolorcodedstring(v1 + '5 5 0', "^1Server notices:", '32 32 0', 1, DRAWFLAG_NORMAL); - while(_notes) - { - - _notice = sprintf(_("^7%s (^3%d sec left)"), _notes.netname , rint(_notes.alpha - time)); - OUT(_notice, 16); - - if(_notes.skin) - m = true; - - if(_notes.alpha <= time) + LL_EACH(cl_notices, it.alpha > time, { + if(it.alpha - cur_time > 0.1) { - _notes.think = SUB_Remove; - _notes.nextthink = time; + cur_time = it.alpha; + string s = sprintf("^3%d", ceil(cur_time - time)); + drawcolorcodedstring(v3 + eX * 0.5 * (time_width - stringwidth(s, true, '1 1 0' * 16)), s, '1 1 0' * 16, 1, DRAWFLAG_NORMAL); + v3.x = v1.x + 10 + time_width; } - - _notes = _notes.chain; - } - + OUT(it.netname, 16); + }); #undef OUT - #undef M1 - #undef M2 - - return m; } #endif // CSQC