-
Notifications
You must be signed in to change notification settings - Fork 50
/
RNScreen.lua
169 lines (137 loc) · 4.6 KB
/
RNScreen.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
--[[
--
-- RapaNui
--
-- by Ymobe ltd (http://ymobe.co.uk)
--
-- LICENSE:
--
-- RapaNui uses the Common Public Attribution License Version 1.0 (CPAL) http://www.opensource.org/licenses/cpal_1.0.
-- CPAL is an Open Source Initiative approved
-- license based on the Mozilla Public License, with the added requirement that you attribute
-- Moai (http://getmoai.com/) and RapaNui in the credits of your program.
]]
RNScreen = {}
function RNScreen:new(o)
o = o or {
name = "",
-- sprites = {},
-- numSprites = 0,
width = 0,
height = 0,
spriteIndex = 0,
viewport = nil,
layer = nil,
layers = nil,
visible = true
}
setmetatable(o, self)
self.__index = self
self.images = {}
self.images_size = 0
return o
end
function RNScreen:getName()
return self.name
end
function RNScreen:setName(name)
self.name = name
end
function RNScreen:initWith(width, height, screenWidth, screenHeight)
self.width = width
self.height = height
self.viewport = MOAIViewport.new()
self.viewport:setSize(screenWidth, screenHeight)
self.viewport:setScale(width, -height)
self.viewport:setOffset(-1, 1)
self.layers = RNLayer:new()
self.layer,self.mainPartition = self.layers:createLayerWithPartition(RNLayer.MAIN_LAYER,self.viewport)
self.layer:setViewport(self.viewport)
self.layer:setPartition(self.mainPartition)
MOAISim.pushRenderPass(self.layer)
end
--[[
layer parameter can be either partition or layer since
both MOAIObjects have the insertProp function.
--]]
function RNScreen:addRNObject(object, mode, layer)
if object == nil then
return
end
if layer == nil then
layer = self.mainPartition
end
object:setLocatingMode(mode)
layer:insertProp(object:getProp())
object:setParentScene(self)
object:updateLocation()
-- self.numSprites = self.numSprites + 1
-- self.sprites[self.numSprites] = object
-- object:setIDInScreen(self.numSprites)
-- object:getProp().rnObjectId = self.numSprites
object:getProp().RNObject = object
end
function RNScreen:removeRNObject(object, layer)
if(layer == nil) then
layer = self.layers:get(RNLayer.MAIN_LAYER)
end
layer:removeProp(object:getProp())
-- local id = object.idInScreen
-- local len = table.getn(self.sprites)
-- local ind = id
-- for i = 1, len, 1 do
-- if (i == ind) then
-- for k = ind + 1, len, 1 do
-- self.sprites[k - 1] = self.sprites[k]
-- self.sprites[k].idInScreen = k - 1
-- self.sprites[k]:getProp().rnObjectId = k - 1
-- end
-- self.sprites[len] = nil
-- end
-- end
--
-- --
-- self.numSprites = table.getn(self.sprites)
end
function RNScreen:getObjectWithHighestLevelOn(x, y)
local props
if config.stretch.status == true then
if config.stretch.letterbox == true then
local toGetX, toGetY = (x - RNFactory.ofx) * RNFactory.Ax, (y - RNFactory.ofy) * RNFactory.Ay
props = { self.mainPartition:propListForPoint(toGetX, toGetY + RNFactory.statusBarHeight * y / RNFactory.height, 0, MOAILayer.SORT_PRIORITY_DESCENDING) }
else
local toGetX, toGetY = (x - RNFactory.ofx) * RNFactory.Ax, (y - RNFactory.ofy) * RNFactory.Ay
props = { self.mainPartition:propListForPoint(toGetX, toGetY + RNFactory.statusBarHeight * y / RNFactory.height, 0, MOAILayer.SORT_PRIORITY_DESCENDING) }
end
else
props = { self.mainPartition:propListForPoint(x, y + RNFactory.statusBarHeight * y / RNFactory.height, 0, MOAILayer.SORT_PRIORITY_DESCENDING) }
end
--Old, deprecated worst way to do this.
-- for i, p in ipairs(props) do
-- for j, k in ipairs(self.sprites) do
-- if k.prop == p then
-- if k.touchable == true then
-- -- print(k.name)
-- return k
-- end
-- end
-- end
-- end
for i = 1, #props do
local currentProp = props[i]
if currentProp.RNObject.touchable == true then
return currentProp.RNObject
end
end
end
function RNScreen:getRNObjectWithHighestLevelOn(x, y)
if self:getObjectWithHighestLevelOn(x, y) ~= nil then
return self:getObjectWithHighestLevelOn(x, y)
else
return nil
end
end
function RNScreen:getImages()
return self.images
end
return RNScreen