Advertisement
snake5

SGScript | coroutine-based simple dialog system

Dec 5th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. function draw_question( question, answers )
  2. {
  3.     x = 64;
  4.     y = 400;
  5.     sel = null;
  6.     for(;;)
  7.     {
  8.         height = 64 + dict_size( answers ) * 24;
  9.         SS_DrawColorRect_WH( x, y, 400, height, 0, 0, 0, 0.5 );
  10.         SS_DrawTextLine( question, Font, x, y, color(1,1,1) );
  11.        
  12.         i = 0;
  13.         mon = null;
  14.         selfunc = null;
  15.         foreach( func, name : answers )
  16.         {
  17.             ay = y + 64 + i * 24;
  18.             mouseon = mpos.x >= x && mpos.x < x + 400 && mpos.y >= ay && mpos.y < ay + 24;
  19.             if( mouseon )
  20.                 mon = i;
  21.             issel = i === sel;
  22.             if( issel )
  23.                 selfunc = func;
  24.             SS_DrawColorRect_WH( x, ay, 400, 24, mouseon - issel * 0.5, 0, 0, 0.5 );
  25.             SS_DrawTextLine_VC( name, Font, x, ay + 12, color(1) );
  26.             i++;
  27.         }
  28.        
  29.         if( curclick && !prevclick )
  30.             sel = mon;
  31.         else if( !curclick && prevclick )
  32.         {
  33.             if( sel !== null && mon === sel )
  34.             {
  35.                 thread _G[ "q_" $ selfunc ]();
  36.                 return;
  37.             }
  38.             sel = null;
  39.         }
  40.        
  41.         yield;
  42.     }
  43. }
  44.  
  45. function q_step0(){ draw_question( "why not?", { "step1" = "Well, let me think about it", "step0" = "No reason" } ); }
  46. function q_step1(){ draw_question( "shall we proceed?", { "step2" = "Yes", "step0" = "No", "info" = "Tell me more" } ); }
  47. function q_info(){ draw_question( "This is a test dialog", { "step1" = "Ok, got it" } ); }
  48. function q_step2(){ draw_question( "what should we do?", { "action1" = "Let's do the action 1", "action2" = "Let's do the action 2", "step1" = "Let's take a step back" } ); }
  49. function q_action1(){ draw_question( "Action 1 done!", { "step2" = "Ok!" } ); }
  50. function q_action2(){ draw_question( "Action 2 done!", { "step2" = "Ok!" } ); }
  51.  
  52. // started with "thread q_step1();"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement