~ubuntu-app-review-contributors/ubuntu-app-reviews/tetracity

« back to all changes in this revision

Viewing changes to options.rb

  • Committer: App Bot
  • Date: 2012-06-12 11:22:25 UTC
  • Revision ID: appbot@holba.ch-20120612112225-v3lrlhszpurkxf56
initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
###
 
2
#
 
3
#    TetraCity
 
4
#    Copyright (C) 2010, 2011 Levi D. Smith
 
5
#
 
6
#    TetraCity is free software: you can redistribute it and/or modify
 
7
#    it under the terms of the GNU General Public License as published by
 
8
#    the Free Software Foundation, either version 3 of the License, or
 
9
#    (at your option) any later version.
 
10
#
 
11
#    TetraCity is distributed in the hope that it will be useful,
 
12
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
#    GNU General Public License for more details.
 
15
#
 
16
#    You should have received a copy of the GNU General Public License
 
17
#    along with TetraCity.  If not, see <http://www.gnu.org/licenses/gpl.txt>.
 
18
#
 
19
###
 
20
 
 
21
MAX_OPTIONS = 8
 
22
 
 
23
class Options
 
24
 
 
25
  GEN_BAG = 0
 
26
  GEN_RANDOM = 1
 
27
 
 
28
  def initialize(i1, i2)
 
29
    @musicVolume = i1
 
30
    @soundEffectsVolume = i2
 
31
    @useLighting = true
 
32
    @mode = "BASIC"
 
33
    @ghostPieceOn = true
 
34
    @pieceGeneration = GEN_BAG
 
35
    @colorScheme = 0
 
36
    @piecePreviewCount = 5
 
37
  end
 
38
 
 
39
  def soundEffectsVolume
 
40
    @soundEffectsVolume
 
41
  end
 
42
  
 
43
  def musicVolume
 
44
    @musicVolume
 
45
  end
 
46
  
 
47
  def useLighting
 
48
      @useLighting
 
49
  end
 
50
    
 
51
    
 
52
  def mode
 
53
      @mode
 
54
  end
 
55
 
 
56
  def ghostPieceOn
 
57
      @ghostPieceOn
 
58
  end
 
59
 
 
60
  def setMode(str)
 
61
    @mode = str  
 
62
  end
 
63
 
 
64
  
 
65
      
 
66
 
 
67
  
 
68
  attr_accessor :soundEffectsVolume
 
69
  attr_accessor :musicVolume
 
70
  attr_accessor :useLighting
 
71
  attr_accessor :mode
 
72
  attr_accessor :ghostPieceOn
 
73
  attr_accessor :pieceGeneration
 
74
  attr_accessor :colorScheme
 
75
  attr_accessor :piecePreviewCount
 
76
 
 
77
end
 
78
 
 
79
def optionsLoop
 
80
  keepLooping = true
 
81
  $selected_option = 0
 
82
  
 
83
  
 
84
  
 
85
  init_throttle()
 
86
  while keepLooping
 
87
    
 
88
    throttle()
 
89
    optionsDraw
 
90
    
 
91
    while event = SDL::Event2.poll
 
92
      case event
 
93
        when SDL::Event::Quit
 
94
            exit
 
95
 
 
96
        when SDL::Event::KeyDown
 
97
          case event.sym
 
98
            when SDL::Key::UP
 
99
              $selected_option -= 1
 
100
 
 
101
              if ($selected_option < 0)
 
102
                $selected_option = 0
 
103
              end
 
104
            when SDL::Key::DOWN
 
105
              $selected_option += 1
 
106
 
 
107
              
 
108
              if ($selected_option > MAX_OPTIONS - 1)
 
109
                $selected_option = MAX_OPTIONS - 1
 
110
              end
 
111
              
 
112
              
 
113
            when SDL::Key::LEFT
 
114
              if ($selected_option == 0)
 
115
                decreaseMusicVolume
 
116
              elsif ($selected_option == 1)
 
117
                decreaseSoundEffectsVolume
 
118
                
 
119
              elsif ($selected_option == 2)
 
120
                setUseLighting(false)
 
121
 
 
122
              elsif ($selected_option == 3)
 
123
                $theOptions.ghostPieceOn = false
 
124
                
 
125
              elsif ($selected_option == 4)
 
126
                $theOptions.pieceGeneration = Options::GEN_BAG
 
127
 
 
128
              elsif ($selected_option == 5)
 
129
                $theOptions.colorScheme -= 1 
 
130
                if ($theOptions.colorScheme < 0)
 
131
                  $theOptions.colorScheme = 0
 
132
                end
 
133
 
 
134
              elsif ($selected_option == 6)
 
135
                $theOptions.piecePreviewCount -= 1 
 
136
                if ($theOptions.piecePreviewCount < 0)
 
137
                  $theOptions.piecePreviewCount = 0
 
138
                end
 
139
 
 
140
              end
 
141
              
 
142
 
 
143
            when SDL::Key::RIGHT
 
144
              if ($selected_option == 0)
 
145
                increaseMusicVolume
 
146
              elsif ($selected_option == 1)
 
147
                increaseSoundEffectsVolume
 
148
 
 
149
              elsif ($selected_option == 2)
 
150
                setUseLighting(true)
 
151
 
 
152
              elsif ($selected_option == 3)
 
153
                $theOptions.ghostPieceOn = true
 
154
 
 
155
              elsif ($selected_option == 4)
 
156
                $theOptions.pieceGeneration = Options::GEN_RANDOM
 
157
 
 
158
              elsif ($selected_option == 5)
 
159
                $theOptions.colorScheme += 1
 
160
                if ($theOptions.colorScheme > 6)
 
161
                  $theOptions.colorScheme = 6
 
162
                end
 
163
 
 
164
              elsif ($selected_option == 6)
 
165
                $theOptions.piecePreviewCount += 1
 
166
                if ($theOptions.piecePreviewCount > 5)
 
167
                  $theOptions.piecePreviewCount = 5
 
168
                end
 
169
 
 
170
 
 
171
              end
 
172
 
 
173
            when SDL::Key::SPACE
 
174
              
 
175
              if ($selected_option == 7)
 
176
                keepLooping = false
 
177
              end
 
178
 
 
179
            when SDL::Key::Q, SDL::Key::ESCAPE
 
180
              keepLooping = false
 
181
              
 
182
            end
 
183
       end
 
184
    end            
 
185
  end
 
186
  
 
187
  
 
188
end
 
189
 
 
190
def optionsDraw
 
191
 
 
192
  glClearColor(0.5, 0.5, 0.5, 1.0);
 
193
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
 
194
 
 
195
  colorHighlight = [1.0, 1.0, 1.0]
 
196
  colorNormal = [0.5, 0.5, 0.5]
 
197
  colorFg=[1.0, 1.0, 1.0]
 
198
  
 
199
  glPushMatrix
 
200
  glLoadIdentity
 
201
  
 
202
  glOrtho(0, 1024, 768, 0, -1, 1)
 
203
  glColor(1.0, 1.0, 1.0)
 
204
 
 
205
  x_offset = 32
 
206
  y_offset = 128
 
207
  width = 800
 
208
  height = 400
 
209
 
 
210
  iCol1 = x_offset + 32
 
211
  iCol2 = x_offset + 400 
 
212
 
 
213
 
 
214
  glBegin(GL_QUADS)
 
215
    glColor(0, 0, 0)
 
216
    z = 0.0
 
217
 
 
218
    glVertex(x_offset, y_offset, z)
 
219
    glVertex(x_offset + width, y_offset, z)
 
220
    glVertex(x_offset + width, y_offset + height, z)
 
221
    glVertex(x_offset, y_offset + height, z)
 
222
 
 
223
  glEnd
 
224
 
 
225
  glBegin(GL_LINES)
 
226
 
 
227
    glColor(1.0, 0.0, 0.0)
 
228
    glVertex(x_offset, y_offset, z)
 
229
    glVertex(x_offset + width, y_offset, z)
 
230
 
 
231
    glColor(0.0, 0.0, 1.0)
 
232
    glVertex(x_offset + width, y_offset, z)
 
233
    glVertex(x_offset + width, y_offset + height, z)
 
234
 
 
235
    glVertex(x_offset + width, y_offset + height, z)
 
236
    glVertex(x_offset, y_offset + height, z)
 
237
 
 
238
    glColor(1.0, 0.0, 0.0)
 
239
    glVertex(x_offset, y_offset + height, z)
 
240
    glVertex(x_offset, y_offset, z)
 
241
 
 
242
  glEnd()
 
243
 
 
244
  drawMenuText("OPTIONS", 200, 150, 128, 16, colorHighlight)
 
245
 
 
246
  x = iCol1
 
247
  y = 200
 
248
  iSpacing = 32
 
249
 
 
250
  y += iSpacing
 
251
  if ($selected_option == 0)
 
252
    colorFg = colorHighlight
 
253
  else
 
254
    colorFg = colorNormal
 
255
  end
 
256
  
 
257
  drawMenuText("Music Volume", x, y, 128, 16, colorFg)
 
258
 
 
259
  drawRectangle(iCol2, y, iCol2 + 128, y + 16, 0.0, 0.5, 0.5, 0.5)
 
260
 
 
261
  drawRectangle(iCol2, y, iCol2 + $theOptions.musicVolume, y + 16, 0.0, 1, 1, 1)
 
262
 
 
263
  y += iSpacing
 
264
  if ($selected_option == 1)
 
265
    colorFg = colorHighlight
 
266
  else
 
267
    colorFg = colorNormal
 
268
  end
 
269
  
 
270
  drawMenuText("Sound Effects Vol", x, y, 128, 16, colorFg)
 
271
 
 
272
  drawRectangle(iCol2, y, iCol2 + 128, y + 16, 0.0, 0.5, 0.5, 0.5)
 
273
  drawRectangle(iCol2, y, iCol2 + $theOptions.soundEffectsVolume, y + 16, 0.0, 1, 1, 1)
 
274
 
 
275
### USE LIGHTING ###
 
276
  y += iSpacing
 
277
  if ($selected_option == 2)
 
278
    colorFg = colorHighlight
 
279
  else
 
280
    colorFg = colorNormal
 
281
  end
 
282
  
 
283
 
 
284
  drawMenuText("Use Lighting", iCol1, y, 128, 16, colorFg)
 
285
  
 
286
  if (! $theOptions.useLighting)
 
287
    colorFg = colorHighlight
 
288
  else
 
289
    colorFg = colorNormal
 
290
  end
 
291
  drawMenuText("OFF", iCol2, y, 128, 16, colorFg)
 
292
 
 
293
  if ($theOptions.useLighting)
 
294
    colorFg = colorHighlight
 
295
  else
 
296
    colorFg = colorNormal
 
297
  end
 
298
  drawMenuText("ON", iCol2 + 128, y, 128, 16, colorFg)
 
299
 
 
300
### GHOST PIECE ###
 
301
 
 
302
  y += iSpacing
 
303
  if ($selected_option == 3)
 
304
    colorFg = colorHighlight
 
305
  else
 
306
    colorFg = colorNormal
 
307
  end
 
308
  
 
309
 
 
310
  drawMenuText("Ghost Piece", iCol1, y, 128, 16, colorFg)
 
311
  
 
312
  if (! $theOptions.ghostPieceOn)
 
313
    colorFg = colorHighlight
 
314
  else
 
315
    colorFg = colorNormal
 
316
  end
 
317
  drawMenuText("OFF", iCol2, y, 128, 16, colorFg)
 
318
 
 
319
  if ($theOptions.ghostPieceOn)
 
320
    colorFg = colorHighlight
 
321
  else
 
322
    colorFg = colorNormal
 
323
  end
 
324
  drawMenuText("ON", iCol2 + 128, y, 128, 16, colorFg)
 
325
 
 
326
### PIECE GENERATION ###
 
327
 
 
328
  y += iSpacing
 
329
  if ($selected_option == 4)
 
330
    colorFg = colorHighlight
 
331
  else
 
332
    colorFg = colorNormal
 
333
  end
 
334
  
 
335
 
 
336
  drawMenuText("Piece Generation", iCol1, y, 128, 16, colorFg)
 
337
  
 
338
  if ($theOptions.pieceGeneration == Options::GEN_BAG)
 
339
    colorFg = colorHighlight
 
340
  else
 
341
    colorFg = colorNormal
 
342
  end
 
343
  drawMenuText("BAG", iCol2, y, 128, 16, colorFg)
 
344
 
 
345
  if ($theOptions.pieceGeneration == Options::GEN_RANDOM)
 
346
    colorFg = colorHighlight
 
347
  else
 
348
    colorFg = colorNormal
 
349
  end
 
350
  drawMenuText("RANDOM", iCol2 + 128, y, 128, 16, colorFg)
 
351
 
 
352
 
 
353
 
 
354
### COLOR SCHEME ###
 
355
 
 
356
  y += iSpacing
 
357
  if ($selected_option == 5)
 
358
    colorFg = colorHighlight
 
359
  else
 
360
    colorFg = colorNormal
 
361
  end
 
362
  
 
363
 
 
364
  drawMenuText("Color Scheme", iCol1, y, 128, 16, colorFg)
 
365
  
 
366
  iColorSchemeChoice = 0
 
367
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
368
    colorFg = colorHighlight
 
369
  else
 
370
    colorFg = colorNormal
 
371
  end
 
372
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
373
 
 
374
 
 
375
  iColorSchemeChoice = 1
 
376
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
377
    colorFg = colorHighlight
 
378
  else
 
379
    colorFg = colorNormal
 
380
  end
 
381
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
382
 
 
383
 
 
384
  iColorSchemeChoice = 2
 
385
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
386
    colorFg = colorHighlight
 
387
  else
 
388
    colorFg = colorNormal
 
389
  end
 
390
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
391
 
 
392
 
 
393
  iColorSchemeChoice = 3
 
394
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
395
    colorFg = colorHighlight
 
396
  else
 
397
    colorFg = colorNormal
 
398
  end
 
399
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
400
 
 
401
 
 
402
  iColorSchemeChoice = 4
 
403
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
404
    colorFg = colorHighlight
 
405
  else
 
406
    colorFg = colorNormal
 
407
  end
 
408
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
409
 
 
410
 
 
411
  iColorSchemeChoice = 5
 
412
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
413
    colorFg = colorHighlight
 
414
  else
 
415
    colorFg = colorNormal
 
416
  end
 
417
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
418
 
 
419
 
 
420
  iColorSchemeChoice = 6
 
421
  if ($theOptions.colorScheme == iColorSchemeChoice)
 
422
    colorFg = colorHighlight
 
423
  else
 
424
    colorFg = colorNormal
 
425
  end
 
426
  drawMenuText("#{iColorSchemeChoice}", iCol2 + (iColorSchemeChoice * 32), y, 32, 16, colorFg)
 
427
 
 
428
 
 
429
### PIECE PREVIEW ###
 
430
 
 
431
  y += iSpacing
 
432
  if ($selected_option == 6)
 
433
    colorFg = colorHighlight
 
434
  else
 
435
    colorFg = colorNormal
 
436
  end
 
437
  
 
438
 
 
439
  drawMenuText("iPiecePreview", iCol1, y, 128, 16, colorFg)
 
440
  
 
441
  iPiecePreviewChoice = 0
 
442
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
443
    colorFg = colorHighlight
 
444
  else
 
445
    colorFg = colorNormal
 
446
  end
 
447
  drawMenuText("OFF", iCol2 + (iPiecePreviewChoice * 32), y, 32, 16, colorFg)
 
448
 
 
449
 
 
450
  iPiecePreviewChoice = 1
 
451
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
452
    colorFg = colorHighlight
 
453
  else
 
454
    colorFg = colorNormal
 
455
  end
 
456
  drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
 
457
 
 
458
 
 
459
  iPiecePreviewChoice = 2
 
460
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
461
    colorFg = colorHighlight
 
462
  else
 
463
    colorFg = colorNormal
 
464
  end
 
465
  drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
 
466
 
 
467
 
 
468
  iPiecePreviewChoice = 3
 
469
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
470
    colorFg = colorHighlight
 
471
  else
 
472
    colorFg = colorNormal
 
473
  end
 
474
  drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
 
475
 
 
476
 
 
477
  iPiecePreviewChoice = 4
 
478
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
479
    colorFg = colorHighlight
 
480
  else
 
481
    colorFg = colorNormal
 
482
  end
 
483
  drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
 
484
 
 
485
 
 
486
  iPiecePreviewChoice = 5
 
487
  if ($theOptions.piecePreviewCount == iPiecePreviewChoice)
 
488
    colorFg = colorHighlight
 
489
  else
 
490
    colorFg = colorNormal
 
491
  end
 
492
  drawMenuText("#{iPiecePreviewChoice}", iCol2 + (iPiecePreviewChoice * 32) + 64, y, 32, 16, colorFg)
 
493
 
 
494
 
 
495
 
 
496
 
 
497
 
 
498
 
 
499
### BACK TO MENU ###
 
500
  y += iSpacing
 
501
  y += iSpacing
 
502
  if ($selected_option == 7)
 
503
    colorFg = colorHighlight
 
504
  else
 
505
    colorFg = colorNormal
 
506
  end
 
507
  
 
508
 
 
509
  drawMenuText("Back to Menu", iCol1, y, 128, 16, colorFg)
 
510
 
 
511
  glPopMatrix
 
512
  SDL::GL.swap_buffers
 
513
 
 
514
end
 
515
 
 
516
def drawRectangle(x1, y1, x2, y2, z, r, g, b)
 
517
 
 
518
  glColor(r, g, b)
 
519
 
 
520
  glBegin(GL_QUADS)
 
521
    glVertex(x1, y1, z)
 
522
    glVertex(x1, y2, z)
 
523
    glVertex(x2, y2, z)
 
524
    glVertex(x2, y1, z)
 
525
  glEnd
 
526
 
 
527
end