]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Allow scrolling the maximized chat history by pressing mouse wheel up/down and page... 974/head
authorterencehill <piuntn@gmail.com>
Mon, 31 Jan 2022 15:53:43 +0000 (16:53 +0100)
committerterencehill <piuntn@gmail.com>
Tue, 1 Feb 2022 09:47:12 +0000 (10:47 +0100)
qcsrc/client/hud/panel/chat.qc
qcsrc/client/hud/panel/chat.qh
qcsrc/client/main.qc

index 07de3b7dd1b9b4b586606dd1dd59432604404789..c1313b86e8f1d058c3ac23e56f19c73be801d097 100644 (file)
@@ -9,6 +9,62 @@ void HUD_Chat_Export(int fh)
        // allow saving cvars that aesthetically change the panel into hud skin files
 }
 
+float chat_maximized_scroll_ofs;
+float chat_maximized_reset_scroll_time;
+float HUD_Panel_Chat_InputEvent(float bInputType, float nPrimary, float nSecondary)
+{
+       if(bInputType == 3)
+       {
+               mousepos.x = nPrimary;
+               mousepos.y = nSecondary;
+               return true;
+       }
+
+       if(bInputType == 2)
+               return false;
+
+       // at this point bInputType can only be 0 or 1 (key pressed or released)
+       bool key_pressed = (bInputType == 0);
+
+       if(!autocvar__con_chat_maximized)
+               return false;
+
+       if(nPrimary == K_MWHEELUP)
+       {
+               if (!key_pressed)
+                       return true;
+               chat_maximized_scroll_ofs += 5 * cvar("con_chatsize");
+               return true;
+       }
+       else if(nPrimary == K_MWHEELDOWN)
+       {
+               if (!key_pressed)
+                       return true;
+               chat_maximized_scroll_ofs -= 5 * cvar("con_chatsize");
+               if (chat_maximized_scroll_ofs < 0)
+                       chat_maximized_scroll_ofs = 0;
+               return true;
+       }
+       else if(nPrimary == K_PGUP)
+       {
+               if (!key_pressed)
+                       return true;
+               chat_maximized_scroll_ofs += vid_conheight / 2;
+               return true;
+       }
+       else if(nPrimary == K_PGDN)
+       {
+               if (!key_pressed)
+                       return true;
+               chat_maximized_scroll_ofs -= vid_conheight / 2;
+               if (chat_maximized_scroll_ofs < 0)
+                       chat_maximized_scroll_ofs = 0;
+               return true;
+       }
+
+       return false;
+}
+
 void HUD_Chat()
 {
        if(!autocvar__hud_configure)
@@ -21,16 +77,26 @@ void HUD_Chat()
                                cvar_set("con_chat", "-1");
                        return;
                }
+
                if(autocvar__con_chat_maximized)
                {
                        if(!hud_draw_maximized) return;
+
+                       chat_maximized_reset_scroll_time = time + 3;
                }
-               else if(chat_panel_modified)
+               else
                {
-                       panel.update_time = time; // forces reload of panel attributes
-                       chat_panel_modified = false;
+                       if(chat_panel_modified)
+                       {
+                               panel.update_time = time; // forces reload of panel attributes
+                               chat_panel_modified = false;
+                       }
+                       if (time > chat_maximized_reset_scroll_time)
+                               chat_maximized_scroll_ofs = 0;
                }
        }
+       else
+               chat_maximized_scroll_ofs = 0;
 
        HUD_Panel_LoadCvars();
 
@@ -57,6 +123,7 @@ void HUD_Chat()
                        chat_panel_modified = true;
                }
                panel_bg_alpha = max(0.75, panel_bg_alpha);
+               panel_size.y += chat_maximized_scroll_ofs;
        }
 
        vector pos, mySize;
index 9ed87d9f3a5159ab499dc78088921f7cc0fdbf14..b17ba1a9aa6c310858cb3bac6ee3c1582f011ca5 100644 (file)
@@ -13,3 +13,5 @@ bool autocvar_con_chatrect;
 //float autocvar_con_chatrect_x;
 //float autocvar_con_chatrect_y;
 float autocvar_con_chatwidth;
+
+float HUD_Panel_Chat_InputEvent(float bInputType, float nPrimary, float nSecondary);
index 5dbfb7209d19127b0600039fbcaeaf16da0ff1ed..649def85c615fc859904c25f129d12c2e84ec1cd 100644 (file)
@@ -4,6 +4,7 @@
 #include <client/draw.qh>
 #include <client/hud/_mod.qh>
 #include <client/hud/panel/centerprint.qh>
+#include <client/hud/panel/chat.qh>
 #include <client/hud/panel/quickmenu.qh>
 #include <client/hud/panel/scoreboard.qh>
 #include <client/items/items.qh>
@@ -452,10 +453,13 @@ float CSQC_InputEvent(int bInputType, float nPrimary, float nSecondary)
 {
        TC(int, bInputType);
        bool override = false;
+
        override |= HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary);
        if (override)
                return true;
 
+       override |= HUD_Panel_Chat_InputEvent(bInputType, nPrimary, nSecondary);
+
        override |= QuickMenu_InputEvent(bInputType, nPrimary, nSecondary);
 
        override |= HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary);