Difference between revisions of "Deponia Based Sliding Interface (CMS)"

From The Official Visionaire Studio: Adventure Game Engine Wiki
(Created page with "{| class="wikitable" style="width:100%" |- ! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By |- | Global Command Checker || De...")
 
Line 3: Line 3:
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
! style="text-align:left" | Name !! style="text-align:left" | Type !! style="text-align:left" | By
 
|-
 
|-
| Global Command Checker || Definition || AFRLme
+
| Deponia Based Sliding Interface || Definition || AFRLme
 
|}
 
|}
  
This script allows you to check which commands can be executed on each object, item or character. This script was made with the coin interface in mind.
+
This script allows you to slide interfaces in - or out - from any direction, on hover or via the mouse wheel.
 +
 
 +
'''''* this page is a work in progress *'''''
  
 
== Instructions ==
 
== Instructions ==
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
 
1. Add the [[#Main_Script|main script]] to the Visionaire Studio Script Editor & set the script as a definition script.<br/>
2. Replace the strings inside of the '''t''' table with the name of your commands; the order is not important, but the names are case sensitive.
+
2. Replace ''inventory'' with whatever name you gave your interface; names are case sensitive.
 +
<syntaxhighlight>
 +
local getInterface = getObject("Interfaces[add interface name here]")
 +
</syntaxhighlight>
 +
3a. Edit ''minOffset'' x & y values; these should reflect initial starting point of the interface.
 +
<syntaxhighlight>
 +
local minOffset = {x = 0, y = 0}
 +
</syntaxhighlight>
 +
3b. Edit ''maxOffset'' x & y values; these should reflect the destination position for the interface.
 
<syntaxhighlight>
 
<syntaxhighlight>
local t = {"close", "examine", "give", "open", "pick_up", "pull", "push", "talk", "use"}
+
local maxOffset = {x = 0, y = 0}
 
</syntaxhighlight>
 
</syntaxhighlight>
3a. Inside of the '''condition''' tab of your your command interface, create a condition for each command you have created; the names should reflect the names given to the interface buttons & those of the '''t''' table.<br/>
+
3c. Edit ''mwOffset'' value; this should reflect the overlap amount of the interface from screen edge - to hide interface on mouse wheel mode; set 0 to keep overlap.
3b. Add "_cond" prefix to the end of each of the conditions you just created; like so...
 
<pre>use_cond
 
talk_cond
 
etc...</pre>
 
4. On mouse over for each object, item & character, create an ''execute a script'' action containing...
 
 
<syntaxhighlight>
 
<syntaxhighlight>
checkObjCmd()
+
local mwOffset = 0
 
</syntaxhighlight>
 
</syntaxhighlight>
5. On mouse out for each object, character & item, create an ''execute a script'' action containing...
+
4a. Edit ''inSpeed'' value; this controls the amount of pixels[squares] the interface should move by on close.
 
<syntaxhighlight>
 
<syntaxhighlight>
resetCmdCond()
+
local inSpeed = 1
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
4b. Edit ''outSpeed'' value; this controls the amount of pixels[squares] the interface should move by on open.
 +
<syntaxhighlight>
 +
local outSpeed = 2
 +
</syntaxhighlight>
 +
5. Edit ''slideDirection'' value; this determines which direction the interface should slide from.
 +
<syntaxhighlight>
 +
local slideDirection = 1 -- from left
 +
local slideDirection = 2 -- from top
 +
local slideDirection = 3 -- from right
 +
local slideDirection = 4 -- from bottom
 +
</syntaxhighlight>
 +
5. ...
  
 
== Main Script ==
 
== Main Script ==
Line 140: Line 157:
 
  end
 
  end
 
end
 
end
 +
</syntaxhighlight>
  
 +
== Event Script ==
 +
<syntaxhighlight>
 
-- * this is the mainLoop event function (all loop events & functions for looping should be added or linked here) * --
 
-- * this is the mainLoop event function (all loop events & functions for looping should be added or linked here) * --
 
function onMainLoop()
 
function onMainLoop()

Revision as of 18:10, 18 March 2014

Name Type By
Deponia Based Sliding Interface Definition AFRLme

This script allows you to slide interfaces in - or out - from any direction, on hover or via the mouse wheel.

* this page is a work in progress *

Instructions

1. Add the main script to the Visionaire Studio Script Editor & set the script as a definition script.
2. Replace inventory with whatever name you gave your interface; names are case sensitive.

local getInterface = getObject("Interfaces[add interface name here]")

3a. Edit minOffset x & y values; these should reflect initial starting point of the interface.

local minOffset = {x = 0, y = 0}

3b. Edit maxOffset x & y values; these should reflect the destination position for the interface.

local maxOffset = {x = 0, y = 0}

3c. Edit mwOffset value; this should reflect the overlap amount of the interface from screen edge - to hide interface on mouse wheel mode; set 0 to keep overlap.

local mwOffset = 0

4a. Edit inSpeed value; this controls the amount of pixels[squares] the interface should move by on close.

local inSpeed = 1

4b. Edit outSpeed value; this controls the amount of pixels[squares] the interface should move by on open.

local outSpeed = 2

5. Edit slideDirection value; this determines which direction the interface should slide from.

local slideDirection = 1 -- from left
local slideDirection = 2 -- from top
local slideDirection = 3 -- from right
local slideDirection = 4 -- from bottom

5. ...

Main Script

--[[
Deponia Based Sliding Interface [v3] (18/03/2013)
Written by AFRLme [Lee Clarke]
-- + --
alternatingfrequencies@hotmail.com | skype @ AFRLme
-- + --
This script is donation optional. In game credit is non-negotiable.
You are free to: ¹ use it in your game(s). ² modify the script.
Do not remove - or edit - this comment block.
--]]

-- * local variables * --
local getInterface = getObject("Interfaces[inventory]") -- stores interface into a variable (replace "inventory" with your interface name)

local minOffset = {x = 0, y = 0} -- replace min offset values with current x,y absolute position of your interface
local maxOffset = {x = 0, y = 0} -- replace max offset values with the x,y values that you want the interface to slide to
local mwOffset = 0 -- this should be same value or slightly larger than the overlap amount of minOffset
local checkOffset = getInterface:getPoint(VInterfaceOffset) -- stores current position of interface on start

local inSpeed = 1 -- replace "1" with x number of squares you want interface to move back to start position on each loop
local outSpeed = 2 -- replace "2" with x number of squares you want interface to move to max position on each loop

local slideDirection = 1 -- set direction interface should slide from (1 = left, 2 = top, 3 = right, 4 = bottom) 

local mwUp = 0 -- this controls if mouse wheel up or down has been executed; by default "0" = nil (!important: do not edit)

-- * function that moves the linked interface * --
function intSlide()
 conds = {} -- create a blank table called "conds" ...
 conds["_temporary_"] = "" -- sets table to temporary; in other words: no data is stored in VS save games!
 conds[1] = getObject("Conditions[slide?]"):getBool(VConditionValue) -- check condition of "slide?"
 conds[2] = getObject("Conditions[mwheel?]"):getBool(VConditionValue) -- check condition of "mwheel?"
 -- * let's create the on mouse over code * --
 if conds[1] and not conds[2] then -- check if "slide?" = true & "mwheel?" = false
  if mwUp ~= 0 then mwUp = 0 end -- check if mouse wheel is active; if it is, then set inactive
  -- * let's slide the x position of the interface based on slideDirection (out) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x < maxOffset.x then checkOffset.x = checkOffset.x + outSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x > maxOffset.x then checkOffset.x = maxOffset.x setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x > maxOffset.x then checkOffset.x = checkOffset.x - outSpeed setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x < maxOffset.x then checkOffset.x = maxOffset.x setIntPos() end
  -- * let's slide the y position of the interface based on SlideDirection (out) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y < maxOffset.y then checkOffset.y = checkOffset.y + outSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y > maxOffset.y then checkOffset.y = maxOffset.y setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y > maxOffset.y then checkOffset.y = checkOffset.y - outSpeed setIntPos()  end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y < maxOffset.y then checkOffset.y = maxOffset.y setIntPos() end
 elseif not conds[1] and not conds[2] then
  if mwUp ~= 0 then mwUp = 0 end -- check if mouse wheel is active; if it is, then set inactive
  -- * let's slide the x position of the interface based on slideDirection (in) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x > minOffset.x then checkOffset.x = checkOffset.x - inSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x < minOffset.x then checkOffset.x = minOffset.x setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x < minOffset.x then checkOffset.x = checkOffset.x + inSpeed setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x > minOffset.x then checkOffset.x = minOffset.x setIntPos() end
  -- * let's slide the y position of the interface based on SlideDirection (in) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y > minOffset.y then checkOffset.y = checkOffset.y - inSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y < minOffset.y then checkOffset.y = minOffset.y setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y < minOffset.y then checkOffset.y = checkOffset.y + inSpeed setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y > minOffset.y then checkOffset.y = minOffset.y setIntPos() end
 end
 -- * let's create the mouse wheel code * --
 if not conds[1] and mwUp == 1 then -- check if mouse wheel up has been rotated
  -- * let's slide the x position of the interface based on slideDirection (out) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x < maxOffset.x then checkOffset.x = checkOffset.x + outSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.x > maxOffset.x then checkOffset.x = maxOffset.x setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x > maxOffset.x then checkOffset.x = checkOffset.x - outSpeed setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.x < maxOffset.x then checkOffset.x = maxOffset.x setIntPos() end
  -- * let's slide the y position of the interface based on SlideDirection (out) * --
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y < maxOffset.y then checkOffset.y = checkOffset.y + outSpeed setIntPos() end
  if (slideDirection == 1 or slideDirection == 2) and checkOffset.y > maxOffset.y then checkOffset.y = maxOffset.y setIntPos() end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y > maxOffset.y then checkOffset.y = checkOffset.y - outSpeed setIntPos()  end
  if (slideDirection == 3 or slideDirection == 4) and checkOffset.y < maxOffset.y then checkOffset.y = maxOffset.y setIntPos() end
 end
 if not conds[1] and mwUp == 2 then -- check if mouse wheel down has been rotated
  -- * let's slide the x position of the interface based on slideDirection (in) * --
  if slideDirection == 1 and checkOffset.x > minOffset.x - mwOffset then checkOffset.x = checkOffset.x - inSpeed setIntPos() end
  if slideDirection == 1 and checkOffset.x < minOffset.x - mwOffset then checkOffset.x = minOffset.x - mwOffset setIntPos() end
  if slideDirection == 2 and checkOffset.x > minOffset.x then checkOffset.x = checkOffset.x - inSpeed setIntPos() end
  if slideDirection == 2 and checkOffset.x < minOffset.x then checkOffset.x = minOffset.x setIntPos() end
  if slideDirection == 3 and checkOffset.x < minOffset.x + mwOffset then checkOffset.x = checkOffset.x + inSpeed setIntPos() end
  if slideDirection == 3 and checkOffset.x > minOffset.x + mwOffset then checkOffset.x = minOffset.x + mwOffset setIntPos() end
  if slideDirection == 4 and checkOffset.x < minOffset.x then checkOffset.x = checkOffset.x + inSpeed setIntPos() end
  if slideDirection == 4 and checkOffset.x > minOffset.x then checkOffset.x = minOffset.x setIntPos() end
  -- * let's slide the y position of the interface based on SlideDirection (in) * --
  if slideDirection == 1 and checkOffset.y > minOffset.y then checkOffset.y = checkOffset.y - inSpeed setIntPos() end
  if slideDirection == 1 and checkOffset.y < minOffset.y then checkOffset.y = minOffset.y setIntPos() end
  if slideDirection == 2 and checkOffset.y > minOffset.y - mwOffset then checkOffset.y = checkOffset.y - inSpeed setIntPos() end
  if slideDirection == 2 and checkOffset.y < minOffset.y - mwOffset then checkOffset.y = minOffset.y - mwOffset setIntPos() end
  if slideDirection == 3 and checkOffset.y < minOffset.y then checkOffset.y = checkOffset.y + inSpeed setIntPos() end
  if slideDirection == 3 and checkOffset.y > minOffset.y then checkOffset.y = minOffset.y setIntPos() end
  if slideDirection == 4 and checkOffset.y < minOffset.y + mwOffset then checkOffset.y = checkOffset.y + inSpeed setIntPos() end
  if slideDirection == 4 and checkOffset.y > minOffset.y + mwOffset then checkOffset.y = minOffset.y + mwOffset setIntPos() end
 end
end -- end intSlide()

 -- * updates the current position of the interface * --
function setIntPos()
 getInterface:setValue(VInterfaceOffset, checkOffset)
end

-- * let's check if mouse wheel mode = true; if true then hide the interface else overlap interface slightly * --
function mwMode()
 if conds[2] then
  if slideDirection == 1 then checkOffset = {x = minOffset.x - mwOffset, y = minOffset.y} setIntPos() end
  if slideDirection == 2 then checkOffset = {x = minOffset.x, y = minOffset.y - mwOffset} setIntPos() end
  if slideDirection == 3 then checkOffset = {x = minOffset.x + mwOffset, y = minOffset.y} setIntPos() end
  if slideDirection == 4 then checkOffset = {x = minOffset.x, y = minOffset.y + mwOffset} setIntPos() end
 else
  checkOffset = {x = minOffset.x, y = minOffset.y}
  setIntPos()
 end
end

Event Script

-- * this is the mainLoop event function (all loop events & functions for looping should be added or linked here) * --
function onMainLoop()
 intSlide() -- loop the function which checks if interface should be sliding in, out or at default position!
end
 
-- * this is the mouse event listener! (all mouse events & functions should be added or linked here) * --
function onMouseEvent(eventType)
 if not getObject("Conditions[mwtoggle?]"):getBool(VConditionValue) then -- if toggle is false then set default
  if eventType == eEvtMouseWheelUp then mwUp = 1 end
  if eventType == eEvtMouseWheelDown then mwUp = 2 end
 else -- inverse mouse wheel
  if eventType == eEvtMouseWheelUp then mwUp = 2 end
  if eventType == eEvtMouseWheelDown then mwUp = 1 end
 end
end

-- * let's create the mouse event listener! * --
registerEventHandler("mouseEvent", "onMouseEvent", {eEvtMouseWheelUp, eEvtMouseWheelDown})
-- * let's create the loop event handler! * --
registerEventHandler("mainLoop", "onMainLoop")