Skip to content

Commit

Permalink
Release version 4.1.0
Browse files Browse the repository at this point in the history
See changelog for list of changes from version 4.0.4
This release officialy closes these issues:
Close #1 - Fix camera on outside IC
Close #2 - Vehicle's IC could be activated from attacher vehicle
Close #4 - Possibility to save toggle style
Close #5 - Update error when using turn on functions
Close #6 - Network communication

Network communication was completely tested by Adam Maršík
  • Loading branch information
LoogleCZ committed Aug 11, 2018
1 parent fef00d8 commit 2c7efd9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 141 deletions.
7 changes: 5 additions & 2 deletions release/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Interactive Control 4.0.4
# Interactive Control 4.1.0

GitHub repository with releases: https://github.com/LoogleCZ/FS17-InteractiveControl

Expand All @@ -8,7 +8,10 @@ Author: Martin Fabík <mar.fabik@gmail.com>

Contributor: GtX from LS Modcompany

Testing: Ago-Systemtech (Modhoster Team)
Testing:

- Ago-Systemtech (Modhoster Team)
- Adam Maršík

## Licence

Expand Down
219 changes: 116 additions & 103 deletions release/icSources/InteractiveControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
-- GitHub project: https://github.com/LoogleCZ/FS17-InteractiveControl
-- If anyone found errors, please contact me at mar.fabik@gmail.com or report it on GitHub
--
-- version ID - 4.0.4
-- version date - 2018-01-25 12:15:00
-- version ID - 4.1.0
-- version date - 2018-08-11 16:30:00
--

InteractiveControl = {};
Expand Down Expand Up @@ -67,7 +67,7 @@ function InteractiveControl:load(savegame)
return calculateIndex+index;
end;

self.LIC.toggleStyleState = 1;
self.LIC.toggleStyleState = Utils.clamp(Utils.getNoNil(getXMLInt(self.xmlFile,"vehicle.interactiveComponents#toggleStyle"), 1), 1, 2);
self.LIC.lastMouseXPos = 0;
self.LIC.lastMouseYPos = 0;
self.LIC.foundInteractiveObject = nil;
Expand Down Expand Up @@ -245,7 +245,7 @@ function InteractiveControl:load(savegame)
k = k + 1;
end;
j = j + 1;
self:actionOnObject(upperLayerIndex, false);
self:actionOnObject(upperLayerIndex, false, true);
self.LIC:loadICButtonFromXML(self, self.xmlFile, key, self.LIC.interactiveObjects[upperLayerIndex], upperLayerIndex);
self.LIC.partsLength[InteractiveControl.OBJECT_TYPE_MONITOR] = self.LIC.partsLength[InteractiveControl.OBJECT_TYPE_MONITOR] + 1;
else
Expand Down Expand Up @@ -424,7 +424,7 @@ function InteractiveControl:postLoad(savegame) -- init actions here
end;

if savegame ~= nil then
local icToggleStyle = getXMLInt(savegame.xmlFile, savegame.key.."#icToggleStyle");
local icToggleStyle = getXMLInt(savegame.xmlFile, savegame.key..".interactiveControl#toggleStyle");
if icToggleStyle ~= nil then
self.LIC.toggleStyleState = icToggleStyle;
end;
Expand Down Expand Up @@ -472,8 +472,7 @@ function InteractiveControl:getSaveAttributesAndNodes(nodeIdent)
return minusIndex+index;
end;

local attributes = 'icStateStyle="' .. tostring(self.LIC.toggleStyleState) .. '" ';
local nodes = "\t\t<interactiveControl>\n";
local nodes = "\t\t<interactiveControl toggleStyle=\"" .. self.LIC.toggleStyleState .. "\">\n";
for k,v in pairs(self.LIC.interactiveObjects) do
if v.objectType == InteractiveControl.OBJECT_TYPE_ANIMATION then
if v.saveStatus then
Expand All @@ -487,7 +486,7 @@ function InteractiveControl:getSaveAttributesAndNodes(nodeIdent)
end;
end;
nodes = nodes .. "\t\t</interactiveControl>";
return attributes, nodes;
return nil, nodes;
end

function InteractiveControl:delete()
Expand All @@ -504,11 +503,9 @@ end;
function InteractiveControl:readStream(streamId, connection) -- OK
local icCount = streamReadInt8(streamId);
for i=0, icCount do
local isOpen = streamReadBool(streamId);
if self.LIC.interactiveObjects[i] ~= nil then
if self.LIC.interactiveObjects[i].synch then
self:actionOnObject(i, isOpen, false);
end;
if self.LIC.interactiveObjects[i].synch then
local isOpen = streamReadBool(streamId);
self:actionOnObject(i, isOpen, true);
end;
end;
end;
Expand All @@ -517,7 +514,9 @@ function InteractiveControl:writeStream(streamId, connection) -- OK
local icCount = (table.getn(self.LIC.interactiveObjects)-1);
streamWriteInt8(streamId, icCount);
for i=0, icCount do
streamWriteBool(streamId, self.LIC.interactiveObjects[i].isOpen);
if self.LIC.interactiveObjects[i].synch then
streamWriteBool(streamId, self.LIC.interactiveObjects[i].isOpen);
end;
end;
end;

Expand All @@ -530,55 +529,45 @@ function InteractiveControl:keyEvent(unicode, sym, modifier, isDown) -- OK
end;

function InteractiveControl:update(dt) -- OK

if self.isClient and self:getIsActiveForSound() then
for _,v in pairs(self.LIC.sounds) do
local object = self.LIC.interactiveObjects[v.componentIndex];

if object.isOpen and v.openSound ~= nil then
SoundUtil.playSample(v.openSound, 0, 0, nil);
else
SoundUtil.stopSample(v.openSound);
end;
if not object.isOpen and v.closeSound ~= nil then
SoundUtil.playSample(v.closeSound, 0, 0, nil);
else
SoundUtil.stopSample(v.closeSound);
end;
if object.isOpen ~= v.componentStatus then
if object.isOpen and v.openingSound ~= nil then
SoundUtil.playSample(v.openingSound, 1, 0, nil);
if v.closingSound ~= nil then
SoundUtil.stopSample(v.closingSound);
end;
if self.isClient then
if self:getIsActiveForSound() then -- sounds
for _,v in pairs(self.LIC.sounds) do
local object = self.LIC.interactiveObjects[v.componentIndex];

if object.isOpen and v.openSound ~= nil then
SoundUtil.playSample(v.openSound, 0, 0, nil);
else
SoundUtil.stopSample(v.openSound);
end;
if not object.isOpen and v.closingSound ~= nil then
SoundUtil.playSample(v.closingSound, 1, 0, nil);
if v.openingSound ~= nil then
SoundUtil.stopSample(v.openingSound);
if not object.isOpen and v.closeSound ~= nil then
SoundUtil.playSample(v.closeSound, 0, 0, nil);
else
SoundUtil.stopSample(v.closeSound);
end;
if object.isOpen ~= v.componentStatus then
if object.isOpen and v.openingSound ~= nil then
SoundUtil.playSample(v.openingSound, 1, 0, nil);
if v.closingSound ~= nil then
SoundUtil.stopSample(v.closingSound);
end;
end;
if not object.isOpen and v.closingSound ~= nil then
SoundUtil.playSample(v.closingSound, 1, 0, nil);
if v.openingSound ~= nil then
SoundUtil.stopSample(v.openingSound);
end;
end;
end;
v.componentStatus = object.isOpen;
end;
v.componentStatus = object.isOpen;
end;
end;

if self.isClient then
self.LIC.toggleStyleState = math.min(2, math.max(self.LIC.toggleStyleState, 1));

if self.LIC.lastCamIndexUsed ~= nil and self.LIC.lastCamIndexUsed ~= self.camIndex then
-- if user toggle cam disable IC
if self.LIC.lastCamIndexUsed ~= nil
and self.LIC.lastCamIndexUsed ~= self.camIndex then
self:toggleICState(nil, false);
end;

if self:getIsActive() then -- toggle IC toggle type
if InputBinding.hasEvent(InputBinding.INTERACTIVE_CONTROL_MODE) then
self.LIC.toggleStyleState = self.LIC.toggleStyleState + 1;
if self.LIC.toggleStyleState > 2 then
self.LIC.toggleStyleState = 1;
end;
end;
end;

if self.isMotorStarted then -- monitor on/off on start
self.forceIsActive = true;
if not self.LIC.isInitialized then
Expand Down Expand Up @@ -614,10 +603,17 @@ function InteractiveControl:update(dt) -- OK
else
self.LIC.isClicked = false;
end;

self.LIC.foundInteractiveObject = nil;

if self.LIC.isInOutsideRange or (self:getIsActive() and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection()) then
if self.LIC.isInOutsideRange or (self:getIsActive() and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() and self.isEntered) then
if self:getIsActive() then -- toggle IC toggle type (only when we have help)
if InputBinding.hasEvent(InputBinding.INTERACTIVE_CONTROL_MODE) then
self.LIC.toggleStyleState = self.LIC.toggleStyleState + 1;
if self.LIC.toggleStyleState > 2 then
self.LIC.toggleStyleState = 1;
end;
end;
end;

if self.LIC.toggleStyleState == 1 then
if InputBinding.hasEvent(InputBinding.INTERACTIVE_CONTROL_SWITCH) then
self:toggleICState(self.LIC.isInOutsideRange);
Expand All @@ -629,16 +625,20 @@ function InteractiveControl:update(dt) -- OK
end;
elseif self.LIC.toggleStyleState == 2 then
if InputBinding.isPressed(InputBinding.INTERACTIVE_CONTROL_SWITCH) then
self:toggleICState(self.LIC.isInOutsideRange, true);
if not self.LIC.isMouseActive then
self:toggleICState(self.LIC.isInOutsideRange, true);
end;
else
self:toggleICState(self.LIC.isInOutsideRange, false);
if self.LIC.isMouseActive then
self:toggleICState(self.LIC.isInOutsideRange, false);
end;
end;
if not self.LIC.isMouseActive then
g_currentMission:addHelpButtonText(g_i18n:getText("InteractiveControl_On"), InputBinding.INTERACTIVE_CONTROL_SWITCH);
end;
end;
end;
if self:getIsActive() and self:getIsActiveForInput(false) and not self:hasInputConflictWithSelection() then
-- help for toggle style
if self.LIC.toggleStyleState == 1 then
if self.LIC.isMouseActive then
g_currentMission:addHelpButtonText(string.format(g_i18n:getText("InteractiveControl_ModeSelect"), g_i18n:getText("button_normal")), InputBinding.INTERACTIVE_CONTROL_MODE, nil, GS_PRIO_HIGH)
Expand All @@ -647,24 +647,33 @@ function InteractiveControl:update(dt) -- OK
if self.LIC.isMouseActive then
g_currentMission:addHelpButtonText(string.format(g_i18n:getText("InteractiveControl_ModeSelect"), g_i18n:getText("InteractiveControl_Quick")), InputBinding.INTERACTIVE_CONTROL_MODE, nil, GS_PRIO_HIGH)
end;
end
end;
end;

if self.LIC.isMouseActive and not self.isEntered then
self.LIC.lastMouseXPos = InputBinding.mousePosXLast;
self.LIC.lastMouseYPos = InputBinding.mousePosYLast;
for _,v in pairs(self.LIC.interactiveObjects) do
v.isEntered = false;
end
if self.LIC.lastMouseXPos ~= nil and self.LIC.lastMouseYPos ~= nil then
for k,v in pairs(self.LIC.interactiveObjects) do
if v.mark ~= nil and self.LIC.foundInteractiveObject == nil then
local worldX,worldY,worldZ = getWorldTranslation(v.mark);
local x,y,z = project(worldX,worldY,worldZ);
if z <= 1 then
if self.LIC.lastMouseXPos > (x-v.size/2) and self.LIC.lastMouseXPos < (x+v.size/2) then
if self.LIC.lastMouseYPos > (y-v.size/2) and self.LIC.lastMouseYPos < (y+v.size/2) then
if v.canOutside then
-- reset components
for _,v in pairs(self.LIC.interactiveObjects) do
v.isEntered = false;
if v.pulse ~= nil then
if v.pulsingMark then
setScale(v.pulse, v.scaleX, v.scaleY, v.scaleZ);
end;
end;
end;

-- for outside IC
if self.LIC.isMouseActive then
if not self.isEntered then
self.LIC.foundInteractiveObject = nil; -- reset and search again
self.LIC.lastMouseXPos = InputBinding.mousePosXLast;
self.LIC.lastMouseYPos = InputBinding.mousePosYLast;
if self.LIC.lastMouseXPos ~= nil and self.LIC.lastMouseYPos ~= nil then
for k,v in pairs(self.LIC.interactiveObjects) do
if v.canOutside and v.mark ~= nil and (v.doNotShow == nil or v.doNotShow == false) then
local worldX,worldY,worldZ = getWorldTranslation(v.mark);
local x,y,z = project(worldX,worldY,worldZ);
if z <= 1 then
if self.LIC.lastMouseXPos > (x-v.size/2) and self.LIC.lastMouseXPos < (x+v.size/2) then
if self.LIC.lastMouseYPos > (y-v.size/2) and self.LIC.lastMouseYPos < (y+v.size/2) then
v.isEntered = true;
self:updateOpenStatus(k);
self:renderOverlayAndInfo(v);
Expand All @@ -677,26 +686,30 @@ function InteractiveControl:update(dt) -- OK
end;
end;
end;
end;

for k,v in pairs(self.LIC.interactiveObjects) do
if v.pulse ~= nil then
if v.pulsingMark then
if v.isEntered then
local sx,sy,sz = getScale(v.pulse);
sx = sx - (v.pulseScaleX/400) * dt;
sy = sy - (v.pulseScaleY/400) * dt;
sz = sz - (v.pulseScaleZ/400) * dt;
if sx < (v.scaleX - v.pulseScaleX) or sy < (v.scaleY - v.pulseScaleY) or sz < (v.scaleZ - v.pulseScaleZ) then
setScale(v.pulse, (v.scaleX + v.pulseScaleX),(v.scaleY + v.pulseScaleY),(v.scaleZ + v.pulseScaleZ))

if self.LIC.foundInteractiveObject ~= nil then
local foundItem = self.LIC.interactiveObjects[self.LIC.foundInteractiveObject];
if foundItem.pulse ~= nil then
if foundItem.pulsingMark then
local sx,sy,sz = getScale(foundItem.pulse);
sx = sx - (foundItem.pulseScaleX/400) * dt;
sy = sy - (foundItem.pulseScaleY/400) * dt;
sz = sz - (foundItem.pulseScaleZ/400) * dt;
if sx < (foundItem.scaleX - foundItem.pulseScaleX)
or sy < (foundItem.scaleY - foundItem.pulseScaleY)
or sz < (foundItem.scaleZ - foundItem.pulseScaleZ) then
setScale(foundItem.pulse,
(foundItem.scaleX + foundItem.pulseScaleX),
(foundItem.scaleY + foundItem.pulseScaleY),
(foundItem.scaleZ + foundItem.pulseScaleZ));
else
setScale(v.pulse, sx, sy, sz);
setScale(foundItem.pulse, sx, sy, sz);
end;
else
setScale(v.pulse, v.scaleX, v.scaleY, v.scaleZ);
end;
end;
end;
else
self.LIC.foundInteractiveObject = nil; -- reset because we don't have IC
end;
end;
end;
Expand All @@ -721,24 +734,20 @@ end;

function InteractiveControl:draw() -- OK - inside needs to be in draw for more accurate results
if self.LIC.isMouseActive and self.isEntered then
for _,v in pairs(self.LIC.interactiveObjects) do
v.isEntered = false;
end
self.LIC.foundInteractiveObject = nil; -- reset and search again
if self.LIC.lastMouseXPos ~= nil and self.LIC.lastMouseYPos ~= nil then
for k,v in pairs(self.LIC.interactiveObjects) do
if v.mark ~= nil and self.LIC.foundInteractiveObject == nil and (v.doNotShow == nil or v.doNotShow == false) then
if v.mark ~= nil and not v.canOutside and (v.doNotShow == nil or v.doNotShow == false) then
local worldX,worldY,worldZ = getWorldTranslation(v.mark);
local x,y,z = project(worldX,worldY,worldZ);
if z <= 1 then
if self.LIC.lastMouseXPos > (x-v.size/2) and self.LIC.lastMouseXPos < (x+v.size/2) then
if self.LIC.lastMouseYPos > (y-v.size/2) and self.LIC.lastMouseYPos < (y+v.size/2) then
if not v.canOutside then
v.isEntered = true;
self:updateOpenStatus(k);
self:renderOverlayAndInfo(v);
self.LIC.foundInteractiveObject = k;
break;
end;
v.isEntered = true;
self:updateOpenStatus(k);
self:renderOverlayAndInfo(v);
self.LIC.foundInteractiveObject = k;
break;
end;
end;
end;
Expand Down Expand Up @@ -791,6 +800,8 @@ function InteractiveControl:toggleICState(isOutside, forceStatus) -- OK

if self.LIC.isMouseActive then
if g_currentMission.player ~= nil then
local x,y,z = getRotation(g_currentMission.player.cameraNode);
g_currentMission.player.backupCamPosition = {x,y,z};
g_currentMission.player.walkingIsLocked = true;
end;
InputBinding.setShowMouseCursor(true);
Expand Down Expand Up @@ -821,6 +832,8 @@ function InteractiveControl:toggleICState(isOutside, forceStatus) -- OK
self.LIC.foundInteractiveObject = nil;
if g_currentMission.player ~= nil then
g_currentMission.player.walkingIsLocked = false;
g_currentMission.player.rotX = g_currentMission.player.backupCamPosition[1];
g_currentMission.player.rotY = g_currentMission.player.backupCamPosition[2];
end;
InputBinding.setShowMouseCursor(false);

Expand Down
Loading

0 comments on commit 2c7efd9

Please sign in to comment.