77-- | |
88-- |_|
99-- https://github.com/swkeep
10+
1011local selected_test = 1
1112local test_refs = {}
1213local global_test_refs = {}
1314local global_status = " "
14- local active_emoji_template = ' |<span style="filter: hue-rotate(300deg);">%s</span>'
15- local inactive_emoji_template = ' |<span style="filter: hue-rotate(150deg);">%s</span>'
16- local emoji_numbers = {
17- " 1️⃣" , " 2️⃣" , " 3️⃣" , " 4️⃣" , " 5️⃣" , " 6️⃣" , " 7️⃣" , " 8️⃣" , " 9️⃣"
18- }
15+ local active_template = ' <span class="test-badge-active">%s</span>'
16+ local inactive_template = ' <span class="test-badge-inactive">%s</span>'
1917
2018local test_slots = {
2119 front = {
@@ -51,18 +49,19 @@ local function unload_selected_test()
5149end
5250
5351local function update_global_status ()
54- global_status = ' '
52+ global_status = " "
5553 for index , ref in pairs (global_test_refs ) do
5654 if ref .active then
57- global_status = global_status .. active_emoji_template :format (emoji_numbers [ index ] )
55+ global_status = global_status .. active_template :format (index )
5856 else
59- global_status = global_status .. inactive_emoji_template :format (emoji_numbers [ index ] )
57+ global_status = global_status .. inactive_template :format (index )
6058 end
6159 end
62- global_status = global_status .. " |"
6360end
6461
65- function InternalGetTestSlot (slot_name , index ) return test_slots [slot_name ][index ] end
62+ function InternalGetTestSlot (slot_name , index )
63+ return test_slots [slot_name ] and test_slots [slot_name ][index ] or nil
64+ end
6665
6766function InternalRegisterTest (init_fn , cleanup_fn , name , display_name , icon , description , badge )
6867 test_refs [# test_refs + 1 ] = {
@@ -76,10 +75,12 @@ function InternalRegisterTest(init_fn, cleanup_fn, name, display_name, icon, des
7675 }
7776end
7877
79- function InternalRegisterGlobalTest (init_fn , cleanup_fn , name , display_name , icon )
78+ function InternalRegisterGlobalTest (init_fn , cleanup_fn , name , display_name , icon , description , badge )
8079 global_test_refs [# global_test_refs + 1 ] = {
8180 name = name ,
8281 display_name = display_name ,
82+ description = description ,
83+ badge = badge ,
8384 init = init_fn ,
8485 cleanup = cleanup_fn ,
8586 icon = icon
8889
8990CreateThread (function ()
9091 if not DEVMODE then return end
91- Wait (250 )
92+ Wait (250 ) -- wait for other examples to register
93+
9294 table.sort (test_refs , function (a , b ) return a .name < b .name end )
9395
9496 local test_menu_options = {
9597 {
9698 template = [[
97- <div class="menu-cell menu-span2" style="display:flex; justify-content:space-between; flex-direction:column; align-items:center; padding:10px; gap:16px;">
98- <div class="menu-label" style="font-weight:bold; color:#fff; font-size:1.8rem;">Payment Method</div>
99- <div class="menu-value" style="color:#00ffcc; font-size:3rem;">{{active_menu}}</div>
99+ <style>
100+ .menu-cell {
101+ display: flex;
102+ flex-direction: column;
103+ align-items: center;
104+ padding: 10px;
105+ gap: 12px;
106+ background: rgba(40,40,40,0.0);
107+ border-radius: 12px;
108+ }
109+
110+ .menu-span2 {
111+ width: 100%;
112+ }
113+
114+ .menu-label {
115+ font-weight: 700;
116+ color: #fff;
117+ font-size: 1.4rem;
118+ }
119+
120+ .menu-value {
121+ color: #00ffcc;
122+ font-size: 2.6rem;
123+ text-align: center;
124+ line-height: 1.1;
125+ min-height: 2.2rem;
126+ }
127+
128+ .center-column {
129+ display: flex;
130+ flex-direction: column;
131+ justify-content: center;
132+ align-items: center;
133+ }
134+ </style>
135+ <div class="menu-cell menu-span2 center-column">
136+ <div class="menu-label">Selected Test</div>
137+ <div class="menu-value">{{active_menu}}</div>
100138</div>
101139]] ,
102140 bind = function ()
103- return { active_menu = test_refs [selected_test ].display_name }
141+ return {
142+ active_menu = test_refs [selected_test ] and test_refs [selected_test ].display_name or " None" ,
143+ }
104144 end
105145 }
106146 }
@@ -113,7 +153,7 @@ CreateThread(function()
113153 icon = test .icon ,
114154 action = function ()
115155 if selected_test == index then
116- warn ( ' Test already selected ' )
156+ unload_selected_test ( )
117157 return
118158 end
119159 unload_selected_test ()
@@ -129,9 +169,71 @@ CreateThread(function()
129169 local global_menu_options = {
130170 {
131171 template = [[
132- <div class="menu-cell menu-span2" style="display:flex; flex-direction:column; align-items:center; padding:10px; gap:8px; background:rgba(50,50,50,0.85); border-radius:8px; border:1px solid #444;">
133- <div class="menu-label" style="font-weight:bold; color:#fff; font-size:1.4rem;">Global Test Status</div>
134- <div class="menu-value" style="font-size:2rem; color:#ffcc00;">{{status}}</div>
172+ <style>
173+ .menu-status {
174+ display: flex;
175+ width: 100%;
176+ flex-direction: column;
177+ align-items: center;
178+ justify-content: center;
179+ padding: 16px 20px;
180+ background: rgba(30,30,30,0.95);
181+ border-radius: 12px;
182+ border: 2px solid #666;
183+ box-shadow: 0 4px 8px rgba(0,0,0,0.4);
184+ }
185+
186+ .menu-status .menu-label {
187+ font-weight: 700;
188+ color: #fff;
189+ font-size: 1.6rem;
190+ margin-bottom: 12px;
191+ text-shadow: 1px 1px 2px #000;
192+ }
193+
194+ .menu-status .menu-value {
195+ font-size: 2.4rem;
196+ font-weight: 700;
197+ text-align: center;
198+ line-height: 2.4rem;
199+ min-height: 3rem;
200+ display: flex;
201+ flex-wrap: wrap;
202+ gap: 6px;
203+ }
204+
205+ .test-badge-active {
206+ color: #00ff00;
207+ background: rgba(0,255,0,0.15);
208+ font-weight: bold;
209+ padding: 4px 8px;
210+ border-radius: 6px;
211+ display: inline-block;
212+ transition: transform 0.2s ease;
213+ }
214+
215+ .test-badge-active:hover {
216+ transform: scale(1.2);
217+ }
218+
219+ .test-badge-inactive {
220+ color: #ff5555;
221+ background: rgba(255,0,0,0.1);
222+ font-weight: bold;
223+ padding: 4px 8px;
224+ border-radius: 6px;
225+ display: inline-block;
226+ opacity: 0.7;
227+ transition: transform 0.2s ease;
228+ }
229+
230+ .test-badge-inactive:hover {
231+ transform: scale(1.1);
232+ }
233+ </style>
234+ <div class="menu-cell menu-span2 menu-status">
235+ <div class="menu-label">Global Test Status</div>
236+ <div class="menu-value">{{{status}}}</div>
135237</div>
136238]] ,
137239 bind = function ()
@@ -140,9 +242,9 @@ CreateThread(function()
140242 }
141243 }
142244
143- for _ , global_ref in pairs (global_test_refs ) do
245+ for index , global_ref in pairs (global_test_refs ) do
144246 global_menu_options [# global_menu_options + 1 ] = {
145- label = global_ref .display_name ,
247+ label = ( " [%d] %s " ): format ( index , global_ref .display_name ) ,
146248 description = global_ref .description ,
147249 icon = global_ref .icon ,
148250 action = function ()
@@ -198,6 +300,8 @@ CreateThread(function()
198300
199301 AddEventHandler (' onResourceStop' , function (resource )
200302 if resource ~= GetCurrentResourceName () then return end
201- if selected_test then test_refs [selected_test ].cleanup () end
303+ if selected_test and test_refs [selected_test ] and test_refs [selected_test ].cleanup then
304+ test_refs [selected_test ].cleanup ()
305+ end
202306 end )
203307end )
0 commit comments