Custom interface component

  • #1, by yokalonaSunday, 29. November 2020, 02:03 3 years ago
    Hello all,
    Little disclaimer. I'm currently desiding "by prototyping" which of the adventure game engines would best fit my little side project.
    I want to have something like to-do list or goal list for a player. In short - it's just a list of text items, like:
    1. Pick up Paycheck
    2. Cash Paycheck
    3. Get Milk
    Items are added on several ocasions automaticly and automaticly removed from that list as well. List has a half-transparent background image, items are not interactive, just plain text(at least for startes).
    My first gues on how to implement that is to use inventory interface component, but, as far as I understand it has some limitations:
    1. Interface must have buttons
    2. Button not only has action(which can be empty of course), but also in some way is a picture
    3. Buttons can not be added programmaticly(is it true?), only enabled or dissabled.
    Second gues is to use scripting to dynamicly add and position "list-item" in some background image(if required), but this approach also have a bit of flaw i I'd like to see this list as one functional block.
    Is it possible to create a custom interface component? Something like extension for VS Engine? If possible, where can I found an example of any custom component or at least give me some direction where to look, please.
    What makes the task even harder is that it's just prototyping phase and it would be greate if solution for this would be as flexible as possible. 

    If I got wrong in my assumptions, please correct me.
    Any help appreciated.

    Newbie

    3 Posts


  • #2, by yokalonaMonday, 30. November 2020, 22:04 3 years ago
    After some digging, I came up with several lua classes, which describes the list item and list itself. After that I'm going to create few objects in scene, like "GetMilk" with text component in it, with required value and font, and discble or enable it if related list item is list.
    Is it the only way or am I missing something? I would like to have this list to be static(on every scene) and always visible, but not clicable, and transperent for mouse actions, dunno if it's even possible.
    Any ideas?

    Newbie

    3 Posts

  • #3, by afrlmeMonday, 30. November 2020, 22:57 3 years ago
    If it's just a dynamic list you want to display over the top of your screen as a GUI type thing, then use an interface & buttons & link values to them. Alternatively you could use Lua draw & a table for storing the list words/sentences into.

    Imperator

    7278 Posts

  • #4, by yokalonaMonday, 30. November 2020, 23:27 3 years ago
    Sorry, don't get it. Could you please provide a little more about "draw" function? I'm looking through site now, but cannot find any mentions of that function other than on forum. Am I missing something?

    Newbie

    3 Posts

  • #5, by afrlmeFriday, 04. December 2020, 12:01 3 years ago
    Sorry for the delay.

    --[[
    
    usage: (via execute a script)
    
    
    
    add_task("pick up paycheck")
    
    remove_task("pick up paycheck")
    
    ]]--
    
    
    
    task_list = {} -- create an empty table for storing tasks into
    
    tl_txt = {} -- create an empty variable for storing the task list texts
    
    
    
    function draw()
    
    
    
      if #task_list > 0 then -- check task_list table contains entries
    
        graphics.font = Fonts["example"] -- specify which font we want to use (this uses all parent properties of linked font; size, color, border, shadow, etc)
    
        tl_txt = ""
    
        -- + --
    
        for i = 1, #task_list do -- iterate through task_list entries
    
            tl_txt = tl_txt .. task_list[i] .. "\n" -- generate text to display
    
            graphics.drawFont(tl_txt, 100, 100, 1) -- text to display, x position, y position, opacity
    
        end
    
      end
    
    
    
    end
    
    
    
    graphics.addDrawFunc("draw()", 1) -- -1 = below scene, 0 = above scene, 1 = above interface
    
    
    
    function add_task(str)
    
    
    
      if #task_list > 0 then
    
       for i = 1, #task_list do
    
         if task_list[i] == str then break end
    
         if i == #task_list and task_list[i] ~= str then
    
           table.insert(task_list, str)
    
         end
    
       end
    
      else
    
       table.insert(task_list, str)
    
      end
    
    
    
    end
    
    
    
    function remove_task(str)
    
    
    
      for i = 1, #task_list do
    
        if task_list[i] == str then
    
          table.remove(task_list, i)
    
        end
    
      end
    
    
    
    end 


    Quick note: the text you insert as arguments into the add_task() & remove_task() functions are case sensitive.

    Imperator

    7278 Posts