- Joined
- Mar 18, 2012
- Messages
- 1,716
UISound
Plays sound files in UIs.
JASS:
library UISound /*v1.1
*************************************************************************************
*
* For your sound needs in custom UIs.
* UISound instances are player id based.
*
* Access the proper instance from UIWindow and UIScreen with the following operator:
*
* method operator audio takes nothing returns UISound
*
* Example: call this.audio.play(file, 1, 0.2)
*
* UISound must use the "Sound" type created by library SoundTools.
*
*************************************************************************************
*
* */ uses /*
*
* */ UIBasic /*
* */ SoundTools /* http://www.hiveworkshop.com/forums/jass-resources-412/system-soundtools-207308/
*
************************************************************************************
*
* 1. Import instruction
* ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* Copy the UISound script into you map.
* You'll also need SoundTools in your map
*
*/
globals
private Table table = 0
private Table save = 0
private Sound mouseClickS = 0
private Sound errorS = 0
private Sound bigButtonClickS = 0
private Sound wayPointBlingS = 0
private integer index = 0
endglobals
struct UISound extends array
private real last
private integer prior
private method condition takes integer priority, real pause returns boolean
local real elapsed = TimerGetElapsed(UI_STAMP)
if (priority > prior) or (last <= elapsed) then
set prior = priority
set last = elapsed + pause
return true
endif
return false
endmethod
method play takes Sound snd, integer priority, real pause returns boolean
local sound s
if (snd != 0) and condition(priority, pause) then
set s = snd.run()
if GetLocalClient() != Player(this) then
call SetSoundVolume(s, 0)
else
call SetSoundVolume(s, 127)
endif
set s = null
endif
return false
endmethod
method searchSoundFile takes string file returns boolean
local integer index = StringHash(file)
if table.has(index) then
return play(table[index], table[-index], table.real[index])
endif
return false
endmethod
method search takes integer index returns boolean
if table.has(index) then
return play(table[index], table[-index], table.real[index])
endif
return false
endmethod
method error takes nothing returns boolean
return play(errorS, 100, .1)
endmethod
method bigButtonClick takes nothing returns boolean
return play(bigButtonClickS, 1, .1)
endmethod
method wayPointBling takes nothing returns boolean
return play(wayPointBlingS, 1, .1)
endmethod
method mouseClick takes nothing returns boolean
return play(mouseClickS, 1, .2)
endmethod
private static method init takes nothing returns nothing
set table = Table.create()
set save = Table.create()
set mouseClickS = Sound.create("Sound\\Interface\\MouseClick1.wav", 239, false, false)
set errorS = Sound.create("Sound\\Interface\\Error.wav", 641, false, false)
set bigButtonClickS = Sound.create("Sound\\Interface\\BigButtonClick.wav", 390, false, false)
set wayPointBlingS = Sound.create("Sound\\Interface\\WayPointBling.wav", 361, false, false)
set save[StringHash("Sound\\Interface\\MouseClick1.wav")] = mouseClick
set save[StringHash("Sound\\Interface\\Error.wav")] = mouseClick
set save[StringHash("Sound\\Interface\\BigButtonClick.wav")] = mouseClick
set save[StringHash("Sound\\Interface\\WayPointBling.wav")] = mouseClick
endmethod
implement UIInit
static method register takes integer index, string file, integer duration, integer priority, real timeout returns nothing
local integer hashed = StringHash(file)
debug local string text = "This index is already taken, index name [ - " + GetObjectName(index) + " - ]!"
debug call ThrowWarning(table.has(index), "UISound", "register", "index", index, text)
if save.has(hashed) then
set table[index] = save[hashed]
else
set table[index] = Sound.createEx(file, duration, false, false, false, 10, 10, "CombatSoundsEAX")
set save[hashed] = table[index]
endif
set table.real[index] = RMinBJ(timeout, duration/1000.)
set table[-index] = priority
endmethod
static method allocateIndex takes string file, integer duration, integer priority, real timeout returns integer
set index = index -1
call register(index, file, duration, priority, timeout)
return index
endmethod
endstruct
endlibrary
Changelog:
- Improved the debug message in register, so doubly registered indexes can be identified faster.
- Mouse click, error, ... can now also accessed via method searchSoundFile().
Last edited: