Script v1_7_1_0
- AI
- Animals
- Collections
- Contracts
- Debug
- Economy
- Elements
- EnvironmentalScore
- Errors
- Events
- GUI
- AnimalScreen
- AnimationElement
- BitmapElement
- BoxLayoutElement
- BreadcrumbsElement
- ButtonElement
- ButtonOverlay
- ChatWindow
- CheckedOptionElement
- ClearElement
- ColorPickButtonElement
- ConstructionScreen
- ContextActionDisplay
- ControlBarDisplay
- DialogElement
- DynamicFadedBitmapElement
- FillLevelsDisplay
- FlowLayoutElement
- FocusManager
- FrameElement
- FrameReferenceElement
- GameInfoDisplay
- GameInfoDisplayMobile
- GamePausedDisplay
- Gui
- GuiDataSource
- GuiElement
- GuiMixin
- GuiOverlay
- GuiProfile
- GuiSoundPlayer
- GuiTopDownCamera
- GuiTopDownCursor
- GuiUtils
- HUDDisplayElement
- HUDElement
- HUDFrameElement
- HUDPopupMessage
- HUDSliderElement
- HUDTextDisplay
- IndexChangeSubjectMixin
- IndexStateElement
- InfoDisplay
- InfoHUDBox
- InGameIcon
- IngameMap
- IngameMapElement
- InputGlyphElement
- InputGlyphElementUI
- InputHelpDisplay
- KeyValueInfoHUDBox
- ListElement
- ListItemElement
- MapOverlayGenerator
- MixerWagonHUDExtension
- MultiTextOptionElement
- MultiValueTween
- Overlay
- PagingElement
- PictureElement
- PlatformIconElement
- PlayerControlPadDisplay
- PlaySampleMixin
- RenderElement
- RoundStatusBar
- ScreenElement
- ScrollingLayoutElement
- SettingsModel
- SideNotification
- SideNotificationMobile
- SliderElement
- SpeakerDisplay
- SpeedMeterDisplay
- SpeedSliderDisplay
- StatusBar
- SteeringSliderDisplay
- TabbedMenu
- TabbedMenuFrameElement
- TabbedMenuWithDetails
- TableElement
- TableHeaderElement
- TerrainLayerElement
- TextBackdropElement
- TextElement
- TextInputElement
- ThreePartBitmapElement
- TimerElement
- ToggleButtonElement
- TopNotification
- Tween
- TweenSequence
- VariableWorkWidthHUDExten...
- VehicleHUDExtension
- VehicleSchemaDisplay
- VideoElement
- WardrobeScreen
- Handtools
- Hud
- I3d
- Input
- Jobs
- Maps
- Materials
- Misc
- Objects
- Parameters
- Placeables
- Placement
- Player
- Shop
- Sounds
- Specialization
- Specializations
- StateMachine
- Statistics
- Tasks
- Triggers
- Utils
- Vehicles
Engine v1_7_1_0
- AI
- Animation
- Camera
- Entity
- Fillplanes
- general
- General
- I3D
- Input
- Lighting
- Math
- Network
- Node
- NoteNode
- Overlays
- Particle System
- Physics
- Rendering
- Scenegraph
- Shape
- Sound
- Spline
- String
- Terrain Detail
- Text Rendering
- Tire Track
- VoiceChat
- XML
Foundation Reference
GuiSoundPlayer
DescriptionThis class loads known GUI sound samples as non-spatial samples to be played in the GUI (menu and HUD).Functions
loadSounds
DescriptionLoad GUI sound samples from definitions.Definition
loadSounds()Code
100 | function GuiSoundPlayer:loadSounds(sampleDefinitionXmlPath) |
101 | local samples = {} |
102 | |
103 | local xmlFile = loadXMLFile("GuiSampleDefinitions", sampleDefinitionXmlPath) |
104 | if xmlFile ~= nil and xmlFile ~= 0 then |
105 | |
106 | for _, key in pairs(GuiSoundPlayer.SOUND_SAMPLES) do |
107 | if key ~= GuiSoundPlayer.SOUND_SAMPLES.NONE then |
108 | local sample = self.soundManager:loadSample2DFromXML(xmlFile, GuiSoundPlayer.SOUND_SAMPLE_DEFINITIONS_XML_ROOT, key, "", 1, AudioGroup.GUI) |
109 | if sample ~= nil then |
110 | local sampleList = {} |
111 | samples[key] = sampleList |
112 | |
113 | -- Build a whole queue so we can play multiple sounds at once |
114 | table.insert(sampleList, sample) |
115 | for i = 2, GuiSoundPlayer.NUM_SAMPLES_PER_SOUND do |
116 | table.insert(sampleList, self.soundManager:cloneSample2D(sample)) |
117 | end |
118 | |
119 | else |
120 | print("Warning: Could not load GUI sound sample [" .. tostring(key) .. "]") |
121 | end |
122 | end |
123 | end |
124 | |
125 | delete(xmlFile) |
126 | end |
127 | |
128 | return samples |
129 | end |
new
DescriptionCreate a new GuiSoundPlayer instance.Definition
new(table soundManager)Arguments
table | soundManager | SoundManager reference |
80 | function GuiSoundPlayer.new(soundManager) |
81 | local self = setmetatable({}, GuiSoundPlayer_mt) |
82 | |
83 | self.soundManager = soundManager |
84 | self.soundSamples = self:loadSounds(GuiSoundPlayer.SOUND_SAMPLE_DEFINITIONS_PATH) -- name -> sample |
85 | |
86 | return self |
87 | end |
playSample
DescriptionPlay a GUI sound sample identified by name. The sample must have been loaded when the GUI was created.Definition
playSample(string sampleName)Arguments
string | sampleName | Name of the sample to play, use one of the identifiers in GuiSoundPlayer.SOUND_SAMPLES. |
135 | function GuiSoundPlayer:playSample(sampleName) |
136 | if sampleName == GuiSoundPlayer.SOUND_SAMPLES.NONE then |
137 | return |
138 | end |
139 | |
140 | local sampleList = self.soundSamples[sampleName] |
141 | |
142 | if sampleList ~= nil then |
143 | if sampleList.lastTime ~= nil and g_time - sampleList.lastTime < GuiSoundPlayer.SAMPLE_REPLAY_TIMEOUT then |
144 | return |
145 | end |
146 | |
147 | -- Get first free |
148 | local sample |
149 | for i = 1, #sampleList do |
150 | if not self.soundManager:getIsSamplePlaying(sampleList[i]) then |
151 | sample = sampleList[i] |
152 | break |
153 | end |
154 | end |
155 | |
156 | if sample ~= nil then |
157 | self.soundManager:playSample(sample) |
158 | sampleList.lastTime = g_time |
159 | end |
160 | else |
161 | print("Warning: Tried playing GUI sample [" .. tostring(sampleName) .. "] which has not been loaded.") |
162 | end |
163 | end |