Advertisement
snake5

sgs-ui: beta version menu building code

Jun 18th, 2014
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // STYLES
  3. //
  4. function MenuButton_Render()
  5. {
  6.     if( this.rx0 == this.rx1 || this.ry0 == this.ry1 )
  7.         return;
  8.    
  9.     theme = this.frame.theme;
  10.     button_render_contents = theme.button_render_contents;
  11.    
  12.     alpha = if( this.clicked, 0.4, if( this.mouseOn, 0.2, 0.1 ) );
  13.     SS_DrawColorRect( this.rx0, this.ry0, this.rx1, this.ry1-1, 0, 0, 0, alpha );
  14.     SS_DrawColorRect( this.rx0, this.ry1-1, this.rx1, this.ry1, 0, 0, 0, alpha+0.1 );
  15.    
  16.     this!button_render_contents();
  17. }
  18.  
  19. FRAME.addStyleSheet(UI_BuildStyleSheet({
  20.     "*button" = { renderfunc = MenuButton_Render },
  21.     "**" = { font = "fonts/armata-regular.ttf", fontSize = 16 },
  22.     "*scrollingautolayout button static" = { font = "fonts/lato-regular.ttf", fontSize = 12, paddingLeft = 72 },
  23.     // main menu
  24.     ".main-menu-frame" = { anchorMode = UI_Anchor_All, renderfunc = function MAIN_MENU_Renderfunc(){ SS_DrawColor2VRect( this.rx0, this.ry0, this.rx1, this.ry1, 0.5, 0.5, 0.5, 1, 0.2, 0.2, 0.2, 1 ); } },
  25.     ".main-menu-frame .title" = { backgroundColor = UIColor( 0 ), anchorMode = UI_Anchor_Hor, font = "fonts/gauge-oblique.ttf", fontSize = 48, textColor = UIColor(0.3,0.7,0.9,1), q0y = 0, q1y = 0.5 },
  26.     ".main-menu" = { q0x = 0.4, q0y = 0.5, q1x = 0.6, q1y = 1.0, overflow = true },
  27.     ".main-menu button" = { height = 36, anchorMode = UI_Anchor_Hor },
  28.     ".main-menu button image" = { width = 36, anchorMode = UI_Anchor_Vert },
  29.     // question window
  30.     ".qwindowbgr" = { backgroundColor = UIColor(0.5,0.5), anchorMode = UI_Anchor_All },
  31.     ".qwindow" = { backgroundColor = UIColor(0,0.5), q0x = 0.3, q0y = 0.3, q1x = 0.7, q1y = 0.7 },
  32.     ".qwindow .title" = { backgroundColor = UIColor(0.3,0.02,0.01,0.5), textColor = UIColor(0.9,1), q0x = 0, q0y = 0, q1x = 1, q1y = 0.3 },
  33.     ".qwindow .btn-yes" = { q0x = 0.1, q0y = 0.6, q1x = 0.4, q1y = 0.9 },
  34.     ".qwindow .btn-no" = { q0x = 0.6, q0y = 0.6, q1x = 0.9, q1y = 0.9 },
  35.     // screen
  36.     ".screen-panel" = { backgroundColor = UIColor( 0, 0.2 ), q0x = 1.22, q0y = 0.22, q1x = 1.98, q1y = 0.98 },
  37.     ".screen-panel .title" = { q0x = 0, q0y = 0, q1x = 1, q1y = 0.1, backgroundColor = UIColor( 0.3, 0.02, 0.01, 0.5 ), textColor = UIColor( 0.9, 1 ) },
  38.     ".screen-panel .btn-back" = { q0x = 0.05, q0y = 0.85, q1x = 0.2, q1y = 0.95 },
  39. }));
  40. UI_EasingFunctions.smooth_fast_start = function( a, b, t ){ return UI_EasingFunctions.smooth( a, b, sqrt( t ) ); };
  41.  
  42. //
  43. // COMMON CONTROLS
  44. //
  45. function CreateYesNoQuestionWindow( question, callback )
  46. {
  47.     bgr = UI_CreateStatic( FRAME.root, 0, 0, 0, 0, "" );
  48.     bgr.addClass( "qwindowbgr" );
  49.    
  50.     window = UI_CreateStatic( bgr, 0, 0, 0, 0, "" );
  51.     window.addClass( "qwindow" );
  52.    
  53.     title = UI_CreateStatic( window, 0, 0, 0, 0, question );
  54.     title.addClass( "title" );
  55.    
  56.     btn_yes = UI_CreateButton( window, 0, 0, 0, 0, "Yes" );
  57.     btn_yes.addClass( "btn-yes" );
  58.     btn_yes.bindEvent( "click", function() use( callback, bgr ){ callback( 1 ); bgr.parent.removeChild( bgr ); } );
  59.    
  60.     btn_no = UI_CreateButton( window, 0, 0, 0, 0, "No" );
  61.     btn_no.addClass( "btn-no" );
  62.     btn_no.bindEvent( "click", function() use( callback, bgr ){ callback( 0 ); bgr.parent.removeChild( bgr ); } );
  63.    
  64.     // background fade in
  65.     tgtbgcol = bgr.backgroundColor;
  66.     bgr.backgroundColor = UIColor(0);
  67.     bgr.animate( { backgroundColor = tgtbgcol }, 0.4 );
  68.     // window: zoom in --> title: slide in from top
  69.     tgtq0x = window.q0x; tgtq0y = window.q0y; tgtq1x = window.q1x; tgtq1y = window.q1y;
  70.     window[]{ q0x = 0.5, q1x = 0.5, q0y = 0.5, q1y = 0.5 };
  71.     titleq0y = title.q0y;
  72.     titleq1y = title.q1y;
  73.     diff = titleq1y - titleq0y;
  74.     title[]{ q0y = titleq0y - diff, q1y = titleq1y - diff };
  75.     window.animate( { q0x = tgtq0x, q0y = tgtq0y, q1x = tgtq1x, q1y = tgtq1y }, 0.2, null, function() use( title, titleq0y, titleq1y )
  76.     {
  77.         title.animate( { q0y = titleq0y, q1y = titleq1y }, 0.2 );
  78.     });
  79. }
  80.  
  81. //
  82. // MAIN MENU
  83. //
  84. UI_BuildControls
  85. ( FRAME.root,
  86. [
  87.     { type = "static", class = "main-menu-frame", children =
  88.     [
  89.         { type = "static", class = "title", caption = "Example Menu" },
  90.         { type = "autolayout", class = "main-menu", children =
  91.         [
  92.             { type = "imagebutton", name = "start", caption = "Start", image = "icons/control_play.png", class = "act-close-info act-close-options act-open-start act-menu-shrink" },
  93.             { type = "imagebutton", name = "info", caption = "Info", image = "icons/information.png", class = "act-close-start act-close-options act-open-info act-menu-shrink" },
  94.             { type = "imagebutton", name = "options", caption = "Options", image = "icons/cog.png", class = "act-close-start act-close-info act-open-options act-menu-shrink" },
  95.             { type = "imagebutton", name = "quit", caption = "Quit", image = "icons/stop.png", class = "act-ask-quit" },
  96.         ]},
  97.     ]},
  98. ]);
  99. function main_menu_shrink()
  100. {
  101.     FRAME.find(".main-menu-frame .title").animate({ q1y = 0.2, textColor = UIColor( 0.3, 0.7, 0.9, 0.5 ) }, 0.5 );
  102.     FRAME.find(".main-menu-frame .main-menu").animate({ q0x = 0.05, q1x = 0.2 }, 0.5 );
  103. }
  104. function main_menu_grow()
  105. {
  106.     FRAME.find(".main-menu-frame .title").animate({ q1y = 0.5, textColor = UIColor( 0.3, 0.7, 0.9, 1 ) }, 0.5 );
  107.     FRAME.find(".main-menu-frame .main-menu").animate({ q0x = 0.4, q1x = 0.6 }, 0.5 );
  108. }
  109. FRAME.find( ".act-menu-shrink" ).bindEvent( "click", main_menu_shrink );
  110. FRAME.find( ".act-menu-grow" ).bindEvent( "click", main_menu_grow );
  111. FRAME.find( ".act-ask-quit" ).bindEvent( "click", function() use( CreateYesNoQuestionWindow ){
  112.     CreateYesNoQuestionWindow( "Do you really want to quit?",
  113.         function( result )
  114.         {
  115.             if( result )
  116.                 global sys_exit = true;
  117.         }
  118.     );
  119. } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement