Active image for dragged item

  • #1, by EvrenTuesday, 15. April 2014, 17:00 10 years ago
    I want to use an active image for inventory item. When dragging the item if cursor is above a scene object or another inventory item I want the cursor image (item image) to change to an active image of that item, and go back to initial image when when there is no scene object. There is no active image section for items, is there an easy workaround for this? It would be a very nice feature smile

    Newbie

    19 Posts


  • #2, by afrlmeTuesday, 15. April 2014, 18:05 10 years ago
    not for dragged items no, but you could essentially create cursors of each item which contain an active/inactive image/animation & when you set the dragged item you swap the cursor containing the dragged item image to the cursor alternative.

    I don't use dragged items myself so I'm not sure if the dragged item cursor is a static image or uses the animation linked to the item? if it uses the animation linked to the item then you could use mouseEvent handler mouse move in a Lua script with some queries to get current dragged item & to check if something is underneath the cursor & then to force the animation of the linked item to play between x & y frame values. In this way you could add inactive state & active state inside of same animation.

    Well it's 2 viable options, I can think of, off the top of my head.

    Imperator

    7278 Posts

  • #3, by EvrenWednesday, 16. April 2014, 00:05 10 years ago
    If I put an animation it and leave image empty it uses animation both in cursor but also in the inventory. Now I have to stop animation all inventory item animations, if that is possible. Maybe it can be done iterating items. Then stop the dragged item's animation, which I can't think of how. Then another script for mouse events. Will I have to check each scene objects and inventory myself too?
    I'll add it on wishlist thread and hope it comes true grin

    Newbie

    19 Posts

  • #4, by afrlmeWednesday, 16. April 2014, 00:42 10 years ago
    hmm no it can be done quite globally... I've already written several scripts for Marvel & various other people which work on their own.

    It's too late for me to type out a script or example code block now, but the basic gist of it would be...
    * add the animation frame(s) to the beginning or end of the item animation that you are wanting to use for the inactive cursor image/animation. Next you add the frames that contain the active image/animation.

    After this we would create a definition script which contains a registerEventHandler with the mouseEvent listener & then we would create a function for the mouseEvent which listens out for when mouse cursor moves... inside this we would query something along the lines of: if current item is a dragged item and an object exists below cursor then get current dragged item, set first/last animation frame values of the current item (this would force it to play between the 2 set values we have just set & ignore the other frames... else if dragged item exists & object below cursor is empty then set frames belonging to inactive animation/image... etc.

    It's a lot simpler than how it actually sounds. Just hard to explain in detail with a few short words. wink

    * edit: I actually wrote a script for one of the members on here last year I think for controlling the animations of the items in inventory. The guy wanted to make the item animation play some kind of pop into inventory effect then change to a static image afterwards. We did that by setting animation frames of new item & on scene start we used a for loop to iterate over all the items already in the inventory to make sure they were correctly set to the static frame.

    Imperator

    7278 Posts

  • #5, by EvrenSunday, 20. April 2014, 04:56 10 years ago
    I thought of adding frames to the animation, but I don't know how to stop item animation. You cannot add an action part to a frame. You do but you can't access item animations from there. Maybe add lua script and stop animation of the object which has that script? How do you do that?
    For another solution, I made the first frame play infinitely. Maybe that will behave like stop animation. So if I change frame that frame will be shown infinitely.

    Also how do I check if there is an object under cursor?

    I'm pretty busy with other things, if this feature will be added in the future I may be able to skip working on this for now.

    Newbie

    19 Posts

  • #6, by afrlmeSunday, 20. April 2014, 13:21 10 years ago
    You can only manipulate active animations (it has to be on screen or preloaded)

    for instance for your item animation you would edit the final animation frame of the inactive part of the animation & click on the actions section & create an execute a script action part containing something like:
    local anim = getObject("ActiveAnimations[item_name]") -- replace item_name with general item name
    anim:setValue(VAnimationFirstFrame, 1) -- replace 1 with first frame of animation chunk + 1
    anim:setValue(VAnimationLastFrame, 4) -- replace 4 with current frame number + 1
    

    * note: animation frames actually start at 1 & not 0 as it says in the editor. hence the reason for + 1.

    What I have done above is forcing the animation to play between the frame values I have set... so say I set the first & last frame to "1", then it would only play the first frame only.

    -- * --

    You can check if an object is under the cursor via various if query action parts or you can use Lua if you want to get the name & manipulate the object underneath the cursor.
    game:getLink(VGameCurrentObject) -- returns the object currently underneath the cursor or returns empty.
    

    local obj = game:getLink(VGameCurrentObject)
    
    if not obj:isEmpty() then -- if object is not empty
     print("the current object is " .. obj:getName())
    end
    

    Imperator

    7278 Posts