Fallout 4

To enable custom styles in your own implementation of Console.as, add the following yellow code to your implementation:

package
{
...

public class ConsoleStyles
{
private var console:Console;
private var percent:Number;
private var fontSize:String;
private var fontColor:String;
private var commandPrompt:String;

public function ConsoleStyles(c:Console)
{
this.console = c;
this.percent = 0;
this.fontSize = "";
this.fontColor = "";
this.commandPrompt = "";
// alternatively, initialize default properties, for example
// this.percent = 80;
// this.fontSize = 28;
// this.fontColor = "0xFFB642";
// this.commandPrompt = "C:\\>";

}

public function init() : void
{
// initialize default Console object settings, for example
// this.console.alpha = 0.8;
// this.console.font = "Consolas bold";

}

public function get Percent() : Number 
{
return this.percent;
}

public function get FontSize() : String
{
return this.fontSize;
}

public function get FontSizeUint() : uint
{
return uint(this.fontSize);
}

public function get FontColor() : String
{
return this.fontColor;
}

public function get FontColorUint() : uint
{
return uint(this.fontColor);
}

public function get FontColorHex() : String
{
return "0x" + this.FontColorUint.toString(16);
}

public function get CommandPrompt() : String
{
return this.commandPrompt;
}
public function ProcessCommand() : Boolean
{
var result:Boolean = false;
var command:String = this.console.CommandEntry.text;
var spaceIndex:int = command.indexOf(" ");
var param:String = "";
if (spaceIndex > 0)
{
param = command.substr(spaceIndex + 1);
command = command.substr(0, spaceIndex).toLowerCase();
if (command == "setconsolepercent")
{
this.percent = param;
this.console.size = this.percent;
this.console.AddHistory(this.console.CommandEntry.text + "\n" + 
"Console screen percent set to " + this.Percent + "\n");
result = true;
}
else if (command == "setconsolefontsize")
{
this.fontSize = param;
this.console.textSize = this.fontSize;
this.console.AddHistory(this.console.CommandEntry.text + "\n" + 
"Console font size set to " + this.FontSize + "\n");
result = true;
}
else if (command == "setconsolefont")
{
this.console.font = param;
this.console.AddHistory(this.console.CommandEntry.text + "\n" +  
"Console font set to " + param + "\n");
result = true;
}
else if (command == "setconsolealpha")
{
this.console.alpha = Number(param);
this.console.AddHistory(this.console.CommandEntry.text + "\n" + 
"Console background alpha set to " + param + "\n");
result = true;
}
else if (command == "setcommandprompt")
{
this.commandPrompt = param;
this.console.SetCommandPrompt(this.commandPrompt);
this.console.AddHistory(this.console.CommandEntry.text  + "\n" +  
"Command prompt set to " + this.CommandPrompt + "\n");
result = true;
}
else if (command == "setconsolefontcolor")
{
this.fontColor = param;
this.console.textColor = this.FontColorUint;
this.console.historyTextColor = this.FontColorUint;
this.console.AddHistory(this.console.CommandEntry.text + "\n" + 
"Console font color set to " + this.FontColorHex + "\n");
result = true;
}
}
return result;
}
}

public class Console extends MovieClip
{
...

private var Styles:ConsoleStyles;

public function Console()
{
...
this.Styles = new ConsoleStyles(this);
this.Styles.init();

this.onResize();
}

...

public function set historyTextColor(color:uint) : void
{
if (this.Styles.FontColor != "")
{
color = this.Styles.FontColorUint;
}

this.CommandHistory.textColor = color;
}

public function set textColor(color:uint) : void
{
if (this.Styles.FontColor != "")
{
color = this.Styles.FontColorUint;
}
this.CommandEntry.textColor = color;
this.CurrentSelection.textColor = color;
this.CommandPrompt_tf.textColor = color;
}

public function set textSize(sz:uint) : void
{
if (this.Styles.FontSize.length > 0)
{
sz = this.Styles.FontSizeUint;
}
SetFieldFontSize(this.CurrentSelection, sz);
SetFieldFontSize(this.CommandHistory, sz - 2);
SetFieldFontSize(this.CommandEntry, sz);
SetFieldFontSize(this.CommandPrompt_tf, sz);
SetFieldWidth(this.CommandPrompt_tf, this.CommandEntry);
this.PositionTextFields();
}

private static function SetFieldWidth(setField:TextField, neighbor:TextField) : void
{
var fontSize:uint = GetFieldFontSize(setField);
setField.width = fontSize * setField.text.length;
neighbor.x = setField.x + setField.textWidth + 10;
}

private static function SetFieldFontSize(field:TextField, sz:uint) : void
{
var format:TextFormat = field.defaultTextFormat;
format.size = Math.max(1, sz);
field.defaultTextFormat = format;
field.setTextFormat(format);
}

private static function GetFieldFontSize(field:TextField) : uint
{
var format:TextFormat = field.defaultTextFormat;
return format.size;
}


public function set size(sz:Number) : void
{
if (this.Styles.Percent > 0)
{
sz = this.Styles.Percent;
}

this.ScreenPercent = sz;
sz = sz / 100;
this.Background.height = stage.stageHeight * sz;
this.PositionTextFields();
}

public function set alpha(a:Number) : void
{
var s:* = this.Background.getChildAt(0);
s.alpha = 2.0 * a;
}

public function set font(f:String) : void
{
SetFieldFontName(this.CurrentSelection, f);
SetFieldFontName(this.CommandEntry, f);
SetFieldFontName(this.CommandHistory, f);
SetFieldFontName(this.CommandPrompt_tf, f);
SetFieldWidth(this.CommandPrompt_tf, this.CommandEntry);
this.PositionTextFields();
}
        
private static function SetFieldFontName(field:TextField, fontName:String) : void
{
var format:TextFormat = field.defaultTextFormat;
var boldIndex:int = fontName.toLowerCase().indexOf(" bold");
if (boldIndex > 0)
{
format.bold = true;
format.font = fontName.substr(0, boldIndex);
}
else
{
format.font = fontName;
}
field.defaultTextFormat = format;
field.setTextFormat(format);
}


public function PositionTextFields() : void
{
var fontSize:uint = GetFieldFontSize(this.CommandPrompt_tf);
this.CommandPrompt_tf.y = -3.0 * fontSize;
this.CommandPrompt_tf.height = 1.5 * fontSize;

this.CommandEntry.y = this.CommandPrompt_tf.y;
this.CommandEntry.height = this.CommandPrompt_tf.height;
this.CurrentSelection.height = 1.5 * fontSize;

this.CurrentSelection.y = this.CurrentSelectionYOffset - this.Background.height;
this.CommandHistory.y = this.CurrentSelection.y + this.CurrentSelection.height;
this.CommandHistory.height = this.CommandEntry.y - this.CommandHistory.y;
}

...

public function SetCommandPrompt(prompt:String) : void
{
if (this.Styles.CommandPrompt.length > 0)
{
prompt = this.Styles.CommandPrompt;
}
GlobalFunc.SetText(this.CommandPrompt_tf, prompt, false);
SetFieldWidth(this.CommandPrompt_tf, this.CommandEntry);
}

...

public function onKeyUp(evt:KeyboardEvent) : void
{
var h:int = 0;
var y:int = 0;
if (evt.keyCode == Keyboard.ENTER || evt.keyCode == Keyboard.NUMPAD_ENTER)
{
if (this.Commands.length >= this.PREVIOUS_COMMANDS)
{
this.Commands.shift();
}
this.Commands.push(this.CommandEntry.text);
if (!this.Styles.ProcessCommand())
{

   this.BGSCodeObj.executeCommand(this.CommandEntry.text);
}
this.ResetCommandEntry();
}
...
}

...
}
}

Article information

Added on

Edited on

Written by

charlieoctopus5000

0 comments