forked from fofix/fofix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dialogs.py
2149 lines (1828 loc) · 76.8 KB
/
Dialogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#####################################################################
# -*- coding: iso-8859-1 -*- #
# #
# Frets on Fire #
# Copyright (C) 2006 Sami Kyöstilä #
# 2008 myfingershurt #
# 2008 Glorandwarf #
# 2008 ShiekOdaSandz #
# 2008 QQStarS #
# 2008 Blazingamer #
# 2008 evilynux <evilynux@gmail.com> #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
#####################################################################
"""A bunch of dialog functions for interacting with the user."""
from __future__ import with_statement
import pygame
from OpenGL.GL import *
import math
import os
import fnmatch
from View import Layer, BackgroundLayer
from Input import KeyListener
from Menu import Menu
from Language import _
from Player import GUITARTYPES, DRUMTYPES, MICTYPES
import Log
import Player
#stump: vocals
import Microphone
# evilynux - MFH-Alarian Mod credits
from Credits import Credits
import Config
#MFH - for loading phrases
def wrapCenteredText(font, pos, text, rightMargin = 1.0, scale = 0.002, visibility = 0.0, linespace = 1.0, allowshadowoffset = False, shadowoffset = (.0022, .0005)):
"""
Wrap a piece of text inside given margins.
@param pos: (x, y) tuple, x defines the centerline
@param text: Text to wrap
@param rightMargin: Right margin
@param scale: Text scale
@param visibility: Visibility factor [0..1], 0 is fully visible
"""
x, y = pos
#MFH: rewriting WrapCenteredText function to properly wrap lines in a centered fashion around a defined centerline (x)
sentence = ""
for n, word in enumerate(text.split(" ")):
w, h = font.getStringSize(sentence + " " + word, scale = scale)
if x + (w/2) > rightMargin or word == "\n":
w, h = font.getStringSize(sentence, scale = scale)
glPushMatrix()
glRotate(visibility * (n + 1) * -45, 0, 0, 1)
if allowshadowoffset == True:
font.render(sentence, (x - (w/2), y + visibility * n), scale = scale, shadowoffset = shadowoffset)
else:
font.render(sentence, (x - (w/2), y + visibility * n), scale = scale)
glPopMatrix()
sentence = word
y += h * linespace
else:
if sentence == "" or sentence == "\n":
sentence = word
else:
sentence = sentence + " " + word
else:
w, h = font.getStringSize(sentence, scale = scale)
glPushMatrix()
glRotate(visibility * (n + 1) * -45, 0, 0, 1)
if allowshadowoffset == True:
font.render(sentence, (x - (w/2), y + visibility * n), scale = scale, shadowoffset = shadowoffset)
else:
font.render(sentence, (x - (w/2), y + visibility * n), scale = scale)
glPopMatrix()
y += h * linespace
return (x, y)
def wrapText(font, pos, text, rightMargin = 0.9, scale = 0.002, visibility = 0.0):
"""
Wrap a piece of text inside given margins.
@param pos: (x, y) tuple, x defines the left margin
@param text: Text to wrap
@param rightMargin: Right margin
@param scale: Text scale
@param visibility: Visibility factor [0..1], 0 is fully visible
"""
x, y = pos
w = h = 0
space = font.getStringSize(" ", scale = scale)[0]
# evilynux - No longer requires "\n" to be in between spaces
for n, sentence in enumerate(text.split("\n")):
y += h
x = pos[0]
if n == 0:
y = pos[1]
for n, word in enumerate(sentence.strip().split(" ")):
w, h = font.getStringSize(word, scale = scale)
if x + w > rightMargin:
x = pos[0]
y += h
glPushMatrix()
glRotate(visibility * (n + 1) * -45, 0, 0, 1)
font.render(word, (x, y + visibility * n), scale = scale)
glPopMatrix()
x += w + space
return (x - space, y)
def fadeScreen(v):
"""
Fade the screen to a dark color to make whatever is on top easier to read.
@param v: Visibility factor [0..1], 0 is fully visible
"""
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_COLOR_MATERIAL)
glBegin(GL_TRIANGLE_STRIP)
glColor4f(0, 0, 0, .3 - v * .3)
glVertex2f(0, 0)
glColor4f(0, 0, 0, .3 - v * .3)
glVertex2f(1, 0)
glColor4f(0, 0, 0, .9 - v * .9)
glVertex2f(0, 1)
glColor4f(0, 0, 0, .9 - v * .9)
glVertex2f(1, 1)
glEnd()
class MainDialog(Layer, KeyListener):
def __init__(self, engine):
self.engine = engine
self.fontDict = self.engine.data.fontDict
self.geometry = self.engine.view.geometry[2:4]
self.fontScreenBottom = self.engine.data.fontScreenBottom
self.aspectRatio = self.engine.view.aspectRatio
self.drawImage = self.engine.drawImage
self.drawStarScore = self.engine.drawStarScore
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
def hidden(self):
self.engine.input.removeKeyListener(self)
class GetText(Layer, KeyListener):
"""Text input layer."""
def __init__(self, engine, prompt = "", text = ""):
self.text = text
self.prompt = prompt
self.engine = engine
self.time = 0
self.accepted = False
if self.engine.data.logClassInits == 1:
Log.debug("GetText class init (Dialogs.py)...")
self.sfxVolume = self.engine.config.get("audio", "SFX_volume")
self.drumHighScoreNav = self.engine.config.get("menu", "drum_navigation") #MFH
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
self.engine.input.enableKeyRepeat()
def hidden(self):
self.engine.input.removeKeyListener(self)
self.engine.input.disableKeyRepeat()
def keyPressed(self, key, unicode):
self.time = 0
c = self.engine.input.controls.getMapping(key)
if key == pygame.K_BACKSPACE and not self.accepted:
self.text = self.text[:-1]
elif unicode and ord(unicode) > 31 and not self.accepted:
self.text += unicode
elif key == pygame.K_LSHIFT or key == pygame.K_RSHIFT:
return True
elif (c in Player.menuYes or key == pygame.K_RETURN) and not self.accepted: #MFH - adding support for green drum "OK"
self.engine.view.popLayer(self)
self.accepted = True
if c in Player.key1s:
self.engine.data.acceptSound.setVolume(self.sfxVolume) #MFH
self.engine.data.acceptSound.play()
elif (c in Player.menuNo or key == pygame.K_ESCAPE) and not self.accepted:
self.text = ""
self.engine.view.popLayer(self)
self.accepted = True
if c in Player.key2s:
self.engine.data.cancelSound.setVolume(self.sfxVolume) #MFH
self.engine.data.cancelSound.play()
elif c in Player.key4s and not self.accepted:
self.text = self.text[:-1]
if c in Player.key4s:
self.engine.data.cancelSound.setVolume(self.sfxVolume) #MFH
self.engine.data.cancelSound.play()
elif c in Player.key3s and not self.accepted:
self.text += self.text[len(self.text) - 1]
self.engine.data.acceptSound.setVolume(self.sfxVolume) #MFH
self.engine.data.acceptSound.play()
elif c in Player.action1s and not self.accepted:
if len(self.text) == 0:
self.text = "A"
return True
letter = self.text[len(self.text)-1]
letterNum = ord(letter)
if letterNum == ord('A'):
letterNum = ord(' ')
elif letterNum == ord(' '):
letterNum = ord('_')
elif letterNum == ord('_'):
letterNum = ord('-')
elif letterNum == ord('-'):
letterNum = ord('9')
elif letterNum == ord('0'):
letterNum = ord('z')
elif letterNum == ord('a'):
letterNum = ord('Z')
else:
letterNum -= 1
self.text = self.text[:-1] + chr(letterNum)
self.engine.data.selectSound.setVolume(self.sfxVolume) #MFH
self.engine.data.selectSound.play()
elif c in Player.action2s and not self.accepted:
if len(self.text) == 0:
self.text = "A"
return True
letter = self.text[len(self.text)-1]
letterNum = ord(letter)
if letterNum == ord('Z'):
letterNum = ord('a')
elif letterNum == ord('z'):
letterNum = ord('0')
elif letterNum == ord('9'):
letterNum = ord('-')
elif letterNum == ord('-'):
letterNum = ord('_')
elif letterNum == ord('_'):
letterNum = ord(' ')
elif letterNum == ord(' '):
letterNum = ord('A')
else:
letterNum += 1
self.text = self.text[:-1] + chr(letterNum)
self.engine.data.selectSound.setVolume(self.sfxVolume) #MFH
self.engine.data.selectSound.play()
return True
def run(self, ticks):
self.time += ticks / 50.0
def render(self, visibility, topMost):
self.engine.view.setViewport(1,0)
font = self.engine.data.font
with self.engine.view.orthogonalProjection(normalize = True):
v = (1 - visibility) ** 2
fadeScreen(v)
self.engine.theme.setBaseColor(1 - v)
if (self.time % 10) < 5 and visibility > .9:
cursor = "|"
else:
cursor = ""
pos = wrapText(font, (.1, .33 - v), self.prompt)
self.engine.theme.setSelectedColor(1 - v)
if self.text is not None:
pos = wrapText(font, (.1, (pos[1] + v) + .08 + v / 4), self.text)
font.render(cursor, pos)
class GetKey(Layer, KeyListener):
"""Key choosing layer."""
def __init__(self, engine, prompt = "", key = None, noKey = False, specialKeyList = []):
self.key = key
self.prompt = prompt
self.engine = engine
self.time = 0
self.accepted = False
self.noKey = noKey
self.toggleEsc = False
self.escTimer = 1000
self.specialKeyList = specialKeyList
if self.engine.data.logClassInits == 1:
Log.debug("GetKey class init (Dialogs.py)...")
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
def hidden(self):
self.engine.input.removeKeyListener(self)
def keyPressed(self, key, unicode):
if key == pygame.K_ESCAPE and not self.accepted:
self.toggleEsc = True
elif not self.accepted and key not in self.specialKeyList:
self.key = key
self.engine.view.popLayer(self)
self.accepted = True
return True
def keyReleased(self, key):
if key == pygame.K_ESCAPE and self.toggleEsc:
if key in self.specialKeyList:
self.escTimer = 1000
self.toggleEsc = False
else:
self.key = key
self.engine.view.popLayer(self)
self.accepted = True
def run(self, ticks):
self.time += ticks / 50.0
if self.toggleEsc:
self.escTimer -= ticks
if self.escTimer < 0:
self.key = None
self.engine.view.popLayer(self)
self.accepted = True
def render(self, visibility, topMost):
self.engine.view.setViewport(1,0)
font = self.engine.data.font
with self.engine.view.orthogonalProjection(normalize = True):
v = (1 - visibility) ** 2
fadeScreen(v)
self.engine.theme.setBaseColor(1 - v)
pos = wrapText(font, (.1, .33 - v), self.prompt)
self.engine.theme.setSelectedColor(1 - v)
if self.key is not None:
text = pygame.key.name(self.key).capitalize()
pos = wrapText(font, (.1, (pos[1] + v) + .08 + v / 4), text)
class LoadingScreen(Layer, KeyListener):
"""Loading screen layer."""
def __init__(self, engine, condition, text, allowCancel = False):
self.engine = engine
self.text = text
self.condition = condition
self.ready = False
self.allowCancel = allowCancel
self.time = 0.0
if self.engine.data.logClassInits == 1:
Log.debug("LoadingScreen class init (Dialogs.py)...")
self.loadingx = self.engine.theme.loadingX
self.loadingy = self.engine.theme.loadingY
self.allowtext = self.engine.config.get("menu", "lphrases")
#Get theme
themename = self.engine.data.themeLabel
self.theme = self.engine.data.theme
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
def keyPressed(self, key, unicode):
c = self.engine.input.controls.getMapping(key)
if self.allowCancel and c in Player.menuNo:
self.engine.view.popLayer(self)
return True
def hidden(self):
self.engine.input.removeKeyListener(self)
def run(self, ticks):
self.time += ticks / 50.0
if not self.ready and self.condition():
self.engine.view.popLayer(self)
self.ready = True
def render(self, visibility, topMost):
self.engine.view.setViewport(1,0)
font = self.engine.data.loadingFont
if not font:
return
with self.engine.view.orthogonalProjection(normalize = True):
v = (1 - visibility) ** 2
fadeScreen(v)
w, h = self.engine.view.geometry[2:4]
self.loadingImg = self.engine.data.loadingImage
#MFH - auto-scaling of loading screen
#Volshebnyi - fit to screen applied
if self.loadingImg:
self.engine.drawImage(self.loadingImg, scale = (1.0,-1.0), coord = (w/2,h/2), stretched = 3)
self.engine.theme.setBaseColor(1 - v)
w, h = font.getStringSize(self.text)
if self.loadingx != None:
if self.loadingy != None:
x = self.loadingx - w / 2
y = self.loadingy - h / 2 + v * .5
else:
x = self.loadingx - w / 2
y = .6 - h / 2 + v * .5
elif self.loadingy != None:
x = .5 - w / 2
y = .6 - h / 2 + v * .5
else:
x = .5 - w / 2
y = .6 - h / 2 + v * .5
if self.allowtext:
if self.theme == 1:
font.render(self.text, (x, y), shadowoffset = (self.engine.theme.shadowoffsetx, self.engine.theme.shadowoffsety))
else:
font.render(self.text, (x, y))
class MessageScreen(Layer, KeyListener):
"""Message screen layer."""
def __init__(self, engine, text, prompt = _("<OK>")):
self.engine = engine
self.text = text
self.time = 0.0
self.prompt = prompt
self.logClassInits = self.engine.config.get("game", "log_class_inits")
if self.logClassInits == 1:
Log.debug("MessageScreen class init (Dialogs.py)...")
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
def keyPressed(self, key, unicode):
c = self.engine.input.controls.getMapping(key)
if c in (Player.menuYes + Player.menuNo) or key in [pygame.K_RETURN, pygame.K_ESCAPE, pygame.K_LCTRL, pygame.K_RCTRL]:
self.engine.view.popLayer(self)
return True
def hidden(self):
self.engine.input.removeKeyListener(self)
def run(self, ticks):
self.time += ticks / 50.0
def render(self, visibility, topMost):
self.engine.view.setViewport(1,0)
font = self.engine.data.font
if not font:
return
with self.engine.view.orthogonalProjection(normalize = True):
v = (1 - visibility) ** 2
fadeScreen(v)
x = .1
y = .3 + v * 2
self.engine.theme.setBaseColor(1 - v)
pos = wrapText(font, (x, y), self.text, visibility = v)
w, h = font.getStringSize(self.prompt, scale = 0.001)
x = .5 - w / 2
y = pos[1] + 3 * h + v * 2
self.engine.theme.setSelectedColor(1 - v)
font.render(self.prompt, (x, y), scale = 0.001)
class FileChooser(BackgroundLayer, KeyListener):
"""File choosing layer."""
def __init__(self, engine, masks, path, prompt = "", dirSelect = False):
self.masks = masks
self.path = os.path.abspath(path)
self.prompt = prompt
self.engine = engine
self.accepted = False
self.selectedFile = None
self.time = 0.0
self.menu = None
self.TOPLEVEL = "?top" #An invalid filesystem character so the top-level-ness is marked
self.driveLetters = None
if os.name == "nt":
import win32api, win32file
driveLetters=win32api.GetLogicalDriveStrings().split('\x00')[:-1]
self.driveLetters = []
#Here we should filter some drives out. Anything inaccessible, or with no space.
#I have been playing around with other scenarios for figuring out whether or not a drive
#is suitable, but this seemed the simplest. (akedrou)
for drive in driveLetters:
try:
size = win32file.GetDiskFreeSpaceEx(drive)
if size > 0:
self.driveLetters.append(drive)
except:
pass
if self.engine.data.logClassInits == 1:
Log.debug("FileChooser class init (Dialogs.py)...")
self.dirSelect = dirSelect
def _getFileCallback(self, fileName):
return lambda: self.chooseFile(fileName)
def _getFileText(self, fileName):
f = os.path.join(self.path, fileName)
if fileName == "..":
return _("[Parent Folder]")
if self.path == self.TOPLEVEL:
return _("%s [Drive]") % fileName
else:
if self.dirSelect == True:
for mask in self.masks:
if fnmatch.fnmatch(fileName, mask):
return _("[Accept Folder]")
if os.path.isdir(f):
return _("%s [Folder]") % fileName
return fileName
def getFiles(self):
files = [".."]
for fn in os.listdir(self.path):
if fn.startswith("."): continue
f = os.path.join(self.path, fn)
for mask in self.masks:
if fnmatch.fnmatch(fn, mask):
break
else:
if not os.path.isdir(f):
continue
files.append(fn)
files.sort()
if self.dirSelect == True and self.path!=self.TOPLEVEL:
files.insert(0, self.path)
return files
def getDisks(self):
return self.driveLetters
def updateFiles(self):
if self.menu:
self.engine.view.popLayer(self.menu)
if self.path == self.TOPLEVEL and os.name != "nt":
self.path = "/"
if self.path == self.TOPLEVEL:
self.menu = Menu(self.engine, choices = [(self._getFileText(f), self._getFileCallback(f)) for f in self.getDisks()], onClose = self.close, onCancel = self.cancel)
else:
self.menu = Menu(self.engine, choices = [(self._getFileText(f), self._getFileCallback(f)) for f in self.getFiles()], onClose = self.close, onCancel = self.cancel)
self.engine.view.pushLayer(self.menu)
def chooseFile(self, fileName):
if self.dirSelect == True and self.path != self.TOPLEVEL:
for mask in self.masks:
if fnmatch.fnmatch(fileName, mask):
self.selectedFile = fileName
accepted = True
self.engine.view.popLayer(self.menu)
self.engine.view.popLayer(self)
self.menu = None
return
if self.path == self.TOPLEVEL:
self.path = ""
path = os.path.abspath(os.path.join(self.path, fileName))
if os.path.isdir(path):
if path == self.path and fileName == "..":
self.path = self.TOPLEVEL
else:
self.path = path
self.updateFiles()
return
self.selectedFile = path
accepted = True
self.engine.view.popLayer(self.menu)
self.engine.view.popLayer(self)
self.menu = None
def cancel(self):
self.accepted = True
self.engine.view.popLayer(self)
def close(self):
if not self.menu:
self.accepted = True
self.engine.view.popLayer(self)
def shown(self):
self.updateFiles()
def getSelectedFile(self):
return self.selectedFile
def run(self, ticks):
self.time += ticks / 50.0
def render(self, visibility, topMost):
v = (1 - visibility) ** 2
# render the background
t = self.time / 100
self.engine.view.setViewport(1,0)
w, h, = self.engine.view.geometry[2:4]
r = .5
#MFH - auto background scaling
if self.engine.data.optionsBG:
self.engine.drawImage(self.engine.data.optionsBG, scale = (1.0,-1.0), coord = (w/2,h/2), stretched = 3)
font = self.engine.data.font
with self.engine.view.orthogonalProjection(normalize = True):
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_COLOR_MATERIAL)
self.engine.theme.setBaseColor(1 - v)
wrapText(font, (.1, .05 - v), self.prompt)
class NeckChooser(Layer, KeyListener):
"""
Item menu layer.
on-demand Neck Select menu
"""
def __init__(self, engine, selected = None, prompt = _("Yellow (#3) / Blue (#4) to change, Green (#1) to confirm:"), player = "default", owner = None):
self.prompt = prompt
self.prompt_x = engine.theme.neck_prompt_x
self.prompt_y = engine.theme.neck_prompt_y
self.engine = engine
self.player = player
self.owner = owner
if self.engine.data.logClassInits == 1:
Log.debug("%s NeckChooser class init (Dialogs.py)..." % (self.player))
splash = showLoadingSplashScreen(self.engine, _("Loading necks..."))
self.neck = []
self.necks = ["2none", "none"]
self.maxNeck = 0
defaultNeck = self.engine.config.get("game", "default_neck")
self.selectedNeck = 0
for i, name in enumerate(Player.playername):
if name == player:
playerNeck = Player.playerpref[i][6]
if playerNeck == "":
playerNeck = defaultNeck
break
else:
playerNeck = defaultNeck
# evilynux - improved loading logic to support arbitrary filenames
# - os.listdir is not guaranteed to return a sorted list, so sort it!
path = self.engine.resource.fileName("necks")
# only list files
neckfiles = [ f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) ]
neckfiles.sort()
for i in neckfiles: #MFH - first go through and find the random neck
if ( os.path.splitext(i)[0] == "randomneck" ): #MFH
randomNeck = i
exists = 1
neckImage = engine.loadImgDrawing(self, "neck"+str(i), os.path.join("necks",str(i)))
if not neckImage:
# evilynux - Warning, Thumbs.db won't fail at engine.loadImgDrawing
exists = 0
continue
else:
exists = 1
if exists == 1:
self.neck.append(str(i)[:-4]) # evilynux - filename w/o extension
self.necks.append(neckImage)
break
for i in neckfiles:
# evilynux - Special cases, ignore these...
if( os.path.splitext(i)[0] == "randomneck" or os.path.splitext(i)[0] == "overdriveneck" ): #MFH
exists = 0
continue
neckImage = engine.loadImgDrawing(self, "neck"+str(i), os.path.join("necks",str(i)))
if not neckImage:
# evilynux - Warning, Thumbs.db won't fail at engine.loadImgDrawing
exists = 0
continue
else:
exists = 1
if exists == 1:
self.neck.append(str(i)[:-4]) # evilynux - filename w/o extension
self.necks.append(neckImage)
self.maxNeck += 1
self.maxNeck -= 1 # evilynux - confusing, but there's an offset of -1
Config.define("player", "neck", str, 0, text = _("Neck"), options = self.neck)
for i, neck in enumerate(self.neck):
if neck == playerNeck:
self.selectedNeck = i
break
else:
for i, neck in enumerate(self.neck):
if neck == defaultNeck:
self.selectedNeck = i
else:
self.selectedNeck = 0
self.necks.append("none")
self.necks.append("2none")
self.accepted = False
self.time = 0.0
#Get theme
self.themename = self.engine.data.themeLabel
self.theme = self.engine.data.theme
#MFH - added simple black background to place in front of Options background, behind Neck BG, for transparent neck displays
if not self.engine.loadImgDrawing(self, "neckBlackBack", ("neckblackback.png")):
self.neckBlackBack = None
self.engine.loadImgDrawing(self, "neckBG", os.path.join("themes",self.themename,"menu","neckchoosebg.png"))
self.engine.loadImgDrawing(self, "neckSelect", os.path.join("themes",self.themename,"menu","neckchooseselect.png"))
# ready... hide the splash screen
hideLoadingSplashScreen(self.engine, splash)
splash = None
def shown(self):
self.engine.input.addKeyListener(self, priority = True)
def hidden(self):
self.engine.input.removeKeyListener(self)
def chooseNeck(self):
if self.player == "default":
self.engine.config.set("game","default_neck",self.neck[self.selectedNeck])
if self.owner: #rather hard-coded...
if self.player != "default":
self.owner.neck = self.neck[self.selectedNeck]
self.engine.view.popLayer(self)
def cancel(self):
self.accepted = False
self.engine.view.popLayer(self)
def keyPressed(self, key, unicode):
c = self.engine.input.controls.getMapping(key)
if c in Player.key1s or key == pygame.K_RETURN:
self.chooseNeck()
elif c in Player.key2s + Player.cancels or key == pygame.K_ESCAPE:
self.cancel()
elif c in Player.key3s + Player.ups + Player.action1s + Player.lefts or key == pygame.K_UP or key == pygame.K_LEFT:
self.selectedNeck -= 1
if self.selectedNeck < 0:
self.selectedNeck = len(self.neck) - 1
elif c in Player.key4s + Player.downs + Player.action2s + Player.rights or key == pygame.K_DOWN or key == pygame.K_RIGHT:
self.selectedNeck += 1
if self.selectedNeck >= len(self.neck):
self.selectedNeck = 0
return True
def keyReleased(self, key):
return
def getSelectedNeck(self):
return self.selectedNeck
def run(self, ticks):
self.time += ticks / 50.0
def render(self, visibility, topMost):
v = (1 - visibility) ** 2
# render the background
t = self.time / 100
self.engine.view.setViewport(1,0)
w, h, = self.engine.view.geometry[2:4]
r = .5
#MFH - draw neck black BG in for transparent necks (covers options BG):
if self.neckBlackBack != None:
#MFH - auto background scaling
self.engine.drawImage(self.neckBlackBack, scale = (1.0,-1.0), coord = (w/2,h/2), stretched = 3)
currentNeck = self.necks[int(self.selectedNeck)+2]
lastNeck1 = self.necks[int(self.selectedNeck)]
if lastNeck1 == "none":
lastNeck1 = self.necks[self.maxNeck+2]
elif lastNeck1 == "2none":
lastNeck1 = self.necks[self.maxNeck+1]
lastNeck = self.necks[int(self.selectedNeck)+1]
if lastNeck == "none":
lastNeck = self.necks[self.maxNeck+2]
nextNeck = self.necks[int(self.selectedNeck)+3]
if nextNeck == "none":
nextNeck = self.necks[2]
nextNeck1 = self.necks[int(self.selectedNeck)+4]
if nextNeck1 == "none":
nextNeck1 = self.necks[2]
elif nextNeck1 == "2none":
nextNeck1 = self.necks[3]
if self.theme == 2:
self.x1 = w*0.067
self.x2 = w*0.187
self.x3 = w*0.307
self.x4 = w*0.427
self.x5 = w*0.547
self.x6 = w*0.296
self.y1 = h*0.420
self.y2 = h*0.420
self.y3 = h*0.420
self.y4 = h*0.420
self.y5 = h*0.420
self.y6 = h*0.420
self.wfac = 384.000
self.wfac2 = 124.000
else:
self.x1 = w*0.05
self.x2 = w*0.175
self.x3 = w*0.296
self.x4 = w*0.42
self.x5 = w*0.539
self.x6 = w*0.296
self.y1 = h*0.420
self.y2 = h*0.554
self.y3 = h*0.415
self.y4 = h*0.554
self.y5 = h*0.402
self.y6 = h*0.423
self.wfac = 374.000
self.wfac2 = 128.000
wfactor = currentNeck.widthf(pixelw = self.wfac)
if self.theme != 2:
neckcoord = (w/1.31,h/2)
else:
neckcoord = (w/1.22,h/2)
self.engine.drawImage(currentNeck, scale = (-wfactor,wfactor), coord = neckcoord)
wfactor = lastNeck1.widthf(pixelw = self.wfac2)
self.engine.drawImage(lastNeck1, scale = (-wfactor,wfactor), coord = (self.x1,self.y1))
wfactor = lastNeck.widthf(pixelw = self.wfac2)
self.engine.drawImage(lastNeck, scale = (-wfactor,wfactor), coord = (self.x2,self.y2))
wfactor = currentNeck.widthf(pixelw = self.wfac2)
self.engine.drawImage(currentNeck, scale = (-wfactor,wfactor), coord = (self.x3,self.y3))
wfactor = nextNeck.widthf(pixelw = self.wfac2)
self.engine.drawImage(nextNeck, scale = (-wfactor,wfactor), coord = (self.x4,self.y4))
wfactor = nextNeck1.widthf(pixelw = self.wfac2)
self.engine.drawImage(nextNeck1, scale = (-wfactor,wfactor), coord = (self.x5,self.y5))
if self.selectedNeck:
self.engine.drawImage(self.neckSelect, scale = (-1.0,1.0), coord = (self.x6, self.y6))
#MFH - draw neck BG on top of necks
#MFH - auto background scaling
self.engine.drawImage(self.neckBG, scale = (1.0,-1.0), coord = (w/2,h/2), stretched = 3)
font = self.engine.data.font
with self.engine.view.orthogonalProjection(normalize = True):
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable(GL_COLOR_MATERIAL)
self.engine.theme.setBaseColor(1 - v)
wrapText(font, (self.prompt_x, self.prompt_y - v), self.prompt)
#==============================================================
class AvatarChooser(Layer, KeyListener):
"""Avatar choosing layer"""
def __init__(self, engine):
self.engine = engine
if self.engine.data.logClassInits == 1:
Log.debug("AvatarChooser class init (Dialogs.py)...")
splash = showLoadingSplashScreen(self.engine, _("Loading avatars..."))
#Get theme
self.themename = self.engine.data.themeLabel
self.theme = self.engine.data.theme
self.avatar = []
self.avatars = []
self.maxAv = 0
self.themeAvs = 0
self.selectedAv = 0
self.scrolling = 0
self.delay = 0
self.rate = 0
self.scroller = [0, self.scrollUp, self.scrollDown]
# evilynux - improved loading logic to support arbitrary filenames
# - os.listdir is not guaranteed to return a sorted list, so sort it!
avatarpath = self.engine.resource.fileName("avatars")
avatarfiles = [ f for f in os.listdir(avatarpath) if os.path.isfile(os.path.join(avatarpath, f)) ]
avatarfiles.sort()
themeavatarfiles = []
themeavatarpath = self.engine.resource.fileName(os.path.join("themes",self.themename,"avatars"))
if os.path.exists(themeavatarpath):
themeavatarfiles = [ f for f in os.listdir(themeavatarpath) if os.path.isfile(os.path.join(themeavatarpath, f)) ]
themeavatarfiles.sort()
for i in themeavatarfiles:
image = engine.loadImgDrawing(self, "av"+str(i), os.path.join("themes",self.themename,"avatars",str(i)))
if not image:
exists = 0
continue
else:
exists = 1
if exists == 1:
self.avatar.append(str(i)[:-4]) # evilynux - filename w/o extension
self.avatars.append(image)
self.maxAv += 1
self.themeAvs = len(self.avatars)
for i in avatarfiles:
image = engine.loadImgDrawing(self, "av"+str(i), os.path.join("avatars",str(i)))
if not image:
exists = 0
continue
else:
exists = 1
if exists == 1:
self.avatar.append(str(i)[:-4]) # evilynux - filename w/o extension
self.avatars.append(image)
self.maxAv += 1
Log.debug("%d Theme Avatars found; %d total." % (self.themeAvs, len(self.avatars)))
self.avScale = []
for avatar in self.avatars:
imgheight = avatar.height1()
imgwidth = avatar.width1()
hFactor = 110.00/imgheight
wFactor = 178.00/imgwidth
self.avScale.append(min(hFactor, wFactor))
self.maxAv -= 1 # evilynux - confusing, but there's an offset of -1
self.accepted = False
self.time = 0.0
self.dist = 1.0
#MFH - added simple black background to place in front of Options background, behind Neck BG, for transparent neck displays
if not self.engine.loadImgDrawing(self, "avFrame", os.path.join("themes",self.themename,"lobby","avatarframe.png")):