Modding Help Interface scripting (advanced advice needed)

Discussion in 'Starbound Modding' started by captainrumbarrels, Jun 6, 2022.

  1. captainrumbarrels

    captainrumbarrels Phantasmal Quasar

    Ahoy me hearties

    I'm in the process of making an interface that is tied to an object. I want the interface to do the following:

    1. Behave like a storage container. I managed to accomplish this with the use of the itemgrid widget. I have tried making a series of itemslot widgets but I cannot get item swapping to function properly. I have scoured the forums at the modding page regarding script panes in the wiki. I also ran a search in the game files and the closest vanilla interface that facilitates what I need is the mech interface.

    This is the simplest lua function I have seen to facilitate this. Afaik this can be useful in having a container interface without other dependencies in the JSON object code. It also means I can launch the window as a "scriptPane" rather than "uiConfig"

    Code:
    function swapItem(widgetName)
      if self.disabled then return end
    
      local partType = string.sub(widgetName, 10)
    
      local currentItem = self.itemSet[partType]
      local swapItem = player.swapSlotItem()
    
      if not swapItem or self.partManager:partConfig(partType, swapItem) then
        player.setSwapSlotItem(currentItem)
        widget.setItemSlotItem(widgetName, swapItem)
        self.itemSet[partType] = swapItem
    
        itemSetChanged()
      end
    end

    2. I have tried implementing a scroll list for some basic crafting. I want the interface to have a list of items that I declare in the interface config itself and populate those items, in a similar way to the tech interface.

    Code:
        "scrollArea" : {
          "type" : "scrollArea",
          "rect" : [5, 69, 174, 230],
          "children" : {
            "itemList" : {
              "type" : "list",
              "schema" : {
                "selectedBG" : "/interface/crafting/craftableselected2.png",
                "unselectedBG" : "/interface/crafting/craftablebackground.png",
                "spacing" : [0, 1],
                "memberSize" : [159, 20],
                "listTemplate" : {
                  "background" : {
                    "type" : "image",
                    "file" : "/interface/crafting/craftablebackground.png",
                    "position" : [2, 0],
                    "zlevel" : -1
                  },
                  "itemName" : {
                    "type" : "label",
                    "position" : [25, 5],
                    "hAnchor" : "left",
                    "wrapWidth" : 116,
                    "value" : "Replace Me"
                  },
                  "itemIcon" : {
                    "type" : "itemslot",
                    "position" : [3, 1],
                    "callback" : "null"
                  },
                  "newIcon" : {
                    "type" : "image",
                    "position" : [119, 5],
                    "file" : "/interface/crafting/new.png",
                    "zlevel" : 2
                  },
                  "moneyIcon" : {
                    "type" : "image",
                    "position" : [122, 1],
                    "file" : "/interface/money.png"
                  },
                  "priceLabel" : {
                    "type" : "label",
                    "position" : [134, 1],
                    "hAnchor" : "left",
                    "value" : "0"
                  },
                  "notcraftableoverlay" : {
                    "type" : "image",
                    "file" : "/interface/crafting/notcraftableoverlay.png",
                    "position" : [2, 0],
                    "zlevel" : 1
                  }
                }
              }
            }
          }
        },

    I have examined the lua functions corresponding to widgets to see how to use them by comparing them to existing vanilla interfaces and again to no avail. Right now I managed to implement a radiogroup widget in the list. When a specific button is toggled, and the craft button is pressed, the lua will check item requirements by checking the player's inventory for those items. I'm also trying to add the spinner widget like in vanilla crafting interfaces but this too is proving challenging. I have experience with spinner widget callbacks for increasing and decreasing values. I don't know how to go about setting the textbox text and having the interface remember that value. I feel confident once figured out I can use that value to set limits on how many items a player can craft. Otherwise the player will be limited to mashing the craft button over and over, and I'll have to make due to with only increasing or decreasing desired object craft amount to the spinner widget.


    3. I Wish to have a input output conversion option. Like a refinery, I want the player to put food waste in 1 input slot, press a button and have specific item or items, in specific output slot / slots. This ties in with the first issue of item slots and item grids.


    A lot of what I want to do seems hard coded, and other code seems to be readily available in the scripted interfaces, but I know what I wish to do IS POSSIBLE, I know scripted vanilla interfaces do what I want to do, I just don't know how to write the lua to mimic that functionality and strip away all the useless stuff I see in these interfaces to do a basic function.

    Advice on this would be greatly appreciated as I have spent quite some time looking at the files before posting this.

    Kind Regards
    - The Fabled Rum Captain
     
  2. Amegatron

    Amegatron Scruffy Nerf-Herder

    Sorry, but from what you've written I can't actually understand what exactly the problem is. I mean, you wrote a lot about what you need, but it's not clear where the problem(s) exactly is.
     

Share This Page