-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogs.py
5530 lines (4683 loc) · 223 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 division
from builtins import chr
from builtins import str
from builtins import range
from past.utils import old_div
import pygame
from OpenGL.GL import *
from OpenGL.GLU import *
import math
import os
import fnmatch
import string
import time
from View import Layer, BackgroundLayer
from Input import KeyListener
from Camera import Camera
from Mesh import Mesh
from Menu import Menu
from Language import _
from Texture import Texture
from Player import GUITARTYPES, DRUMTYPES, MICTYPES
import Theme
import Log
import Song
import Data
import Player
import Guitar
import random
from Shader import shaders
import Resource
#myfingershurt: drums :)
import Drum
#stump: vocals
import Microphone
# evilynux - MFH-Alarian Mod credits
from Credits import Credits
import Config
import Settings
#MFH - for cd/song list
from Svg import ImgDrawing, SvgContext
#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)
#space = font.getStringSize(" ", scale = scale)[0]
#startXpos = x - (rightMargin-x) #for a symmetrical text wrapping
#x = startXpos
sentence = ""
for n, word in enumerate(text.split(" ")):
w, h = font.getStringSize(sentence + " " + word, scale = scale)
if x + (old_div(w,2)) > rightMargin or word == "\n":
w, h = font.getStringSize(sentence, scale = scale)
#x = startXpos
glPushMatrix()
glRotate(visibility * (n + 1) * -45, 0, 0, 1)
if allowshadowoffset == True:
font.render(sentence, (x - (old_div(w,2)), y + visibility * n), scale = scale, shadowoffset = shadowoffset)
else:
font.render(sentence, (x - (old_div(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 - (old_div(w,2)), y + visibility * n), scale = scale, shadowoffset = shadowoffset)
else:
font.render(sentence, (x - (old_div(w,2)), y + visibility * n), scale = scale)
glPopMatrix()
y += h * linespace
#if word == "\n":
# continue
#x += w + space
return (x, y)
#space = font.getStringSize(" ", scale = scale)[0]
#startXpos = x - (rightMargin-x) #for a symmetrical text wrapping
#x = startXpos
#for n, word in enumerate(text.split(" ")):
# w, h = font.getStringSize(word, scale = scale)
# if x + w > rightMargin*1.11 or word == "\n":
# x = startXpos
# y += h*.5 # Worldrave - Modified spacing between lines
# if word == "\n":
# continue
# 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 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 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
self.logClassInits = self.engine.config.get("game", "log_class_inits")
if self.logClassInits == 1:
Log.debug("GetText class init (Dialogs.py)...")
self.sfxVolume = self.engine.config.get("audio", "SFX_volume")
self.drumHighScoreNav = self.engine.config.get("game", "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, str):
self.time = 0
c = self.engine.input.controls.getMapping(key)
#if (c in Player.KEY1S or key == pygame.K_RETURN) and not self.accepted:
#if (c in Player.KEY1S or key == pygame.K_RETURN or c in Player.DRUM4S) and not self.accepted: #MFH - adding support for green drum "OK"
if key == pygame.K_BACKSPACE and not self.accepted:
self.text = self.text[:-1]
elif str and ord(str) > 31 and not self.accepted:
self.text += str
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)
self.engine.view.setOrthogonalProjection(normalize = True)
font = self.engine.data.font
try:
v = (1 - visibility) ** 2
fadeScreen(v)
Theme.setBaseColor(1 - v)
if (self.time % 10) < 5 and visibility > .9:
cursor = "|"
else:
cursor = ""
pos = wrapText(font, (.1, .33 - v), self.prompt)
Theme.setSelectedColor(1 - v)
if self.text is not None:
pos = wrapText(font, (.1, (pos[1] + v) + .08 + old_div(v, 4)), self.text)
font.render(cursor, pos)
finally:
self.engine.view.resetProjection()
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
self.logClassInits = self.engine.config.get("game", "log_class_inits")
if self.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, str):
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)
self.engine.view.setOrthogonalProjection(normalize = True)
font = self.engine.data.font
try:
v = (1 - visibility) ** 2
fadeScreen(v)
Theme.setBaseColor(1 - v)
pos = wrapText(font, (.1, .33 - v), self.prompt)
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 + old_div(v, 4)), text)
finally:
self.engine.view.resetProjection()
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
self.logClassInits = self.engine.config.get("game", "log_class_inits")
if self.logClassInits == 1:
Log.debug("LoadingScreen class init (Dialogs.py)...")
self.loadingx = Theme.loadingX
self.loadingy = Theme.loadingY
self.allowtext = self.engine.config.get("game", "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, str):
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)
self.engine.view.setOrthogonalProjection(normalize = True)
#font = self.engine.data.font
font = self.engine.data.loadingFont
if not font:
return
try:
v = (1 - visibility) ** 2
fadeScreen(v)
w, h = self.engine.view.geometry[2:4]
#MFH - auto-scaling of loading screen
#Volshebnyi - fit to screen applied
self.engine.drawImage(self.engine.data.loadingImage, scale = (1.0,-1.0), coord = (old_div(w,2),old_div(h,2)), stretched = 3)
Theme.setBaseColor(1 - v)
w, h = font.getStringSize(self.text)
if self.loadingx != None:
if self.loadingy != None:
x = self.loadingx - old_div(w, 2)
y = self.loadingy - old_div(h, 2) + v * .5
else:
x = self.loadingx - old_div(w, 2)
y = .6 - old_div(h, 2) + v * .5
elif self.loadingy != None:
x = .5 - old_div(w, 2)
y = .6 - old_div(h, 2) + v * .5
else:
x = .5 - old_div(w, 2)
y = .6 - old_div(h, 2) + v * .5
if self.allowtext:
if self.theme == 1:
font.render(self.text, (x, y), shadowoffset = (Theme.shadowoffsetx, Theme.shadowoffsety))
else:
font.render(self.text, (x, y))
finally:
self.engine.view.resetProjection()
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, str):
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)
self.engine.view.setOrthogonalProjection(normalize = True)
font = self.engine.data.font
if not font:
return
try:
v = (1 - visibility) ** 2
fadeScreen(v)
x = .1
y = .3 + v * 2
Theme.setBaseColor(1 - v)
pos = wrapText(font, (x, y), self.text, visibility = v)
w, h = font.getStringSize(self.prompt, scale = 0.001)
x = .5 - old_div(w, 2)
y = pos[1] + 3 * h + v * 2
Theme.setSelectedColor(1 - v)
font.render(self.prompt, (x, y), scale = 0.001)
finally:
self.engine.view.resetProjection()
class SongChooser(Layer, KeyListener):
"""Song choosing layer."""
def __init__(self, engine, prompt = "", selectedLibrary = None, selectedSong = None):
self.prompt = prompt
self.engine = engine
self.logClassInits = self.engine.config.get("game", "log_class_inits")
if self.logClassInits == 1:
Log.debug("SongChooser class init (Dialogs.py)...")
#MFH - retrieve game parameters:
self.gamePlayers = self.engine.config.get("game", "players")
self.gameMode1p = self.engine.config.get("game","game_mode")
self.gameMode2p = self.engine.config.get("game","multiplayer_mode")
if self.gameMode1p == 2:
self.careerMode = True
else:
self.careerMode = False
self.drumNav = self.engine.config.get("game", "drum_navigation") #MFH
self.career_title_color = Theme.hexToColor(Theme.career_title_colorVar)
self.song_name_text_color = Theme.hexToColor(Theme.song_name_text_colorVar)
self.song_name_selected_color = Theme.hexToColor(Theme.song_name_selected_colorVar)
self.artist_text_color = Theme.hexToColor(Theme.artist_text_colorVar)
self.artist_selected_color = Theme.hexToColor(Theme.artist_selected_colorVar)
self.library_text_color = Theme.hexToColor(Theme.library_text_colorVar)
self.library_selected_color = Theme.hexToColor(Theme.library_selected_colorVar)
self.songlist_score_color = Theme.hexToColor(Theme.songlist_score_colorVar)
self.songlistcd_score_color = Theme.hexToColor(Theme.songlistcd_score_colorVar)
self.song_rb2_name_color = Theme.hexToColor(Theme.song_rb2_name_colorVar)
self.song_rb2_name_selected_color = Theme.hexToColor(Theme.song_rb2_name_selected_colorVar)
self.song_rb2_diff_color = Theme.hexToColor(Theme.song_rb2_diff_colorVar)
self.song_rb2_artist_color = Theme.hexToColor(Theme.song_rb2_artist_colorVar)
self.scrolling = 0
self.delay = 0
self.rate = 0
self.scroller = [0, self.scrollUp, self.scrollDown]
self.listRotation = self.engine.config.get("game", "songlistrotation")
self.songCoverType = self.engine.config.get("game", "songcovertype")
self.listingMode = engine.config.get("game","song_listing_mode")
self.songIcons = engine.config.get("game", "song_icons")
self.preLoadSongLabels = engine.config.get("game", "preload_labels")
Log.debug("Songlist artist colors: " + str(self.artist_text_color) + " / " + str(self.artist_selected_color))
#MFH
try:
self.song_cd_xpos = Theme.song_cd_Xpos
Log.debug("song_cd_xpos found: " + str(self.song_cd_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_cd_xpos: %s" % e)
self.song_cd_xpos = None
try:
self.song_cdscore_xpos = Theme.song_cdscore_Xpos
Log.debug("song_cdscore_xpos found: " + str(self.song_cdscore_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_cdscore_xpos: %s" % e)
self.song_cdscore_xpos = None
try:
self.song_list_xpos = Theme.song_list_Xpos
Log.debug("song_list_xpos found: " + str(self.song_list_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_list_xpos: %s" % e)
self.song_list_xpos = None
try:
self.song_listscore_xpos = Theme.song_listscore_Xpos
Log.debug("song_listscore_xpos found: " + str(self.song_listscore_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_listscore_xpos: %s" % e)
self.song_listscore_xpos = None
try:
self.song_listcd_cd_xpos = Theme.song_listcd_cd_Xpos
Log.debug("song_listcd_cd_xpos found: " + str(self.song_listcd_cd_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_listcd_cd_xpos: %s" % e)
self.song_listcd_cd_xpos = None
try:
self.song_listcd_cd_ypos = Theme.song_listcd_cd_Ypos
Log.debug("song_listcd_cd_ypos found: " + str(self.song_listcd_cd_ypos))
except Exception as e:
Log.warn("Unable to load Theme song_listcd_cd_ypos: %s" % e)
self.song_listcd_cd_ypos = None
try:
self.song_listcd_score_xpos = Theme.song_listcd_score_Xpos
Log.debug("song_listcd_score_xpos found: " + str(self.song_listcd_score_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_listcd_score_xpos: %s" % e)
self.song_listcd_score_xpos = None
try:
self.song_listcd_score_ypos = Theme.song_listcd_score_Ypos
Log.debug("song_listcd_score_ypos found: " + str(self.song_listcd_score_ypos))
except Exception as e:
Log.warn("Unable to load Theme song_listcd_score_ypos: %s" % e)
self.song_listcd_score_ypos = None
try:
self.song_listcd_list_xpos = Theme.song_listcd_list_Xpos
Log.debug("song_listcd_list_xpos found: " + str(self.song_listcd_list_xpos))
except Exception as e:
Log.warn("Unable to load Theme song_listcd_list_xpos: %s" % e)
self.song_listcd_list_xpos = None
#pre-determine these values and just replace them with these variables in the render function:
#Blazingamer CD X position fix
if self.song_cd_xpos == None:
self.song_cd_xpos = 0.0
elif self.song_cd_xpos > 5:
self.song_cd_xpos = 5.0
elif self.song_cd_xpos < 0:
self.song_cd_xpos = 0.0
if self.song_cdscore_xpos == None:
self.song_cdscore_xpos = 0.6
if self.song_list_xpos == None:
self.song_list_xpos = 0.15
if self.song_listscore_xpos == None:
self.song_listscore_xpos = 0.8
#Qstick - List/CD mode element positions
if self.song_listcd_cd_xpos == None:
self.song_listcd_cd_xpos = .75
if self.song_listcd_cd_ypos == None:
self.song_listcd_cd_ypos = .6
if self.song_listcd_score_xpos == None:
self.song_listcd_score_xpos = 0.6
if self.song_listcd_score_ypos == None:
self.song_listcd_score_ypos = 0.5
if self.song_listcd_list_xpos == None:
self.song_listcd_list_xpos = .1
self.time = 0
self.lastTime = 0
self.accepted = False
self.selectedIndex = 0
self.camera = Camera()
self.cassetteHeight = .8
self.cassetteWidth = 4.0
self.libraryHeight = 1.2
self.libraryWidth = 4.0
self.titleHeight = 2.4
self.titleWidth = 4.0
self.itemAngles = None
self.itemLabels = None
self.selectedOffset = 0.0
self.cameraOffset = 0.0
self.selectedItem = None
self.song = None
self.songCountdown = 1024
self.songLoader = None
self.initialItem = selectedSong
self.library = selectedLibrary
self.searchText = ""
self.searching = False
self.halfTime = 0
#RF-mod
self.previewDisabled = self.engine.config.get("audio", "disable_preview")
self.sortOrder = self.engine.config.get("game", "sort_order")
self.rotationDisabled = self.engine.config.get("performance", "disable_librotation")
self.spinnyDisabled = self.engine.config.get("game", "disable_spinny")
self.sortorder = engine.config.get("game", "sort_order")
self.sortdirection = engine.config.get("game", "sort_direction")
self.sfxVolume = self.engine.config.get("audio", "SFX_volume")
self.engine.data.selectSound.setVolume(self.sfxVolume)
#Get Theme
themename = self.engine.data.themeLabel
self.theme = self.engine.data.theme
self.display = self.engine.config.get("coffee", "song_display_mode")
if self.display == 4:
if Theme.songListDisplay != None:
self.display = Theme.songListDisplay
else:
self.display = 1
self.tut = self.engine.config.get("game", "tut")
self.songback = Theme.songback
self.filepathenable = self.engine.config.get("coffee", "songfilepath")
temp = self.engine.config.get("game", "search_key")
if temp != "None":
self.searchKey = ord(temp[0])
else:
self.searchKey = ord('/')
# Use the default library if this one doesn't exist
if not self.library or not os.path.isdir(self.engine.resource.fileName(self.library)):
self.library = Song.DEFAULT_LIBRARY
if self.tut == True:
self.library = self.engine.tutorialFolder
self.loadCollection()
#MFH configurable default instrument display with 5th / orange fret
# need to keep track of the instrument number and instrument name
self.instrument = Song.parts[self.engine.config.get("game", "songlist_instrument")]
if self.display == 0:
self.engine.resource.load(self, "cassette", lambda: Mesh(self.engine.resource.fileName("cassette.dae")), synch = True)
self.engine.resource.load(self, "label", lambda: Mesh(self.engine.resource.fileName("label.dae")), synch = True)
self.engine.resource.load(self, "libraryMesh", lambda: Mesh(self.engine.resource.fileName("library.dae")), synch = True)
self.engine.resource.load(self, "libraryLabel", lambda: Mesh(self.engine.resource.fileName("library_label.dae")), synch = True)
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchoosepaper.png"))
elif self.display == 1:
try:
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchooseback.png"))
except IOError:
self.background = None
self.engine.loadImgDrawing(self, "paper", os.path.join("themes",themename,"menu","songchoosepaper.png"))
self.engine.loadImgDrawing(self, "selected", os.path.join("themes",themename,"menu","selected.png"))
self.scoreTimer = 0
# evilynux - configurable default highscores difficulty display
self.diff = Song.difficulties[self.engine.config.get("game", "songlist_difficulty")]
elif self.display == 2:
self.engine.resource.load(self, "cassette", lambda: Mesh(self.engine.resource.fileName("cassette.dae")), synch = True)
self.engine.resource.load(self, "label", lambda: Mesh(self.engine.resource.fileName("label.dae")), synch = True)
self.engine.resource.load(self, "libraryMesh", lambda: Mesh(self.engine.resource.fileName("library.dae")), synch = True)
self.engine.resource.load(self, "libraryLabel", lambda: Mesh(self.engine.resource.fileName("library_label.dae")), synch = True)
try:
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchooselistcd.png"))
except IOError:
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchoosepaper.png"))
try:
self.engine.loadImgDrawing(self, "selectedlistcd", os.path.join("themes",themename,"menu","selectedlistcd.png"))
except IOError:
self.engine.loadImgDrawing(self, "selected", os.path.join("themes",themename,"menu","selected.png"))
self.selectedlistcd = None
elif self.display == 3:
try:
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchooserb2.png"))
except IOError:
self.background = None
self.engine.loadImgDrawing(self, "background", os.path.join("themes",themename,"menu","songchoosepaper.png"))
try:
self.engine.loadImgDrawing(self, "selected", os.path.join("themes",themename,"menu","selectedrb2.png"))
except IOError:
self.engine.loadImgDrawing(self, "selected", os.path.join("themes",themename,"menu","selected.png"))
try:
self.engine.loadImgDrawing(self, "tierbg", os.path.join("themes",themename,"menu","tier.png"))
except IOError:
self.tierbg = None
try:
self.engine.loadImgDrawing(self, "emptyLabel", os.path.join("themes",themename,"menu","emptylabel.png"))
except IOError:
self.emptyLabel = None
try:
self.engine.loadImgDrawing(self, "lockedLabel", os.path.join("themes",themename,"menu","lockedlabel.png"))
except IOError:
self.lockedLabel = self.emptyLabel
try:
self.engine.loadImgDrawing(self, "diffimg1", os.path.join("themes",themename,"menu","diff1.png"))
self.engine.loadImgDrawing(self, "diffimg2", os.path.join("themes",themename,"menu","diff2.png"))
self.engine.loadImgDrawing(self, "diffimg3", os.path.join("themes",themename,"menu","diff3.png"))
except IOError:
self.diffimg1 = self.engine.data.star3
self.diffimg2 = self.engine.data.star4
self.diffimg3 = self.engine.data.starPerfect
#song icon loading
if self.songIcons:
self.itemIcons = []
self.itemIconNames = []
iconFolder = engine.resource.fileName(os.path.join("themes",themename,"menu","icon"))
if os.path.exists(iconFolder):
for filename in os.listdir(iconFolder):
if os.path.splitext(filename)[1].lower() == ".png":
thisfile = self.engine.resource.fileName("themes",themename,"menu","icon",filename)
if os.path.exists(thisfile):
self.itemIcons.append(ImgDrawing(self.engine.data.svg, thisfile))
self.itemIconNames.append(os.path.splitext(filename)[0])
self.scoreTimer = 0
# evilynux - configurable default highscores difficulty display
self.diff = Song.difficulties[self.engine.config.get("game", "songlist_difficulty")]
#if self.rotationDisabled:
# item = self.items[self.selectedIndex]
# Log.debug(os.path.join(self.library, item.songName, "label.png"))
# try:
# if isinstance(item, Song.SongInfo):
#
# self.engine.loadImgDrawing(self, "currentlabel", os.path.join(self.library, item.songName, "label.png"))
# elif isinstance(item, Song.LibraryInfo):
# self.engine.loadImgDrawing(self, "currentlabel", os.path.join(item.libraryName, "label.png"))
# else:
# self.currentlabel = None
# except IOError:
# self.currentlabel = None
# evilynux - Shall we show hit% and note streak?
self.extraStats = self.engine.config.get("game", "songlist_extra_stats")
#myfingershurt: adding yellow fret preview again
self.playSong = False
#worldrave - Use setlistguidebuttons image if it exists.
try:
self.engine.loadImgDrawing(self, "setlistguidebuttons", os.path.join("themes",themename,"menu","setlistguidebuttons.png"))
except IOError:
self.setlistguidebuttons = None
#racer: preview graphic
try:
self.engine.loadImgDrawing(self, "preview", os.path.join("themes",themename,"menu","preview.png"))
except IOError:
self.preview = None
#racer: highscores are changed by fret
self.highScoreChange = False
self.highScoreType = self.engine.config.get("game", "HSMovement")
self.instrumentChange = False #MFH
def loadCollection(self):
Log.debug("Dialogs.loadCollection() function call...")
self.loaded = False
#showLoadingScreen(self.engine, lambda: self.loaded, text = _("Browsing Collection..."))
self.splash = showLoadingSplashScreen(self.engine, _("Browsing Collection..."))
self.loadStartTime = time.time()
# evilynux - Has to be synchronous so we don't return with an empty library list!
self.engine.resource.load(self, "libraries", lambda: Song.getAvailableLibraries(self.engine, self.library), onLoad = self.libraryListLoaded, synch = True)
#showLoadingScreen(self.engine, lambda: self.loaded, text = _("Browsing Collection..."))
def libraryListLoaded(self, libraries):
Log.debug("Dialogs.libraryListLoaded() function call...")
#self.engine.resource.load(self, "songs", lambda: Song.getAvailableSongs(self.engine, self.library), onLoad = self.songListLoaded)
self.engine.resource.load(self, "songs", lambda: Song.getAvailableSongsAndTitles(self.engine, self.library, progressCallback=self.progressCallback), onLoad = self.songListLoaded, synch = True) # evilynux - Less BlackSOD[?]
def progressCallback(self, percent):
if time.time() - self.loadStartTime > 7:
changeLoadingSplashScreenText(self.engine, self.splash, _("Browsing Collection...") + ' (%d%%)' % (percent*100))
def isInt(self, possibleInt):
try:
#MFH - remove any leading zeros (for songs with 01. or 02. for example)
splitName = possibleInt.split("0",1)
while splitName[0] == "":
splitName = possibleInt.split("0",1)
if len(splitName) > 1:
if splitName[0] == "":
possibleInt = splitName[1]
if str(int(possibleInt)) == str(possibleInt):
#Log.debug("Dialogs.isInt: " + str(possibleInt) + " = TRUE")
return True
else:
#Log.debug("Dialogs.isInt: " + str(possibleInt) + " = FALSE")
return False
except Exception as e:
return False
#Log.debug("Dialogs.isInt: " + str(possibleInt) + " = FALSE, exception: " + str(e) )
def removeSongOrderPrefixFromItem(self, item):
if not item.name.startswith("."):
splitName = item.name.split(".",1)
#Log.debug("Dialogs.songListLoaded: Separating song name from prefix: " + str(splitName) )
if self.isInt(splitName[0]) and len(splitName) > 1:
item.name = splitName[1]
#while len(splitName) > 1: #now remove any remaining leading spaces
splitName[0] = ""
while splitName[0] == "":
splitName = item.name.split(" ",1)
if len(splitName) > 1:
if splitName[0] == "":
item.name = splitName[1]
#Log.debug("Dialogs.songListLoaded: Removing song name prefix, new name = " + splitName[1])
else:
Log.debug("Song name starting with a period filtered from prefix removal logic: " + item.name)
def songListLoaded(self, songs):
if self.songLoader:
self.songLoader.cancel() # evilynux - cancel() became stop() - akedrou: when?
self.selectedIndex = 0
if self.display != 4:
#MFH: Here, scan self.songs for a SongInfo followed by a TitleInfo. Insert a BlankSpaceInfo object in between them. (one will already be in front of a CareerResetterInfo)
addingBlankSpaces = True
foundEndOfCareerYet = False
while addingBlankSpaces:
lastObjectWasASong = False
for i, item in enumerate(self.songs):
if isinstance(item, Song.SongInfo):
lastObjectWasASong = True
elif isinstance(item, Song.TitleInfo):
if lastObjectWasASong:
self.songs.insert(i, Song.BlankSpaceInfo())
Log.debug("Dialogs.py: Inserted blank space in self.songs list before " + item.getName())
break #now that the self.songs list has changed, we must re-enumerate and look for the next place to insert a space
lastObjectWasASong = False
elif isinstance(item, Song.BlankSpaceInfo):
if item.name == _("End of Career") and not foundEndOfCareerYet: #also want to insert a blank space after the end of career marker
self.songs.insert(i, Song.BlankSpaceInfo()) #insert a blank space before End of Career
self.songs.insert(i+2, Song.BlankSpaceInfo()) #...and after End of Career (which is now shifted up one index)
foundEndOfCareerYet = True
Log.debug("Dialogs.py: Inserted blank space in self.songs list after " + item.getName())
break #now that the self.songs list has changed, we must re-enumerate and look for the next place to insert a space
lastObjectWasASong = False
else:
lastObjectWasASong = False
else: #executed after the for loop finishes
addingBlankSpaces = False #finished adding blank spaces, exit while loop