]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/net_notice.qc
Merge branch 'terencehill/menu_hudskin_selector' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / net_notice.qc
1 #include "net_notice.qh"
2
3 REGISTER_NET_TEMP(TE_CSQC_SVNOTICE)
4
5 #ifdef SVQC
6 void sv_notice_join_think()
7 {
8     SELFPARAM();
9     int argc = tokenizebyseparator(autocvar_sv_join_notices, "|");
10     if (argc <= 0) return;
11     for (int i = 0; i < argc; ++i)
12         sv_notice_to(this, argv(i), autocvar_sv_join_notices_time, false);
13 }
14
15 void sv_notice_join(entity _to)
16 {
17     // to-do: make sv_join_notices support per-entry times
18     if (autocvar_sv_join_notices == "") return;
19     defer(_to, 1, sv_notice_join_think);
20 }
21
22 void sv_notice_to(entity _to, string _notice, float _howlong, float _modal)
23 {
24         msg_entity = _to;
25         WriteHeader(MSG_ONE, TE_CSQC_SVNOTICE);
26         WriteString(MSG_ONE, _notice);
27         WriteLong(MSG_ONE, _howlong);
28         WriteByte(MSG_ONE, _modal);
29 }
30
31 void sv_notice_toall(string _notice, float _howlong, float _modal)
32 {
33     entity _head;
34     FOR_EACH_REALCLIENT(_head)
35         sv_notice_to(_head, _notice, _howlong, _modal);
36
37 }
38
39 #endif // SVQC
40
41 #ifdef CSQC
42 NET_HANDLE(TE_CSQC_SVNOTICE, bool isNew)
43 {
44         cl_notice_read();
45         return true;
46 }
47 entity cl_notices;
48 STATIC_INIT(cl_notice)
49 {
50     cl_notices = LL_NEW();
51 }
52 void cl_notice_read()
53 {
54     entity _notice = new(sv_notice);
55     make_pure(_notice);
56     _notice.netname = strzone(ReadString());
57     _notice.alpha = ReadLong() + time;
58     _notice.skin = ReadByte();
59     LL_PUSH(cl_notices, _notice);
60 }
61
62 void cl_notice_run()
63 {
64     bool flag = false;
65     LL_EACH(cl_notices, it.alpha > time, LAMBDA(flag = true; break));
66     if (!flag) return;
67     const int M1 = 30;
68     const int M2 = 10;
69
70     vector v1 = '1 1 0' * M1;
71     vector v2 = '0 0 0';
72     v2.x = vid_conwidth - (2 * M1);
73     v2.y = vid_conheight - (2 * M1);
74     drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL);
75
76     v1 = '1 1 0' * (M1 + M2);
77     v2.x = vid_conwidth - (2 * (M1 + M2));
78     v2.y = vid_conheight - (2 * (M1 + M2));
79     drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
80
81     vector v3 = v1 + '10 10 0';
82     #define OUT(s, z) MACRO_BEGIN { drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3.y += z + 4; } MACRO_END
83
84     OUT(_("^1Server notices:"), 32);
85     LL_EACH(cl_notices, it.alpha > time, LAMBDA(
86         string s = sprintf(_("^7%s (^3%d sec left)"), it.netname , rint(it.alpha - time));
87         OUT(s, 16);
88     ));
89     #undef OUT
90 }
91
92 #endif // CSQC