Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- VehicleSellingPoint class |
2 | -- |
3 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
4 | |
5 | source("dataS/scripts/SellSpecificVehicleEvent.lua"); -- TODO: that goes into the selling dialog |
6 | |
7 | VehicleSellingPoint = {} |
8 | |
9 | local VehicleSellingPoint_mt = Class(VehicleSellingPoint); |
10 | |
11 | function VehicleSellingPoint:onCreate(id) |
12 | local vehicleSellingPoint = VehicleSellingPoint:new(id); |
13 | table.insert(g_currentMission.updateables, vehicleSellingPoint); |
14 | g_currentMission.vehicleSellingPointBase = vehicleSellingPoint; |
15 | -- print("created VehicleSellingPoint, id: ", id); |
16 | end; |
17 | |
18 | function VehicleSellingPoint:new(name) |
19 | local self = {}; |
20 | setmetatable(self, VehicleSellingPoint_mt); |
21 | |
22 | self.id = name; |
23 | |
24 | self.sellTriggerId = getChildAt(self.id, 0); |
25 | self.sellIconId = getChildAt(self.sellTriggerId, 0); |
26 | addTrigger(self.sellTriggerId, "triggerCallback", self); |
27 | |
28 | self.sellAreaTriggerId = getChildAt(self.id, 1); |
29 | addTrigger(self.sellAreaTriggerId, "sellAreaTriggerCallback", self); |
30 | |
31 | self.shapesCount = {}; |
32 | self.currentVehicle = nil; |
33 | self.currentVehicleId = 0; |
34 | |
35 | self.activateText = g_i18n:getText("SellSpecificVehicle"); |
36 | |
37 | self.isEnabled = true; |
38 | self.objectActivated = false; |
39 | |
40 | if g_isDemo or g_isGamescomVersion or (not g_currentMission.missionInfo:isa(FSCareerMissionInfo)) then |
41 | setVisibility(self.sellIconId, false); |
42 | end; |
43 | |
44 | return self; |
45 | end; |
46 | |
47 | function VehicleSellingPoint:delete() |
48 | |
49 | if g_currentMission:getIsClient() then |
50 | removeTrigger(self.sellTriggerId); |
51 | removeTrigger(self.sellAreaTriggerId); |
52 | end; |
53 | end; |
54 | |
55 | function VehicleSellingPoint:getIsActivatable() |
56 | return self.isEnabled and g_currentMission.controlPlayer; |
57 | end; |
58 | |
59 | function VehicleSellingPoint:drawActivate() |
60 | return; |
61 | end; |
62 | |
63 | function VehicleSellingPoint:onActivateObject() |
64 | -- TODO: check if there is a vehicle at all inside the trigger |
65 | |
66 | local sellVehicleDialog = g_gui:showGui("SellVehicleDialog"); |
67 | self:determineCurrentVehicle(); |
68 | g_sellVehicleDialog:setVehicle(self.currentVehicle, self.currentVehicleId); |
69 | g_sellVehicleDialog:setCallbacks(nil, nil); |
70 | g_sellVehicleDialog:setReturnScreen(""); |
71 | |
72 | self.objectActivated = true; |
73 | g_currentMission:addActivatableObject(self); |
74 | end; |
75 | |
76 | function VehicleSellingPoint:update(dt) |
77 | if self.isEnabled then |
78 | rotate(self.sellIconId, 0, 0.002 * dt, 0); |
79 | end; |
80 | end; |
81 | |
82 | function VehicleSellingPoint:triggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
83 | |
84 | if self.isEnabled and not g_isGamescomVersion and not g_isDemo and g_currentMission.missionInfo:isa(FSCareerMissionInfo) then |
85 | if onEnter or onLeave then |
86 | if g_currentMission.player ~= nil and otherId == g_currentMission.player.rootNode then |
87 | if onEnter then |
88 | if not self.objectActivated then |
89 | g_currentMission:addActivatableObject(self); |
90 | self.objectActivated = true; |
91 | end |
92 | else |
93 | if self.objectActivated then |
94 | g_currentMission:removeActivatableObject(self); |
95 | self.objectActivated = false; |
96 | end |
97 | end; |
98 | end; |
99 | end; |
100 | end; |
101 | |
102 | end; |
103 | |
104 | function VehicleSellingPoint:sellAreaTriggerCallback(triggerId, otherId, onEnter, onLeave, onStay) |
105 | if onEnter or onLeave then |
106 | if self.shapesCount[otherId] == nil then |
107 | self.shapesCount[otherId] = 0; |
108 | end; |
109 | |
110 | if onEnter then |
111 | self.shapesCount[otherId] = self.shapesCount[otherId]+1; |
112 | elseif onLeave then |
113 | self.shapesCount[otherId] = self.shapesCount[otherId]-1; |
114 | end; |
115 | |
116 | self:determineCurrentVehicle(); |
117 | end; |
118 | end; |
119 | |
120 | function VehicleSellingPoint:determineCurrentVehicle() |
121 | self.currentVehicle = nil; |
122 | |
123 | for vehicleId, count in pairs(self.shapesCount) do |
124 | if count > 0 then |
125 | self.currentVehicle = g_currentMission.nodeToVehicle[vehicleId]; |
126 | self.currentVehicleId = vehicleId; |
127 | if self.currentVehicle ~= nil then |
128 | break; |
129 | end; |
130 | end; |
131 | -- invalid vehicle (not existing or left), remove from list |
132 | self.shapesCount[vehicleId] = nil; |
133 | end; |
134 | |
135 | -- if self.currentVehicle ~= nil then |
136 | -- print("VEHICLE: " .. tostring(self.currentVehicle.configFileName)); |
137 | -- else |
138 | -- print("NO VEHICLE"); |
139 | -- end; |
140 | |
141 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de