]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/quickmenu.qc
Quickmenu: fix an almost unnoticeable wrong highlighting due to precision errors
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / quickmenu.qc
index 3233d1b9ba9ea22acaf0d2cf3f869f08f5704473..65c3ab2f8738260897e57f5a78ed7dcf577dac3d 100644 (file)
@@ -83,12 +83,12 @@ bool QuickMenu_Open(string mode, string submenu, string file)
        if(mode == "file")
        {
                if(file == "" || file == "0")
-                       LOG_INFO("No file name is set in hud_panel_quickmenu_file, loading default quickmenu\n");
+                       LOG_INFO("No file name is set in hud_panel_quickmenu_file, loading default quickmenu");
                else
                {
                        fh = fopen(file, FILE_READ);
                        if(fh < 0)
-                               LOG_INFOF("Couldn't open file \"%s\", loading default quickmenu\n", file);
+                               LOG_INFOF("Couldn't open file \"%s\", loading default quickmenu", file);
                }
                if(fh < 0)
                        mode = "default";
@@ -335,28 +335,32 @@ bool QuickMenu_Page_Load(string target_submenu, bool new_page)
                                QuickMenu_Page_LoadEntry(QuickMenu_Page_Entries, substring(s, 1, -1), "");
                        QuickMenu_skip_submenu(substring(s, 1, -1));
                }
-               else if(entry_num >= first_entry && substring(s, 0, 1) == QM_TAG_TITLE)
+               else if(substring(s, 0, 1) == QM_TAG_TITLE)
                {
                        ++QuickMenu_Buffer_Index;
-                       cmd = QuickMenu_Buffer_Get();
-                       string command_code = substring(cmd, 0, 1);
-                       if(command_code == QM_TAG_COMMAND)
-                               cmd = substring(cmd, 1, -1);
-                       else if(command_code == QM_TAG_PLCOMMAND)
+                       if(entry_num >= first_entry)
                        {
-                               // throw away the current quickmenu buffer and load a new one
-                               cmd = substring(cmd, 1, -1);
-                               strunzone(z_submenu);
-                               if(HUD_Quickmenu_PlayerListEntries_Create(cmd, stof(substring(s, 1, 1)), stof(substring(s, 2, 1))))
-                                       return QuickMenu_Page_Load("", 0);
-                               QuickMenu_Close();
-                               return false;
-                       }
+                               cmd = QuickMenu_Buffer_Get();
+                               string command_code = substring(cmd, 0, 1);
+                               if(command_code == QM_TAG_COMMAND)
+                                       cmd = substring(cmd, 1, -1);
+                               else if(command_code == QM_TAG_PLCOMMAND)
+                               {
+                                       // throw away the current quickmenu buffer and load a new one
+                                       cmd = substring(cmd, 1, -1);
+                                       strunzone(z_submenu);
+                                       if(HUD_Quickmenu_PlayerListEntries_Create(cmd, stof(substring(s, 1, 1)), stof(substring(s, 2, 1))))
+                                               return QuickMenu_Page_Load("", 0);
+                                       QuickMenu_Close();
+                                       return false;
+                               }
+
+                               tokenize_console(cmd);
+                               QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = (argv(1) && argv(0) == "toggle");
 
-                       tokenize_console(cmd);
-                       QuickMenu_Page_Command_Type[QuickMenu_Page_Entries] = (argv(1) && argv(0) == "toggle");
+                               QuickMenu_Page_LoadEntry(QuickMenu_Page_Entries, substring(s, 1, -1), cmd);
+                       }
 
-                       QuickMenu_Page_LoadEntry(QuickMenu_Page_Entries, substring(s, 1, -1), cmd);
                }
 
                ++entry_num;
@@ -519,10 +523,10 @@ void QuickMenu_Mouse()
 
        if (mousepos.x >= panel_pos.x && mousepos.y >= first_entry_pos && mousepos.x <= panel_pos.x + panel_size.x && mousepos.y <= first_entry_pos + entries_height)
        {
-               float entry_num;
-               entry_num = floor((mousepos.y - first_entry_pos) / fontsize.y);
+               int entry_num = min(QuickMenu_Page_Entries - 1, floor((mousepos.y - first_entry_pos) / fontsize.y));
                if (QuickMenu_IsLastPage || entry_num != QUICKMENU_MAXLINES - 2)
                {
+                       // recycling panel_pos as entry_pos
                        panel_pos.y = first_entry_pos + entry_num * fontsize.y;
                        vector color;
                        if(mouseClicked & S_MOUSE1)