diff --git a/src/config/constants.ms b/src/config/constants.ms index d83d630..05dd0b1 100644 --- a/src/config/constants.ms +++ b/src/config/constants.ms @@ -4,16 +4,16 @@ PIXEL_WIDTH = 960 PIXEL_HEIGHT = 640 TILE_SIZE = 16 -TILE_DISPLAY_WIDTH = PIXEL_WIDTH / TILE_SIZE -TILE_DISPLAY_HEIGHT = PIXEL_HEIGHT / TILE_SIZE +TILE_DISPLAY_WIDTH = floor(PIXEL_WIDTH / TILE_SIZE) +TILE_DISPLAY_HEIGHT = floor(PIXEL_HEIGHT / TILE_SIZE) TILE_DISPLAY_XMAX = TILE_DISPLAY_WIDTH - 1 TILE_DISPLAY_YMAX = TILE_DISPLAY_HEIGHT - 1 TILE_INDEX_SOLID = 219 UI_FONT_WIDTH = 16 UI_FONT_HEIGHT = 24 -UI_DISPLAY_WIDTH = PIXEL_WIDTH / UI_FONT_WIDTH -UI_DISPLAY_HEIGHT = PIXEL_HEIGHT / UI_FONT_HEIGHT +UI_DISPLAY_WIDTH = floor(PIXEL_WIDTH / UI_FONT_WIDTH) +UI_DISPLAY_HEIGHT = floor(PIXEL_HEIGHT / UI_FONT_HEIGHT) UI_DISPLAY_XMAX = UI_DISPLAY_WIDTH - 1 UI_DISPLAY_YMAX = UI_DISPLAY_HEIGHT - 1 diff --git a/src/factories/entities.ms b/src/factories/entities.ms index c7086c5..abdfd26 100644 --- a/src/factories/entities.ms +++ b/src/factories/entities.ms @@ -91,7 +91,14 @@ makeSimpleVillager = function(map, pnt) end function e.examineOverride = function() - ui.showMessage(phrases.getRandom(), e.name) + message = phrases.getRandom() + options = [ + "That's nice.", + "Bugger off.", + "You don't say?", + ] + result = ui.showMessage(message, options, e.name) + Service.messages.report("You said: '{0}'".fill([ options[result] ])) return true end function diff --git a/src/ui.ms b/src/ui.ms index a93b25a..ff44ab2 100644 --- a/src/ui.ms +++ b/src/ui.ms @@ -130,6 +130,6 @@ examine = function(entities) return (new ui.ExamineWindow).examine(entities) end function -showMessage = function(message, title="Message") - ui.MessageWindow.make(message, title).show() +showMessage = function(message, options, title="Message") + return ui.MessageWindow.make(message, options, title).show() end function diff --git a/src/ui/MessageWindow.ms b/src/ui/MessageWindow.ms index 2faa528..dc41fa9 100644 --- a/src/ui/MessageWindow.ms +++ b/src/ui/MessageWindow.ms @@ -1,32 +1,82 @@ MessageWindow = {} -MessageWindow.make = function(message, title) +MessageWindow.make = function(message, options, title) wnd = (new MessageWindow) wnd.bounds = rect.make(4, 4, constants.UI_DISPLAY_WIDTH - 4 * 2, constants.UI_DISPLAY_HEIGHT - 4 * 2) wnd.title = title wnd.message = message + + wnd.selectedOptionIndex = 0 + if options == null or options.len == 0 then + wnd.options = [ "OK" ] + else + wnd.options = options + end if + return wnd end function +MessageWindow.drawOption = function(optionIndex, isSelected) + // a=Color.white + // b=Color.black + innerBounds = self.messageBounds + text = self.options[optionIndex] + yDelta = self.options.len - optionIndex - 2 + + // c=Color.blue.light + Display.hud.print(text, innerBounds.left + 2, innerBounds.top + 1 + yDelta, Color.white, Color.black) + + if isSelected then + Display.hud.print(">", innerBounds.left, innerBounds.top + 1 + yDelta, Color.blue.light, Color.black) + end if +end function + +MessageWindow.drawOptions = function() + for n in range(self.options.len - 1) + isSelected = (self.selectedOptionIndex == n) + // globals.err=[self.selectedOptionIndex, isSelected, n] + self.drawOption(n, isSelected) + end for +end function + MessageWindow.draw = function() ui.drawWindow(Display.hud, self.bounds, self.title) lineCount = ui.drawText(Display.hud, self.message, self.messageBounds) + + self.drawOptions() end function // Returns the index of the selected item. MessageWindow.show = function() - self.draw + self.draw() result = null while true delta = 0 k = key.get.code - if keybindings.exit.contains(k) then + if keybindings.up.contains(k) then + delta = -1 + else if keybindings.down.contains(k) then + delta = 1 + else if keybindings.exit.contains(k) then + result = -1 break else if keybindings.select.contains(k) then + result = self.selectedOptionIndex break end if + + if delta != 0 then + self.selectedOptionIndex += delta + if self.selectedOptionIndex < 0 or self.selectedOptionIndex >= self.options.len then + self.selectedOptionIndex -= delta + else + self.draw() + end if + end if end while + + return result end function MessageWindow.messageBounds = function()