-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.lua
1280 lines (1001 loc) · 35.7 KB
/
main.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
------------------------------------------------------------------------------
--
-- This file is part of the Solar2D game engine.
-- For overview and more information on licensing please refer to README.md
-- Home page: https://github.com/coronalabs/corona
-- Contact: [email protected]
--
------------------------------------------------------------------------------
local widget = require "widget"
local simErr, simulator = pcall(require, "simulator")
if not simErr then
simulator = require "simulator_stub"
end
local json = require "json"
local lfs = require "lfs"
-- Reference locals
local stage = display.getCurrentStage()
local screenW, screenH = display.contentWidth, display.contentHeight
local halfW, halfH = screenW*.5, screenH*.5
local platform = system.getInfo( "platformName" )
local userHome = nil
if platform == "Mac OS X" then
userHome = os.getenv("HOME")
end
local uiFont = "HelveticaNeue"
local dirSeparator = "/"
if platform == "Win" then
uiFont = "Arial"
dirSeparator = "\\"
end
-- Colors and fonts
local windowBackgroundColor = { 29/255 , 29/255 , 29/255, 1 }
local topBlockBackgroundColor = { 37/255, 37/255, 37/255, 1 }
local linesColor = { 1, 1, 1, 10/100}
local hintsBGColor = { 37/255, 37/255, 37/255, 1 }
local tabColorSelected = {238/255, 238/255, 238/255, 1}
local tabColorHidden = {159/255, 159/255, 159/255, 1}
local textColorNormal = tabColorSelected
local textColorSelected = { 249/255, 111/255, 41/255, 1 }
local textColorLinks = {177/255,177/255,177/255,1}
local textColorCopyright = { 115/255, 115/255, 115/255 }
local textColorHits = { 165/255, 165/255, 165/255 }
local fontSizeTabBar = 17.5
local fontSizeProjectButtons = 17.5
local fontSizeSections = 17.5
local fontSizeLinkAndNews = 12.5
local fontSizeTooltip = 11
local fontSizeCopyright = 10
local fontSizeRecetProjectName = 15
local fontSizeRecetProjectPath = 12.5
local fontRegular = native.newFont("Exo2-Regular", 35)
local fontBold = native.newFont("Exo2-Bold", 35)
-- Local module vars/groups/etc
local uiTouchesDisabled = false
local isRetinaEnabled = (platform == "Mac OS X")
-- Log analytics when opening URLs
local function OpenURL(url, tag)
local tag = tag or url
system.openURL(url)
simulator.analytics("welcome", "link", tag)
end
-- Creating Pointer Location variable to hold all the pointer location data
-- Need this inorder to disable and enable the mouse pointers
local g_pointerLocations = {}
g_pointerLocations.button = {}
g_pointerLocations.button.text = {}
g_pointerLocations.button.image = {}
g_pointerLocations.project = {}
g_pointerLocations.quickLink = {}
g_pointerLocations.feeds = {}
g_pointerLocations.chrome = {}
-- Limit the length of displayed strings to some number of pixels
local function limitDisplayLength(len, str, font, fontSize, isPath)
local process
local origStr = str
local txtObj = nil
repeat
txtObj = display.newText( str, 0, 0, font, fontSize )
width = txtObj.width
txtObj:removeSelf( )
if width > len and str:len() > 3 then
str = str:gsub('...$', '') -- reduce length of string by 3 characters
-- str = str .. "…" -- this messes things up because … is a UTF-8 character
end
until width <= len
-- return the possibly trimmed string and add an elipsis if it was trimmed
return str .. (str ~= origStr and "…" or "")
end
-- Functions to enable and remove pointers
local function setPointers(element, cursor) --Will set pointer for all elements in array
if element then
for k, v in pairs(element) do
local location = v
location.cursor = cursor
simulator.setCursorRect(location)
end
end
end
local function setPointer(element, cursor) --Will set pointer to single element
element.cursor = cursor
simulator.setCursorRect(element)
end
local function removeAllPointers()
-- Method to remove simulator pointing arrow
local cursor = "none"
setPointers(g_pointerLocations.button.text,cursor)
setPointers(g_pointerLocations.button.image,cursor)
setPointers(g_pointerLocations.project,cursor)
setPointers(g_pointerLocations.link,cursor)
setPointers(g_pointerLocations.feeds,cursor)
setPointers(g_pointerLocations.chrome,cursor)
end
local function restoreAllPointers()
-- Method to remove simulator pointing arrow
local cursor = "pointingHand"
setPointers(g_pointerLocations.button.text,cursor)
setPointers(g_pointerLocations.button.image,cursor)
setPointers(g_pointerLocations.project,cursor)
setPointers(g_pointerLocations.link,cursor)
setPointers(g_pointerLocations.feeds,cursor)
setPointers(g_pointerLocations.chrome,cursor)
end
-----------------------------------------------------------------------------------------
local hovered = {}
local hoveredListeners = {}
local function howerListener(event)
if event.target == nil then
for k, v in pairs(hoveredListeners) do
if (not hovered[k]) == (not hovered[k]) and v.state == (not hovered[k]) then
v.state = not (not hovered[k])
for i=1,#v.listeners do
v.listeners[i](v.state)
end
end
end
hovered = {}
else
hovered[event.target] = true
end
end
local function addHoverObject(object, onHover)
if hoveredListeners[object] then
hoveredListeners[object].listeners[#hoveredListeners[object].listeners + 1] = onHover
else
object:addEventListener( "mouse", howerListener )
hoveredListeners[object] = {
state = false,
listeners = {onHover,},
}
end
end
Runtime:addEventListener("mouse", howerListener)
-----------------------------------------------------------------------------------------
-- Functions to enable/disable uiTouches (used as an onComplete listeners for some transitions)
local enableTouches = function()
uiTouchesDisabled = false
end
local disableTouches = function()
uiTouchesDisabled = true
end
local function unescape(str)
str = string.gsub( str, '<', '<' )
str = string.gsub( str, '>', '>' )
str = string.gsub( str, '"', '"' )
str = string.gsub( str, ''', "'" )
str = string.gsub( str, '—', "-" )
str = string.gsub( str, '–', "-" )
str = string.gsub( str, '&#(%d+);', function(n) return (tonumber(n) > 255 and "" or string.char(n)) end )
str = string.gsub( str, '&', '&' ) -- and finally ...
return str
end
-----------------------------------------------------------------------------------------
local function jsonFile( filename, base )
base = base or system.ResourceDirectory
local path = system.pathForFile( filename, base )
local contents
local file = io.open( path, "r" )
if file then
contents = file:read( "*a" )
io.close( file ) -- close the file after using it
end
return contents
end
-----------------------------------------------------------------------------------------
-- Utility Functions
local function scaleForRetina( text )
if isRetinaEnabled then
text.xScale = 0.5
text.yScale = 0.5
end
end
local function newRetinaText( text, x, y, size, bold )
local obj
if isRetinaEnabled then
obj = display.newText( text, x, y, bold and fontBold or fontRegular, size*2 )
obj.xScale = 0.5
obj.yScale = 0.5
else
obj = display.newText( text, x, y, bold and fontBold or fontRegular, size )
end
return obj
end
-----------------------------------------------------------------------------------------
-- Background rectangles and lines
-- background
display.setDefault('background', unpack(windowBackgroundColor))
local bgRect = display.newRect(halfW, halfH, screenW, screenH )
bgRect:setFillColor(unpack(windowBackgroundColor))
-- Lines
local vertLine = display.newLine( 634, 0, 634, display.contentHeight )
vertLine:setStrokeColor( unpack(linesColor) )
vertLine.strokeWidth = 1
local footerLine = display.newLine( 34, 649.75, 633.5, 649.75 )
footerLine:setStrokeColor( unpack(linesColor) )
footerLine.strokeWidth = 1
local latestNewsLine = display.newLine( 301.5, 488.5, 301.5, 627.5 )
latestNewsLine:setStrokeColor( unpack(linesColor) )
latestNewsLine.strokeWidth = 1
-- header rect
local bgTop = display.newRect(halfW, 40, screenW, 80 )
bgTop:setFillColor(unpack(topBlockBackgroundColor))
-- Solar2D Logo
local g_solar2dLogo = display.newImageRect( "assets/CoronaLogo.png", 144.5, 45.5)
g_solar2dLogo.x = 927 + g_solar2dLogo.contentWidth*0.5
g_solar2dLogo.y = 15 + g_solar2dLogo.contentHeight*0.5
g_pointerLocations.chrome['coronaLogo'] =
{
cursor = "pointingHand",
x = g_solar2dLogo.x - g_solar2dLogo.contentWidth*0.5,
y = g_solar2dLogo.y - g_solar2dLogo.contentHeight*0.5,
width = g_solar2dLogo.contentWidth,
height = g_solar2dLogo.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.chrome['coronaLogo'])
g_solar2dLogo:addEventListener("tap", function () OpenURL("https://solar2d.com", "homepage") end)
-- Display the Solar2D version text (build number)
local buildNum = system.getInfo( "build" )
local version = newRetinaText(buildNum, 0, 0, 15)
version:setFillColor(1, 1, 1, 50/255)
version.anchorX = 1
version.x = 1071.5
version.y = 60
g_pointerLocations.chrome['version'] =
{
cursor = "pointingHand",
x = version.x - version.contentWidth,
y = version.y - version.contentHeight*0.5,
width = version.contentWidth,
height = version.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.chrome['version'])
version:addEventListener("tap", function () OpenURL("https://github.com/coronalabs/corona/releases", "daily-builds") end)
-- Create tab bar
local g_tabBarBase = 80
local g_currentTab = "tab1"
local g_browser = {}
local g_browserFactory = require("browser")
local function handleTabBarEvent( newTab )
local url = ""
if newTab == "tab2" then
url = "https://docs.coronalabs.com/api"
elseif newTab == "tab3" then
url = "https://forums.solar2d.com"
end
if newTab == "tab1" and g_currentTab ~= "tab1" then
if g_browser[g_currentTab] then
g_browser[g_currentTab]:hide()
end
restoreAllPointers()
elseif newTab ~= "tab1" then
-- It's a browser tab
if g_browser[g_currentTab] then
g_browser[g_currentTab]:hide()
end
if not g_browser[newTab] then
g_browser[newTab] = g_browserFactory.create()
end
removeAllPointers()
g_browser[newTab]:show(halfW, halfH + g_tabBarBase/2, display.contentWidth - 8, (display.contentHeight - g_tabBarBase) - 10, url)
end
g_currentTab = newTab
end
local function makeTabBar( listener )
local tabLabels = {"Projects", "Documentation", "Forums"}
local tabXs = {66, 230, 410, 551}
local tabButtons = {}
local function highlightTabs(selected)
for i = 1, #tabButtons do
tabButtons[i].highlight(selected == i)
end
end
for i = 1, #tabLabels do
local tab = {}
local title = newRetinaText(tabLabels[i], tabXs[i], 45, fontSizeTabBar)
local highlight = display.newGroup()
local h = display.newImageRect(highlight, "assets/selectedTab.png", title.contentWidth, 24)
h.x = tabXs[i]
h.y = 78
local l = display.newImageRect(highlight, "assets/selectedTabL.png", 10, 24)
l.x = h.x - h.contentWidth*0.5 - l.contentWidth*0.5
l.y = 78
local r = display.newImageRect(highlight, "assets/selectedTabR.png", 10, 24)
r.x = h.x + h.contentWidth*0.5 + r.contentWidth*0.5
r.y = 78
local tabName = "tab" .. i
function tab.highlight( enable )
title:setFillColor( unpack(enable and tabColorSelected or tabColorHidden) )
highlight.isVisible = enable
end
local rc = display.newRect( tabXs[i], 56, highlight.contentWidth+10, 48 )
rc.alpha = 0
rc.isHitTestable = true
rc:addEventListener( "touch", function ( event )
if event.phase == "ended" then
handleTabBarEvent(tabName)
highlightTabs(i)
end
end )
tabButtons[#tabButtons+1] = tab
end
highlightTabs(1)
end
makeTabBar(handleTabBarEvent)
-----------------------------------------------------------------------------------------
-- QUICK LINKS
-----------------------------------------------------------------------------------------
local quickLinks = display.newImageRect("assets/groupLinks.png", 17, 17)
quickLinks.x = 44
quickLinks.y = 500
local quickLinksTitle = newRetinaText("Quick Links", quickLinks.x+quickLinks.contentWidth*0.5+5, quickLinks.y, fontSizeSections)
quickLinksTitle.anchorX = 0
quickLinksTitle:setFillColor(unpack(textColorNormal))
local function setupQuickLinks()
local quickLinksData = {
{
x = 34,
y = 548,
title="Getting Started",
link="https://docs.coronalabs.com/guide/programming/index.html?utm_source=simulator", -- Getting Started
},
{
x = 34,
y = 585,
title="Developer Guides",
link="https://docs.coronalabs.com/guide/index.html?utm_source=simulator", -- Learn
},
{
x = 34,
y = 622,
title="Samples",
link="https://coronalabs.com/resources/tutorials/sample-code/?utm_source=simulator", -- samples
simShow = "sampleCode",
},
{
x = 162,
y = 548,
title="Demos",
link="https://docs.coronalabs.com/guide/programming/index.html?utm_source=simulator#demo-projects", -- Demos
},
{
x = 162,
y = 585,
title="Ads / Monetization",
link="https://docs.coronalabs.com/guide/monetization/monetization/?utm_source=simulator", -- Ads & monetization
},
{
x = 162,
y = 622,
title="Request a Feature",
link="https://github.com/coronalabs/corona/issues", -- Request a Feature
},
}
-- onRelease Event Listeners for Links
local function onQuickLink(link)
if not uiTouchesDisabled then
disableTouches()
if link.simShow then
simulator.show( link.simShow )
simulator.analytics("welcome", "link", link.title)
else
OpenURL( link.link, link.title )
end
timer.performWithDelay( 500, enableTouches )
end
return true
end
for i = 1, #quickLinksData do
local link = quickLinksData[i]
local quickLinkBtn = newRetinaText(link.title, link.x, link.y, fontSizeLinkAndNews)
quickLinkBtn:setFillColor( unpack(textColorLinks) )
quickLinkBtn.anchorX = 0
local function onHover( hover )
quickLinkBtn:setFillColor( unpack(hover and textColorSelected or textColorLinks) )
end
addHoverObject(quickLinkBtn, onHover)
quickLinkBtn:addEventListener( "touch", function( event )
if event.phase == 'ended' then
onQuickLink(link)
end
end )
g_pointerLocations.quickLink[i] =
{
cursor = "pointingHand",
x = quickLinkBtn.x - (quickLinkBtn.anchorX * quickLinkBtn.contentWidth),
y = quickLinkBtn.y - (quickLinkBtn.anchorY * quickLinkBtn.contentHeight),
width = quickLinkBtn.contentWidth,
height = quickLinkBtn.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.quickLink[i])
end
end
setupQuickLinks()
-- -----------------------------------------------------------------------------------------
-- -- RECENT NEWS
-- -----------------------------------------------------------------------------------------
local latestGroup = display.newGroup( )
local latestNews = display.newImageRect(latestGroup, "assets/groupNews.png", 17, 17)
latestNews.x = 351
latestNews.y = 500
local latestNewsTitle = newRetinaText( "Latest News", latestNews.x+latestNews.contentWidth*0.5+5, quickLinks.y, fontSizeSections)
latestGroup:insert(latestNewsTitle)
latestNewsTitle.anchorX = 0
latestNewsTitle:setFillColor(unpack(textColorNormal))
latestGroup:insert( latestNewsLine )
latestGroup.isVisible = false
local function newTooltip(object, text )
local x = object.x + object.contentWidth*(0.5-object.anchorX)
local y = object.y - object.contentHeight*object.anchorY
local border = 2
local triangle = display.newImageRect( "assets/tooltip.png", 15, 8 )
triangle.anchorY = 1
triangle.x = x
triangle.y = y
local label = newRetinaText(text, x, y - border - triangle.contentHeight , fontSizeTooltip)
label:translate(0, -label.contentHeight*0.5)
label:setFillColor( unpack(textColorHits) )
if label.x + label.contentWidth*0.5 + border + 10 > display.contentWidth then
label:translate(display.contentWidth-(label.x + label.contentWidth*0.5 + border + 10), 0)
end
local bgRc = display.newRect( label.x, label.y, label.contentWidth+border*2, label.contentHeight+border*2 )
bgRc:setFillColor( unpack(hintsBGColor) )
local tooltip = display.newGroup( )
tooltip.alpha = 0
tooltip:insert( triangle )
tooltip:insert( bgRc )
tooltip:insert( label )
local tooltipFadein = nil
local function tooltipObjectHover( hover )
if hover then
if not tooltipFadein then
tooltipFadein = transition.fadeIn( tooltip, { time=200 } )
end
else
tooltip.alpha = 0
if tooltipFadein then
transition.cancel( tooltipFadein )
tooltipFadein = nil
end
end
end
addHoverObject(object, tooltipObjectHover)
return tooltip
end
local function loadFeedPanel(feedModificationDate, blogFeed)
if not (feedScroll == nil) then
feedScroll:removeSelf()
feedScroll = nil
end
if feedModificationDate then
-- If more than a month has passed since the news feed was updated, hide the "Latest News" panel
local numSecondsInAMonth = (60*60*24*30)
if (os.time() - feedModificationDate) > numSecondsInAMonth then
return
end
else
return
end
if not blogFeed or #blogFeed == 0 then
return
end
latestGroup.isVisible = true
local feedYs = {548, 585, 622}
for i = 1, #feedYs do
if blogFeed[i] then
local text = unescape(blogFeed[i].title)
local url = blogFeed[i].url:gsub('&#(%d+);', function(n) return string.char(n) end) -- fix broken URL encoding
if url:find('%?') then
url = url .. "&ref=homescreen"
else
url = url .. "?ref=homescreen"
end
-- text = text .. ' ' .. text
local availableWidth = 280
local shortedText = limitDisplayLength(availableWidth, text, fontRegular, fontSizeLinkAndNews)
local newsItem = newRetinaText(shortedText, 344, feedYs[i], fontSizeLinkAndNews)
newsItem:setFillColor( unpack(textColorLinks) )
newsItem.anchorX = 0
if text ~= shortedText then
newTooltip(newsItem, text)
end
local function onHover( hover )
newsItem:setFillColor( unpack(hover and textColorSelected or textColorLinks) )
end
addHoverObject(newsItem, onHover)
newsItem:addEventListener( "touch", function( e )
if e.phase == "ended" then
OpenURL( url, "newsfeed-item" )
end
end )
g_pointerLocations.feeds[i] =
{
cursor = "pointingHand",
x = newsItem.x - (newsItem.anchorX * newsItem.contentWidth),
y = newsItem.y - (newsItem.anchorY * newsItem.contentHeight),
width = newsItem.contentWidth,
height = newsItem.contentHeight,
}
if g_currentTab == "tab1" then
simulator.setCursorRect(g_pointerLocations.feeds[i])
end
end
end
end
-- Parse a HTTP header date and return the number of seconds since the epoch
local function parseHTTPDateFormat(dateStr)
if dateStr == nil then
-- print("parseHTTPDateFormat: missing date")
return nil
end
local datePattern = '(%d+) (%a+) (%d+)'
local dayMatch, monthMatch, yearMatch = dateStr:match(datePattern)
local year = 0
local day = 0
local month = 0
if dayMatch and monthMatch and yearMatch then
local months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
for k,v in ipairs(months) do
if monthMatch == v then
month = k
break
end
end
day = dayMatch
year = yearMatch
end
if month == 0 then
-- print("parseHTTPDateFormat: unrecognized date format: "..tostring(dateStr))
return nil
end
return os.time{year=year, month=month, day=day, hour=0}
end
-- BUTTONS
local function onNewProject()
if not uiTouchesDisabled then
disableTouches()
simulator.show( "new" )
simulator.analytics("welcome", "button", "New Project")
timer.performWithDelay( 500, enableTouches )
end
return true
end
local function onOpenProject()
if not uiTouchesDisabled then
disableTouches()
-- Launch the actual simulator (open project)
simulator.show( "open" )
simulator.analytics("welcome", "button", "Open Project")
timer.performWithDelay( 500, enableTouches )
end
return true
end
local function onRelaunchProject()
if not uiTouchesDisabled then
simulator.show( "relaunchProject" )
end
return true
end
local bigButtons = {
{
title = "New Project",
x = 125,
y = 265,
y2 = 341,
w = 89,
h = 73.5,
image = "assets/projectNew.png",
hover = "assets/projectNewHover.png",
handler = onNewProject,
},
{
title = "Open Project",
x = 305,
y = 265,
y2 = 341,
w = 89,
h = 73.5,
image = "assets/projectOpen.png",
hover = "assets/projectOpenHover.png",
handler = onOpenProject,
},
{
title = "Relaunch Project",
x = 485,
y = 265,
y2 = 341,
w = 89,
h = 73.5,
image = "assets/projectRelaunch.png",
hover = "assets/projectRelaunchHover.png",
handler = onRelaunchProject,
}
}
function addProjectButtons()
for i = 1, #bigButtons do
local info = bigButtons[i]
local btn = display.newImageRect(info.image, info.w, info.h )
btn.x = info.x
btn.y = info.y
local btnHover = display.newImageRect(info.hover, info.w, info.h )
btnHover.isVisible = false
btnHover.x = info.x
btnHover.y = info.y
local btnName = newRetinaText(info.title, info.x, info.y2, fontSizeProjectButtons, true)
btnName:setFillColor( unpack(textColorNormal) )
local function onHover( hover )
btn.isVisible = not hover
btnHover.isVisible = hover
btnName:setFillColor( unpack(hover and textColorSelected or textColorNormal) )
end
local h = info.y2-info.y+btnName.contentHeight*0.5+info.h*0.5
local clickRect = display.newRect(info.x, info.y-info.h*0.5 + h*0.5, math.max(info.w, btnName.contentWidth), h )
clickRect.isVisible = false
clickRect.isHitTestable = true
addHoverObject(clickRect, onHover)
clickRect:addEventListener( "touch", function( e )
if e.phase == "ended" then
info.handler()
end
end )
g_pointerLocations.button.image[i] =
{
cursor = "pointingHand",
x = clickRect.x - (clickRect.anchorX * clickRect.contentWidth),
y = clickRect.y - (clickRect.anchorY * clickRect.contentHeight),
width = clickRect.contentWidth,
height = clickRect.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.button.image[i])
end
end
addProjectButtons()
-------------------
-- Copyright Notice
-------------------
local copyright1 = newRetinaText("© 2020-2021 Solar2D ", 34, 675, fontSizeCopyright)
copyright1:translate( copyright1.contentWidth*0.5, 0 )
copyright1:setFillColor( unpack(textColorCopyright) )
local copyright2 = newRetinaText("Term of service", copyright1.x + copyright1.contentWidth*0.5, copyright1.y, fontSizeCopyright)
copyright2:setFillColor( unpack(textColorCopyright) )
copyright2:translate(copyright2.contentWidth*0.5, 0)
local unlderlineY = copyright2.y+copyright2.contentHeight*0.5 - 1.5
local underline = display.newLine(copyright2.x - copyright2.contentWidth*0.5, unlderlineY, copyright2.x + copyright2.contentWidth*0.5, unlderlineY)
underline:setStrokeColor( unpack(textColorCopyright) )
local function onHover( hover )
underline:setStrokeColor( unpack(hover and textColorSelected or textColorCopyright) )
copyright2:setFillColor( unpack(hover and textColorSelected or textColorCopyright) )
end
addHoverObject(copyright2, onHover)
copyright2:addEventListener( "touch", function( event )
if event.phase == "ended" then
OpenURL("https://solar2d.com/LICENSE.txt", "Term of service")
end
end )
g_pointerLocations.quickLink[#g_pointerLocations.quickLink+1] =
{
cursor = "pointingHand",
x = copyright2.x - (copyright2.anchorX * copyright2.contentWidth),
y = copyright2.y - (copyright2.anchorY * copyright2.contentHeight),
width = copyright2.contentWidth,
height = copyright2.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.quickLink[#g_pointerLocations.quickLink])
local copyright3 = newRetinaText(" & ", 34, 675, fontSizeCopyright)
copyright3.x = copyright2.x + copyright2.contentWidth*0.5 + copyright3.contentWidth*0.5
copyright3:setFillColor( unpack(textColorCopyright) )
local copyright4 = newRetinaText("Privacy Policy.", copyright3.x + copyright3.contentWidth*0.5, copyright3.y, fontSizeCopyright)
copyright4:setFillColor( unpack(textColorCopyright) )
copyright4:translate(copyright4.contentWidth*0.5, 0)
local unlderlineY = copyright4.y+copyright4.contentHeight*0.5 - 1.5
local underline = display.newLine(copyright4.x - copyright4.contentWidth*0.5, unlderlineY, copyright4.x + copyright4.contentWidth*0.5, unlderlineY)
underline:setStrokeColor( unpack(textColorCopyright) )
local function onHover( hover )
underline:setStrokeColor( unpack(hover and textColorSelected or textColorCopyright) )
copyright4:setFillColor( unpack(hover and textColorSelected or textColorCopyright) )
end
addHoverObject(copyright4, onHover)
copyright4:addEventListener( "touch", function( event )
if event.phase == "ended" then
OpenURL("https://solar2d.com/PRIVACY_POLICY.txt", "Privacy Policy")
end
end )
g_pointerLocations.quickLink[#g_pointerLocations.quickLink+1] =
{
cursor = "pointingHand",
x = copyright4.x - (copyright4.anchorX * copyright4.contentWidth),
y = copyright4.y - (copyright4.anchorY * copyright4.contentHeight),
width = copyright4.contentWidth,
height = copyright4.contentHeight,
}
simulator.setCursorRect(g_pointerLocations.quickLink[#g_pointerLocations.quickLink])
-------------------
--- RECENT PROJECTS
-------------------
local recentProjects = display.newImageRect("assets/groupRecent.png", 17, 17)
recentProjects.x = 694
recentProjects.y = 151
local recentProjectsTitle = newRetinaText("Recent Projects", recentProjects.x+recentProjects.contentWidth*0.5+5, recentProjects.y, fontSizeSections)
recentProjectsTitle.anchorX = 0
recentProjectsTitle:setFillColor(unpack(textColorNormal))
local recentsGroup = display.newGroup( )
local projectsButtonWidth = 325
local function createProjectActions(x, y, projectURL)
local group = display.newGroup()
local activeGroup = display.newGroup()
group:insert( activeGroup )
local mini = display.newImageRect( group, "assets/miniMenu.png", 17,17 )
mini:translate(x,y)
local miniActive = display.newImageRect( activeGroup, "assets/miniMenuHover.png", 17,17 )
miniActive:translate(x,y)
local function createActiveButton(x, img, hover, tooltipText, func)
local btn = display.newImageRect( activeGroup, img, 17,17 )
btn.x = x
btn.y = y
local btnHover = display.newImageRect( activeGroup, hover, 17,17 )
btnHover.x = x
btnHover.y = y
btnHover.isVisible = false
btnHover.isHitTestable = true
local tooltip = newTooltip(btnHover, tooltipText)
activeGroup:insert( tooltip )
addHoverObject(btnHover, function( hover )
btnHover.isVisible = hover
btn.isVisible = not hover
end)
btnHover:addEventListener( "touch", function( event )
if event.phase == "ended" then
-- howerListener{}
func()
return true
end
end )
end
x = x-32
createActiveButton(x, "assets/miniSandbox.png", "assets/miniSandboxHover.png", "Show Project Sandbox", function()
if not uiTouchesDisabled then
disableTouches()
simulator.show( "showSandbox", projectURL)
timer.performWithDelay( 500, enableTouches )
end
end)
x = x-32
createActiveButton(x, "assets/miniBrowse.png", "assets/miniBrowseHover.png", "Show Project Files", function()
if not uiTouchesDisabled then
disableTouches()
simulator.show( "showFiles", projectURL)
timer.performWithDelay( 500, enableTouches )
end
end)
x = x-32
createActiveButton(x, "assets/miniEdit.png", "assets/miniEditHover.png", "Open in Editor", function()
if not uiTouchesDisabled then
disableTouches()
simulator.show( "editProject", projectURL)
timer.performWithDelay( 500, enableTouches )
end
end)
x = x-32
createActiveButton(x, "assets/miniOpen.png", "assets/miniOpenHover.png", "Open", function()
if not uiTouchesDisabled then
disableTouches()
simulator.show( "open", projectURL)
timer.performWithDelay( 500, enableTouches )
end