~swag/armagetronad/0.2.9-sty+ct+ap-fork

« back to all changes in this revision

Viewing changes to src/tron/gTeam.cpp

  • Committer: SwagTron
  • Date: 2019-03-05 07:13:03 UTC
  • Revision ID: swagtron-20190305071303-5m4cn9hs6h8ydsgf
- Ported toggle from 0.4. Seems kind of hacky. Had to add another FindConfigItem of type tConfItemBase due to tab completion using the previous tString function. Plan to change this later, but I really needed the toggle function. Tried to cast the two, but that did not work out. Seemed like the bug-less option for the time being. Those unfamiliar with this function, you can now toggle boolean commands (Ex. toggle text_out)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
You should have received a copy of the GNU General Public License
21
21
along with this program; if not, write to the Free Software
22
22
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
  
 
23
 
24
24
***************************************************************************
25
25
 
26
26
*/
28
28
#include "gTeam.h"
29
29
#include "uMenu.h"
30
30
#include "ePlayer.h"
31
 
#include "eTeam.h"
 
31
#include "eTeam.h"
 
32
 
 
33
static tOutput* PrepareTeamText(tOutput* text, eTeam* team, const ePlayerNetID* player, const char* textTemplate)
 
34
{
 
35
    if (team)
 
36
    {
 
37
        text->SetTemplateParameter(1 , team->Name() );
 
38
        text->SetTemplateParameter(2 , team->NumPlayers() );
 
39
        if (team->PlayerMayJoin(player))
 
40
            text->SetTemplateParameter(3, "0x00ff00");
 
41
        else
 
42
            text->SetTemplateParameter(3, "0xff0000");
 
43
    }
 
44
    else
 
45
    {
 
46
        text->SetTemplateParameter(1 , tOutput("$team_empty") );
 
47
        text->SetTemplateParameter(2 , 0 );
 
48
        text->SetTemplateParameter(3 , "0x00ff00" );
 
49
    }
 
50
    *text << textTemplate << "0xffffff";
 
51
    return text;
 
52
}
32
53
 
33
54
// sets the spectator mode of a local player
34
55
static void SetSpectator( ePlayerNetID * player, bool spectate )
52
73
 
53
74
class gMenuItemPlayerTeam: public uMenuItem
54
75
{
55
 
    ePlayerNetID*   player;
56
 
    eTeam*          team;
57
 
    bool            canJoin_;
 
76
    ePlayerNetID*       player;
 
77
    eTeam*                      team;
58
78
public:
59
 
    gMenuItemPlayerTeam(uMenu *M,ePlayerNetID* p, eTeam* t, bool canJoin )
 
79
    gMenuItemPlayerTeam(uMenu *M,ePlayerNetID* p, eTeam* t)
60
80
            : uMenuItem( M, tOutput("$team_menu_join_help") ),
61
81
            player ( p ),
62
 
            team ( t),
63
 
            canJoin_( canJoin )
 
82
            team ( t)
64
83
    {
65
84
    }
66
85
 
67
86
    virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
68
87
    {
69
 
        tOutput text( "$team_menu_join", team->Name() );
70
 
        DisplayTextSpecial( x, y, text, selected, alpha * ( canJoin_ ? 1 : ( selected ? .8 : .5 ) ) );
 
88
        tOutput text/*( "$team_menu_join", team->Name() )*/;
 
89
        PrepareTeamText(&text, team, player, "$team_menu_join");
 
90
        DisplayTextSpecial( x, y, text, selected, alpha );
71
91
    }
72
92
 
73
93
    virtual void Enter()
76
96
        player->SetTeamWish( team );
77
97
        menu->Exit();
78
98
    }
 
99
};
 
100
 
 
101
class gMenuItemSpacer: public uMenuItem
 
102
{
 
103
    public:
 
104
        gMenuItemSpacer(uMenu *M)
 
105
        : uMenuItem( M, tOutput() )
 
106
        {
 
107
        }
 
108
 
 
109
        virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
 
110
        {
 
111
        }
 
112
 
 
113
        virtual bool IsSelectable()
 
114
        {
 
115
            return false;
 
116
        }
 
117
};
 
118
 
 
119
class gMenuItemStatus: public uMenuItem
 
120
{
 
121
    ePlayerNetID *player;
 
122
    bool currentTeam;
 
123
public:
 
124
    gMenuItemStatus(uMenu *M, ePlayerNetID *playerID, bool displayCurrentTeam)
 
125
    : uMenuItem( M, tOutput() ), player(playerID), currentTeam(displayCurrentTeam)
 
126
    {
 
127
    }
 
128
 
 
129
    virtual void Render(REAL x,REAL y,REAL alpha=1,bool selected=0)
 
130
    {
 
131
        tOutput text;
 
132
        if  (currentTeam)
 
133
            PrepareTeamText(&text, player->CurrentTeam(), player, "$team_menu_info_current_team");
 
134
        else
 
135
            PrepareTeamText(&text, player->NextTeam(), player, "$team_menu_info_next_team");
 
136
        DisplayTextSpecial( x, y, text, false, alpha );
 
137
    }
 
138
 
 
139
    virtual bool IsSelectable()
 
140
    {
 
141
        return false;
 
142
    }
79
143
};
80
144
 
81
145
class gMenuItemNewTeam: public uMenuItem
82
146
{
83
 
    ePlayerNetID*   player;
 
147
    ePlayerNetID*       player;
84
148
public:
85
149
    gMenuItemNewTeam( uMenu *M,ePlayerNetID* p )
86
150
            : uMenuItem( M, tOutput("$team_menu_create_help") ),
103
167
 
104
168
class gMenuItemSpectate: public uMenuItem
105
169
{
106
 
    ePlayerNetID*   player;
 
170
    ePlayerNetID*       player;
107
171
public:
108
172
    gMenuItemSpectate( uMenu *M,ePlayerNetID* p )
109
173
            : uMenuItem( M, tOutput("$team_menu_spectate_help") ),
141
205
 
142
206
    virtual void Enter()
143
207
    {
144
 
        int i;
 
208
        int i = 0;
145
209
 
146
210
        tOutput title;
147
211
        title.SetTemplateParameter( 1, player->GetName() );
148
212
        title << "$team_menu_player_title";
149
213
        uMenu playerMenu( title );
150
 
        tArray<uMenuItem*> items;
 
214
        tArray<uMenuItem*> items;
 
215
 
 
216
        if ( player->NextTeam()!=NULL )
 
217
        {
 
218
            items[0] = tNEW(gMenuItemPlayerTeam) (&playerMenu, player, NULL);
 
219
        }
151
220
 
152
221
        if ( !player->IsSpectating() )
153
222
        {
154
223
            items[ items.Len() ] = tNEW( gMenuItemSpectate ) ( &playerMenu, player );
155
224
        }
156
225
 
157
 
        for ( i = eTeam::teams.Len()-1; i>=0; --i )
 
226
        // first pass add teams who probably can't be joined
 
227
        for (i = 0; i<eTeam::teams.Len(); i++ )
158
228
        {
159
229
            eTeam *team = eTeam::teams(i);
160
 
            if ( team != player->NextTeam() )
 
230
            if ( team != player->NextTeam() && team->PlayerMayJoin( player ) )
161
231
            {
162
 
                items[ items.Len() ] = tNEW( gMenuItemPlayerTeam ) ( &playerMenu, player, team, team->PlayerMayJoin( player )  );
 
232
                items[ items.Len() ] = tNEW( gMenuItemPlayerTeam ) ( &playerMenu, player, team );
163
233
            }
 
234
        }
 
235
 
 
236
        // second pass add teams who probably can be joined
 
237
        // Note: these will appear above the unjoinable ones.
 
238
        for (i = 0; i<eTeam::teams.Len(); i++ )
 
239
        {
 
240
            eTeam *team = eTeam::teams(i);
 
241
            if ( team != player->NextTeam() && team->PlayerMayJoin( player ))
 
242
                items[ items.Len() ] = tNEW( gMenuItemPlayerTeam ) ( &playerMenu, player, team );
164
243
        }
165
244
 
166
245
        if ( player->IsSpectating() ||
169
248
        )
170
249
        {
171
250
            items[ items.Len() ] = tNEW( gMenuItemNewTeam ) ( &playerMenu, player );
172
 
        }
 
251
        }
 
252
 
 
253
        items[items.Len()] = tNEW ( gMenuItemSpacer ) ( &playerMenu );
 
254
        items[items.Len()] = tNEW ( gMenuItemStatus ) ( &playerMenu, player, false);
 
255
        items[items.Len()] = tNEW ( gMenuItemStatus ) ( &playerMenu, player, true);
173
256
 
174
257
        playerMenu.Enter();
175
258