diff --git a/assets/OEM437_12.png b/assets/OEM437_12.png new file mode 100644 index 0000000..e8e1fb3 Binary files /dev/null and b/assets/OEM437_12.png differ diff --git a/assets/micro-font.png b/assets/micro-font.png new file mode 100644 index 0000000..493d5c4 Binary files /dev/null and b/assets/micro-font.png differ diff --git a/main.ms b/main.ms index 7659905..2f6fe7e 100644 --- a/main.ms +++ b/main.ms @@ -72,12 +72,72 @@ ensureImport "townGenerator" ensureImport "mapgen" ensureImport "fov" +ensureImport "constants" ensureImport "keybindings" ensureImport "settings" Display = {} +HeadsUpDisplay = {} + +HeadsUpDisplay.initTiles = function(displayNumber) + display(displayNumber).mode = displayMode.tile + display(displayNumber).tileSet = file.loadImage("assets/OEM437_8.png") + display(displayNumber).tileSetTileSize = 8 + display(displayNumber).cellSize = 16 + display(displayNumber).extent = [constants.TILE_DISPLAY_WIDTH, constants.TILE_DISPLAY_HEIGHT] + return display(displayNumber) +end function + +HeadsUpDisplay.init = function(displayNumberFront, displayNumberBack) + self.display = self.initTiles(displayNumberFront) + self.displayBack = self.initTiles(displayNumberBack) + return self +end function + +HeadsUpDisplay.setCellBackColor = function(x, y, backColor) + if backColor isa Color then + backColor = backColor.str() + end if + self.displayBack.setCell x, y, constants.TILE_INDEX_SOLID + self.displayBack.setCellTint x, y, backColor +end function + +HeadsUpDisplay.setCell = function(x, y, tile, color="#FFFFFF", backColor = "#00000000") + if tile isa string then + tile = code(tile) + end if + if color isa Color then + color = color.str() + end if + self.display.setCell x, y, tile + self.display.setCellTint x, y, color + self.setCellBackColor x, y, backColor +end function + +HeadsUpDisplay.clear = function() + for y in range(0, constants.TILE_DISPLAY_YMAX) + for x in range(0, constants.TILE_DISPLAY_XMAX) + self.setCell x, y, 0, color.black, color.clear + end for + end for +end function + +HeadsUpDisplay.print = function(text, x, y, color="#FFFFFF", backColor="#00000000") + for ch in text + self.setCell x, y, code(ch), color, backColor + x += 1 + end for +end function + Display.initialize = function() + HUD = 0 + HUD_BACK = 1 + PARTICLES_0 = 2 + PARTICLES_1 = 3 + MAP_0 = 4 + MAP_1 = 5 + activate = function(n) display(n).mode = displayMode.text display(n).delimiter = "" @@ -89,40 +149,45 @@ Display.initialize = function() return display(n) end function - Display.hud = activate(0) + activateTiles = function(n) + return HeadsUpDisplay.init(n) + end function + + // Display.hud = activate(0) + Display.hud = HeadsUpDisplay.init(HUD, HUD_BACK) - Display.particles = activate(1) - deactivate(1) - activate(2) + Display.particles = activate(PARTICLES_0) + deactivate(PARTICLES_0) + activate(PARTICLES_1) - Display.particles = display(1) + Display.particles = display(PARTICLES_0) Display.flipParticles = function() - if display(1).mode == displayMode.off then - display(1).mode = displayMode.text - display(2).mode = displayMode.text - Display.particles = display(2) - display(2).mode = displayMode.off + if display(PARTICLES_0).mode == displayMode.off then + display(PARTICLES_0).mode = displayMode.text + display(PARTICLES_1).mode = displayMode.text + Display.particles = display(PARTICLES_1) + display(PARTICLES_1).mode = displayMode.off else - display(1).mode = displayMode.text - display(2).mode = displayMode.text - Display.particles = display(1) - display(1).mode = displayMode.off + display(PARTICLES_0).mode = displayMode.text + display(PARTICLES_1).mode = displayMode.text + Display.particles = display(PARTICLES_0) + display(PARTICLES_0).mode = displayMode.off end if end function - Display.map = activate(3) - deactivate(3) - activate(4) + Display.map = activate(MAP_0) + deactivate(MAP_0) + activate(MAP_1) Display.flipMap = function() - if display(3).mode == displayMode.off then - activate(3) - Display.map = activate(4) - deactivate(4) + if display(MAP_0).mode == displayMode.off then + activate(MAP_0) + Display.map = activate(MAP_1) + deactivate(MAP_1) else - activate(4) - Display.map = activate(3) - deactivate(3) + activate(MAP_1) + Display.map = activate(MAP_0) + deactivate(MAP_0) end if end function end function @@ -167,20 +232,20 @@ drawEntities = function(display, map, renderOffset) end function drawHUD = function(display, player) - display.color = color.clear - display.backColor = color.clear + // display.color = color.clear + // display.backColor = color.clear display.clear() - display.row = 26 + // display.row = 26 - display.column = 0 - display.color = color.white - display.backColor = color.black + // display.column = 0 + // display.color = color.white + // display.backColor = color.black statusBar = "HP: {0} / {1} LVL: {2} XP: {3} / {4} world: {5}".fill([player.currentHP, player.maxHP, player.level, player.xp, player.xpToNextLevel, Service.world.currentLevel]) statusBar = statusBar + " " * (67 - statusBar.len) - display.print(statusBar) - + display.print(statusBar, 0, 39, color.white, color.black) + Service.messages.update() end function diff --git a/src/hud.ms b/src/hud.ms index 4616c9f..6e4a0c7 100644 --- a/src/hud.ms +++ b/src/hud.ms @@ -11,12 +11,10 @@ Message.make = function(text, foregroundColor = null, backgroundColor = null) end function Message.draw = function(row) - Display.hud.row = row - Display.hud.column = 0 ratio = self.lifeSpan / self.maxLifeSpan - Display.hud.color = color.lerp(color.clear, self.foregroundColor, ratio) - Display.hud.backColor = color.lerp(color.clear, self.backgroundColor, ratio) - Display.hud.print(self.text) + fg = color.lerp(color.clear, self.foregroundColor, ratio) + bg = color.lerp(color.clear, self.backgroundColor, ratio) + Display.hud.print self.text, 0, row, fg, bg end function MessageLog = {} diff --git a/src/ui.ms b/src/ui.ms index cc8130f..361b737 100644 --- a/src/ui.ms +++ b/src/ui.ms @@ -5,9 +5,12 @@ DEFAULT_BACKGROUND_COLOR = color.black drawCell = function(display, x, y, fg, bg, text) if fg isa Color then fg = fg.str() if bg isa Color then bg = bg.str() - display.setCell(x, y, text) - display.setCellColor(x, y, fg) - display.setCellBackColor(x, y, bg) + + // display.setCell(x, y, text) + // display.setCellColor(x, y, fg) + // display.setCellBackColor(x, y, bg) + + display.setCell x, y, text, fg, bg end function clearRect = function(display, bounds, text = null, foregroundColor = null, backgroundColor = null) @@ -38,30 +41,34 @@ drawCenteredText = function(display, x1, x2, y, fg, bg, text) if bg isa Color then bg = bg.str() centerX = floor((x1 + x2) / 2) - display.row = y - display.column = centerX - floor(text.len / 2) - display.color = fg - display.backColor = bg - display.print(text) + + // display.row = y + // display.column = centerX - floor(text.len / 2) + // display.color = fg + // display.backColor = bg + // display.print(text) + + display.print text, centerX - floor(text.len / 2), y, fg, bg end function // Returns the number of lines printed. -drawText = function(display, text, bounds, fg, bg) - display.backColor = math.coalesce(bg, DEFAULT_BACKGROUND_COLOR) - display.color = math.coalesce(fg, DEFAULT_FOREGROUND_COLOR) +drawText = function(display, text, bounds, fg, bg=null) + color = math.coalesce(fg, DEFAULT_FOREGROUND_COLOR) + backColor = math.coalesce(bg, DEFAULT_BACKGROUND_COLOR) lineCount = 0 while text - display.row = bounds.bottom - lineCount - display.column = bounds.x + x = bounds.x + y = bounds.bottom - lineCount + if text.len <= bounds.width then - display.print(text) + display.print text, x, y, color, backColor return lineCount + 1 end if foundCut = false for i in range(bounds.width, 0) if text[i] == " " then - display.print(text[:i]) + display.print text[:i], x, y, color, backColor text = text[i + 1:] foundCut = true break @@ -69,7 +76,7 @@ drawText = function(display, text, bounds, fg, bg) end for if not foundCut then // Couldn't find a space to cut on so, out of desperation, just cut at width. - display.print(text[:bounds.width]) + display.print text[:bounds.width], x, y, color, backColor text = text[bounds.width:] end if lineCount += 1 @@ -86,21 +93,21 @@ WINDOW_TITLE_BACKGROUND = color.black drawWindow = function(display, bounds, title=null) ui.clearRect(display, bounds) - drawVerticalLine(display, bounds.left, bounds.top + 1, bounds.bottom - 1, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "|") - drawVerticalLine(display, bounds.right, bounds.top + 1, bounds.bottom - 1, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "|") - drawHorizontalLine(display, bounds.left + 1, bounds.right - 1, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "-") - drawHorizontalLine(display, bounds.left + 1, bounds.right - 1, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "-") + drawVerticalLine(display, bounds.left, bounds.top + 1, bounds.bottom - 1, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 186) + drawVerticalLine(display, bounds.right, bounds.top + 1, bounds.bottom - 1, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 186) + drawHorizontalLine(display, bounds.left + 1, bounds.right - 1, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 205) + drawHorizontalLine(display, bounds.left + 1, bounds.right - 1, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 205) - drawCell(display, bounds.left, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "+") - drawCell(display, bounds.right, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "+") - drawCell(display, bounds.left, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "+") - drawCell(display, bounds.right, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "+") + drawCell(display, bounds.left, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 200) + drawCell(display, bounds.right, bounds.top, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 188) + drawCell(display, bounds.left, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 201) + drawCell(display, bounds.right, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 187) if title != null then title = " {0} ".fill([ title ]) halfLength = floor(title.len / 2) - drawCell(display, bounds.centerX - halfLength - 2, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "]") - drawCell(display, bounds.centerX - halfLength + title.len - 1, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, "[") + drawCell(display, bounds.centerX - halfLength - 2, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 181) + drawCell(display, bounds.centerX - halfLength + title.len - 1, bounds.bottom, WINDOW_BORDER_FOREGROUND, WINDOW_BORDER_BACKGROUND, 198) drawCenteredText(display, bounds.left, bounds.right, bounds.bottom, WINDOW_TITLE_FOREGROUND, WINDOW_TITLE_BACKGROUND, title) end if diff --git a/src/ui/ExamineSelectListItem.ms b/src/ui/ExamineSelectListItem.ms index c2bb3c8..4cbb5e2 100644 --- a/src/ui/ExamineSelectListItem.ms +++ b/src/ui/ExamineSelectListItem.ms @@ -17,20 +17,17 @@ ExamineSelectListItem.draw = function(parent, isSelected) bg = parent.ITEM_BACKGROUND.str() fg = parent.ITEM_FOREGROUND.str() end if - parent.display.backColor = bg - parent.display.color = fg x = parent.listBounds.left y = parent.getItemRow(self.index) - - self.entity.tile.draw(parent.display, x, y) + + // The backgroundColor won't actually be visible. It'll be overwritten in that last for-loop. + parent.display.setCell x, y, self.entity.tile.char, self.entity.tile.foregroundColor, self.entity.tile.backgroundColor - parent.display.row = y - parent.display.column = x + 2 - parent.display.print(self.entity.str()) + parent.display.print self.entity.str(), x + 2, y, fg, bg for x in range(parent.listBounds.left, parent.listBounds.right) - parent.display.setCellBackColor(x, y, bg) + parent.display.setCellBackColor x, y, bg end for end function diff --git a/src/ui/ExamineWindow.ms b/src/ui/ExamineWindow.ms index 28b6661..90fa310 100644 --- a/src/ui/ExamineWindow.ms +++ b/src/ui/ExamineWindow.ms @@ -15,25 +15,18 @@ end function ExamineWindow.reset = function(entities) list = self.generateList(entities) - self.selectList.init(Display.hud, rect.make(4, 4, 68 - 4 * 2, 26 - 4 * 2)) + self.selectList.init(Display.hud, rect.make(4, 4, constants.TILE_DISPLAY_WIDTH - 4 * 2, constants.TILE_DISPLAY_HEIGHT - 4 * 2)) self.selectList.reset(list) end function -ExamineWindow.draw = function(title, description="") +ExamineWindow.draw = function(title) //, description="") windowBounds = self.selectList.windowBounds ui.drawWindow(Display.hud, windowBounds, title) - ui.drawVerticalLine(Display.hud, windowBounds.centerX, windowBounds.top + 1, windowBounds.bottom - 1, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, "|") + ui.drawVerticalLine(Display.hud, windowBounds.centerX, windowBounds.top + 1, windowBounds.bottom - 1, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 179) + ui.drawCell(Display.hud, windowBounds.centerX, windowBounds.top, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 207) - Display.hud.color = ui.WINDOW_BORDER_FOREGROUND - Display.hud.row = windowBounds.top - Display.hud.column = windowBounds.centerX - Display.hud.print("+") - - Display.hud.backColor = color.black - Display.hud.color = color.white - Display.hud.row = windowBounds.bottom - 1 - Display.hud.column = windowBounds.left + 1 - Display.hud.print(description) + // Unused? + // Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, color.white, color.black self.selectList.drawItems() end function diff --git a/src/ui/InventorySelectListItem.ms b/src/ui/InventorySelectListItem.ms index 9c83d39..8fb30a2 100644 --- a/src/ui/InventorySelectListItem.ms +++ b/src/ui/InventorySelectListItem.ms @@ -20,23 +20,24 @@ InventorySelectListItem.draw = function(parent, isSelected) bg = parent.ITEM_BACKGROUND.str() fg = parent.ITEM_FOREGROUND.str() end if - parent.display.backColor = bg - parent.display.color = fg x = parent.listBounds.left y = parent.getItemRow(self.index) - item.tile.draw(parent.display, x, y) + // The backgroundColor won't actually be visible. It'll be overwritten in that last for-loop. + parent.display.setCell x, y, item.tile.char, item.tile.foregroundColor, item.tile.backgroundColor - parent.display.row = y - parent.display.column = x + 2 - parent.display.print(stack.str()) + // parent.display.row = y + // parent.display.column = x + 2 + // parent.display.print(stack.str()) + parent.display.print stack.str(), x + 2, y, fg, bg if self.entity.isEquipped(item) then - parent.display.print(" [E]") + // parent.display.print(" [E]") + parent.display.print " [E]", x + 2 + stack.str().len, y, fg, bg end if for x in range(parent.listBounds.left, parent.listBounds.right) - parent.display.setCellBackColor(x, y, bg) + parent.display.setCellBackColor x, y, bg end for end function diff --git a/src/ui/InventorySelectWindow.ms b/src/ui/InventorySelectWindow.ms index edd33cf..c45142d 100644 --- a/src/ui/InventorySelectWindow.ms +++ b/src/ui/InventorySelectWindow.ms @@ -15,25 +15,18 @@ end function InventorySelectWindow.reset = function(entity) list = self.generateList(entity) - self.selectList.init(Display.hud, rect.make(4, 4, 68 - 4 * 2, 26 - 4 * 2)) + self.selectList.init(Display.hud, rect.make(4, 4, constants.TILE_DISPLAY_WIDTH - 4 * 2, constants.TILE_DISPLAY_HEIGHT - 4 * 2)) self.selectList.reset(list) end function -InventorySelectWindow.draw = function(title, description="") +InventorySelectWindow.draw = function(title) //, description="") windowBounds = self.selectList.windowBounds ui.drawWindow(Display.hud, windowBounds, title) - ui.drawVerticalLine(Display.hud, windowBounds.centerX, windowBounds.top + 1, windowBounds.bottom - 1, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, "|") + ui.drawVerticalLine(Display.hud, windowBounds.centerX, windowBounds.top + 1, windowBounds.bottom - 1, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 179) + ui.drawCell(Display.hud, windowBounds.centerX, windowBounds.top, ui.WINDOW_BORDER_FOREGROUND, ui.WINDOW_BORDER_BACKGROUND, 207) - Display.hud.color = ui.WINDOW_BORDER_FOREGROUND - Display.hud.row = windowBounds.top - Display.hud.column = windowBounds.centerX - Display.hud.print("+") - - Display.hud.backColor = color.black - Display.hud.color = color.white - Display.hud.row = windowBounds.bottom - 1 - Display.hud.column = windowBounds.left + 1 - Display.hud.print(description) + // I'm not actually using the description anywhere. + // Display.hud.print description, windowBounds.left + 1, windowBounds.bottom - 1, color.white, color.black self.selectList.drawItems() end function diff --git a/src/ui/SelectList.ms b/src/ui/SelectList.ms index 6d4dacb..9378f86 100644 --- a/src/ui/SelectList.ms +++ b/src/ui/SelectList.ms @@ -30,7 +30,7 @@ SelectList.listBounds = function() end function SelectList.detailBounds = function() - return rect.make(self.windowBounds.centerX + 1, self.windowBounds.top + 1, self.windowBounds.width / 2 - 2, self.windowBounds.height - 2) + return rect.make(self.windowBounds.centerX + 1, self.windowBounds.top + 2, self.windowBounds.width / 2 - 2, self.windowBounds.height - 3) end function SelectList.maxDisplayLines = function()