----------------------------------
-- Creates the dialogs of the game
----------------------------------
function newDialogs()
   local o = {}
   
   
   -----------------------------
   -- Constructors of the dialog
   -----------------------------
   function o:construct()
      self.dialogs = {}
      self.activeDialog = nil
      
      local sprite = newSprite("images/dialogs.png", 0, 0, 260, 125)
      self:addDialog("pause", sprite, "resume", "main-menu")
      
      sprite = newSprite("images/dialogs.png", 0, 125, 260, 125)
      self:addDialog("win", sprite, "replay", "main-menu")
      
      sprite = newSprite("images/dialogs.png", 0, 250, 260, 125)
      self:addDialog("lose-round-not-over", sprite, "finish-round", nil)
      
      sprite = newSprite("images/dialogs.png", 0, 375, 260, 125)
      self:addDialog("lose-round-over", sprite, "replay", "main-menu")
      
      return self
   end
   
   
   --------------------
   -- Adds a new dialog
   --------------------
   function o:addDialog(name, sprite, crossAction, circleAction)
      local dialog =
      {
         name = name,
         sprite = sprite,
         crossAction = crossAction,
         circleAction = circleAction,
      }
      sprite:setCenter(0.5, 0.5)
      self.dialogs[name] = dialog
   end
   
   
   ---------------------------------------
   -- Sets the active dialog from its name
   ---------------------------------------
   function o:setActiveDialog(name)
      self.activeDialog = name and self.dialogs[name]
   end
   
   
   ----------------------------------------------
   -- Gets the name of the active dialog (or nil)
   ----------------------------------------------
   function o:getActiveDialog()
      return self.activeDialog
   end
   
   
   ----------------------------------------------
   -- Seeds a button-pressed event to the dialogs,
   -- and returns the action to apply (or nil)
   ----------------------------------------------
   function o:seedButtonPress(button)
      if (self.activeDialog) then
         if (button == Button.CROSS) then
            return self.activeDialog.crossAction
         elseif (button == Button.CIRCLE) then
            return self.activeDialog.circleAction
         end
      end
   end
   
   
   ----------------------------------
   -- Updates the dialogs of the game
   ----------------------------------
   function o:update(dt)
   end
   
   
   --------------------------------
   -- Draws the dialogs of the game
   --------------------------------
   function o:draw()
      if (self.activeDialog) then
         self.activeDialog.sprite:draw(240, 136)
      end
   end
   
   
   return o:construct()
end
