My idea for use of slider is following: use slider to set a value and pass this value to a button, which sends command to eventhandler. But I really dont know how to correctly write that. Would anyone help me? But I need this to work in zforms...
Here is whole menu code:
Code: Select all
class tentMenuHandler : soa_ZF_Handler {
tentMenu link;
override void buttonClickCommand(soa_ZF_Button caller, string command) {
if ( command == "tentButton01" ) {
soaEventHandler.SendNetworkEvent("sleepInTent");
let thisMenu = Menu.GetCurrentMenu();
if( thisMenu !=null ) thisMenu.Close();
} else if ( command == "tentButton02" ) {
soaEventHandler.SendNetworkEvent("packTent");
Menu.MenuSound("sounds/itemPickup");
let thisMenu = Menu.GetCurrentMenu();
if( thisMenu !=null ) thisMenu.Close();
}
}
}
class tentMenu : soa_ZF_GenericMenu {
tentMenuHandler handler;
font smallfont;
soa_ZF_Image tent_background;
soa_ZF_Button tentButton01;
soa_ZF_Button tentButton02;
soa_ZF_Label tentMenu_nadpis;
soa_ZF_Label tentMenu_podnadpis;
soa_ZF_Label tentMenu_btn01_lbl;
soa_ZF_Label tentMenu_btn02_lbl;
soa_ZF_Slider tentMenu_slider;
double sliderValue;
override void Init( Menu parent ) {
// overall init ////////////////////////////////////////////////////////
vector2 baseRes = (320, 200); //set base resolution
super.init(parent); //call parent menu function to init
SetBaseResolution(baseRes);
smallfont = "smallfont";
handler = new("tentMenuHandler"); //call the handler instance
handler.link = self; //set handler pointer to menu
// menu background /////////////////////////////////////////////////////
tent_background = soa_ZF_Image.Create(
(0, 0), //position
(320, 200), //size
"graphics/soaMenu/menuBack2.png",
soa_ZF_Image.AlignType_TopLeft
);
tent_background.pack(mainframe);
// add buttons /////////////////////////////////////////////////////////
// create the button's textures ////////////////////////////////////////
let buttonIdle = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuButtonIdle.png", true);
let buttonHover = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuButtonHover.png", false);
let buttonClick = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuButtonClick.png", false);
let handlIdle = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuSliderHndIdle.png", true);
let handlHover = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuSliderHndHover.png", false);
let handlClick = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuSliderHndClick.png", true);
let sliderBackground = soa_ZF_BoxTextures.CreateSingleTexture("graphics/soaMenu/menuSliderSteps.png", true);
// slider //
tentMenu_slider = soa_ZF_Slider.Create (
( ((baseRes.X - 32.0) / 2.0) - 67, ((baseRes.Y - 16.0) / 2.0) + 20 ),//Vector2 pos,
( 166, 8 ),//Vector2 size,
1.0, //double low,
23.0, //double high,
sliderValue, //double value,
1.0, //double step,
3.0, //double handleWidth,
handlIdle,//BoxTextures handle,
handlHover, //BoxTextures handleHover,
handlClick, //handleClick : handlClick, //BoxTextures handleClick = NULL,
sliderBackground, //background : sliderBackground, //BoxTextures background = NULL,
handler, //cmdHandler : handler,//Handler cmdHandler = NULL,
"tentButton01"//string command = ""
);
tentMenu_slider.pack(mainframe);
// button01
tentButton01 = soa_ZF_Button.Create(
(((baseRes.X - 32.0) / 2.0) - 50, ((baseRes.Y - 16.0) / 2.0) + 40),//position
(32, 16), //size
cmdHandler : handler, //command handler
command : "tentButton01", //command string for button
inactive: buttonIdle,
hover: buttonHover,
click: buttonClick
);
tentButton01.pack(mainframe);
// button02
tentButton02 = soa_ZF_Button.Create(
(((baseRes.X - 32.0) / 2.0) + 50, ((baseRes.Y - 16.0) / 2.0) + 40),//position
(32, 16), //size
cmdHandler : handler, //command handler
command : "tentButton02", //command string for button
inactive: buttonIdle,
hover: buttonHover,
click: buttonClick
);
tentButton02.pack(mainframe);
// add labels //////////////////////////////////////////////////////////
// nadpis
tentMenu_nadpis = soa_ZF_Label.Create(
(0, tentButton01.GetPosY() + tentButton02.GetHeight() - 90),
(0, smallFont.GetHeight()),
text: "$M_tentMenuNadpis", //label's text: [ Bedroll Menu ]
fnt: smallfont, //font !string! to use > if 'null', uses default smallfont
wrap: false, //auto text wrap
autoSize: true, //auto resize elements
textColor: Font.CR_GREEN //text color
);
tentMenu_nadpis.SetPosX((baseRes.X / 2.0) - (smallFont.stringWidth(tentMenu_nadpis.GetText ()) / 2.0));
tentMenu_nadpis.pack(mainframe);
// podnadpis
tentMenu_podnadpis = soa_ZF_Label.Create(
(0, tentButton01.GetPosY() + tentButton02.GetHeight() - 70),
(0, smallFont.GetHeight()),
text: "$M_tentMenuPodnadpis", //label's text: [ Bedroll Menu ]
fnt: smallfont, //font !string! to use > if 'null', uses default smallfont
wrap: false, //auto text wrap
autoSize: true, //auto resize elements
textColor: Font.CR_WHITE //text color
);
tentMenu_podnadpis.SetPosX((baseRes.X / 2.0) - (smallFont.stringWidth(tentMenu_podnadpis.GetText ()) / 2.0));
tentMenu_podnadpis.pack(mainframe);
// button 1 label
tentMenu_btn01_lbl = soa_ZF_Label.Create (
(0, tentButton01.GetPosY() + tentButton01.GetHeight() - 25), //tentButton01.GetPosX() - 5
(0, 8), //size
text: "$M_tentMenu_btn1", //label's text: Sleep in\nbedroll
fnt: smallfont, //font to use
wrap: false, //auto text wrap
autoSize: true, //auto resize elements
textColor: Font.CR_WHITE //text color
);
tentMenu_btn01_lbl.SetPosX( ( tentButton01.GetPosX() + 16 ) - (smallfont.stringWidth(tentMenu_btn01_lbl.GetText()) / 2.0) );
tentMenu_btn01_lbl.pack(mainframe);
// button 2 label
tentMenu_btn02_lbl = soa_ZF_Label.Create (
(0, tentButton02.GetPosY() + tentButton02.GetHeight() - 25),
(0, 16),
text: "$M_tentMenu_btn2", //label's text: Pack the\nbedroll
fnt: smallfont, //font to use
wrap: false, //auto text wrap
autoSize: true, //auto resize elements
textColor: Font.CR_WHITE //text color
);
tentMenu_btn02_lbl.SetPosX( ( tentButton02.GetPosX() + 16 ) - (smallfont.stringWidth(tentMenu_btn02_lbl.GetText()) / 2.0) );
tentMenu_btn02_lbl.pack(mainframe);
Menu.MenuSound("sounds/journalUse");
}
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////