Differences From
Artifact [6c49562563]:
118 118 end
119 119
120 120 local function abilityMenu(a)
121 121 -- select primary/secondary abilities or activate ritual abilities
122 122 local p = {kind = 'vert'}
123 123 for _, o in ipairs(a.order) do
124 124 local m = a.menu[o]
125 - table.insert(p, {kind='label', text=m.label, w=a.w, h = .5})
125 + table.insert(p, {kind='hbar', fac=0.5, text=string.format("<b>%s</b>",m.label), w=a.w, h = .5})
126 126 table.insert(p, wrapMenu(a.w, a.h, 1.2, 2, m.opts))
127 127 end
128 128 return p
129 129 end
130 130
131 131 local function pptrMatch(a,b)
132 132 if a == nil or b == nil then return false end
................................................................................
459 459 return true
460 460 end
461 461 end;
462 462 };
463 463 };
464 464 })
465 465
466 +-- TODO destroy suit interfaces when power runs out or suit/chip is otherwise disabled
466 467 starlit.interface.install(starlit.type.ui {
467 468 id = 'starlit:compile-matter-component';
469 + sub = {
470 + suit = function(state, user, evt)
471 + if evt.kind == 'disrobe' then state:close()
472 + elseif evt.kind == 'power' and evt.mode == 'off' then state:close() end
473 + end;
474 + playerInventory = function(state,user)
475 + -- refresh
476 + end;
477 + };
468 478 pages = {
469 479 index = {
470 480 setupState = function(state, user, ctx)
471 - if ctx.context == 'suit' then
472 - end
473 481 state.pgm = ctx.program
482 + state.select = {}
483 + local E = starlit.mod.electronics
484 + if ctx.context == 'suit' then
485 + state.fetch = function()
486 + local cst = user.entity:get_inventory():get_list 'starlit_suit_chips'
487 + local cl = {order={}, map={}}
488 + for i, c in ipairs(cst) do
489 + if not c:is_empty() then
490 + local d = E.chip.read(c)
491 + local co = {
492 + stack = c;
493 + data = d;
494 + }
495 + table.insert(cl.order, co)
496 + cl.map[d.uuid] = co
497 + end
498 + end
499 + if state.select.chip and not cl.map[state.select.chip.data.uuid] then
500 + -- chip no longer available
501 + user:suitSound 'starlit-error'
502 + state.select = {}
503 + end
504 + state.select.chips = cl
505 +
506 + state.select.scms = {}
507 + if state.select.chip then
508 + state.select.scms = E.chip.usableSoftware({state.select.chip.stack},nil,
509 + function(s) return s.sw.kind == 'schematic' end)
510 + end
511 + end
512 + end
513 + end;
514 +
515 + onClose = function(state, user)
516 + user:suitSound 'starlit-quit'
517 + end;
518 + handle = function(state, user, q)
519 + local sel = state.select
520 + state.fetch()
521 + local chips = state.select.chips
522 + local function chirp()
523 + user:suitSound 'starlit-nav'
524 + end
525 + local function onPickChip(chip)
526 + chirp()
527 + sel.chip = chip
528 + return true
529 + end
530 + local function onPickScm(scm)
531 + chirp()
532 + sel.scm = scm
533 + return true
534 + end
535 +
536 + if sel.chip == nil then
537 + for k in next, q do
538 + local id = k:match "^chip_(%d+)$"
539 + if id then
540 + local cm = chips.map[tonumber(id)]
541 + if cm then return onPickChip(cm) end
542 + end
543 + end
544 + elseif sel.scm == nil then
545 + if q.back then chirp() sel.chip = nil return true end
546 + for k in next, q do
547 + local id = k:match "^scm_(%d+)$"
548 + if id then
549 + local cm = state.select.scms[tonumber(id)]
550 + if cm then return onPickScm(cm) end
551 + end
552 + end
553 + else
554 + if q.back then chirp() sel.scm = nil return true end
555 + end
474 556 end;
557 +
475 558 render = function(state, user)
559 + local sel, pgmSelector = state.select, {}
560 + state.fetch()
561 +
562 + local function pushSelector(id, item, label, desc, req)
563 + local rh = .5
564 + local label = {kind = 'text', w = 10-1.5, h=1.5;
565 + text = '<global valign=middle>'..label }
566 + if req then
567 + label.h = label.h - rh - .2
568 +
569 + local imgs = {}
570 + for ci,c in ipairs(req) do
571 + for ei, e in ipairs(c.list) do
572 + table.insert(imgs, {kind = 'img', w=rh, h=rh, img=e.img})
573 + end
574 + end
575 + label = {kind = 'vert', w = 10-1.5, h=1.5;
576 + label;
577 + {kind ='hztl', w=10-1.5, h=rh; unpack(imgs); }
578 + }
579 + end
580 + table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.5;
581 + {kind = 'contact', id=id, w=1.5, h=1.5;
582 + item = item;
583 + color = {hue=220, sat=0, lum=0};
584 + desc = desc;
585 + };
586 + label;
587 + })
588 + end
589 +
590 + local back = {kind = 'button', id='back', label = '<- Back', w=10,h=1.2}
591 + if sel.chips == nil then
592 + table.insert(pgmSelector, {kind = 'img', img = 'starlit-ui-alert.png', w=2, h=2})
593 + elseif sel.chip == nil then
594 + for i, c in ipairs(sel.chips.order) do
595 + -- TODO filter out chips without schematics?
596 + pushSelector('chip_' .. c.data.uuid, c.stack, c.data.label)
597 + end
598 + else
599 + if sel.scm == nil then
600 + for idx, ent in ipairs(sel.scms) do
601 + local fab = ItemStack(ent.sw.output):get_definition()._starlit.fab
602 + if fab.flag.print then
603 + local req = fab:visualize()
604 + pushSelector('scm_' .. idx, ent.sw.output, ent.sw.name, nil, req)
605 + end
606 + end
607 + table.insert(pgmSelector, back)
608 + else
609 + local output = ItemStack(sel.scm.sw.output):get_definition()
610 + local fab = output._starlit.fab
611 + local sw = sel.scm.sw
612 + table.insert(pgmSelector, {kind = 'hztl', w=10, h=1.2;
613 + {kind = 'img', item = sw.output, w=1.2, h=1.2, desc=output.description};
614 + {kind = 'text', text = string.format('<global valign=middle><b>%s</b>', sw.name), w=10-1.2,h=1.2};
615 + })
616 + local inputTbl = {kind = 'vert', w=5,h=0;
617 + {kind = 'hbar', w=5, h=.5, text='Input'}};
618 + local costTbl = {kind = 'vert', w=5,h=0; spacing=.25;
619 + {kind = 'hbar', w=5, h=.5, text='Process'}};
620 + local reqPane = {kind = 'pane', id='reqPane', w=10, h=7;
621 + {kind = 'hztl', w=10,h=0; inputTbl, costTbl}
622 + }
623 + local req = fab:visualize()
624 + for ci,c in ipairs(req) do
625 + table.insert(inputTbl, {kind = 'label', w=4.5, h=1, x=.5;
626 + text=lib.str.capitalize(c.header)});
627 + for ei,e in ipairs(c.list) do
628 + table.insert(inputTbl, {kind = 'hztl', w=4, h=.5, x=1;
629 + {kind='img', w=.5,h=.5, img=e.img};
630 + {kind='label', w=3.3,h=.5,x=.2, text=e.label};
631 + });
632 + end
633 + end
634 + if sw.cost then
635 + local function pushCost(t, val)
636 + table.insert(costTbl, {kind='text', w=4.5,h=.5,x=.5;
637 + text=string.format('<b>%s</b>: %s',t,val);
638 + })
639 + end
640 + if sw.cost.cycles then
641 + pushCost('Energy', lib.math.siUI('J', sel.scm.powerCost))
642 + pushCost('Compute', lib.math.siUI({'cycle','cycles'}, sw.cost.cycles, true))
643 + end
644 + end
645 + table.insert(pgmSelector, reqPane)
646 + table.insert(pgmSelector, {kind = 'hztl', w=10,h=1.2;
647 + {kind = 'button', id='back', label = '<- Back', w=5,h=1.2};
648 + {kind = 'button', id='print', label = 'Print ->', w=5,h=1.2, color={hue=120,sat=0,lum=0}};
649 + })
650 + end
651 + end
652 +
476 653 return starlit.ui.build {
477 - kind = 'vert', padding = 0.5; w = 5, h = 5, mode = 'sw';
478 - {kind = 'label', w = 4, h = 1, text = 'hello'};
654 + kind = 'hztl', padding = 0.5; w = 20, h = 10, mode = 'sw';
655 + {kind = 'vert', w = 5, h = 5;
656 + {kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><left>Recent Prints</left></b>'};
657 + };
658 + {kind = 'vert', w = 10, h = 10;
659 + {kind = 'hbar', fac=0, w = 10, h = .5, text = '<b>Program Select</b>'};
660 + {kind = 'pane', w = 10, h = 9.5, id='pgmSelect';
661 + unpack(pgmSelector)
662 + };
663 + };
664 + {kind = 'vert', w = 5, h = 10;
665 + {kind = 'hbar', fac=0, w = 5, h = .5, text = '<b><right>Print Queue</right></b>'};
666 + };
479 667 }
480 668 end;
481 669 };
482 670 };
483 671 })