Differences From
Artifact [497adf50ee]:
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
133 - return a.chipID == b.chipID and a.pgmIndex == b.pgmIndex
133 + return (a.chipID ~= nil and (a.chipID == b.chipID and a.pgmIndex == b.pgmIndex))
134 + or (a.ref ~= nil and a.ref == b.ref)
134 135 end
135 136
136 137 starlit.interface.install(starlit.type.ui {
137 138 id = 'starlit:user-menu';
138 139 pages = {
139 140 compiler = {
140 141 setupState = function(state, user)
................................................................................
357 358 local st = string.format('%s / %s', s.desc(amt, true), s.desc(max))
358 359 table.insert(tb, {kind = 'hztl', padding = 0.25;
359 360 {kind = 'label', w=2, h=barh, text = s.name};
360 361 {kind = 'hbar', w=4, h=barh, fac = sv, text = st, color=s.color};
361 362 })
362 363 end
363 364 local abilities = {
364 - {id = 'abl_sprint', label = 'Sprint', img = 'starlit-ui-icon-ability-sprint.png'};
365 + maneuver = {};
366 + direct = {};
367 + passive = {};
365 368 }
366 - table.insert(tb, wrapMenu(6.25,4, 1,2, abilities))
369 + state.abilityMap = {}
370 + for i, a in pairs(user:species().abilities) do
371 + local id = 'abl_'..a.id;
372 + state.abilityMap[id] = a;
373 + table.insert(abilities[a.powerKind], {
374 + id = id;
375 + label = a.name;
376 + desc = a.desc;
377 + img = a.img;
378 +
379 + -- HACK
380 + color = pptrMatch(user.power.maneuver, {ref=a}) and
381 + {hue = 150, sat = 0, lum = .3} or nil;
382 + });
383 + end
384 + for i, n in ipairs {'maneuver', 'direct', 'passive'} do
385 + if next(abilities[n]) then
386 + table.insert(tb, wrapMenu(6.25,4, 1,2, abilities[n]))
387 + end
388 + end
367 389 return starlit.ui.build(tb)
390 + end;
391 + handle = function(state, user, q)
392 + for k,a in pairs(state.abilityMap) do
393 + if q[k] then
394 + if a.powerKind == 'maneuver' then
395 + if pptrMatch(user.power.maneuver, {ref=a}) then
396 + user.power.maneuver = nil
397 + else
398 + user.power.maneuver = {ref=a}
399 + end
400 + user:suitSound 'starlit-configure'
401 + return true
402 + elseif a.powerKind == 'direct' then
403 + elseif a.powerKind == 'passive' then
404 + else error('bad ability kind ' .. a.powerKind) end
405 + break
406 + end
407 + end
368 408 end;
369 409 };
370 410 suit = {
371 411 render = function(state, user)
372 412 local suit = user:getSuit()
373 413 local suitDef = suit:def()
374 414 local chipW, chipH = listWrap(suitDef.slots.chips, 5)