1 /* $Id: PlayerSelectView.cpp,v 1.15 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 "PlayerSelectView.h"
21 #include "PlayerSelect.h"
22 #include "LoadImage.h"
23 #include "BaseView.h"
24 #include "RCFile.h"
25
26 extern RCFile *theRC;
27
28 extern long wins;
29
30 extern bool isComm;
31
PlayerSelectView()32 PlayerSelectView::PlayerSelectView() {
33 m_offset = 0;
34 m_textures[0] = 0;
35 m_selectPlayer = 0;
36 }
37
~PlayerSelectView()38 PlayerSelectView::~PlayerSelectView() {
39 if ( m_selectPlayer )
40 delete m_selectPlayer;
41 }
42
43 bool
Init(PlayerSelect * playerSelect)44 PlayerSelectView::Init( PlayerSelect *playerSelect ) {
45 ImageData image;
46 int i, j;
47
48 static char pname[][30] = {"images/PenAttack.jpg", "images/ShakeCut.jpg",
49 "images/PenDrive.jpg"};
50
51 m_playerSelect = playerSelect;
52
53 if ( m_textures[0] == 0 ) {
54 glGenTextures( PLAYERS+2, m_textures );
55
56 for ( i = 0 ; i < PLAYERS ; i++ ){
57 image.LoadFile( &(pname[i][0]) );
58 glBindTexture(GL_TEXTURE_2D, m_textures[i] );
59 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
60 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
61 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
62 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
63 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
64 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
65
66 glTexImage2D(GL_TEXTURE_2D, 0, 3, image.GetWidth(), image.GetHeight(),
67 0, GL_RGBA, GL_UNSIGNED_BYTE, image.GetImage() );
68 }
69 }
70
71 char filename[256];
72 sprintf( filename, _("%s.pbm"), "images/SelectPlayer" );
73
74 m_selectPlayer = new ImageData();
75 m_selectPlayer->LoadFile( filename );
76
77 return true;
78 }
79
80 bool
Redraw()81 PlayerSelectView::Redraw() {
82 int i;
83
84 glColor4f( 0.0, 0.0, 0.0, 0.0 );
85
86 if ( m_playerSelect->GetSelected() > 0 ) {
87 int player;
88
89 if ( m_playerSelect->GetRotate() < 0 )
90 player = (360+(m_playerSelect->GetRotate()%360))/(360/PLAYERS);
91 else
92 player = (m_playerSelect->GetRotate()%360)/(360/PLAYERS);
93
94 glPushMatrix();
95 if ( m_playerSelect->GetSelected() < 100 ) {
96 if ( theRC->gmode != GMODE_SIMPLE )
97 glEnable(GL_TEXTURE_2D);
98 glTranslatef( -0.01F*m_playerSelect->GetSelected(),
99 -1.5F+0.01F*m_playerSelect->GetSelected(), 1.4F );
100 glRotatef( m_playerSelect->GetSelected()*360.0F/100, 0.0F, 0.0F, 1.0F );
101 } else {
102 glEnable(GL_TEXTURE_2D);
103 glTranslatef( -0.01F*100, -1.5F+0.01F*100, 1.4F );
104 }
105
106 glBindTexture(GL_TEXTURE_2D, m_textures[player] );
107 glBegin(GL_QUADS);
108 glTexCoord2f(0.0F, 1.0F); glVertex3f(-0.60F, 0.0F, -0.84F);
109 glTexCoord2f(0.0F, 0.0F); glVertex3f(-0.60F, 0.0F, 0.84F);
110 glTexCoord2f(1.0F, 0.0F); glVertex3f( 0.60F, 0.0F, 0.84F);
111 glTexCoord2f(1.0F, 1.0F); glVertex3f( 0.60F, 0.0F, -0.84F);
112 glEnd();
113 glPopMatrix();
114
115 if ( !isComm ) {
116 if ( m_playerSelect->GetSelected() > 100 ) {
117 glPushMatrix();
118 if ( m_playerSelect->GetSelected() < 150 )
119 glTranslatef( 0.02F*(m_playerSelect->GetSelected()-100),
120 18.5F-0.4F*(m_playerSelect->GetSelected()-100), 1.4F );
121 else
122 glTranslatef( 0.01F*100, -1.5F+0.01F*100, 1.4F );
123
124 glBindTexture(GL_TEXTURE_2D, m_textures[(player+wins+1)%PLAYERS] );
125 glBegin(GL_QUADS);
126 glTexCoord2f(0.0F, 1.0F); glVertex3f(-0.60F, 0.0F, -0.84F);
127 glTexCoord2f(0.0F, 0.0F); glVertex3f(-0.60F, 0.0F, 0.84F);
128 glTexCoord2f(1.0F, 0.0F); glVertex3f( 0.60F, 0.0F, 0.84F);
129 glTexCoord2f(1.0F, 1.0F); glVertex3f( 0.60F, 0.0F, -0.84F);
130 glEnd();
131 glPopMatrix();
132 }
133 }
134 } else {
135 if ( theRC->gmode != GMODE_SIMPLE ||
136 (m_playerSelect->GetRotate()%360)%(360/PLAYERS) == 0 )
137 glEnable(GL_TEXTURE_2D);
138
139 for ( i = 0 ; i < PLAYERS ; i++ ){
140 glPushMatrix();
141 glRotatef( m_playerSelect->GetRotate()-i*360.0F/PLAYERS, 0.0F, 0.0F, 1.0F );
142 glBindTexture(GL_TEXTURE_2D, m_textures[i] );
143 glBegin(GL_QUADS);
144 glTexCoord2f(0.0F, 1.0F); glVertex3f(-0.60F, -1.5F, 1.4F-0.84F);
145 glTexCoord2f(0.0F, 0.0F); glVertex3f(-0.60F, -1.5F, 1.4F+0.84F);
146 glTexCoord2f(1.0F, 0.0F); glVertex3f( 0.60F, -1.5F, 1.4F+0.84F);
147 glTexCoord2f(1.0F, 1.0F); glVertex3f( 0.60F, -1.5F, 1.4F-0.84F);
148 glEnd();
149 glPopMatrix();
150 }
151
152 glColor4f( 1.0F, 1.0F, 1.0F, 0.0F );
153
154 glPushMatrix();
155 glMatrixMode(GL_PROJECTION);
156 glPushMatrix();
157 glLoadIdentity();
158 gluOrtho2D( 0.0F, (GLfloat)BaseView::GetWinWidth(),
159 0.0F, (GLfloat)BaseView::GetWinHeight() );
160 glMatrixMode(GL_MODELVIEW);
161 glLoadIdentity();
162
163 glRasterPos2i( 200, 100 );
164 glBitmap( 400, 70, 0.0F, 0.0F, 0.0F, 0, m_selectPlayer->GetImage() );
165
166 glMatrixMode(GL_PROJECTION);
167 glPopMatrix();
168 glMatrixMode(GL_MODELVIEW);
169 glPopMatrix();
170 }
171
172 glDisable(GL_TEXTURE_2D);
173
174 return true;
175 }
176
177 bool
RedrawAlpha()178 PlayerSelectView::RedrawAlpha() {
179 return true;
180 }
181