1 /* $Id: TrainingSelectView.cpp,v 1.12 2002/12/24 14:56:15 nan Exp $ */
2
3 // Copyright (C) 2000, 2001, 2002 $B?@Fn(B $B5H9((B(Kanna Yoshihiro)
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 #include "ttinc.h"
20 #include "TrainingSelectView.h"
21 #include "LoadImage.h"
22 #include "PlayerSelect.h"
23 #include "BaseView.h"
24 #include "RCFile.h"
25
26 extern RCFile *theRC;
27
28 extern long wins;
29
TrainingSelectView()30 TrainingSelectView::TrainingSelectView() : PlayerSelectView() {
31 }
32
~TrainingSelectView()33 TrainingSelectView::~TrainingSelectView() {
34 }
35
36 bool
Init(PlayerSelect * playerSelect)37 TrainingSelectView::Init( PlayerSelect *playerSelect ) {
38 ImageData image;
39 int i, j;
40
41 static char pname[][30] = {"images/FastRally.jpg", "images/Footwork.jpg" };
42
43 m_playerSelect = playerSelect;
44
45 if ( m_textures[0] == 0 ) {
46 glGenTextures( TRAININGPLAYERS+2, m_textures );
47
48 for ( i = 0 ; i < TRAININGPLAYERS ; i++ ){
49 image.LoadFile( &(pname[i][0]) );
50 glBindTexture(GL_TEXTURE_2D, m_textures[i] );
51 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
52 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
53 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
54 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
55 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
56 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
57
58 glTexImage2D(GL_TEXTURE_2D, 0, 3, image.GetWidth(), image.GetHeight(),
59 0, GL_RGBA, GL_UNSIGNED_BYTE, image.GetImage() );
60 }
61 }
62
63 char filename[256];
64 sprintf( filename, _("%s.pbm"), "images/SelectPlayer" );
65
66 m_selectPlayer = new ImageData();
67 m_selectPlayer->LoadFile( filename );
68
69 return true;
70 }
71
72 bool
Redraw()73 TrainingSelectView::Redraw() {
74 int i;
75
76 if ( theRC->gmode != GMODE_SIMPLE ||
77 (m_playerSelect->GetRotate()%360)%(360/PLAYERS) == 0 )
78 glEnable(GL_TEXTURE_2D);
79
80 glColor4f( 0.0, 0.0, 0.0, 0.0 );
81
82 if ( m_playerSelect->GetSelected() > 0 ) {
83 int player;
84
85 if ( m_playerSelect->GetRotate() < 0 )
86 player = (360+(m_playerSelect->GetRotate()%360))/(360/TRAININGPLAYERS);
87 else
88 player = (m_playerSelect->GetRotate()%360)/(360/TRAININGPLAYERS);
89
90 glPushMatrix();
91 if ( m_playerSelect->GetSelected() < 100 ) {
92 glTranslatef( -0.01F*m_playerSelect->GetSelected(),
93 -1.5F+0.01F*m_playerSelect->GetSelected(), 1.4F );
94 glRotatef( m_playerSelect->GetSelected()*360.0F/100, 0.0F, 0.0F, 1.0F );
95 } else
96 glTranslatef( -0.01F*100, -1.5F+0.01F*100, 1.4F);
97
98 glBindTexture(GL_TEXTURE_2D, m_textures[player] );
99 glBegin(GL_QUADS);
100 glTexCoord2f(0.0F, 1.0F); glVertex3f(-0.60F, 0.0F, -0.84F);
101 glTexCoord2f(0.0F, 0.0F); glVertex3f(-0.60F, 0.0F, 0.84F);
102 glTexCoord2f(1.0F, 0.0F); glVertex3f( 0.60F, 0.0F, 0.84F);
103 glTexCoord2f(1.0F, 1.0F); glVertex3f( 0.60F, 0.0F, -0.84F);
104 glEnd();
105 glPopMatrix();
106 } else {
107 for ( i = 0 ; i < TRAININGPLAYERS ; i++ ){
108 glPushMatrix();
109 glRotatef( m_playerSelect->GetRotate()-i*360.0F/TRAININGPLAYERS, 0.0F, 0.0F, 1.0F );
110 glBindTexture(GL_TEXTURE_2D, m_textures[i] );
111 glBegin(GL_QUADS);
112 glTexCoord2f(0.0F, 1.0F); glVertex3f(-0.60F, -1.5F, 1.4F-0.84F);
113 glTexCoord2f(0.0F, 0.0F); glVertex3f(-0.60F, -1.5F, 1.4F+0.84F);
114 glTexCoord2f(1.0F, 0.0F); glVertex3f( 0.60F, -1.5F, 1.4F+0.84F);
115 glTexCoord2f(1.0F, 1.0F); glVertex3f( 0.60F, -1.5F, 1.4F-0.84F);
116 glEnd();
117 glPopMatrix();
118 }
119
120 glColor4f( 1.0F, 1.0F, 1.0F, 0.0F );
121
122 glPushMatrix();
123 glMatrixMode(GL_PROJECTION);
124 glPushMatrix();
125 glLoadIdentity();
126 gluOrtho2D( 0.0F, (GLfloat)BaseView::GetWinWidth(),
127 0.0F, (GLfloat)BaseView::GetWinHeight() );
128 glMatrixMode(GL_MODELVIEW);
129 glLoadIdentity();
130
131 glRasterPos2i( 200, 100 );
132 glBitmap( 400, 70, 0.0F, 0.0F, 0.0F, 0, m_selectPlayer->GetImage() );
133
134 glMatrixMode(GL_PROJECTION);
135 glPopMatrix();
136 glMatrixMode(GL_MODELVIEW);
137 glPopMatrix();
138 }
139
140 glDisable(GL_TEXTURE_2D);
141
142 return true;
143 }
144