starlit  Diff

Differences From Artifact [16bf595c8c]:

To Artifact [5149fd5b74]:


131
132
133
134
135
136
137

138
139
140
141
142
143
144

145
146
147
148
149
150
151
...
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
...
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
		return climg('',         'starlit-ui-button-sw.png')       ..
		       climg(':hovered', 'starlit-ui-button-sw-hover.png') ..
		       climg(':pressed', 'starlit-ui-button-sw-press.png')
	end
	local function widget(...)
		table.insert(lines, string.format(...))
	end

	if def.kind == 'vert' then
		for _, w in ipairs(def) do
			local src, st = starlit.ui.build(w, state)
			widget('container[%s,%s]%scontainer_end[]', state.x, state.y, src)
			state.y=state.y + state.spacing + st.h
			state.w = math.max(state.w, st.w)
		end

		state.w = state.w + state.padding
		state.h = state.y + state.padding/2
	elseif def.kind == 'hztl' then
		for _, w in ipairs(def) do
			local src, st = starlit.ui.build(w, state)
			widget('container[%s,%s]%scontainer_end[]', state.x, state.y, src)
			-- TODO alignments
................................................................................
				def.id)
		end
		state.w = state.w + state.padding
		state.h = state.h + state.padding/2
	elseif def.kind == 'list' then
		local slotTypes = {
			plain = {hue = 200, sat = -.1, lum = 0};
			element = {hue = 20, sat = -.3, lum = 0};
			chip = {hue = 0, sat = -1, lum = 0};
			psi = {hue = 300, sat = 0, lum = 0};
			power = {hue = 50, sat = 0, lum = .2};
		}
		local img
		if state.mode == 'hw' then
			img = lib.image('starlit-ui-slot-physical.png');
		else
			img = lib.image('starlit-ui-slot.png'):shift(slotTypes[def.listContent or 'plain']);
		end
		local spac = state.spacing




		widget('style_type[list;spacing=%s,%s]',spac,spac)
		assert(def.w and def.h, 'ui-lists require a fixed size')
		for lx = 0, def.w-1 do
		for ly = 0, def.h-1 do
			local ox, oy = state.x + lx*(1+spac), state.y + ly*(1+spac)
			table.insert(lines, string.format('image[%s,%s;1.1,1.1;%s]', ox-0.05,oy-0.05, img:render()))
		end end
		table.insert(lines, string.format('listcolors[#00000000;#ffffff10]')) -- FIXME
		table.insert(lines, string.format('list[%s;%s;%s,%s;%s,%s;%s]',
			E(def.target), E(def.inv),
			state.x, state.y,
			def.w,   def.h,
			def.idx))
		local sm = 1
		state.w = def.w * sm + (spac * (def.w - 1))
		state.h = def.h * sm + (spac * (def.h - 1))
	elseif def.kind == 'contact' then
................................................................................
		if def.color then table.insert(lines, btnColorDef(def.id)) end
		local img = def.img
		local desc
		if def.item then
			img  = ItemStack(def.item):get_name()
			desc = ItemStack(def.item):get_description()
		end

		widget('%simage_button%s[%s,%s;%s,%s;%s;%s;%s]',
			def.item and 'item_' or '',
			def.close and '_exit' or '',
			state.x, state.y, def.w, def.h,
			E(img), E(def.id), E(def.label or ''))
		if desc and not def.desc then
			widget('tooltip[%s;%s]', E(def.id), E(desc))

		end
	elseif def.kind == 'button' then
		if def.color then table.insert(lines, btnColorDef(def.id)) end
		local label = E(def.label or '')
		if state.fg then label = lib.color(state.fg):fmt(label) end
		widget('button%s[%s,%s;%s,%s;%s;%s]',
			def.close and '_exit' or '',
			state.x, state.y, def.w, def.h,
			E(def.id), label)




	elseif def.kind == 'img' then
		widget('%s[%s,%s;%s,%s;%s]',
			def.item and 'item_image' or 'image',
			state.x, state.y, def.w, def.h, E(def.item or def.img))
	elseif def.kind == 'label' then
		local txt = E(def.text)
		if state.fg then txt = lib.color(state.fg):fmt(txt) end
................................................................................
		if def.text then
			widget('hypertext[%s,%s;%s,%s;;%s]',
				state.x, state.y, def.w, def.h,
				string.format('<global halign=center valign=middle color=%s>%s', fg:hex(), E(def.text)))
		end
	end

	if def.desc then
		local coord
		if def.id then
			coord = E(def.id)
		else
			coord = string.format("%s,%s;%s,%s", state.x, state.y, def.w, def.h)
		end
		widget('tooltip[%s;%s;#000000;#ffffff]', coord, E(def.desc))







>







>







 







|

|









>
>
>
>









|







 







>





|

>









>
>
>
>







 







|







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
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
...
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
		return climg('',         'starlit-ui-button-sw.png')       ..
		       climg(':hovered', 'starlit-ui-button-sw-hover.png') ..
		       climg(':pressed', 'starlit-ui-button-sw-press.png')
	end
	local function widget(...)
		table.insert(lines, string.format(...))
	end
	local specializedTooltip = false
	if def.kind == 'vert' then
		for _, w in ipairs(def) do
			local src, st = starlit.ui.build(w, state)
			widget('container[%s,%s]%scontainer_end[]', state.x, state.y, src)
			state.y=state.y + state.spacing + st.h
			state.w = math.max(state.w, st.w)
		end
		state.y = state.y - state.spacing
		state.w = state.w + state.padding
		state.h = state.y + state.padding/2
	elseif def.kind == 'hztl' then
		for _, w in ipairs(def) do
			local src, st = starlit.ui.build(w, state)
			widget('container[%s,%s]%scontainer_end[]', state.x, state.y, src)
			-- TODO alignments
................................................................................
				def.id)
		end
		state.w = state.w + state.padding
		state.h = state.h + state.padding/2
	elseif def.kind == 'list' then
		local slotTypes = {
			plain = {hue = 200, sat = -.1, lum = 0};
-- 			element = {hue = 20, sat = -.3, lum = 0};
			chip = {hue = 0, sat = -1, lum = 0};
-- 			psi = {hue = 300, sat = 0, lum = 0};
			power = {hue = 50, sat = 0, lum = .2};
		}
		local img
		if state.mode == 'hw' then
			img = lib.image('starlit-ui-slot-physical.png');
		else
			img = lib.image('starlit-ui-slot.png'):shift(slotTypes[def.listContent or 'plain']);
		end
		local spac = state.spacing
		local target = def.target
		if not target and def.node then
			target=string.format('nodemeta:%s,%s,%s', def.node.x,def.node.y,def.node.z)
		end
		widget('style_type[list;spacing=%s,%s]',spac,spac)
		assert(def.w and def.h, 'ui-lists require a fixed size')
		for lx = 0, def.w-1 do
		for ly = 0, def.h-1 do
			local ox, oy = state.x + lx*(1+spac), state.y + ly*(1+spac)
			table.insert(lines, string.format('image[%s,%s;1.1,1.1;%s]', ox-0.05,oy-0.05, img:render()))
		end end
		table.insert(lines, string.format('listcolors[#00000000;#ffffff10]')) -- FIXME
		table.insert(lines, string.format('list[%s;%s;%s,%s;%s,%s;%s]',
			E(target), E(def.inv),
			state.x, state.y,
			def.w,   def.h,
			def.idx))
		local sm = 1
		state.w = def.w * sm + (spac * (def.w - 1))
		state.h = def.h * sm + (spac * (def.h - 1))
	elseif def.kind == 'contact' then
................................................................................
		if def.color then table.insert(lines, btnColorDef(def.id)) end
		local img = def.img
		local desc
		if def.item then
			img  = ItemStack(def.item):get_name()
			desc = ItemStack(def.item):get_description()
		end
		desc = def.desc or desc
		widget('%simage_button%s[%s,%s;%s,%s;%s;%s;%s]',
			def.item and 'item_' or '',
			def.close and '_exit' or '',
			state.x, state.y, def.w, def.h,
			E(img), E(def.id), E(def.label or ''))
		if desc then
			widget('tooltip[%s;%s]', E(def.id), E(desc))
			specializedTooltip = true
		end
	elseif def.kind == 'button' then
		if def.color then table.insert(lines, btnColorDef(def.id)) end
		local label = E(def.label or '')
		if state.fg then label = lib.color(state.fg):fmt(label) end
		widget('button%s[%s,%s;%s,%s;%s;%s]',
			def.close and '_exit' or '',
			state.x, state.y, def.w, def.h,
			E(def.id), label)
		if def.desc then
			widget('tooltip[%s;%s]', E(def.id), E(def.desc))
			specializedTooltip = true
		end
	elseif def.kind == 'img' then
		widget('%s[%s,%s;%s,%s;%s]',
			def.item and 'item_image' or 'image',
			state.x, state.y, def.w, def.h, E(def.item or def.img))
	elseif def.kind == 'label' then
		local txt = E(def.text)
		if state.fg then txt = lib.color(state.fg):fmt(txt) end
................................................................................
		if def.text then
			widget('hypertext[%s,%s;%s,%s;;%s]',
				state.x, state.y, def.w, def.h,
				string.format('<global halign=center valign=middle color=%s>%s', fg:hex(), E(def.text)))
		end
	end

	if def.desc and not specializedTooltip then
		local coord
		if def.id then
			coord = E(def.id)
		else
			coord = string.format("%s,%s;%s,%s", state.x, state.y, def.w, def.h)
		end
		widget('tooltip[%s;%s;#000000;#ffffff]', coord, E(def.desc))