|
| 1 | +import Shared.GlobalFunc; |
| 2 | +import gfx.io.GameDelegate; |
| 3 | + |
| 4 | +class Console extends MovieClip |
| 5 | +{ |
| 6 | + static var PREVIOUS_COMMANDS: Number = 32; |
| 7 | + static var HistoryCharBufferSize: Number = 8192; |
| 8 | + static var ConsoleInstance = null; |
| 9 | + |
| 10 | + /* Stage Elements */ |
| 11 | + var Background: MovieClip; |
| 12 | + |
| 13 | + var CurrentSelection: TextField; |
| 14 | + var CommandHistory: TextField; |
| 15 | + var CommandEntry: TextField; |
| 16 | + var CurrentCell: TextField; |
| 17 | + |
| 18 | + var Commands: Array = new Array(); |
| 19 | + |
| 20 | + var Animating: Boolean; |
| 21 | + var Hiding: Boolean; |
| 22 | + var Shown: Boolean; |
| 23 | + |
| 24 | + var CurrentSelectionYOffset: Number; |
| 25 | + var OriginalHeight: Number; |
| 26 | + var OriginalWidth: Number; |
| 27 | + var PreviousCommandOffset: Number; |
| 28 | + var ScreenPercent: Number; |
| 29 | + var TextXOffset: Number; |
| 30 | + |
| 31 | + |
| 32 | + function Console() |
| 33 | + { |
| 34 | + super(); |
| 35 | + _global.gfxExtensions = true; |
| 36 | + GlobalFunc.MaintainTextFormat(); |
| 37 | + |
| 38 | + CurrentSelectionYOffset = _height + CurrentSelection._y; |
| 39 | + TextXOffset = CommandEntry._x; |
| 40 | + |
| 41 | + OriginalHeight = Stage.height; |
| 42 | + OriginalWidth = Stage.width; |
| 43 | + |
| 44 | + ScreenPercent = 100 * (_height / Stage.height); |
| 45 | + PreviousCommandOffset = 0; |
| 46 | + |
| 47 | + Shown = false; |
| 48 | + Animating = false; |
| 49 | + Hiding = false; |
| 50 | + |
| 51 | + CommandEntry.setNewTextFormat(CommandEntry.getTextFormat()); |
| 52 | + CommandEntry.text = ""; |
| 53 | + CommandEntry.noTranslate = true; |
| 54 | + |
| 55 | + CurrentSelection.setNewTextFormat(CurrentSelection.getTextFormat()); |
| 56 | + CurrentSelection.text = "Selected reference: None"; |
| 57 | + CurrentSelection.noTranslate = true; |
| 58 | + |
| 59 | + CommandHistory.setNewTextFormat(CommandHistory.getTextFormat()); |
| 60 | + CommandHistory.text = ""; |
| 61 | + CommandHistory.noTranslate = true; |
| 62 | + |
| 63 | + CurrentCell.setNewTextFormat(CurrentCell.getTextFormat()); |
| 64 | + CurrentCell.text = "Current cell: None"; |
| 65 | + CurrentCell.noTranslate = true; |
| 66 | + |
| 67 | + Stage.align = "BL"; |
| 68 | + Stage.scaleMode = "noScale"; |
| 69 | + |
| 70 | + Stage.addListener(this); |
| 71 | + Key.addListener(this); |
| 72 | + |
| 73 | + Console.ConsoleInstance = this; |
| 74 | + |
| 75 | + onResize(); |
| 76 | + } |
| 77 | + |
| 78 | + static function Show(): Void |
| 79 | + { |
| 80 | + if (Console.ConsoleInstance != null && !Console.ConsoleInstance.Animating) { |
| 81 | + Console.ConsoleInstance._parent._y = Console.ConsoleInstance.OriginalHeight; |
| 82 | + Console.ConsoleInstance._parent.gotoAndPlay("show_anim"); |
| 83 | + Selection.setFocus(Console.ConsoleInstance.CommandEntry, 0); |
| 84 | + Console.ConsoleInstance.Animating = true; |
| 85 | + Selection.setSelection(Console.ConsoleInstance.CommandEntry.length, Console.ConsoleInstance.CommandEntry.length); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + static function ShowComplete(): Void |
| 90 | + { |
| 91 | + if (Console.ConsoleInstance != null) { |
| 92 | + Console.ConsoleInstance.Shown = true; |
| 93 | + Console.ConsoleInstance.Animating = false; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + static function Hide(): Void |
| 98 | + { |
| 99 | + if (Console.ConsoleInstance != null && !Console.ConsoleInstance.Animating) { |
| 100 | + Console.ConsoleInstance._parent.gotoAndPlay("hide_anim"); |
| 101 | + Selection.setFocus(null, 0); |
| 102 | + Console.ConsoleInstance.ResetCommandEntry(); |
| 103 | + Console.ConsoleInstance.Animating = true; |
| 104 | + Console.ConsoleInstance.Hiding = true; |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + static function HideComplete(): Void |
| 109 | + { |
| 110 | + if (Console.ConsoleInstance != null) { |
| 111 | + Console.ConsoleInstance.Shown = false; |
| 112 | + Console.ConsoleInstance.Animating = false; |
| 113 | + Console.ConsoleInstance.Hiding = false; |
| 114 | + GameDelegate.call("HideComplete", []); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + static function Minimize(): Void |
| 119 | + { |
| 120 | + if (Console.ConsoleInstance != null) |
| 121 | + Console.ConsoleInstance._parent._y = Console.ConsoleInstance.OriginalHeight - Console.ConsoleInstance.CommandHistory._y; |
| 122 | + } |
| 123 | + |
| 124 | + static function SetCurrentSelection(selectionText: String): Void |
| 125 | + { |
| 126 | + if (Console.ConsoleInstance != null) { |
| 127 | + if(selectionText != "") { |
| 128 | + var refID: String = selectionText.substr((selectionText.indexOf("(", 0) + 1), 8); |
| 129 | + Console.ConsoleInstance.CurrentSelection.text = "Selected reference: " + selectionText.substring(0, (selectionText.indexOf("(", 0) - 1)) + " (ReferenceID " + refID.toUpperCase() + ")"; |
| 130 | + } else { |
| 131 | + Console.ConsoleInstance.CurrentSelection.text = "Selected reference: None"; |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + static function QShown(): Boolean |
| 137 | + { |
| 138 | + return Console.ConsoleInstance != null && Console.ConsoleInstance.Shown && !Console.ConsoleInstance.Animating; |
| 139 | + } |
| 140 | + |
| 141 | + static function QHiding(): Boolean |
| 142 | + { |
| 143 | + return Console.ConsoleInstance != null && Console.ConsoleInstance.Hiding; |
| 144 | + } |
| 145 | + |
| 146 | + static function PreviousCommand(): Void |
| 147 | + { |
| 148 | + if (Console.ConsoleInstance != null) { |
| 149 | + if (Console.ConsoleInstance.PreviousCommandOffset < Console.ConsoleInstance.Commands.length) |
| 150 | + ++Console.ConsoleInstance.PreviousCommandOffset; |
| 151 | + if (0 != Console.ConsoleInstance.Commands.length && 0 != Console.ConsoleInstance.PreviousCommandOffset) |
| 152 | + Console.ConsoleInstance.CommandEntry.text = Console.ConsoleInstance.Commands[Console.ConsoleInstance.Commands.length - Console.ConsoleInstance.PreviousCommandOffset]; |
| 153 | + Selection.setSelection(Console.ConsoleInstance.CommandEntry.length, Console.ConsoleInstance.CommandEntry.length); |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + static function NextCommand(): Void |
| 158 | + { |
| 159 | + if (Console.ConsoleInstance != null) { |
| 160 | + if (Console.ConsoleInstance.PreviousCommandOffset > 1) |
| 161 | + --Console.ConsoleInstance.PreviousCommandOffset; |
| 162 | + if (0 != Console.ConsoleInstance.Commands.length && 0 != Console.ConsoleInstance.PreviousCommandOffset) |
| 163 | + Console.ConsoleInstance.CommandEntry.text = Console.ConsoleInstance.Commands[Console.ConsoleInstance.Commands.length - Console.ConsoleInstance.PreviousCommandOffset]; |
| 164 | + Selection.setSelection(Console.ConsoleInstance.CommandEntry.length, Console.ConsoleInstance.CommandEntry.length); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + static function AddHistory(aText: String): Void |
| 169 | + { |
| 170 | + if (Console.ConsoleInstance != null) { |
| 171 | + Console.ConsoleInstance.CommandHistory.text = Console.ConsoleInstance.CommandHistory.text + aText; |
| 172 | + if (Console.ConsoleInstance.CommandHistory.text.length > Console.HistoryCharBufferSize) |
| 173 | + Console.ConsoleInstance.CommandHistory.text = Console.ConsoleInstance.CommandHistory.text.substr(0 - Console.HistoryCharBufferSize); |
| 174 | + Console.ConsoleInstance.CommandHistory.scroll = Console.ConsoleInstance.CommandHistory.maxscroll; |
| 175 | + } |
| 176 | + } |
| 177 | + |
| 178 | + static function ClearHistory(): Void |
| 179 | + { |
| 180 | + if (Console.ConsoleInstance != null) |
| 181 | + Console.ConsoleInstance.CommandHistory.text = ""; |
| 182 | + } |
| 183 | + |
| 184 | + static function SetHistoryCharBufferSize(aNumChars: Number): Void |
| 185 | + { |
| 186 | + Console.HistoryCharBufferSize = aNumChars; |
| 187 | + } |
| 188 | + |
| 189 | + static function SetTextColor(aColor: Number): Void |
| 190 | + { |
| 191 | + Console.ConsoleInstance.CommandEntry.textColor = aColor; |
| 192 | + Console.ConsoleInstance.CurrentSelection.textColor = aColor; |
| 193 | + Console.ConsoleInstance.CurrentCell.textColor = aColor; |
| 194 | + } |
| 195 | + |
| 196 | + static function SetTextSize(aPointSize: Number): Void |
| 197 | + { |
| 198 | + var textFormat: TextFormat = undefined; |
| 199 | + |
| 200 | + textFormat = Console.ConsoleInstance.CurrentSelection.getNewTextFormat(); |
| 201 | + textFormat.size = Math.max(1, aPointSize); |
| 202 | + Console.ConsoleInstance.CurrentSelection.setTextFormat(textFormat); |
| 203 | + Console.ConsoleInstance.CurrentSelection.setNewTextFormat(textFormat); |
| 204 | + |
| 205 | + textFormat = Console.ConsoleInstance.CommandHistory.getNewTextFormat(); |
| 206 | + textFormat.size = Math.max(1, aPointSize - 2); |
| 207 | + Console.ConsoleInstance.CommandHistory.setTextFormat(textFormat); |
| 208 | + Console.ConsoleInstance.CommandHistory.setNewTextFormat(textFormat); |
| 209 | + |
| 210 | + textFormat = Console.ConsoleInstance.CommandEntry.getNewTextFormat(); |
| 211 | + textFormat.size = Math.max(1, aPointSize); |
| 212 | + Console.ConsoleInstance.CommandEntry.setTextFormat(textFormat); |
| 213 | + Console.ConsoleInstance.CommandEntry.setNewTextFormat(textFormat); |
| 214 | + |
| 215 | + textFormat = Console.ConsoleInstance.CurrentCell.getNewTextFormat(); |
| 216 | + textFormat.size = Math.max(1, aPointSize); |
| 217 | + Console.ConsoleInstance.CurrentCell.setTextFormat(textFormat); |
| 218 | + Console.ConsoleInstance.CurrentCell.setNewTextFormat(textFormat); |
| 219 | + |
| 220 | + Console.PositionTextFields(); |
| 221 | + } |
| 222 | + |
| 223 | + static function SetHistoryTextColor(aColor: Number): Void |
| 224 | + { |
| 225 | + Console.ConsoleInstance.CommandHistory.textColor = aColor; |
| 226 | + } |
| 227 | + |
| 228 | + static function SetSize(aPercent: Number): Void |
| 229 | + { |
| 230 | + Console.ConsoleInstance.ScreenPercent = aPercent; |
| 231 | + aPercent = aPercent / 100; |
| 232 | + Console.ConsoleInstance.Background._height = Stage.height * aPercent; |
| 233 | + |
| 234 | + Console.PositionTextFields(); |
| 235 | + } |
| 236 | + |
| 237 | + static function PositionTextFields(): Void |
| 238 | + { |
| 239 | + Console.ConsoleInstance.CurrentSelection._y = Console.ConsoleInstance.CurrentSelectionYOffset - Console.ConsoleInstance.Background._height; |
| 240 | + Console.ConsoleInstance.CommandHistory._y = Console.ConsoleInstance.CurrentSelection._y + Console.ConsoleInstance.CurrentSelection._height; |
| 241 | + Console.ConsoleInstance.CommandHistory._height = Console.ConsoleInstance.CommandEntry._y - Console.ConsoleInstance.CommandHistory._y; |
| 242 | + |
| 243 | + Console.ConsoleInstance.CurrentCell._y = Console.ConsoleInstance.CurrentSelection._y - Console.ConsoleInstance.CurrentCell._height; |
| 244 | + Console.ConsoleInstance.CurrentCell._x = Console.ConsoleInstance.CurrentSelection._x; |
| 245 | + } |
| 246 | + |
| 247 | + function ResetCommandEntry(): Void |
| 248 | + { |
| 249 | + CommandEntry.text = ""; |
| 250 | + PreviousCommandOffset = 0; |
| 251 | + } |
| 252 | + |
| 253 | + function onKeyDown(): Void |
| 254 | + { |
| 255 | + if (Key.getCode() == 13 || Key.getCode() == 108) { |
| 256 | + if (CommandEntry.text.length != 0) { |
| 257 | + if (Commands.length >= Console.PREVIOUS_COMMANDS) |
| 258 | + Commands.shift(); |
| 259 | + Commands.push(CommandEntry.text); |
| 260 | + Console.AddHistory(CommandEntry.text + "\n"); |
| 261 | + if(CommandEntry.text.substr(0, 5).toLowerCase() == "exui_") { |
| 262 | + var exuiCommand: String = CommandEntry.text.substr(5).toLowerCase(); |
| 263 | + if(exuiCommand == "fullscreen") { |
| 264 | + setFullscreen(); |
| 265 | + /* |
| 266 | + Background._height = Stage.height * 2; |
| 267 | + CurrentCell._y = -Stage.height; |
| 268 | + CurrentSelection._y = CurrentCell._y + CurrentCell._height; |
| 269 | + CommandHistory._y = CurrentSelection._y + CurrentSelection._height; |
| 270 | + CommandHistory._height = Math.abs(CommandEntry._y - CommandHistory._y); |
| 271 | + */ |
| 272 | + |
| 273 | + ResetCommandEntry(); |
| 274 | + return; |
| 275 | + } else if(exuiCommand == "help") { |
| 276 | + var sMessage: String = "exui_fullscreen - Expand the console to cover the entire screen.\n"; |
| 277 | + sMessage += "exui_loadmenu: FILEPATH - Open the given .swf file as a new menu. The path is relative to '\\Skyrim\\Data\\Interface' and should not include the file extension. Call again to close the menu.\n"; |
| 278 | + sMessage += "exui_log: MESSAGE - Write MESSAGE to the Papyrus log.\n"; |
| 279 | + sMessage += "exui_getcrosshairref - Get information regarding the reference, provided that it can be activated, currently in the crosshairs.\n"; |
| 280 | + sMessage += "exui_sendmodevent: EVENTNAME, STRINGARG, NUMARG - Send an SKSE mod event with the given event name, string argument, and number argument.\n"; |
| 281 | + Console.AddHistory(sMessage); |
| 282 | + |
| 283 | + ResetCommandEntry(); |
| 284 | + return; |
| 285 | + } else if(exuiCommand.substr(0, 5) == "log: ") { |
| 286 | + skse.SendModEvent("EXUI_WriteToPapyrusLog", exuiCommand.substr(5)); |
| 287 | + |
| 288 | + ResetCommandEntry(); |
| 289 | + return; |
| 290 | + } else if(exuiCommand.substr(0, 15) == "getcrosshairref") { |
| 291 | + skse.SendModEvent("EXUI_GetCurrentCrosshairRef"); |
| 292 | + |
| 293 | + ResetCommandEntry(); |
| 294 | + return; |
| 295 | + } else if(exuiCommand.substr(0, 10) == "loadmenu: ") { |
| 296 | + exuiCommand = exuiCommand.substr(10); |
| 297 | + skse.SendModEvent("EXUI_LoadMenu", exuiCommand); |
| 298 | + |
| 299 | + ResetCommandEntry(); |
| 300 | + return; |
| 301 | + } else if(exuiCommand.substr(0, 13) == "sendmodevent:") { |
| 302 | + exuiCommand = CommandEntry.text.substr(19); |
| 303 | + |
| 304 | + sendEvent(exuiCommand.split(", ")); |
| 305 | + ResetCommandEntry(); |
| 306 | + return; |
| 307 | + } |
| 308 | + } |
| 309 | + GameDelegate.call("ExecuteCommand", [CommandEntry.text]); |
| 310 | + ResetCommandEntry(); |
| 311 | + } |
| 312 | + return; |
| 313 | + } |
| 314 | + if (Key.getCode() == 33) { |
| 315 | + var imaxScrollIndex: Number = CommandHistory.bottomScroll - CommandHistory.scroll; |
| 316 | + var iminScrollIndex: Number = CommandHistory.scroll - imaxScrollIndex; |
| 317 | + CommandHistory.scroll = iminScrollIndex <= 0 ? 0 : iminScrollIndex; |
| 318 | + return; |
| 319 | + } |
| 320 | + if (Key.getCode() == 34) { |
| 321 | + imaxScrollIndex = CommandHistory.bottomScroll - CommandHistory.scroll; |
| 322 | + iminScrollIndex = CommandHistory.scroll + imaxScrollIndex; |
| 323 | + CommandHistory.scroll = iminScrollIndex > CommandHistory.maxscroll ? CommandHistory.maxscroll : iminScrollIndex; |
| 324 | + } |
| 325 | + } |
| 326 | + |
| 327 | + private function sendEvent(parameters: Array): Void |
| 328 | + { |
| 329 | + if((parameters.length <= 3) && (parameters.length > 0)) { |
| 330 | + if(parameters[2] != undefined) |
| 331 | + parameters[2] = Number(parameters[2]); |
| 332 | + |
| 333 | + if(parameters.length == 1) |
| 334 | + skse.SendModEvent(parameters[0]); |
| 335 | + |
| 336 | + if(parameters.length == 2) |
| 337 | + skse.SendModEvent(parameters[0], parameters[1]); |
| 338 | + |
| 339 | + if(parameters.length == 3) |
| 340 | + skse.SendModEvent(parameters[0], parameters[1], parameters[2]); |
| 341 | + } |
| 342 | + } |
| 343 | + |
| 344 | + function onResize(): Void |
| 345 | + { |
| 346 | + Background._width = Stage.width; |
| 347 | + CommandEntry._width = CommandHistory._width = CurrentSelection._width = CurrentCell._width = Stage.width - TextXOffset * 2; |
| 348 | + Console.SetSize(ScreenPercent); |
| 349 | + } |
| 350 | + |
| 351 | + public function setCurrentCell(/* values */): Void |
| 352 | + { |
| 353 | + /* |
| 354 | + arguments[1] = arguments[1].toString(16).toUpperCase(); |
| 355 | + while(arguments[1].length < 8) { |
| 356 | + arguments[1] = "0" + arguments[1]; |
| 357 | + } |
| 358 | + */ |
| 359 | + arguments[1] = generateFormID(arguments[1]); |
| 360 | + if (Console.ConsoleInstance != null) |
| 361 | + Console.ConsoleInstance.CurrentCell.text = "Current cell: '" + arguments[0] + "' (FormID " + arguments[1] + ")"; |
| 362 | + } |
| 363 | + |
| 364 | + public function setCurrentCrosshairRef(/* values */): Void |
| 365 | + { |
| 366 | + arguments[1] = generateFormID(arguments[1]); |
| 367 | + arguments[2] = generateFormID(arguments[2]); |
| 368 | + var sMessage: String = "Current crosshair reference: '" + arguments[0] + "' (ReferenceID " + arguments[2] + ", FormID " + arguments[1] + ")"; |
| 369 | + Console.AddHistory(sMessage + "\n"); |
| 370 | + } |
| 371 | + |
| 372 | + private function generateFormID(anFormID: Number): String |
| 373 | + { |
| 374 | + var asFormID: String = anFormID.toString(16).toUpperCase(); |
| 375 | + while(asFormID.length < 8) { |
| 376 | + asFormID = "0" + asFormID; |
| 377 | + } |
| 378 | + return asFormID; |
| 379 | + } |
| 380 | + |
| 381 | + public function setFullscreen(): Void |
| 382 | + { |
| 383 | + Background._height = Stage.height * 2; |
| 384 | + CurrentCell._y = -Stage.height; |
| 385 | + CurrentSelection._y = CurrentCell._y + CurrentCell._height; |
| 386 | + CommandHistory._y = CurrentSelection._y + CurrentSelection._height; |
| 387 | + CommandHistory._height = Math.abs(CommandEntry._y - CommandHistory._y); |
| 388 | + } |
| 389 | +} |
0 commit comments