User Tools

Site Tools


hpl3:community:scripting:terminal_basics

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
hpl3:community:scripting:terminal_basics [2015/10/08 01:51]
valetheimpaler
hpl3:community:scripting:terminal_basics [2015/11/10 07:15] (current)
valetheimpaler
Line 1: Line 1:
-====== Setting up a simple Terminal ​(Not even close to being finished) ​======+====== Setting up a simple ​Station ​Terminal ======
  
-I started ​this a bit late and need sleepwill finish tomorrowTotally pointless reading atm.+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 completionI AM SO SORRYI 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? =====
  
-After much demand, here is a guide on how to set up a basic terminal in SOMA.This guide will cover these concepts:+(Note: This guide is pretty big, but be patient and you will be able to set up your own terminal!) ​After much demand, here is a guide on how to set up a basic terminal in SOMA.This guide will cover these concepts:
  
     * Setting up your script/map for a terminal     * Setting up your script/map for a terminal
-    * Basic terminal logichow the game reads what you code, and where to code it+    * Basic terminal logichow the game reads what you code, and where to code it
     * How to use some of the fast functions for GUI included in SOMA, such as a main menu, back button, adding dialog, displaying an image, etc.     * How to use some of the fast functions for GUI included in SOMA, such as a main menu, back button, adding dialog, displaying an image, etc.
  
Line 64: Line 66:
 </​code>​ </​code>​
  
-This is the template setup. I do not recommend you delete this from any script! It is good reference and a good starting point for your first terminal in any map. Also, check+This is the template setup. I do not recommend you delete this from any script! It is good reference and a good starting point for your first terminal in any map. Also, check the part of your scipt where the #​include'​s are; add the lines:
  
-the part of your scipt where the #​include'​s are; add the lines: +<code c>#​include "​helper_imgui_station.hps"​
- +
-<code c> +
-#include "​helper_imgui_station.hps"​+
 #include "​helper_imgui_station_app_audioplayback.hps"​ #include "​helper_imgui_station_app_audioplayback.hps"​
 #include "​helper_imgui_station_app_photoviewer.hps"​ #include "​helper_imgui_station_app_photoviewer.hps"​
 </​code>​ </​code>​
  
-These will include some functions that quickly setup SOMA's terminal GUI.+These will include some functions that can quickly setup SOMA's terminal'​s ​GUI, which you will need if you directly follow this terminal'​s setup. Now, going back to the template for your terminal, edit it to look something like this (you dont have to copy the //comments, but do read them over as they contain information): ​ //''/''​ 
 + 
 +''​ ''​ 
 + 
 +<code c> 
 +         /////////////////////////////////////////​ 
 + // ============== 
 + // TERMINALS 
 + // ============== 
 + //​{//////////////////////////////////////​ 
 + 
 + //​------------------------------------------------------- 
 + /////////////////////////////////////////​ 
 + // Terminal room_terminal 
 + //​{//////////////////////////////////////​ 
 + //​------------------------------------------------------- 
 + void room_terminal_OnGui(const tString&​in asEntityName,​ float asTimeStep) 
 +
 + //​variables 
 + int lActiveApp = -1; //these variables are only necessary if your terminal will have a menu with multiple sub-programs. This variable indicates the active app on the terminal. 
 + int lBackApp ​ = -1; //This variable indicates what app the back button will bring you to. 
 + bool bDrawBackButton = true; //This variable is a true or false that determines if the terminal will draw the back button. 
 + //you can of course create more variables as necessary, but these are the basic ones for a terminal with multiple menus. 
 + 
 + //​----------------------------------------- 
 + 
 + //this is where the main code will be written. 
 + 
 +
 + 
 + //​--------------------------------------------- 
 + 
 + void room_terminal_GuiEnter(const tString&​in asEntityName) 
 +
 + //This code runs whenever the player enters the terminal. 
 +
 + 
 + //​--------------------------------------------- 
 + 
 + void room_terminal_GuiLeave(const tString&​in asEntityName) 
 +
 + //This code runs whenever the player leaves the terminal. 
 +
 + 
 + //​------------------------------------------------------- 
 + //} END Terminal room_terminal 
 + //​------------------------------------------------------- 
 + 
 + //} END TERMINALS 
 +</​code>​ 
 + 
 +''​ ''​ 
 + 
 +(Do not directly copy this code as it was indented with spaces instead of Tab) 
 + 
 +Make sure you replace my lines as necessary. Your '​Terminal'​ and 'End Terminal'​ comments should have your terminal'​s name instead, and the callbacks should be what you named them in the editor. Reference which ones are which by reviewing the image of the terminal tab above (in the 'just let me add my terminal already'​ section). Also decide if your terminal will have a menu with multiple programs. If not, don't bother writing in the variables above the functions section. 
 + 
 +Now the basic code for a simple terminal is setup, and we can adjust it for our needs in the next section. Don't bother testing your map, as in its current state the terminal won't do anything. 
 + 
 +===== 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. 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.
  
hpl3/community/scripting/terminal_basics.1444269106.txt.gz · Last modified: 2015/10/08 01:51 by valetheimpaler