Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _G.
- {
- tex_background = TEXTURE("ui/bg1.png"),
- tex_button_core_n = TEXTURE("ui/button_core.png"),
- tex_button_core_h = TEXTURE("ui/button_core_h.png"),
- tex_button_core_c = TEXTURE("ui/button_core_c.png"),
- tex_button_core_f = TEXTURE("ui/button_core_f.png"),
- };
- function ButtonShader( ctrl )
- {
- tex = if( ctrl.clickedL, tex_button_core_c,
- if( ctrl.hover, tex_button_core_h, tex_button_core_n ) );
- ctrl.DTex( tex );
- ctrl.DButton( 0, 0, ctrl.width, ctrl.height, 4, 4/128 );
- ctrl.DFont( "core", ctrl.height / 2 );
- ctrl.DText( ctrl.text, ctrl.width / 2,
- ctrl.height / 2 + ctrl.InvIS( ctrl.clickedL ),
- HALIGN_CENTER, VALIGN_CENTER );
- if( ctrl.focused )
- {
- ctrl.DTex( tex_button_core_f );
- ctrl.DButton( 0, 0, ctrl.width, ctrl.height, 4, 4/128 );
- }
- }
- function CreateButton( x, y, w, h, text )
- {
- ctrl = this.CreateControl( x, y, w, h );
- ocb = ctrl.eventCallback;
- function button_callback( ev ) use( ocb )
- {
- if( ev.type == GUI_Event_BtnUp )
- {
- if( this.Hit( ev.x, ev.y ) && ev.button == GUI_MB_Left )
- this.InvokeCallbacks( "onclick" );
- return 1;
- }
- return this!ocb( ev );
- }
- ctrl.eventCallback = button_callback;
- ctrl.shaders.push( ButtonShader );
- ctrl.text = text;
- ctrl.focusable = true;
- return ctrl;
- }
- function YesNoQuestion( text )
- {
- answer = null;
- factor = 0.0;
- scr_overlay = ROOT.CreateScreen( GUI_ScrMode_Crop, 100, 100 ).{ z = 1000 };
- scr_overlay.shaders.push(function( ctrl )
- {
- ctrl.DCol( 0, 0.5 );
- ctrl.DQuad( 0, 0, ctrl.width, ctrl.height );
- });
- scr_bgr = ROOT.CreateScreen( GUI_ScrMode_Fit, 200, 100 ).{
- z = 1001, xscale = 0.4, yscale = 0.4, text = text };
- scr_bgr.shaders.push(function( ctrl ) use( factor )
- {
- // background
- ctrl.DCol( 0.1, 0.3, 0.7, 0.5 );
- ctrl.DQuad( 0, 0, 200, 100 );
- // top border
- ctrl.DCol( 0.7, 1 );
- ctrl.DQuad( 0, 0, 200 * factor, 20 );
- ctrl.DCol( 0.8, 1 );
- ctrl.DQuad( 0, 20, 200 * factor, 21 );
- ctrl.DCol( 0.0, 0.2 );
- ctrl.DQuad( 0, 21, 200 * factor, 24 );
- // question text
- ctrl.DCol( 0.02, 1 * factor );
- ctrl.DFont( "core", 10 );
- ctrl.DText( ctrl.text, 5, 10, HALIGN_LEFT, VALIGN_CENTER );
- });
- btn_yes = scr_bgr!CreateButton( 10, 70, 60, 20, "Yes" );
- btn_yes.AddCallback( "onclick", function() use(answer){ answer = true; } );
- btn_no = scr_bgr!CreateButton( 200-70, 70, 60, 20, "No" );
- btn_no.AddCallback( "onclick", function() use(answer){ answer = false; } );
- SetFocusRoot( scr_bgr );
- function min(a,b){ return if(a<b,a,b); }
- while( factor < 1 )
- {
- factor = min( factor + 0.05, 1 );
- yield 0.01;
- }
- while( answer === null )
- {
- yield;
- }
- return answer;
- }
- global scr_background = ROOT.CreateScreen( GUI_ScrMode_Crop, 512, 512 ).{ z = -1 };
- t = 0;
- scr_background.shaders.push(function( ctrl, dt ) use( t )
- {
- t += dt;
- ctrl.DTex( tex_background );
- ctrl.DQuadExt( 0, 0, 512, 512, t * -0.02 );
- process_threads();
- });
- global scr_mainmenu = ROOT.CreateScreen( GUI_ScrMode_Fit, 100, 100 );
- scr_mainmenu.shaders.push(function( ctrl )
- {
- ctrl.DCol( 0, 0.5 );
- ctrl.DQuad( 5, 5, ctrl.width - 5, ctrl.height - 5 );
- });
- global scr_button1 = scr_mainmenu!CreateButton( 10, 10, 40, 5, "Click me" );
- scr_button1.AddCallback( "onclick", function()
- {
- println( "clicked!" );
- thread YesNoQuestion( "Do you want to do something?" );
- });
- global scr_button2 = scr_mainmenu!CreateButton( 10, 20, 40, 5, "Click me 2" );
- scr_button2.AddCallback( "onclick", function()
- {
- println( "clicked 2!" );
- thread YesNoQuestion( "Do you want to do something?" );
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement