]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/cl_minigames_hud.qc
Merge branch 'master' into TimePath/global_self
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / cl_minigames_hud.qc
index 7df7609794339ca7a10a440219286d18486d889f..51155f236fffaf0357b4615a3e0123c91cc1cd97 100644 (file)
@@ -1,7 +1,8 @@
 #include "minigames.qh"
 #include "../../client/mapvoting.qh"
 
-float HUD_mouse_over(entity somepanel)
+// whether the mouse is over the given panel
+bool HUD_mouse_over(entity somepanel)
 {
        vector pos = stov(cvar_string(strcat("hud_panel_", somepanel.panel_name, "_pos")));
        vector sz = stov(cvar_string(strcat("hud_panel_", somepanel.panel_name, "_size")));
@@ -13,6 +14,7 @@ float HUD_mouse_over(entity somepanel)
 // Minigame Board
 // ====================================================================
 
+// Draws the minigame game board
 void HUD_MinigameBoard ()
 {
        entity hud_minigame = world;
@@ -38,6 +40,7 @@ void HUD_MinigameBoard ()
 // ====================================================================
 // Minigame Status
 // ====================================================================
+// Draws the minigame status panel
 void HUD_MinigameStatus ()
 {
        entity hud_minigame = world;
@@ -76,22 +79,22 @@ entity HUD_MinigameMenu_entries;
 entity HUD_MinigameMenu_last_entry;
 
 // Minigame menu options: insert entry after the given location
-void HUD_MinigameMenu_InsertEntry(entity new, entity prev)
+void HUD_MinigameMenu_InsertEntry(entity newentry, entity prev)
 {
        if ( !HUD_MinigameMenu_entries )
        {
-               HUD_MinigameMenu_entries = new;
-               HUD_MinigameMenu_last_entry = new;
+               HUD_MinigameMenu_entries = newentry;
+               HUD_MinigameMenu_last_entry = newentry;
                return;
        }
        
-       new.list_prev = prev;
-       new.list_next = prev.list_next;
+       newentry.list_prev = prev;
+       newentry.list_next = prev.list_next;
        if ( prev.list_next )
-               prev.list_next.list_prev = new;
+               prev.list_next.list_prev = newentry;
        else
-               HUD_MinigameMenu_last_entry = new;
-       prev.list_next = new;
+               HUD_MinigameMenu_last_entry = newentry;
+       prev.list_next = newentry;
        
 }
 
@@ -101,13 +104,10 @@ entity HUD_MinigameMenu_activeitem;
 
 // Click the given item
 void HUD_MinigameMenu_Click(entity menuitem)
-{
+{SELFPARAM();
        if ( menuitem )
        {
-               entity e = self;
-               self = menuitem;
-               menuitem.use();
-               self = e;
+               WITH(entity, self, menuitem, menuitem.use());
        }
 }
 
@@ -164,14 +164,14 @@ entity HUD_MinigameMenu_SpawnSubEntry(string s, void() click, entity parent)
 
 // Click action for Create sub-entries
 void HUD_MinigameMenu_ClickCreate_Entry()
-{
+{SELFPARAM();
        minigame_cmd("create ",self.netname);
 }
 
 // Helper click action for collapsible entries
 // returns true when you have to create the sub-entries
-float HUD_MinigameMenu_Click_ExpandCollapse()
-{
+bool HUD_MinigameMenu_Click_ExpandCollapse()
+{SELFPARAM();
        entity e;
        if ( self.flags & 2 )
        {
@@ -188,6 +188,8 @@ float HUD_MinigameMenu_Click_ExpandCollapse()
                }
                if ( self.list_next )
                        self.list_next.list_prev = self;
+               else
+                       HUD_MinigameMenu_last_entry = self;
        }
        else
        {
@@ -206,7 +208,7 @@ float HUD_MinigameMenu_Click_ExpandCollapse()
 
 // Click action for the Create menu
 void HUD_MinigameMenu_ClickCreate()
-{
+{SELFPARAM();
        if ( HUD_MinigameMenu_Click_ExpandCollapse() )
        {
                entity e;
@@ -226,14 +228,14 @@ void HUD_MinigameMenu_ClickCreate()
 
 // Click action for Join sub-entries
 void HUD_MinigameMenu_ClickJoin_Entry()
-{
+{SELFPARAM();
        minigame_cmd("join ",self.netname);
        HUD_MinigameMenu_EraseEntry(self);
 }
 
 // Click action for the Join menu
 void HUD_MinigameMenu_ClickJoin()
-{
+{SELFPARAM();
        if ( HUD_MinigameMenu_Click_ExpandCollapse() )
        {
                entity e = world;
@@ -263,24 +265,24 @@ void HUD_MinigameMenu_ClickNoop()
 // Click action for Quit
 void HUD_MinigameMenu_ClickQuit()
 {
+       deactivate_minigame();
        minigame_cmd("end");
 }
 
 // Click action for Invite sub-entries
 void HUD_MinigameMenu_ClickInvite_Entry()
-{
+{SELFPARAM();
        minigame_cmd("invite #",self.netname);
 }
 
 // Click action for the Invite menu
 void HUD_MinigameMenu_ClickInvite()
-{
+{SELFPARAM();
        if ( HUD_MinigameMenu_Click_ExpandCollapse() )
        {
-               float i;
                entity e;
                entity prev = self;
-               for(i = 0; i < maxclients; ++i)
+               for(int i = 0; i < maxclients; ++i)
                {
                        if ( player_localnum != i && playerslots[i] && GetPlayerName(i) != "" &&
                                !findfloat(world,minigame_playerslot,i+1) && playerslots[i].ping )
@@ -299,7 +301,7 @@ void HUD_MinigameMenu_ClickInvite()
 }
 
 void HUD_MinigameMenu_ClickCustomEntry()
-{
+{SELFPARAM();
        if ( active_minigame )
                active_minigame.minigame_event(active_minigame,"menu_click",self.netname);
 }
@@ -311,12 +313,12 @@ void HUD_MinigameMenu_CustomEntry(entity parent, string menumessage, string even
                menumessage, HUD_MinigameMenu_ClickCustomEntry, parent );
        e.netname = event_arg;
        HUD_MinigameMenu_InsertEntry(e, parent);
-       dprint("CustomEntry ",ftos(num_for_edict(parent))," ",menumessage," ",event_arg,"\n");
+       //dprint("CustomEntry ",ftos(num_for_edict(parent))," ",menumessage," ",event_arg,"\n");
 }
 
 // Click action for the Current Game menu
 void HUD_MinigameMenu_ClickCurrentGame()
-{
+{SELFPARAM();
        if ( HUD_MinigameMenu_Click_ExpandCollapse() )
        {
                HUD_MinigameMenu_InsertEntry( HUD_MinigameMenu_SpawnSubEntry(
@@ -329,7 +331,7 @@ void HUD_MinigameMenu_ClickCurrentGame()
        }
 }
 // Whether the minigame menu panel is open
-float HUD_MinigameMenu_IsOpened()
+bool HUD_MinigameMenu_IsOpened()
 {
        return !!HUD_MinigameMenu_entries;
 }
@@ -461,7 +463,7 @@ void HUD_MinigameMenu_DrawColoredEntry(vector pos, string s, vector fontsize)
                                                          fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
-// minigame menu panel UI
+// Minigame menu panel UI
 void HUD_MinigameMenu ()
 {      
        if ( !HUD_MinigameMenu_IsOpened() )
@@ -479,13 +481,12 @@ void HUD_MinigameMenu ()
 
        HUD_MinigameMenu_DrawEntry(panel_pos,_("Minigames"),hud_fontsize*2,'0.25 0.47 0.72');
        panel_pos_y += hud_fontsize_y*2;
-       
-       entity e;
+
        vector color;
        vector offset;
        float itemh;
        vector imgsz = '22 22 0'; // NOTE: if changed, edit where HUD_MinigameMenu_activeitem is selected
-       for ( e = HUD_MinigameMenu_entries; e != world; e = e.list_next )
+       for ( entity e = HUD_MinigameMenu_entries; e != world; e = e.list_next )
        {
                color = e.colormod;
                
@@ -574,7 +575,6 @@ float HUD_Minigame_InputEvent(float bInputType, float nPrimary, float nSecondary
        }
        else
        {
-               
                if(bInputType == 0) {
                        if(nPrimary == K_ALT) hudShiftState |= S_ALT;
                        if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
@@ -592,11 +592,9 @@ float HUD_Minigame_InputEvent(float bInputType, float nPrimary, float nSecondary
                
                // allow some binds
                string con_keys;
-               float keys;
-               float i;
                con_keys = findkeysforcommand("toggleconsole", 0);
-               keys = tokenize(con_keys); // findkeysforcommand returns data for this
-               for (i = 0; i < keys; ++i)
+               int keys = tokenize(con_keys); // findkeysforcommand returns data for this
+               for (int i = 0; i < keys; ++i)
                {
                        if(nPrimary == stof(argv(i)))
                                return false;
@@ -693,7 +691,7 @@ void HUD_Minigame_Mouse()
                        cursorsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
-float HUD_Minigame_Showpanels()
+bool HUD_Minigame_Showpanels()
 {
        return HUD_MinigameMenu_IsOpened() && ( autocvar__hud_configure || minigame_isactive() );
 }