Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //From my Amnesia Rebirth Tutorial Series
- //Episode 47 ImGui Pt.1! Messages!
- //https://www.youtube.com/playlist?list=PL4KkjlmOwLwwMVqedCNpi6caUxhgyf8Qr
- //-----------------------------------------------------------
- //Set a category to use from your .lang file (leave blank if you wish to use a literal string)
- ImGui_SetTransCategory("Messages");
- //category (String)- the name of the category you wish to read from. Should match the category name you are using in your .lang file.
- //Create label data variable
- cImGuiLabelData label;
- //Returns a vector with a screen position (calculates the position on the screen fiven only a value between 0 and 1)
- ImGui_NrmPos(0,0,10.0)
- //xPosNormalized (float)- the normalized x position (between 0 and 1). Ex. 0.5 will be the center of the x axis.
- //yPosNormalized (float)- the normalized y position (between 0 and 1). Ex. 0.5 will be the center of the y axis.
- //zPosNormalized (float)- the normalized z position (between 0 and 1). Note: Not used when printing text on screen.
- //Returns a vector with the size in screen to work on (1,1 for whole screen)
- ImGui_NrmSize(1.0f,1.0f)
- //xSizeNormalized (float)- the normalized x size (between 0 and 1). Ex. 0.5 will be half the x zxis.
- //ySizeNormalized (float)- the normalized y size (between 0 and 1). Ex. 0.5 will be half the y axis.
- //Print a label on the players GUI
- ImGui_DoLabelExt("Message_1", label, ImGui_NrmPos(0,0,10.0), ImGui_NrmSize(1.0f,1.0f));
- //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.
- //labelData (cImGuiLabelData)- the label data variable that stores all your text format data.
- //screenPosition (cVector3f)- a 3D vector that indicates the x, y, z screen position of where the text should be placed.
- //screenSpaceSize (cVector2f)- a 2D vector that indicates the x, y in screen size. (Use 1.0, 1.0 for whole screen)
- //The OnGui function
- void OnGui(float afTimeStep)
- {
- }
- //Global variable showMessage that stores whether or not we want to show our message
- bool showMessage = false;
- //Put an if inside the OnGui function with our boolean variable
- if(showMessage){
- }
- //Specify how you want your text alligned (use eFontAlign_ to find a position)
- label.mFontAlign = eFontAlign_Center;
- //Specify the x,y size of the font in a vector2f format
- label.mFont.mvSize = cVector2f(50,50);
- //Change color of text to a preset one using cColor_
- label.mColorBase = cColor_Red;
- //Change color of text to specific color
- //Check color wheel color https://www.colorspire.com/
- //Normalize the RGB colors by dividing by 255
- label.mColorBase = cColor(.501, 0, 1.0);
- //Change the transparency of the text (a float from 0 to 1, 0 = 0% visible and 1 = 100% visible)
- label.mColorBase.a = 1.0f;
- //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)
- float messageFadeInAndOutTime = 5.0f;
- //Create an oscillator that return the color and transparancy of a color to another color and then change it back repeatedly
- ImGui_FadeOscillateColor("label", cColor(1, 1, 1, 0), cColor(1, 1, 1, 1), messageFadeInAndOutTime, eEasing_Linear);
- //oscillatorName (String)- the name of the osillator which you can call later in your code.
- //startColor (cColor)- the color and transparancy to start the oscillator at. cColor(R, G, B, a).
- //goalColor (cColor)- the color and transparancy to reach. cColor(R, G, B, a).
- //oscillationTime (float)- the total time it should take for the ossilator to make one full cycle (From A to B and back to A).
- //easingFunction (eEasing)- the function that should be used to get from color A to color B and back. (Use eEasing_Linear for basic usage)
- //Set the transparency of the text using a color oscillator
- label.mColorBase.a = ImGui_FadeOscillateColor("label", cColor(1, 1, 1, 0), cColor(1, 1, 1, 1), messageFadeInAndOutTime, eEasing_Linear).a;
- //If statement to disable message when fade is done
- if(label.mColorBase.a == 0) showMessage = false;
- /////////////////////////////////////
- //All code written in today's episode
- /////////////////////////////////////
- void OnGui(float afTimeStep){
- message1();
- }
- void message1(){
- if(showMessage){
- float messageFadeInAndOutTime = 5.0f;
- cImGuiLabelData label;
- label.mFontAlign = eFontAlign_Center;
- label.mFont.mvSize = cVector2f(50, 50);
- //label.mColorBase = cColor_Red;
- //label.mColorBase = cColor(0.568, 0, 1);
- //label.mColorBase.a = .25f;
- label.mColorBase = ImGui_FadeOscillateColor("label", cColor(0.568, 0, 1, 0), cColor(0.568, 0, 1, 1), messageFadeInAndOutTime, eEasing_Linear);
- //label.mColorBase.a = ImGui_FadeOscillateColor("label", cColor(0.568, 0, 1, 0), cColor(0.568, 0, 1, 1), messageFadeInAndOutTime, eEasing_Linear).a;
- ImGui_SetTransCategory("Messages");
- ImGui_DoLabelExt("Message_2", label, ImGui_NrmPos(0,0,10), ImGui_NrmSize(1, 1));
- if(label.mColorBase.a == 0) showMessage = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement