Both sides previous revision Previous revision Next revision | Previous revision | ||
hpl3:community:scripting:terminal_basics [2015/11/10 05:22] valetheimpaler |
hpl3:community:scripting:terminal_basics [2015/11/10 07:15] (current) valetheimpaler |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Setting up a simple Terminal (Getting there) ====== | + | ====== Setting up a simple Station Terminal ====== |
- | Still incomplete, but further along. Check back soon! | + | Check here >>[[https://www.frictionalgames.com/forum/thread-31645.html|www.frictionalgames.com/forum/thread-31645.html]]<< |
+ | |||
+ | To the people who actually have been waiting for this page's completion, I AM SO SORRY. I only recently got an actual internet connection so expect things to speed up in terms of page completion. Again, sorry for the wait, but the page has been expanded enough for you to add a text box! Check the 'Terminal still isnt shiny' section for details, and I'll add more later. | ||
===== What is in this tutorial, and what should I know/do first? ===== | ===== What is in this tutorial, and what should I know/do first? ===== | ||
Line 132: | Line 134: | ||
===== My terminal still isn't shiny! What do? ===== | ===== My terminal still isn't shiny! What do? ===== | ||
- | It doesn't do anything fun yet, but your terminal //is // running. Now you just have to decide what it runs. Most of this stuff will be dealt with in the void terminal_onGui function. This part of the tutorial is about setting up a single window stylized like the regular SOMA terminals which will display text and an image. I'll provide the code and then explain all of it with detailed comments and insight. For this part of the tutorial, we WILL ONLY be looking at the onGui function. | + | It doesn't do anything fun yet, but your terminal //is // running. Now you just have to decide what it runs. Most of this stuff will be dealt with in the void terminal_onGui function. This part of the tutorial is about setting up a single window stylized like the regular SOMA terminals which will display text and an image. I'll provide the code and then explain all of it with detailed comments and insight. For this part of the tutorial, we WILL ONLY be looking at the onGui function. We'll keep adding bits of code on as we go along so you can gain a better understanding of how the individual lines function. Start by adding the following to your variables section: |
+ | |||
+ | <code c> | ||
+ | cImGuiWindowData windowData = StationGui_CreateDefaultWindowData(); //Creates default window data which is stored in a class | ||
+ | cImGuiTextFrameData textFrame = ImGui_GetDefaultTextFrame(); //Creates default textbox data and is stored in a class | ||
+ | textFrame.mFont.SetFile("sansation_large_bold.fnt"); //sets the font | ||
+ | textFrame.mFontAlign = eFontAlign_Left; //Aligns the text to the left side of the text box. You can also align it to the center or the right side of the text box. | ||
+ | textFrame.mbUseBackgroundGfx = false; //Default is true. If true the background behind the frame will be filled in with a solid color and it will look like it was made in MS paint. | ||
+ | textFrame.mFont.mvSize = ImGui_NrmSizeKeepRatio(0.04); //Sets the font size to 4% of the screen size. | ||
+ | </code> | ||
+ | |||
+ | This creates an ImGuiWindowData class object, as noted by the c, named windowData, with the default window parameters. These parameters include things such as font coloring and sizing, window coloring, and padding (I suspect these are the window borders?), as well as some GFX properties that require further investigation. The following line creates a class called textFrame that we will be using for our textbox. Everything beneath that line tweaks the text frame's properties. Then, add the following lines to the onGui's main code section: | ||
+ | |||
+ | <code c> | ||
+ | ImGui_SetTransCategory(""); | ||
+ | StationGui_DoWindowStart("WindowTitle", windowData, ImGui_NrmPos(0.05, 0.05, 2), ImGui_NrmSize(0.9, 0.9), false); | ||
+ | ImGui_DoTextFrameExt("This is a text box.", 0, 0, 0, textFrame, ImGui_NrmPos(0.025f, 0.025f, 2), ImGui_NrmSizeGroup(0.95, 0.95)); | ||
+ | StationGui_DoWindowEnd(); | ||
+ | </code> | ||
+ | |||
+ | The first line, ImGui_SetTransCategory sets the category used in your language file. If you use " " as the input which I have done, it will directly take string input for your functions. The next line actually initiates our window; it sets up its title, location, and sizing, while using our windowData class as a base. The ImGui_NrmPos(cVector3f()) and ImGui_NrmSize(cVector2f()) functions I will explain momentarily. The following line , ImGui_DoTextFrameExt, draws in a text box within our window. If your language category was set to " ", then whatever you write in quotations will be the text displayed in the text box. If you set the language category to an actual category within your mod's lang file, then write the entry name within the quotes instead. The 3 0's I still need to look into, but the following textFrame value is the class we created earlier for our textbox. The ImGui_NrmPos and the ImGui_NrmSizeGroup I will now note on. | ||
+ | |||
+ | As mentioned above, there are some values inputted into the program named ImGui_NrmPos, ImGui_NrmSize, etc. NrmPos is the item's postion on the screen using a 3d vector input. Simply put, the first value, in a range of 0-1, is how offset the object's x coordinate is, with 0.5 being centered, 0 being at the exact left side, and 1 being at the very right edge. The second value within the is the object's y offset, with 0 at the top, 0.5 centered, and 1.0 at the bottom of the display. The third value is the layer; object with a value of 1 here draw in first, and object with a value of 2 second, and so on. (Keeping in mind that objects draw on top of each other, so drawing in second means the image will appear on top of whatever drew in first.) ImGui_NrmSize is the object's scaling relative to the screen, with the first value being how large it's x value will be and the second it's y. If you use NrmPosGroup or NrmSizeGroup, than the objects positioning or scale will be relative to whatever it is drawn to; so, if drawn within a window, it's size is based off of it's parent window instead of the overall screen. | ||
+ | |||
+ | If you don't understand this, don't worry; ask a more experienced coder on the forum to help explain, and for now just copy this code. There's only so much I can get across with a wall of text. | ||
+ | |||
+ | The last line is equally important to all the others, especially if you are using multiple windows. I haven't tested this yet, but I suspect the game will crash if you do not include this last line. | ||