Simple Sliding Interface

  • #1, by redsparkSaturday, 03. December 2016, 19:24 3 years ago
    I was looking at the various sliding interface examples and they make my brain hurt looking at them.  So I tried to come up with a simple version.  It requires a Value and a Condition created in the interface that stores the state of the interface.  But it seems to work.

    Can anyone tell me if there is something wrong with doing it this way?  Thanks.

    The code is as follows:
    --[[
    *********************************************************************************
    INVENTORY
    *********************************************************************************]]--
    local inventory_States = {
    [1] = function () end, -- Holding state
    [2] = function () -- Lower State
    local inventory = getObject("Interfaces[inventory]")
    local p = inventory:getPoint(VInterfaceOffset)
    if p.y<=640 then
    getObject("Values[inventory_state]"):setValue(VValueInt, 1)
    getObject("Conditions[inventory_lowered]"):setValue(VConditionValue, true)
    else
    p.y= p.y-2
    inventory:setValue(VInterfaceOffset,p)
    end
    end,
    [3] = function () -- Raise State
    local inventory = getObject("Interfaces[inventory]")
    local p = inventory:getPoint(VInterfaceOffset)
    if p.y>=696 then
    getObject("Values[inventory_state]"):setValue(VValueInt, 1)
    getObject("Conditions[inventory_lowered]"):setValue(VConditionValue, false)
    else
    p.y= p.y+2
    inventory:setValue(VInterfaceOffset,p)
    end
    end
    }
    --[[
    *********************************************************************************
    HANDLERS
    *********************************************************************************]]--
    function onMainLoop()
    -- Update Inventory Interface
    local inventory_state = getObject("Values[inventory_state]"):getInt(VValueInt)
    inventory_States[inventory_state]()
    end

    registerEventHandler("mainLoop", "onMainLoop")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

    Forum Fan

    117 Posts


  • #2, by afrlmeSaturday, 03. December 2016, 21:23 3 years ago
    I don't think so, but I have shared much simpler methods a little while ago that only required a few lines of script thanks to Simon's addition of both shorthand Lua script & the to tween funtion.

    Here's a quick example...
    local int = Interfaces["example"]

    if int.InterfaceOffset == 0 then -- slide in with slow easing
     int:to(3000, { InterfaceOffset = {x = -200, y = int.InterfaceOffset.y} }, easeQuintIn)
    elseif int.InterfaceOffset == -200 then -- slide out with bounce at end
     int:to(3000, { InterfaceOffset = {x = 0, y = int.InterfaceOffset.y} }, easeBounceOut)
    end
    1
    2
    3
    4
    5
    6
    7


    Quick note: the example is just for sliding out from the left side of the screen. It's not as elaborate as my Deponia slide out interface as this is just for one direction & only triggers if interface is at fully open or fully closed position unlike the deponia one which had a bit of math query to allow interupting mid-open while keeping the same slide movement speed. Still this is much simpler & it works + easing options. smile

    * edit: updated script. Forgot to close off the data structure bits correctly with an additional }

    Imperator

    6809 Posts

  • #3, by redsparkSunday, 04. December 2016, 00:43 3 years ago
    Thank you.  I'll try to see what I can do with that.  I like the easing. smile

    Forum Fan

    117 Posts

  • #4, by afrlmeSunday, 04. December 2016, 01:30 3 years ago
    No problem. wink

    Here's a quick breakdown of the to() functions I included...
    -- game/object/animation/character:to(delay, {data structure field you want to affect - can actually add multiple fields by separating with ,}, easing, loop, pendulum)

    game.CurrentScene.SceneObjects["ball"]:to(10000, {Rotation = math.rad(360)}, easeLinearOut, true, false) -- rotate ball continous 360 degrees (clockwise - I think) over 10 seconds

    ActiveAnimations["cloud"]:to(math.random(10000, 30000), { AnimationCurrentPosition = {x = -500, y = ActiveAnimations["cloud"].AnimationCurrentPosition.y} }, easeLinearOut, true, false) -- move cloud over random time then reset back to initial position once destination reached (only really good if animation initial position is outside of the scene)
    1
    2
    3
    4
    5
    6

    Imperator

    6809 Posts

  • #5, by redsparkSunday, 04. December 2016, 13:34 3 years ago
    Thanks.  So with the to() function you can schedule movement of any object.  That's a lot easier than what I had.

    Forum Fan

    117 Posts

  • #6, by afrlmeSunday, 04. December 2016, 15:40 3 years ago
    You can use the to() tweening function for transitioning lots of things from current scene brightness to another. Or the current integer value of a vs value, or the position of something such as an animation, interface or scene object. Or the opacity of a scene object, character or interface, or the volume level of the background music for a scene & so on & so on. I think it's one of the most useful functions that Simon has added to VS overall as I use it for a lot of things.

    P.S: pretty much any data structure field that is a number in some form or another can be affected by it, so that's position coordinates, opactity, volume levels, integer & float values, etc. Very useful & saves a lot of time. Wish it had been around when I wrote my first & second Deponia sliding interface scripts...

    Imperator

    6809 Posts

  • #7, by sebastianSunday, 04. December 2016, 20:18 3 years ago
    P.S: pretty much any data structure field that is a number in some form or another can be affected by it, so that's position coordinates, opactity, volume levels, integer & float values, etc. Very useful & saves a lot of time. Wish it had been around when I wrote my first & second Deponia sliding interface scripts...

    I would love to see these in the wiki with examples  grin

    Thread Captain

    2336 Posts

  • #8, by afrlmeSunday, 04. December 2016, 20:56 3 years ago
    I provided a few examples above. I don't think the to() function is documented at all in the wiki? Could be wrong though.

    Imperator

    6809 Posts

  • #9, by bananeisafreeMonday, 05. December 2016, 11:54 3 years ago
    Hmm, question, is there an equivalent to the "interfaceoffset" command but just for buttons (or objects for that matter) ?
    The idea here would be to have a button just peeking behind the main chunk of the interface and placing your mouse / clicking on it would reveal the rest.

    It would be pretty neat on a VerbCoin !

    Forum Fan

    120 Posts

  • #10, by sebastianMonday, 05. December 2016, 12:33 3 years ago
    when the Button has an animation,you can move that animation smile 

    Thread Captain

    2336 Posts

  • #11, by afrlmeMonday, 05. December 2016, 12:39 3 years ago
    You would have to create each button as a new interface. For scene objects sure, because you can use either of the move object action parts found under scene actions added to one of the prior versions of VS 4.x.

    As for interfaces, you can create new interface classes via the explorer tool. It's been explained a few times on here before, so see if you can find it via search.

    Anyway, you can open up the explorer tool with ctrl+e or you can find it via the menu bar under tools > explorer. Here's a super quick rundown of creating new interface classes (should you need them)...

    1. open up the explorer tool

    2. scroll down the explorer tool list until you find eInterfaceClasses.

    3. right click on it & select the create option (only option there is).

    4. left click on the newly created interface class. Give it an appropriate name.

    5. expand the new interface & left click on InterfaceClassName & give that the same name as what you just called the new interface class (!important).

    6. rinse & repeat for any other interface classes you want to create.

    ----

    @Sebastian: aye the animation, but not the interaction polygon. I guess it depends if they need to move that too.

    Imperator

    6809 Posts

Write post