Just thought that I would share a little... I implemented this in my game and found that I was lacking some audio for the sliders and checkboxes that I was using... So I whacked in some quick code that lets you store two audio pieces in the settings for each slider and checkbox and play one when you hover and the other when you click. Thought that it would be a nice addition and needed it anyway for my project anyhow, here are the changes:
In the "MarbleX GUI.agc" file:
type MX_CheckboxInfo
exist as integer
visible as integer
spr_checkbox as integer
spr_checkboxhover as integer
spr_checkboxchecked as integer
text as integer //text object
hovered as integer //not _necessary_ for gui to work, but allows users to check if mouse is hovered
checked as integer
hoversound //** Added by Paronamixxe **
hoversound_flag as integer //** Added by Paronamixxe **
pressedsound //** Added by Paronamixxe **
endtype
...
type MX_SliderInfo
exist as integer
visible as integer
spr_slider as integer
spr_sliderhover as integer
spr_sliderpressed as integer
spr_sliderbar as integer
text as integer //text object - goes MX_FontGap above sliderbar (although height is taken from slider)
originaltext$ as string //for when printvalue=1, so can always add text to original
hovered as integer //not _necessary_ for gui to work, but allows users to check if mouse is hovered
pressed as integer
valuemin# as float //the smallest value of the slider
valuemax# as float //the largest value of the slider
value# as float //...duh
printvalue as integer //whether or not the current value of the slider is added to the end of its text
hoversound //** Added by Paronamixxe **
hoversound_flag as integer //** Added by Paronamixxe **
pressedsound //** Added by Paronamixxe **
endtype
In the "MarbleX GUI Slider.agc" file:
function MX_UpdateSliders()
for i=0 to MX_SliderCount-1
if MX_Slider[i].exist=1 and MX_Slider[i].visible=1
setspritevisible(MX_Slider[i].spr_slider,1)
if MX_Slider[i].spr_sliderhover<>-1 then setspritevisible(MX_Slider[i].spr_sliderhover,0)
setspritevisible(MX_Slider[i].spr_sliderpressed,0)
if MX_GotMouse=1
if getspritehittest(MX_Slider[i].spr_slider,getrawmousex(),getrawmousey())=1
if MX_Slider[i].hoversound_flag = 0 //** Added by Paronamixxe **
PlaySound ( MX_Slider[i].hoversound )
MX_Slider[i].hoversound_flag = 1
Endif
if MX_Slider[i].spr_sliderhover<>-1
setspritevisible(MX_Slider[i].spr_slider,0)
setspritevisible(MX_Slider[i].spr_sliderhover,1)
setspritevisible(MX_Slider[i].spr_sliderpressed,0)
endif
MX_Slider[i].hovered=1
else
if MX_Slider[i].spr_sliderhover<>-1
setspritevisible(MX_Slider[i].spr_slider,1)
setspritevisible(MX_Slider[i].spr_sliderhover,0)
setspritevisible(MX_Slider[i].spr_sliderpressed,0)
endif
MX_Slider[i].hovered=0
MX_Slider[i].hoversound_flag = 0 //**Added by Paronamixxe**
endif
endif
if MX_TouchCount>0
if MX_ClickedOn$=""
if getspritehittest(MX_Slider[i].spr_slider,MX_Touch[0].posx#,MX_Touch[0].posy#)=1 or getspritehittest(MX_Slider[i].spr_sliderbar,MX_Touch[0].posx#,MX_Touch[0].posy#)=1
MX_ClickedOn$="slider_"+str(i,0)
PlaySound ( MX_Slider[i].pressedsound ) //**Added by Paronamixxe**
endif
endif
endif
if left(MX_ClickedOn$,7)="slider_"
sldr=val(mid(MX_ClickedOn$,8,-1))
setspritevisible(MX_Slider[sldr].spr_slider,0)
if MX_Slider[sldr].spr_sliderhover<>-1 then setspritevisible(MX_Slider[sldr].spr_sliderhover,0)
setspritevisible(MX_Slider[sldr].spr_sliderpressed,1)
posx#=MX_Clamp(getspritex(MX_Slider[sldr].spr_sliderbar)+MX_SliderBorder,getspritex(MX_Slider[sldr].spr_sliderbar)+getspritewidth(MX_Slider[sldr].spr_sliderbar)-getspritewidth(MX_Slider[sldr].spr_slider)-MX_SliderBorder,MX_Touch[0].posx#-(getspritewidth(MX_Slider[sldr].spr_slider)/2))
setspriteposition(MX_Slider[sldr].spr_slider,posx#,getspritey(MX_Slider[sldr].spr_slider))
setspriteposition(MX_Slider[sldr].spr_sliderhover,posx#,getspritey(MX_Slider[sldr].spr_sliderhover))
setspriteposition(MX_Slider[sldr].spr_sliderpressed,posx#,getspritey(MX_Slider[sldr].spr_sliderpressed))
MX_Slider[sldr].value#=MX_ResizeValue(getspritex(MX_Slider[sldr].spr_sliderbar)+MX_SliderBorder,getspritex(MX_Slider[sldr].spr_sliderbar)+getspritewidth(MX_Slider[sldr].spr_sliderbar)-getspritewidth(MX_Slider[sldr].spr_slider)-MX_SliderBorder,posx#,MX_Slider[sldr].valuemin#,MX_Slider[sldr].valuemax#)
if MX_Slider[sldr].printvalue=2
settextstring(MX_Slider[sldr].text,MX_Slider[sldr].originaltext$+str(MX_Slider[sldr].value#,0))
else
if MX_Slider[sldr].printvalue=1
settextstring(MX_Slider[sldr].text,MX_Slider[sldr].originaltext$+str(MX_Slider[sldr].value#,3))
else
settextstring(MX_Slider[sldr].text,MX_Slider[sldr].originaltext$)
endif
endif
endif
endif
next i
endfunction
...
function MX_SetSliderSounds ( index , hoversound_temp , pressedsound_temp ) //** Added by Paronamixxe **
MX_Slider[index].hoversound = hoversound_temp
MX_Slider[index].pressedsound = pressedsound_temp
endfunction
And finally, in the "MarbleX GUI Checkbox.agc" file:
function MX_UpdateCheckboxes()
for i=0 to MX_CheckboxCount-1
if MX_Checkbox[i].exist=1 and MX_Checkbox[i].visible=1
setspritevisible(MX_Checkbox[i].spr_checkbox,1-MX_Checkbox[i].checked)
if MX_Checkbox[i].spr_checkboxhover<>-1 then setspritevisible(MX_Checkbox[i].spr_checkboxhover,0)
setspritevisible(MX_Checkbox[i].spr_checkboxchecked,MX_Checkbox[i].checked)
if MX_GotMouse=1
if getspritehittest(MX_Checkbox[i].spr_checkbox,getrawmousex(),getrawmousey())=1
if MX_Checkbox[i].hoversound_flag = 0 //** Added by Paronamixxe **
PlaySound ( MX_Slider[i].hoversound )
MX_Checkbox[i].hoversound_flag = 1
Endif
if MX_Checkbox[i].spr_checkboxhover<>-1
setspritevisible(MX_Checkbox[i].spr_checkbox,0)
setspritevisible(MX_Checkbox[i].spr_checkboxhover,1-MX_Checkbox[i].checked)
setspritevisible(MX_Checkbox[i].spr_checkboxchecked,MX_Checkbox[i].checked)
endif
MX_Checkbox[i].hovered=1
else
if MX_Checkbox[i].spr_checkboxhover<>-1
setspritevisible(MX_Checkbox[i].spr_checkbox,1-MX_Checkbox[i].checked)
setspritevisible(MX_Checkbox[i].spr_checkboxhover,0)
setspritevisible(MX_Checkbox[i].spr_checkboxchecked,MX_Checkbox[i].checked)
endif
MX_Checkbox[i].hovered=0
MX_Checkbox[i].hoversound_flag = 0 //** Added by Paronamixxe **
endif
endif
if MX_TouchCount>0
if MX_ClickedOn$=""
if getspritehittest(MX_Checkbox[i].spr_checkbox,MX_Touch[0].posx#,MX_Touch[0].posy#)=1
PlaySound ( MX_Checkbox[i].pressedsound ) //** Added by Paronamixxe **
setspritevisible(MX_Checkbox[i].spr_checkbox,MX_Checkbox[i].checked)
if MX_Checkbox[i].spr_checkboxhover<>-1 then setspritevisible(MX_Checkbox[i].spr_checkboxhover,0)
setspritevisible(MX_Checkbox[i].spr_checkboxchecked,1-MX_Checkbox[i].checked)
MX_Checkbox[i].checked=1-MX_Checkbox[i].checked //simple auto-toggle
MX_ClickedOn$="checkbox" //doesn't have to be anything in particular, just not blank
endif
endif
endif
endif
next i
endfunction
...
function MX_SetCheckboxSounds ( index , hoversound_temp , pressedsound_temp ) //** Added by Paronamixxe **
MX_Checkbox[index].hoversound = hoversound_temp
MX_Checkbox[index].pressedsound = pressedsound_temp
endfunction
Nothing major, nothing advanced, yet adds some depth to the controls
Cheers
nope.