extends Control class_name LoadingScreenNode func InitLoadingScreen(file: String) -> LoadingScreen: var loadingScreenIni = INI.Load(file) var keys = loadingScreenIni.keys() var title = keys[randi_range(0, len(keys) - 1)] var randomScreen: Dictionary = loadingScreenIni[title] var loadingScreen = LoadingScreen.new() loadingScreen.imgpath = randomScreen["image path"] if randomScreen.has("disablebackground"): loadingScreen.disablebackground = randomScreen["disablebackground"].to_lower() == "true" else: loadingScreen.disablebackground = true for i in range(1, 5): if randomScreen.has(str("text", i)): loadingScreen.txt.push_back(randomScreen[str("text", i)]) loadingScreen.alignx = randomScreen["align x"] loadingScreen.aligny = randomScreen["align y"] loadingScreen.title = title return loadingScreen var selectedLoadingScreen: LoadingScreen var background: TextureRect var loadingImage: TextureRect var bgImage: CompressedTexture2D const COUR_FONT = preload("res://GFX/font/cour/Courier New.ttf") var textPos = Vector2(0, 0) func DrawText(text: String, x: int, y: int, font, fontSize: float, shadowed: bool = false, center: bool = false): textPos.x = x textPos.y = y if center: var textSize = COUR_FONT.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, fontSize * Global.menuScale) textPos.x -= textSize.x / 2 if shadowed: draw_string(font, textPos + Vector2.ONE, text, HORIZONTAL_ALIGNMENT_LEFT, -1, fontSize * Global.menuScale, Color.BLACK) draw_string(font, textPos, text, HORIZONTAL_ALIGNMENT_LEFT, -1, fontSize * Global.menuScale) func generateTextRows(string = "", mw = 0): var arrayIndex = 0; var strings = [""]; var needToSplit = false; var justSplit = false; for chr in string: justSplit = false; if needToSplit and chr == " ": needToSplit = false justSplit = true strings.push_back("") arrayIndex += 1 if COUR_FONT.get_string_size(strings[arrayIndex], HORIZONTAL_ALIGNMENT_LEFT, -1).x > mw and !needToSplit: needToSplit = true if not justSplit: strings[arrayIndex] += chr return strings func renderTextRows(rows: Array, x: int, y: int): for i in range(rows.size()): var textSize = COUR_FONT.get_string_size(rows[i], HORIZONTAL_ALIGNMENT_LEFT, -1, 19 * Global.menuScale) DrawText(rows[i], x, y + (textSize.y * i), COUR_FONT, 19, true, true) var loadProgressIndex: int = 0 var loadingText: Array = [] var percent: int = 0 func LoadProgress(progress: int): if progress > ((100 / loadingText.size()) * (loadProgressIndex + 1)): loadProgressIndex += 1 loadProgressIndex = min(loadProgressIndex, loadingText.size() - 1) percent = progress queue_redraw() func _ready() -> void: background = $Background loadingImage = $LoadingImage selectedLoadingScreen = InitLoadingScreen("Loadingscreens\\loadingscreens.ini") if selectedLoadingScreen.disablebackground: background.visible = false else: bgImage = Global.LoadTexture("Loadingscreens/loadingback.jpg") background.texture = bgImage background.visible = true #selectedLoadingScreen.img = ImageTexture.create_from_image(Utils.KeyBackground(Global.LoadTexture(str("Loadingscreens/", selectedLoadingScreen.imgpath)), Color(0, 0, 0, 1))) selectedLoadingScreen.img = Global.LoadTexture(str("Loadingscreens/", selectedLoadingScreen.imgpath)) loadingImage.texture = selectedLoadingScreen.img for text in selectedLoadingScreen.txt: loadingText.push_back(generateTextRows(text, 400)) # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta: float) -> void: Global.menuScale = size.y / 1024.0 if background.visible: background.size.x = bgImage.get_width() * Global.menuScale background.size.y = bgImage.get_height() * Global.menuScale background.position.x = size.x / 2 - background.size.x / 2 background.position.y = size.y / 2 - background.size.y / 2 loadingImage.size.x = selectedLoadingScreen.img.get_width() * Global.menuScale loadingImage.size.y = selectedLoadingScreen.img.get_height() * Global.menuScale match selectedLoadingScreen.alignx: "center": loadingImage.position.x = size.x / 2 - loadingImage.size.x / 2 "right": loadingImage.position.x = size.x - loadingImage.size.x match selectedLoadingScreen.aligny: "center": loadingImage.position.y = size.y / 2 - loadingImage.size.y / 2 "bottom": loadingImage.position.y = size.y - loadingImage.size.y @onready var binkMeterImg = Global.LoadTexture("GFX/BlinkMeter.jpg") var firstloop = true var nomore = false var loaded = false func _draw(): Global.menuScale = size.y / 1024.0 var width = 300 var height = 20 var x = size.x / 2 - width / 2 var y = size.y / 2 + 30 - 100 Utils.DrawLineRect(self, x, y, width + 4, height, Color.WHITE) print(int((width - 2) * (percent / 100.0) / 10)) for i in range(1, int((width + 10) * (percent / 100.0) / 10)): Utils.DrawImage(self, binkMeterImg, x + 3 + 10 * (i - 1), y + 3) if selectedLoadingScreen.title == "CWM": pass # TODO! else: DrawText(selectedLoadingScreen.title, size.x / 2 + 1, size.y / 2 + 80 + 1, COUR_FONT, 58, true, true) renderTextRows(loadingText[loadProgressIndex], size.x / 2, size.y / 2 + 121) DrawText(str("LOADING - ", percent, " %"), size.x / 2, size.y / 2 - 100, COUR_FONT, 19, true, true) if percent == 100: #If firstloop And SelectedLoadingScreen\title <> "CWM" Then PlaySound_Strict LoadTempSound(("SFX\Horror\Horror8.ogg")) if firstloop: firstloop = false loaded = true Global.PlayTempSound("SFX/Horror/Horror8.ogg") DrawText("PRESS ANY KEY TO CONTINUE", size.x / 2, size.y - 50, COUR_FONT, 19, false, true)