1# GemRB - Infinity Engine Emulator
2# Copyright (C) 2003 The GemRB Project
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License
6# as published by the Free Software Foundation; either version 2
7# of the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17#
18#
19#character generation, sounds (GUICG19)
20import GemRB
21
22import CharGenCommon
23import GUICommon
24from GUIDefines import *
25from ie_restype import RES_WAV
26from ie_sounds import CHAN_CHAR1
27from ie_stats import IE_SEX
28
29SoundSequence = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m" ]
30# bg1 default soundset is whack, but at least provides the same amount of sounds
31SoundSequence2 = [ "03", "08", "09", "10", "11", "17", "18", "19", "20", "21", "22", "38", "39" ]
32VoiceList = 0
33CharSoundWindow = 0
34SoundIndex = 0
35
36def OnLoad():
37	global CharSoundWindow, VoiceList
38
39	CharSoundWindow=GemRB.LoadWindow(19, "GUICG")
40
41	VoiceList = CharSoundWindow.GetControl (45)
42	Voices = VoiceList.ListResources (CHR_SOUNDS)
43	GUICommon.AddDefaultVoiceSet (VoiceList, Voices)
44	# preselect the default entry to avoid an infinite loop if Play is pressed immediately
45	VoiceList.SetVarAssoc ("Selected", 0)
46
47	PlayButton = CharSoundWindow.GetControl (47)
48	PlayButton.SetState (IE_GUI_BUTTON_ENABLED)
49	PlayButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PlayPress)
50	PlayButton.SetText (17318)
51
52	TextArea = CharSoundWindow.GetControl (50)
53	TextArea.SetText (11315)
54
55	BackButton = CharSoundWindow.GetControl(10)
56	BackButton.SetText(15416)
57	DoneButton = CharSoundWindow.GetControl(0)
58	DoneButton.SetText(11973)
59	DoneButton.MakeDefault()
60
61	VoiceList.SetEvent(IE_GUI_TEXTAREA_ON_SELECT, ChangeVoice)
62	DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
63	BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, lambda: CharGenCommon.back(CharSoundWindow))
64	CharSoundWindow.ShowModal(MODAL_SHADOW_NONE)
65	return
66
67def PlayPress():
68	global CharSoundWindow, SoundIndex, SoundSequence
69
70	CharSound = VoiceList.QueryText()
71	SoundSeq = SoundSequence
72	if CharSound == "default":
73		SoundSeq = SoundSequence2
74	MyChar = GemRB.GetVar ("Slot")
75	Gender = GemRB.GetPlayerStat (MyChar, IE_SEX)
76	CharSound = GUICommon.OverrideDefaultVoiceSet (Gender, CharSound)
77
78	while (not GemRB.HasResource (CharSound + SoundSeq[SoundIndex], RES_WAV)):
79		NextSound()
80	# play the sound like it was a speech, so any previous yells are quieted
81	GemRB.PlaySound (CharSound + SoundSeq[SoundIndex], CHAN_CHAR1, 0, 0, 4)
82	NextSound()
83	return
84
85def NextSound():
86	global SoundIndex, SoundSequence
87	SoundIndex += 1
88	if SoundIndex >= len(SoundSequence):
89		SoundIndex = 0
90	return
91
92def ChangeVoice():
93	global SoundIndex
94	SoundIndex = 0
95	return
96
97def NextPress():
98	CharSoundWindow.Close()
99	CharSound = VoiceList.QueryText ()
100	MyChar = GemRB.GetVar ("Slot")
101	Gender = GemRB.GetPlayerStat (MyChar, IE_SEX)
102	CharSound = GUICommon.OverrideDefaultVoiceSet (Gender, CharSound)
103	GemRB.SetPlayerSound(MyChar,CharSound)
104	CharGenCommon.next()
105	return
106