- Home /
Text Adventure: Moving text field?
Hello, I am the creator of a very unique text adventure. I am purchased an asset called Tidy Text Adventures and I love what it has to offer for my game. However it is necessary that I modify it to fit my needs. So far I've changed the font type and the font color placement etc. But each time I type a command in the text field and press enter, the text field moves down a space eventually obscuring itself from view. I have scoured the UI file in hopes to find what is causing this but to no avail. Can someone help me find what needs changing/ commenting out to stop this from happening? Thanks bunches -- TheIronHobo
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class TTA_UI : MonoBehaviour {
public TextAsset textAsset;
TTA_World world;
//We put all of our styles in this skin (custom styles)
//And we reference them by their output type name
public GUISkin UIskin;
public GUIStyle GetStyleForOutputType(TTA_OutputType outputType){
return UIskin.GetStyle(outputType.ToString());
}
void Awake(){
SetUIState(TTA_UIState.Title);
}
//And these are the three functions that will handle the unusual requests
void NewGame(){
SetUIState(TTA_UIState.NewGame);
}
void QuitGame(){
SetUIState(TTA_UIState.Quit);
}
void HandleVictory(){
SetUIState(TTA_UIState.Victory);
}
string input = "";
List<TTA_OutputEntry> output = new List<TTA_OutputEntry>();
bool keyDown = false;
enum TTA_UIState{
Title,
Game,
NewGame,
Victory,
Quit
}
TTA_UIState uiState;
void SetUIState(TTA_UIState uiState){
this.uiState = uiState;
switch(uiState){
case TTA_UIState.Title:{
//Load!
if(TTA_Utilities.HasWorldSave(textAsset.name)){
world = TTA_Utilities.LoadSavedWorld(textAsset.name);
}
else{
world = TTA_Utilities.WorldFromString(textAsset.text);
}
//Important! We really want to do this
TTA_InputTranslation.InitializeTranslation(NewGame,QuitGame,HandleVictory);
output = TTA_InputTranslation.GetTitleStatus(world);
break;
}
case TTA_UIState.Game:{
output = TTA_InputTranslation.GetBeginningStatus(world);
break;
}
case TTA_UIState.NewGame:{
break;
}
case TTA_UIState.Quit:{
break;
}
case TTA_UIState.Victory:{
break;
}
}
}
void OnGUI(){
GUILayout.BeginArea(new Rect(320, 100, 600, 600));
GUILayout.BeginVertical();
GUI.color = Color.black;
GUI.skin = UIskin;
GUILayout.Space(20.0f);
GUILayout.BeginHorizontal();
GUILayout.Space (20.0f);
GUILayout.BeginVertical();
switch(uiState){
case TTA_UIState.Title:{
DrawGameDisplay();
break;
}
case TTA_UIState.Game:{
GUI.FocusControl ("TEXT");
DrawGameDisplay();
break;
}
case TTA_UIState.NewGame:{
DrawNewGame();
break;
}
case TTA_UIState.Quit:{
DrawQuit();
break;
}
case TTA_UIState.Victory:{
DrawGameDisplay();
break;
}
}
GUILayout.EndVertical();
GUILayout.Space (5.0f);
GUILayout.EndHorizontal();
GUILayout.Space(900.0f);
GUILayout.EndVertical();
GUILayout.EndArea();
}
void DrawNewGame(){
GUILayout.FlexibleSpace();
GUILayout.Box(world.language.newGameWarning,GetStyleForOutputType(TTA_OutputType.New_Game));
GUILayout.FlexibleSpace();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.black;
if(GUILayout.Button("Yes")){
//New game
//We'll need to reload
TTA_Utilities.ClearSave(textAsset.name);
SetUIState(TTA_UIState.Title);
}
GUI.backgroundColor = Color.black;
if(GUILayout.Button("No")){
SetUIState(TTA_UIState.Game);
}
GUI.backgroundColor = c;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
void DrawQuit(){
GUILayout.FlexibleSpace();
GUILayout.Box(world.language.quitMessage,GetStyleForOutputType(TTA_OutputType.Quit));
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
Color c = GUI.backgroundColor;
GUI.backgroundColor = Color.black;
if(GUILayout.Button("Yes")){
//Quit the game.
//What does that even mean? Nothing
SetUIState(TTA_UIState.Title);
}
GUI.backgroundColor = Color.black;
if(GUILayout.Button("No")){
SetUIState(TTA_UIState.Game);
}
GUI.backgroundColor = c;
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
}
void DrawGameDisplay(){
for(int i = 0; i < output.Count; i++){
if(i > 0){
if(output[i].outputType == output[i].outputType){
GUILayout.Label("");
}
}
GUILayout.Label(output[i].entry,GetStyleForOutputType(output[i].outputType));
}
if(uiState == TTA_UIState.Game){
GUILayout.Space(15.0f);
GUILayout.BeginHorizontal();
GUI.SetNextControlName("TEXT");
input = GUILayout.TextField(input,GUILayout.ExpandWidth(true));
if(GUILayout.Button("Go", GUILayout.ExpandWidth(false))){
HandleInput(input);
input = "";
}
GUILayout.EndHorizontal();
}
if(uiState == TTA_UIState.Victory){
GUILayout.Space(15.0f);
GUILayout.BeginHorizontal();
if(GUILayout.Button("Quit")){
//Quit
TTA_Utilities.ClearSave(textAsset.name);
SetUIState(TTA_UIState.Title);
}
GUILayout.FlexibleSpace();
if(GUILayout.Button("New")){
//Restart
TTA_Utilities.ClearSave(textAsset.name);
SetUIState(TTA_UIState.Title);
}
GUILayout.EndHorizontal();
GUILayout.Space(15.0f);
}
if(Event.current.type == EventType.keyDown ||
Event.current.type == EventType.KeyDown){
if(!keyDown){
if(uiState == TTA_UIState.Title){
SetUIState(TTA_UIState.Game);
}
else if(uiState == TTA_UIState.Victory){
//Do nothing
}
else{
HandleInput(input);
}
input = "";
}
keyDown = true;
}
if(Event.current.type == EventType.KeyUp ||
Event.current.type == EventType.keyUp){
keyDown = false;
}
}
void HandleInput(string input){
if(string.IsNullOrEmpty(input)){
return;
}
//This is all here so that I can plainly lay out the process through which the
//logic flows in order to apply your language
//
//I figure this is probably one of the most common things that people will want to tweak,
//So I've exposed the working components here (instead of summing it up in a single "DrawGame" function)
//We'll convert it into a basic sentence
List<TTA_Word> sentence = TTA_InputTranslation.ProcessInput(input,world);
//And then we'll filter that sentence into valid things
sentence = TTA_InputTranslation.FilterInput(sentence,world);
//And then we'll turn it into something we can use
TTA_InputResult result = TTA_InputTranslation.TranslateSentence(sentence,world);
//And now that that is done, we'll get something to actually draw.
//At the culmination of this, we will
output = TTA_InputTranslation.ProcessInputResult(result,output,world);
//Just a nice little function to strip the empty results and replace them with [None] (it's easier for debugging)
FilterOutput();
}
void FilterOutput(){
for(int i = 0; i < output.Count; i++){
if(string.IsNullOrEmpty(output[i].entry)){
output[i].entry = "[None]";
}
}
}
}
I may have found the problem in a seperate file altogether
Answer by TheIronHobo · Jul 21, 2013 at 08:05 AM
For the very small number of you that might find this useful the way to not make it scroll is to comment out
case TTA_CommandType.None:{
currentState.Add(new TTA_OutputEntry(world.language.GetGeneralFailureMessage(),TTA_OutputType.Failure));
break;
}
from the input translation file. Finally I can get some rest...
Your answer
![](https://koobas.hobune.stream/wayback/20220613110531im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to changes font, color & size of the text in textfield? 2 Answers
Textfield doubt, multiplayer purpose... 2 Answers
TextField text component not updating 2 Answers
Unity GUI text displaying as noise 1 Answer
how to put the name of a car ??? 0 Answers