]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Graphical friends list TimePath/friendslist
authorTimePath <andrew.hardaker1995@gmail.com>
Wed, 26 Aug 2015 12:06:37 +0000 (22:06 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Wed, 26 Aug 2015 12:06:37 +0000 (22:06 +1000)
12 files changed:
gfx/menu/luma/skinvalues.txt
gfx/menu/luminos/skinvalues.txt
gfx/menu/wickedx/skinvalues.txt
gfx/menu/xaw/skinvalues.txt
qcsrc/common/mutators/mutator/social.qc
qcsrc/common/mutators/mutator/social.qh [new file with mode: 0644]
qcsrc/common/util.qc
qcsrc/common/util.qh
qcsrc/menu/classes.inc
qcsrc/menu/skin-customizables.inc
qcsrc/menu/xonotic/dialog_social.qc [new file with mode: 0644]
qcsrc/menu/xonotic/mainwindow.qc

index c997fea25772cd797dc361c60304db04e7cc3b5b..f9e5109b3eb6c40927031af09819f45d73698206 100644 (file)
@@ -86,6 +86,7 @@ COLOR_DIALOG_MUTATORS         '1 1 1'
 COLOR_DIALOG_MAPINFO          '1 1 1'
 COLOR_DIALOG_USERBIND         '1 1 1'
 COLOR_DIALOG_SINGLEPLAYER     '1 1 1'
+COLOR_DIALOG_SOCIAL           '1 1 1'
 COLOR_DIALOG_CREDITS          '1 1 1'
 COLOR_DIALOG_WEAPONS          '1 1 1'
 COLOR_DIALOG_VIEW             '1 1 1'
@@ -112,6 +113,7 @@ POSITION_DIALOG_MULTIPLAYER   '0.9 0.4 0'
 POSITION_DIALOG_SINGLEPLAYER  '0.15 0.4 0'
 POSITION_DIALOG_SETTINGS      '0.5 1 0'
 POSITION_DIALOG_CREDITS       '-0.05 1.2 0'
+POSITION_DIALOG_SOCIAL        '0.5 1.2 0'
 POSITION_DIALOG_QUIT          '1.05 1.2 0'
 
 // font
index ca0384fb554135f88ed4bf13a41c3b3e849497f9..33b450b974078d68b805760476cedd2e7decd589 100755 (executable)
@@ -62,6 +62,7 @@ POSITION_DIALOG_MULTIPLAYER     '0.9 0.4 0'
 POSITION_DIALOG_SINGLEPLAYER    '0.15 0.4 0'
 POSITION_DIALOG_SETTINGS        '0.5 1 0'
 POSITION_DIALOG_CREDITS         '-0.05 1.2 0'
+POSITION_DIALOG_SOCIAL          '0.5 1.2 0'
 POSITION_DIALOG_QUIT            '1.05 1.2 0'
 
 // tooltips
@@ -185,6 +186,7 @@ COLOR_DIALOG_MUTATORS           '1 1 1'
 COLOR_DIALOG_MAPINFO            '1 1 1'
 COLOR_DIALOG_USERBIND           '1 1 1'
 COLOR_DIALOG_SINGLEPLAYER       '1 1 1'
+COLOR_DIALOG_SOCIAL             '1 1 1'
 COLOR_DIALOG_CREDITS            '1 1 1'
 COLOR_DIALOG_WEAPONS            '1 1 1'
 COLOR_DIALOG_VIEW               '1 1 1'
index b7011a0b0e18369246a573e86f52dd0d22174bb4..0cefa564cd407a858b8d7594adcd498336c5b029 100644 (file)
@@ -62,6 +62,7 @@ POSITION_DIALOG_MULTIPLAYER     '0.8 0.4 0'
 POSITION_DIALOG_SINGLEPLAYER    '0.2 0.4 0'
 POSITION_DIALOG_SETTINGS        '0.5 0.95 0'
 POSITION_DIALOG_CREDITS         '-0.05 1.2 0'
+POSITION_DIALOG_SOCIAL          '0.5 1.2 0'
 POSITION_DIALOG_QUIT            '1.05 1.2 0'
 
 // tooltips
@@ -185,6 +186,7 @@ COLOR_DIALOG_MUTATORS           '1 1 1'
 COLOR_DIALOG_MAPINFO            '1 1 1'
 COLOR_DIALOG_USERBIND           '1 1 1'
 COLOR_DIALOG_SINGLEPLAYER       '1 1 1'
+COLOR_DIALOG_SOCIAL             '1 1 1'
 COLOR_DIALOG_CREDITS            '1 1 1'
 COLOR_DIALOG_WEAPONS            '1 1 1'
 COLOR_DIALOG_VIEW               '1 1 1'
index 5f4bbaad40211135e157b03f89e82e99ef337475..788470b3c50f1aef2cc8a48cc49f1522c6adc29d 100644 (file)
@@ -29,6 +29,7 @@ COLOR_DIALOG_MUTATORS           '1 1 1'
 COLOR_DIALOG_MAPINFO            '1 1 1'
 COLOR_DIALOG_USERBIND           '1 1 1'
 COLOR_DIALOG_SINGLEPLAYER       '1 1 1'
+COLOR_DIALOG_SOCIAL             '1 1 1'
 COLOR_DIALOG_CREDITS            '1 1 1'
 COLOR_DIALOG_WEAPONS            '1 1 1'
 COLOR_DIALOG_VIEW               '1 1 1'
@@ -46,6 +47,7 @@ POSITION_DIALOG_MULTIPLAYER     '0.9 0.5 0'
 POSITION_DIALOG_SINGLEPLAYER    '0.1 0.1 0'
 POSITION_DIALOG_SETTINGS        '0.1 0.9 0'
 POSITION_DIALOG_CREDITS         '0.3 1.2 0'
+POSITION_DIALOG_SOCIAL          '0.6 1.2 0'
 POSITION_DIALOG_QUIT            '0.9 1.2 0'
 
 // mouse
index 52dd90a059bde14a3253672b4f54e0edce375797..3ea0b0f9c68f93cb8a57089c95c229f0fd18ec7f 100644 (file)
@@ -1,12 +1,11 @@
 #ifdef MENUQC
+#include "social.qh"
 REGISTER_MUTATOR(social, true);
 
 void Social_send(int to, string msg);
 
 string Social_invite_accept;
 
-int Social_db = -1;
-
 STATIC_INIT(Social) {
     Social_db = db_load("social.db");
 }
@@ -101,6 +100,7 @@ MUTATOR_HOOKFUNCTION(social, GameCommand) {
         int id = stoi(argv(1));
         string nick = substring(cmd_string, argv_start_index(2), argv_end_index(-1) - argv_start_index(2));
         db_put(Social_db, itos(id), nick);
+        MUTATOR_CALLHOOK(Social_Add, id, nick);
         return true;
     }
     if (cmd_name == "sremove" && cmd_argc == 2) {
@@ -109,7 +109,7 @@ MUTATOR_HOOKFUNCTION(social, GameCommand) {
         return true;
     }
     if (cmd_name == "slist") {
-        FOREACH_DB(Social_db, LAMBDA(
+        FOREACH_DB(Social_db, true, LAMBDA(
             printf("%s: %s\n", k, v);
         ));
         return true;
diff --git a/qcsrc/common/mutators/mutator/social.qh b/qcsrc/common/mutators/mutator/social.qh
new file mode 100644 (file)
index 0000000..f8cc8a7
--- /dev/null
@@ -0,0 +1,14 @@
+#ifdef MENUQC
+#ifndef SOCIAL_H
+#define SOCIAL_H
+#include "../base.qh"
+/** Called when a friend is added */
+#define EV_Social_Add(i, o) \
+    /**/ i(int, mutator_argv_int_0) \
+    /**/ i(string, mutator_argv_string_0) \
+    /**/
+MUTATOR_HOOKABLE(Social_Add, EV_Social_Add);
+
+int Social_db = -1;
+#endif
+#endif
index 6e14a7f5af2c691324f7d7ca9e202f69e6a702d2..e0428d43faa908c8db4db6f8607f80c659c46211 100644 (file)
@@ -349,7 +349,7 @@ void db_dump(int db, string pFilename)
        if (fh < 0)
                error(strcat("Can't dump DB to ", pFilename));
        fputs(fh, "0\n");
-       FOREACH_DB(db, LAMBDA(
+       FOREACH_DB(db, true, LAMBDA(
                fputs(fh, strcat("\\", k, "\\", v, "\n"));
        ));
        fclose(fh);
index b4aa5b3052320b461fa3e2dd887e3b2b392c73dc..fc26e8a5d4b53d3cbf178893826f71e38fa08f0c 100644 (file)
@@ -90,23 +90,23 @@ void db_close(int db);
 string db_get(int db, string key);
 void db_put(int db, string key, string value);
 void db_delete(float db, string pKey);
-#define FOREACH_INFO(s, f) do { \
+#define FOREACH_INFO(s, cond, f) do { \
        string __s = s; \
        int __m = tokenizebyseparator(__s, "\\"); \
        for (int __j = 2; __j < __m; __j += 2) { \
-               string k = argv(__j - 1), v = argv(__j); \
-               f; \
+               noref string k = argv(__j - 1), v = uri_unescape(argv(__j)); \
+               if (cond) f; \
        } \
 } while (0)
-#define FOREACH_BUF(db, f) do { \
+#define FOREACH_BUF(db, cond, f) do { \
     int __db = db; \
     int __n = buf_getsize(__db); \
     for (int __i = 0; __i < __n; ++__i) { \
-       f; \
+       if (cond) f; \
        } \
 } while (0)
-#define FOREACH_DB(db, f) do { \
-    FOREACH_BUF(db, FOREACH_INFO(bufstr_get(__db, __i), f)); \
+#define FOREACH_DB(db, cond, f) do { \
+    FOREACH_BUF(db, true, FOREACH_INFO(bufstr_get(__db, __i), cond, f)); \
 } while (0)
 
 // stringbuffer loading/saving
index aee7166e1b3676a0a5052c454b664466836d5c81..8e0d266e2189292be00d512d40676ee37c2872f7 100644 (file)
@@ -99,6 +99,7 @@
 #include "xonotic/dialog_settings_video.qc"
 #include "xonotic/dialog_singleplayer.qc"
 #include "xonotic/dialog_singleplayer_winner.qc"
+#include "xonotic/dialog_social.qc"
 #include "xonotic/dialog_teamselect.qc"
 #include "xonotic/gametypelist.qc"
 #include "xonotic/image.qc"
index d5e1f82eba4ab0ece3d7fb7995ec4b7838c455a3..a55a6cdf1cdf7ca1e3e94c8b62d1d1ceaa00cc9d 100644 (file)
@@ -63,6 +63,7 @@ SKINBEGIN
        SKINVECTOR(COLOR_DIALOG_MAPINFO, '0.7 0.7 1');
        SKINVECTOR(COLOR_DIALOG_USERBIND, '0.7 0.7 1');
        SKINVECTOR(COLOR_DIALOG_SINGLEPLAYER, '1 1 0.7');
+       SKINVECTOR(COLOR_DIALOG_SOCIAL, '1 1 1');
        SKINVECTOR(COLOR_DIALOG_CREDITS, '0.7 0.7 1');
        SKINVECTOR(COLOR_DIALOG_WEAPONS, '1 0.7 0.7');
        SKINVECTOR(COLOR_DIALOG_VIEW, '1 0.7 0.7');
@@ -80,6 +81,7 @@ SKINBEGIN
        SKINVECTOR(POSITION_DIALOG_SINGLEPLAYER, '0.1 0.1 0');
        SKINVECTOR(POSITION_DIALOG_SETTINGS, '0.1 0.9 0');
        SKINVECTOR(POSITION_DIALOG_CREDITS, '0.3 1.2 0');
+       SKINVECTOR(POSITION_DIALOG_SOCIAL, '0.5 1.2 0');
        SKINVECTOR(POSITION_DIALOG_QUIT, '0.9 1.2 0');
 
        // mouse
diff --git a/qcsrc/menu/xonotic/dialog_social.qc b/qcsrc/menu/xonotic/dialog_social.qc
new file mode 100644 (file)
index 0000000..28ebdef
--- /dev/null
@@ -0,0 +1,116 @@
+#ifndef DIALOG_SOCIAL_H
+#define DIALOG_SOCIAL_H
+
+#include "../../common/mutators/mutator/social.qh"
+#include "datasource.qc"
+CLASS(FriendSource, DataSource)
+    METHOD(FriendSource, getEntry, entity(int i, void(string name, string icon) returns))
+    {
+        int idx = 0;
+        string name = string_null;
+        FOREACH_DB(Social_db, idx++ == i, LAMBDA(
+            name = v;
+            break;
+        ));
+        if (returns) returns(name, string_null);
+        return DataSource_true;
+    }
+    METHOD(FriendSource, reload, int(string filter)) {
+        int n = 0;
+        FOREACH_DB(Social_db, true, LAMBDA(++n));
+        return n;
+    }
+ENDCLASS(FriendSource)
+
+entity Social_inst;
+
+#include "listbox.qc"
+CLASS(XonoticFriendsList, XonoticListBox)
+    ATTRIB(XonoticFriendsList, alphaBG, float, 0)
+    ATTRIB(XonoticFriendsList, itemAbsSize, vector, '0 0 0')
+    ATTRIB(XonoticFriendsList, origin, vector, '0 0 0')
+    ATTRIB(XonoticFriendsList, realFontSize, vector, '0 0 0')
+    ATTRIB(XonoticFriendsList, realUpperMargin, float, 0)
+    ATTRIB(XonoticFriendsList, rowsPerItem, float, 2)
+    ATTRIB(XonoticFriendsList, stringFilterBox, entity, NULL)
+    ATTRIB(XonoticFriendsList, stringFilter, string, string_null)
+    ATTRIB(XonoticFriendsList, typeToSearchString, string, string_null)
+    ATTRIB(XonoticFriendsList, typeToSearchTime, float, 0)
+    ATTRIB(XonoticFriendsList, source, DataSource, NULL)
+    ATTRIB(XonoticFriendsList, onChange, void(entity, entity), func_null)
+    ATTRIB(XonoticFriendsList, onChangeEntity, entity, NULL)
+    string XonoticFriendsList_cb_name;
+    void XonoticFriendsList_cb(string _name, string _icon)
+    {
+        XonoticFriendsList_cb_name = _name;
+    }
+    METHOD(XonoticFriendsList, drawListBoxItem, void(entity this, int i, vector absSize, bool isSelected, bool isFocused))
+    {
+        if (!this.source) return;
+        if (!this.source.getEntry(i, XonoticFriendsList_cb)) return;
+        string name = XonoticFriendsList_cb_name;
+        if (isSelected) {
+            draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
+        } else if (isFocused) {
+            this.focusedItemAlpha = getFadedAlpha(this.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
+            draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, this.focusedItemAlpha);
+        }
+        string s = draw_TextShortenToWidth(strdecolorize(name), 1, 0, this.realFontSize);
+        draw_Text(this.realUpperMargin * eY + (0.5 * this.realFontSize.x) * eX, s, this.realFontSize, '1 1 1', SKINALPHA_TEXT, 0);
+    }
+    METHOD(XonoticFriendsList, refilter, void(entity this))
+    {
+        if (!this.source) {
+            this.nItems = 0;
+            return;
+        }
+        this.nItems = this.source.reload(this.stringFilter);
+    }
+    METHOD(XonoticFriendsList, resizeNotify, void(entity this, vector relOrigin, vector relSize, vector absOrigin, vector absSize))
+    {
+        super.resizeNotify(this, relOrigin, relSize, absOrigin, absSize);
+
+        this.itemAbsSize = '0 0 0';
+        this.realFontSize_y = this.fontSize / (this.itemAbsSize_y = (absSize.y * this.itemHeight));
+        this.realFontSize_x = this.fontSize / (this.itemAbsSize_x = (absSize.x * (1 - this.controlWidth)));
+        this.realUpperMargin = 0.5 * (1 - this.realFontSize.y);
+    }
+    INIT(XonoticFriendsList) {
+       Social_inst = this;
+    }
+    CONSTRUCTOR(XonoticFriendsList, DataSource _source) {
+        CONSTRUCT(XonoticFriendsList);
+        this.source = _source;
+        this.configureXonoticListBox(this);
+        this.refilter(this);
+    }
+ENDCLASS(XonoticFriendsList)
+
+#include "dialog.qc"
+CLASS(XonoticSocialDialog, XonoticDialog)
+    METHOD(XonoticSocialDialog, fill, void(entity));
+    ATTRIB(XonoticSocialDialog, title, string, _("Social"))
+    ATTRIB(XonoticSocialDialog, color, vector, SKINCOLOR_DIALOG_SOCIAL)
+    ATTRIB(XonoticSocialDialog, intendedWidth, float, 0.5)
+    ATTRIB(XonoticSocialDialog, rows, float, 20)
+    ATTRIB(XonoticSocialDialog, columns, float, 2)
+    ATTRIB(XonoticSocialDialog, friendsList, XonoticFriendsList, NEW(XonoticFriendsList, NEW(FriendSource)))
+ENDCLASS(XonoticSocialDialog)
+
+#endif
+
+#ifdef IMPLEMENTATION
+
+REGISTER_MUTATOR(social_refreshmenu, true);
+MUTATOR_HOOKFUNCTION(social_refreshmenu, Social_Add) {
+    Social_inst.refilter(Social_inst);
+}
+
+METHOD(XonoticSocialDialog, fill, void(entity this))
+{
+    int
+    col = 0, width = 2;
+    this.gotoRC(this, 0, col);
+        this.TD(this, this.rows, width, this.friendsList);
+}
+#endif
index eafa1842fd84332d721fcb8af47f8d120fa3a111..27cf689039c78f08e3224e2963a8647758222a89 100644 (file)
@@ -238,6 +238,12 @@ void MainWindow_configureMainWindow(entity me)
                n.setNexposee(n, i, SKINPOSITION_DIALOG_CREDITS, SKINALPHAS_MAINMENU_x, SKINALPHAS_MAINMENU_y);
                n.pullNexposee(n, i, eY * (SKINHEIGHT_TITLE * SKINFONTSIZE_TITLE / conheight));
 
+               i = NEW(XonoticSocialDialog);
+               i.configureDialog(i);
+               n.addItemCentered(n, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);
+               n.setNexposee(n, i, SKINPOSITION_DIALOG_SOCIAL, SKINALPHAS_MAINMENU_x, SKINALPHAS_MAINMENU_y);
+               n.pullNexposee(n, i, eY * (SKINHEIGHT_TITLE * SKINFONTSIZE_TITLE / conheight));
+
                i = NEW(XonoticQuitDialog);
                i.configureDialog(i);
                n.addItemCentered(n, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z);