Skip to content

Commit

Permalink
Merge pull request #5505 from Atermonera/optimize_supply
Browse files Browse the repository at this point in the history
Optimizes supply UI
  • Loading branch information
Anewbe committed Aug 17, 2018
2 parents ef1f0cb + 21a2772 commit 6ea25d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 59 deletions.
53 changes: 25 additions & 28 deletions code/game/machinery/computer/supply.dm
Expand Up @@ -11,7 +11,7 @@
var/temp = null
var/reqtime = 0 //Cooldown for requisitions - Quarxink
var/can_order_contraband = 0
var/last_viewed_group = "categories"
var/active_category = null
var/menu_tab = 0
var/list/expanded_packs = list()

Expand Down Expand Up @@ -48,8 +48,7 @@
/obj/machinery/computer/supplycomp/ui_interact(mob/user, ui_key = "supply_records", var/datum/nanoui/ui = null, var/force_open = 1, var/key_state = null)
var/data[0]
var/shuttle_status[0] // Supply shuttle status
var/supply_pack[0] // List of supply packs, sorted by category
var/sorted_pack[0] // List of supply packs, sorted by category, with numerical indices for nanoUI iteration
var/pack_list[0] // List of supply packs within the active_category
var/orders[0]
var/receipts[0]

Expand Down Expand Up @@ -106,30 +105,23 @@
else
shuttle["mode"] = SUP_SHUTTLE_ERROR

// Uses two separate lists, one of which indexes on the category for easy insertion
for(var/cat in all_supply_groups) // Global list of supply categories
supply_pack[cat] = list() // Create an index for the category

for(var/pack_name in supply_controller.supply_pack)
var/datum/supply_pack/P = supply_controller.supply_pack[pack_name]
var/list/pack = list(
"name" = P.name,
"cost" = P.cost,
"contraband" = P.contraband,
"manifest" = uniquelist(P.manifest),
"random" = P.num_contained,
"expand" = 0,
"ref" = "\ref[P]"
)


if(P in expanded_packs)
pack["expand"] = 1

supply_pack[P.group][++supply_pack[P.group].len] = pack

for(var/index in supply_pack)
sorted_pack[++sorted_pack.len] = list("name" = index, "category_packs" = supply_pack[index])
if(P.group == active_category)
var/list/pack = list(
"name" = P.name,
"cost" = P.cost,
"contraband" = P.contraband,
"manifest" = uniquelist(P.manifest),
"random" = P.num_contained,
"expand" = 0,
"ref" = "\ref[P]"
)

if(P in expanded_packs)
pack["expand"] = 1

pack_list[++pack_list.len] = pack

// Compile user-side orders
// Status determines which menus the entry will display in
Expand Down Expand Up @@ -169,7 +161,9 @@
data["order_auth"] = (authorization & SUP_ACCEPT_ORDERS) // Whether this ui is permitted to accept/deny requested orders
data["shuttle"] = shuttle_status
data["supply_points"] = supply_controller.points
data["supply_packs"] = sorted_pack
data["categories"] = all_supply_groups
data["active_category"] = active_category
data["supply_packs"] = pack_list
data["orders"] = orders
data["receipts"] = receipts
data["contraband"] = can_order_contraband
Expand All @@ -184,8 +178,8 @@
ui.set_initial_data(data)
// open the new ui window
ui.open()
// auto update every five Master Controller tick
ui.set_auto_update(5)
// auto update every 20 Master Controller tick
ui.set_auto_update(20) // Longer term to reduce the rate of data collection and processing



Expand All @@ -210,6 +204,9 @@
if(href_list["switch_tab"])
menu_tab = href_list["switch_tab"]

if(href_list["active_category"])
active_category = href_list["active_category"]

if(href_list["pack_ref"])
var/datum/supply_pack/S = locate(href_list["pack_ref"])

Expand Down
62 changes: 31 additions & 31 deletions nano/templates/supply_records.tmpl
Expand Up @@ -73,9 +73,9 @@

<!-- List supply pack categories -->
{{if data.currentTab == 1}}
{{for data.supply_packs}}
{{for data.categories}}
<div class='item'>
{{:helper.link(value.name, 'bookmark', {'switch_tab' : value.name})}}
{{:helper.link(value, 'bookmark', {'switch_tab' : value, 'active_category' : value})}}
</div>
{{/for}}

Expand Down Expand Up @@ -187,39 +187,39 @@
<!-- List supplypacks from individual category -->
<!-- currentTab will be set to the category name -->
{{else}}
{{for data.supply_packs}}
{{if data.currentTab == value.name}}
<div class='item'>
{{:helper.link('Back to categories', 'arrow-return-1-w', {'switch_tab' : 1})}}
</div>

<h4>
{{:data.active_category}}
</h4>

{{for data.supply_packs :packValue:packIndex}}
{{if !packValue.contraband || data.contraband}}
<div class='item'>
{{:helper.link('Back to categories', 'arrow-return-1-w', {'switch_tab' : 1})}}
<!-- Sending 'expand' will toggle the value of packValue.expand -->
{{:helper.link(packValue.name + ' - ' + packValue.cost, packValue.expand ? 'folder-open' : 'folder-collapsed', {'cartridge_topic' : 1, 'pack_ref' : packValue.ref, 'expand' : 1})}}
</div>

{{for value.category_packs :packValue:packIndex}}
{{if !packValue.contraband || data.contraband}}
<div class='item'>
<!-- Sending 'expand' will toggle the value of packValue.expand -->
{{:helper.link(packValue.name + ' - ' + packValue.cost, packValue.expand ? 'folder-open' : 'folder-collapsed', {'cartridge_topic' : 1, 'pack_ref' : packValue.ref, 'expand' : 1})}}

{{if packValue.expand}}
<div class='item'>
<div class='itemLabel'>
{{if packValue.random}}
Contains any {{:packValue.random}} of:<br>
{{/if}}

{{for packValue.manifest :manifestElem:manifestIndex}}
{{:manifestElem}}<br>
{{/for}}
</div>

{{if packValue.expand}}
<div class='item'>
<div class='itemLabel'>
{{if packValue.random}}
Contains any {{:packValue.random}} of:<br>
{{/if}}

{{for packValue.manifest :manifestElem:manifestIndex}}
{{:manifestElem}}<br>
{{/for}}
</div>

<div class='itemContent'>
{{:helper.link('Request', 'cart', {'cartridge_topic' : 1, 'pack_ref' : packValue.ref, 'request' : 1, 'user' : data.user})}}
</div>
</div>
<hr>
{{/if}}
{{/if}}
{{/for}}
<div class='itemContent'>
{{:helper.link('Request', 'cart', {'cartridge_topic' : 1, 'pack_ref' : packValue.ref, 'request' : 1, 'user' : data.user})}}
</div>
</div>
<hr>
{{/if}}
{{/if}}
{{/for}}
{{/if}}
Expand Down

0 comments on commit 6ea25d6

Please sign in to comment.