Advertisement
ZoriaRPG

Simple Text Box Function

Oct 25th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.06 KB | None | 0 0
  1.  
  2. const int MESSAGE_OUT_X = 92;
  3. const int MESSAGE_OUT_Y = 40;
  4. const int MESSAGE_OUT_WIDTH = 128;
  5. const int MESSAGE_OUT_HEIGHT = 12`;
  6. const int MESSAGE_OUT_LAYER = 6;
  7. const int MESSAGE_OUT_BLACK = 0x0F;
  8. const int MESSAGE_OUT_TEXT_COLOUR = 0x01; //White, in the Classic tileset
  9. const int MESSAGE_OUT_TEXT_FONT = 9; //NES
  10. const int MESSAGE_OUT_TEXT_XOFS = 4; //Text offset from edge of rectangle.
  11. const int MESSAGE_OUT_TEXT_YOFS = 4; //Text offset from edge of rectangle.
  12.  
  13. //DrawMessageBox(MESSAGE_OUT_LAYER, MESSAGE_OUT_X, MESSAGE_OUT_Y, MESSAGE_OUT_WIDTH, MESSAGE_OUT_HEIGHT, id, MESSAGE_OUT_BLACK, MESSAGE_OUT_TEXT_COLOUR, text_colour, true);
  14. bool DrawMessageBox(int layer, int x, int y, int height, int width, int message, int colour, int text_colour, int font, bool opaque_bg)
  15. {
  16.     Screen->Rectangle(layer,x,y,height,width,colour,100, 0,0,0,true,Cond(opaque_bg,OP_OPAQUE,OP_TRANS));
  17.     int buf[256];
  18.     GetMessage(id,buf);
  19.     Screen->DrawString(6,x+MESSAGE_OUT_TEXT_XOFS,y+MESSAGE_OUT_TEXT_YOFS,font,text_colour, -1,0,buf,128);
  20.     while(!Link->PressB || !Link->PressA )
  21.     {
  22.         Waitframe(); //or WaitNoAction()
  23.     }
  24.     return true;
  25. }
  26.  
  27. const int FONST_SPACING_NES = 9; //8 pixels plus one for spacing. ...or does the NES font have two pixels for spacing? or none?
  28.  
  29. //Only uses NES font, but is autosized. to width of string. Won't handle line-wraps!
  30. //DrawMessageBoxAS(MESSAGE_OUT_LAYER, MESSAGE_OUT_X, MESSAGE_OUT_Y, MESSAGE_OUT_WIDTH, MESSAGE_OUT_HEIGHT, id, MESSAGE_OUT_BLACK, MESSAGE_OUT_TEXT_COLOUR, text_colour, true);
  31. bool DrawMessageBoxAS(int layer, int x, int y, int height, int width, int message, int colour, int text_colour, bool opaque_bg)
  32. {
  33.     int width;
  34.     int buf[256];
  35.     GetMessage(id,buf);
  36.     for ( int q = 0; buf[q] != 0; ++q )
  37.     {
  38.         size += FONST_SPACING_NES;
  39.     }
  40.    
  41.     Screen->Rectangle(layer,x,y,height,width,colour,100, 0,0,0,true,Cond(opaque_bg,OP_OPAQUE,OP_TRANS));
  42.    
  43.    
  44.     Screen->DrawString(6,x+MESSAGE_OUT_TEXT_XOFS,y+MESSAGE_OUT_TEXT_YOFS,0,text_colour, -1,0,buf,128);
  45.     while(!Link->PressB || !Link->PressA )
  46.     {
  47.         Waitframe(); //or WaitNoAction()
  48.     }
  49.     return true;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement