Simple Sliding Interface

  • #1, z redsparkSaturday, 03. December 2016, 19:24 hodinky 8 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")

    Fanoušek fóra

    122 Posts


  • #2, z afrlmeSaturday, 03. December 2016, 21:23 hodinky 8 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


    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 }

    Imperátor

    7285 Posts

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

    Fanoušek fóra

    122 Posts

  • #4, z afrlmeSunday, 04. December 2016, 01:30 hodinky 8 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) 
    

    Imperátor

    7285 Posts

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

    Fanoušek fóra

    122 Posts

  • #6, z afrlmeSunday, 04. December 2016, 15:40 hodinky 8 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...

    Imperátor

    7285 Posts

  • #7, z sebastianSunday, 04. December 2016, 20:18 hodinky 8 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

    Kapitán

    2346 Posts

  • #8, z afrlmeSunday, 04. December 2016, 20:56 hodinky 8 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.

    Imperátor

    7285 Posts

  • #9, z bananeisafreeMonday, 05. December 2016, 11:54 hodinky 8 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 !

    Fanoušek fóra

    120 Posts

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

    Kapitán

    2346 Posts

  • #11, z afrlmeMonday, 05. December 2016, 12:39 hodinky 8 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.

    Imperátor

    7285 Posts