#ifdef INTERFACE
-CLASS(Button) EXTENDS(Label)
+CLASS(Button, Label)
METHOD(Button, configureButton, void(entity, string, float, string))
METHOD(Button, draw, void(entity))
METHOD(Button, showNotify, void(entity))
METHOD(Button, mousePress, float(entity, vector))
METHOD(Button, mouseDrag, float(entity, vector))
METHOD(Button, mouseRelease, float(entity, vector))
- METHOD(Button, focusEnter, void(entity))
+ METHOD(Button, playClickSound, void(entity))
ATTRIB(Button, onClick, void(entity, entity), func_null)
ATTRIB(Button, onClickEntity, entity, NULL)
ATTRIB(Button, src, string, string_null)
ATTRIB(Button, srcMulti, float, 1) // 0: button square left, text right; 1: button stretched, text over it
ATTRIB(Button, buttonLeftOfText, float, 0)
ATTRIB(Button, focusable, float, 1)
+ ATTRIB(Button, allowFocusSound, float, 1)
ATTRIB(Button, pressed, float, 0)
ATTRIB(Button, clickTime, float, 0)
ATTRIB(Button, disabled, float, 0)
if(me.srcMulti)
me.keepspaceLeft = 0;
else
- me.keepspaceLeft = min(0.8, absSize_y / absSize_x);
+ me.keepspaceLeft = min(0.8, absSize.y / absSize.x);
SUPER(Button).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
}
void Button_configureButton(entity me, string txt, float sz, string gfx)
{
if(key == K_ENTER || key == K_SPACE || key == K_KP_ENTER)
{
+ me.playClickSound(me);
me.clickTime = 0.1; // delayed for effect
return 1;
}
float Button_mouseDrag(entity me, vector pos)
{
me.pressed = 1;
- if(pos_x < 0) me.pressed = 0;
- if(pos_y < 0) me.pressed = 0;
- if(pos_x >= 1) me.pressed = 0;
- if(pos_y >= 1) me.pressed = 0;
+ if(pos.x < 0) me.pressed = 0;
+ if(pos.y < 0) me.pressed = 0;
+ if(pos.x >= 1) me.pressed = 0;
+ if(pos.y >= 1) me.pressed = 0;
return 1;
}
float Button_mousePress(entity me, vector pos)
{
if (!me.disabled)
{
- if(cvar("menu_sounds"))
- localsound("sound/misc/menu2.wav");
+ me.playClickSound(me);
if(me.onClick)
me.onClick(me, me.onClickEntity);
}
{
me.focusable = !me.disabled;
}
-void Button_focusEnter(entity me)
-{
- if(cvar("menu_sounds") > 1)
- localsound("sound/misc/menu1.wav");
- SUPER(Button).focusEnter(me);
-}
void Button_draw(entity me)
{
vector bOrigin, bSize;
}
else
{
- bOrigin = eY * (0.5 * (1 - me.realFontSize_y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize_x));
+ bOrigin = eY * (0.5 * (1 - me.realFontSize.y)) + eX * (0.5 * (me.keepspaceLeft - me.realFontSize.x));
bSize = me.realFontSize;
}
if(me.disabled)
SUPER(Button).draw(me);
}
+void Dialog_Close(entity button, entity me);
+void Button_playClickSound(entity me)
+{
+ if(me.onClick == DialogOpenButton_Click)
+ m_play_click_sound(MENU_SOUND_OPEN);
+ else if(me.onClick == Dialog_Close)
+ m_play_click_sound(MENU_SOUND_CLOSE);
+ else
+ m_play_click_sound(MENU_SOUND_EXECUTE);
+}
#endif