Advertisement
TechOFreak

Episode 47 Functions

Aug 7th, 2021
1,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.04 KB | None | 0 0
  1. //From my Amnesia Rebirth Tutorial Series
  2. //Episode 47 ImGui Pt.1! Messages!
  3. //https://www.youtube.com/playlist?list=PL4KkjlmOwLwwMVqedCNpi6caUxhgyf8Qr
  4. //-----------------------------------------------------------
  5.  
  6. //Set a category to use from your .lang file (leave blank if you wish to use a literal string)
  7. ImGui_SetTransCategory("Messages");
  8. //category (String)- the name of the category you wish to read from. Should match the category name you are using in your .lang file.
  9.  
  10. //Create label data variable
  11. cImGuiLabelData label;
  12.  
  13. //Returns a vector with a screen position (calculates the position on the screen fiven only a value between 0 and 1)
  14. ImGui_NrmPos(0,0,10.0)
  15. //xPosNormalized (float)- the normalized x position (between 0 and 1). Ex. 0.5 will be the center of the x axis.
  16. //yPosNormalized (float)- the normalized y position (between 0 and 1). Ex. 0.5 will be the center of the y axis.
  17. //zPosNormalized (float)- the normalized z position (between 0 and 1). Note: Not used when printing text on screen.
  18.  
  19. //Returns a vector with the size in screen to work on (1,1 for whole screen)
  20. ImGui_NrmSize(1.0f,1.0f)
  21. //xSizeNormalized (float)- the normalized x size (between 0 and 1). Ex. 0.5 will be half the x zxis.
  22. //ySizeNormalized (float)- the normalized y size (between 0 and 1). Ex. 0.5 will be half the y axis.
  23.  
  24. //Print a label on the players GUI
  25. ImGui_DoLabelExt("Message_1", label, ImGui_NrmPos(0,0,10.0), ImGui_NrmSize(1.0f,1.0f));
  26. //entryName (String)- the entry name that contains the text you wish to print (from the .lang file). If TransCategory is "" then it will print out whatever String is written here.
  27. //labelData (cImGuiLabelData)- the label data variable that stores all your text format data.
  28. //screenPosition (cVector3f)- a 3D vector that indicates the x, y, z screen position of where the text should be placed.
  29. //screenSpaceSize (cVector2f)- a 2D vector that indicates the x, y in screen size. (Use 1.0, 1.0 for whole screen)
  30.  
  31. //The OnGui function
  32. void OnGui(float afTimeStep)
  33. {
  34.  
  35. }
  36.  
  37. //Global variable showMessage that stores whether or not we want to show our message
  38. bool showMessage = false;
  39.  
  40. //Put an if inside the OnGui function with our boolean variable
  41. if(showMessage){
  42.    
  43. }
  44.  
  45. //Specify how you want your text alligned (use eFontAlign_ to find a position)
  46. label.mFontAlign = eFontAlign_Center;
  47.  
  48. //Specify the x,y size of the font in a vector2f format
  49. label.mFont.mvSize = cVector2f(50,50);
  50.  
  51. //Change color of text to a preset one using cColor_
  52. label.mColorBase = cColor_Red;
  53.            
  54. //Change color of text to specific color
  55. //Check color wheel color https://www.colorspire.com/
  56. //Normalize the RGB colors by dividing by 255
  57. label.mColorBase = cColor(.501, 0, 1.0);
  58.  
  59. //Change the transparency of the text (a float from 0 to 1, 0 = 0% visible and 1 = 100% visible)
  60. label.mColorBase.a = 1.0f;
  61.  
  62. //Total time message will be on screen fading in and out (2.5 seconds fading in and 2.5 fading out while using a linear easing function)
  63. float messageFadeInAndOutTime = 5.0f;
  64.  
  65. //Create an oscillator that return the color and transparancy of a color to another color and then change it back repeatedly
  66. ImGui_FadeOscillateColor("label", cColor(1, 1, 1, 0), cColor(1, 1, 1, 1), messageFadeInAndOutTime, eEasing_Linear);
  67. //oscillatorName (String)- the name of the osillator which you can call later in your code.
  68. //startColor (cColor)- the color and transparancy to start the oscillator at. cColor(R, G, B, a).
  69. //goalColor (cColor)- the color and transparancy to reach. cColor(R, G, B, a).
  70. //oscillationTime (float)- the total time it should take for the ossilator to make one full cycle (From A to B and back to A).
  71. //easingFunction (eEasing)- the function that should be used to get from color A to color B and back. (Use eEasing_Linear for basic usage)
  72.  
  73. //Set the transparency of the text using a color oscillator
  74. label.mColorBase.a = ImGui_FadeOscillateColor("label", cColor(1, 1, 1, 0), cColor(1, 1, 1, 1), messageFadeInAndOutTime, eEasing_Linear).a;
  75.  
  76. //If statement to disable message when fade is done
  77. if(label.mColorBase.a == 0) showMessage = false;
  78.  
  79.  
  80. /////////////////////////////////////
  81. //All code written in today's episode
  82. /////////////////////////////////////
  83.  
  84. void OnGui(float afTimeStep){
  85.     message1();
  86. }
  87.  
  88. void message1(){
  89.     if(showMessage){
  90.         float messageFadeInAndOutTime = 5.0f;
  91.            
  92.         cImGuiLabelData label;
  93.         label.mFontAlign = eFontAlign_Center;
  94.         label.mFont.mvSize = cVector2f(50, 50);
  95.         //label.mColorBase = cColor_Red;
  96.         //label.mColorBase = cColor(0.568, 0, 1);
  97.         //label.mColorBase.a = .25f;
  98.         label.mColorBase = ImGui_FadeOscillateColor("label", cColor(0.568, 0, 1, 0), cColor(0.568, 0, 1, 1), messageFadeInAndOutTime, eEasing_Linear);
  99.         //label.mColorBase.a = ImGui_FadeOscillateColor("label", cColor(0.568, 0, 1, 0), cColor(0.568, 0, 1, 1), messageFadeInAndOutTime, eEasing_Linear).a;
  100.            
  101.         ImGui_SetTransCategory("Messages");
  102.         ImGui_DoLabelExt("Message_2", label, ImGui_NrmPos(0,0,10), ImGui_NrmSize(1, 1));
  103.            
  104.         if(label.mColorBase.a == 0) showMessage = false;
  105.     }
  106. }
  107.    
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement