mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-17 02:54:44 +01:00
Crafting TGUI improvements (#19170)
* Reduced number of istype() calls per ui_data() by ((2*requirements_num) + catalysts_num + tools_num)*recipes_in_category_num * Added a "Compact" mode for crafting
This commit is contained in:
committed by
Joan Lung
parent
ca36e24fd2
commit
1caec83f5d
@@ -4,6 +4,7 @@
|
||||
var/list/categories = list(CAT_WEAPON,CAT_AMMO,CAT_ROBOT,CAT_FOOD,CAT_MISC,CAT_PRIMAL)
|
||||
var/datum/action/innate/crafting/button
|
||||
var/display_craftable_only = FALSE
|
||||
var/display_compact = FALSE
|
||||
|
||||
|
||||
|
||||
@@ -239,24 +240,26 @@
|
||||
/datum/personal_crafting/ui_interact(mob/user, ui_key = "main", datum/tgui/ui = null, force_open = 0, datum/tgui/master_ui = null, datum/ui_state/state = not_incapacitated_turf_state)
|
||||
ui = SStgui.try_update_ui(user, src, ui_key, ui, force_open)
|
||||
if(!ui)
|
||||
ui = new(user, src, ui_key, "personal_crafting", "Crafting Menu", 600, 800, master_ui, state)
|
||||
ui = new(user, src, ui_key, "personal_crafting", "Crafting Menu", 700, 800, master_ui, state)
|
||||
ui.open()
|
||||
|
||||
|
||||
/datum/personal_crafting/ui_data(mob/user)
|
||||
var/list/data = list()
|
||||
var/cur_category = categories[viewing_category]
|
||||
data["busy"] = busy
|
||||
data["prev_cat"] = categories[prev_cat()]
|
||||
data["category"] = categories[viewing_category]
|
||||
data["category"] = cur_category
|
||||
data["next_cat"] = categories[next_cat()]
|
||||
data["display_craftable_only"] = display_craftable_only
|
||||
data["display_compact"] = display_compact
|
||||
|
||||
var/list/surroundings = get_surroundings(user)
|
||||
var/list/can_craft = list()
|
||||
var/list/cant_craft = list()
|
||||
for(var/rec in crafting_recipes)
|
||||
var/datum/crafting_recipe/R = rec
|
||||
if(R.category != categories[viewing_category])
|
||||
if(R.category != cur_category)
|
||||
continue
|
||||
if(check_contents(R, surroundings))
|
||||
can_craft += list(build_recipe_data(R))
|
||||
@@ -294,6 +297,10 @@
|
||||
display_craftable_only = !display_craftable_only
|
||||
usr << "<span class='notice'>You will now [display_craftable_only ? "only see recipes you can craft":"see all recipes"].</span>"
|
||||
. = TRUE
|
||||
if("toggle_compact")
|
||||
display_compact = !display_compact
|
||||
usr << "<span class='notice'>Crafting menu is now [display_compact? "compact" : "full size"].</span>"
|
||||
. = TRUE
|
||||
|
||||
|
||||
//Next works nicely with modular arithmetic
|
||||
@@ -318,27 +325,23 @@
|
||||
var/tool_text = ""
|
||||
var/catalyst_text = ""
|
||||
|
||||
for(var/A in R.reqs)
|
||||
if(ispath(A, /obj))
|
||||
var/obj/O = A
|
||||
req_text += " [R.reqs[A]] [initial(O.name)],"
|
||||
else if(ispath(A, /datum/reagent))
|
||||
var/datum/reagent/RE = A
|
||||
req_text += " [R.reqs[A]] [initial(RE.name)],"
|
||||
for(var/a in R.reqs)
|
||||
//We just need the name, so cheat-typecast to /atom for speed (even tho Reagents are /datum they DO have a "name" var)
|
||||
//Also these are typepaths so sadly we can't just do "[a]"
|
||||
var/atom/A = a
|
||||
req_text += " [R.reqs[A]] [initial(A.name)],"
|
||||
req_text = replacetext(req_text,",","",-1)
|
||||
data["req_text"] = req_text
|
||||
|
||||
for(var/C in R.chem_catalysts)
|
||||
if(ispath(C, /datum/reagent))
|
||||
var/datum/reagent/RE = C
|
||||
catalyst_text += " [R.chem_catalysts[C]] [initial(RE.name)],"
|
||||
for(var/a in R.chem_catalysts)
|
||||
var/atom/A = a //cheat-typecast
|
||||
catalyst_text += " [R.chem_catalysts[A]] [initial(A.name)],"
|
||||
catalyst_text = replacetext(catalyst_text,",","",-1)
|
||||
data["catalyst_text"] = catalyst_text
|
||||
|
||||
for(var/O in R.tools)
|
||||
if(ispath(O, /obj))
|
||||
var/obj/T = O
|
||||
tool_text += " [R.tools[O]] [initial(T.name)],"
|
||||
for(var/a in R.tools)
|
||||
var/atom/A = a //cheat-typecast
|
||||
tool_text += " [R.tools[A]] [initial(A.name)],"
|
||||
tool_text = replacetext(tool_text,",","",-1)
|
||||
data["tool_text"] = tool_text
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
+13
-13
File diff suppressed because one or more lines are too long
@@ -2,87 +2,145 @@
|
||||
import { filterMulti } from 'util/filter'
|
||||
component.exports = {
|
||||
data: {
|
||||
filter: ''
|
||||
filter: '',
|
||||
tooltiptext(req_text, catalyst_text, tool_text){
|
||||
//This function is to get around the issue where you can't embed moustache variables within moustache statements
|
||||
//It's also less cramped than the tooltip attribute of the button tag :P
|
||||
let text = ""
|
||||
if(req_text){
|
||||
text += "REQUIREMENTS: " + req_text + " "
|
||||
}
|
||||
if(catalyst_text){
|
||||
text += "CATALYSTS: " + catalyst_text + " "
|
||||
}
|
||||
if(tool_text){
|
||||
text += "TOOLS: " + tool_text
|
||||
}
|
||||
return text
|
||||
}
|
||||
},
|
||||
oninit () {
|
||||
this.on({
|
||||
hover (event) {
|
||||
this.set('hovered', event.context.params)
|
||||
},
|
||||
unhover (event) {
|
||||
this.set('hovered')
|
||||
}
|
||||
})
|
||||
this.observe('filter', (newkey, oldkey, keypath) => {
|
||||
const categories = this.findAll('.display:not(:first-child)')
|
||||
let categories = null
|
||||
if(this.get('data.display_compact')){
|
||||
//This doesn't work, but it's necessary to not cause a script error with compact mode
|
||||
//Also hidden in compact mode
|
||||
categories = this.findAll('.section')
|
||||
} else {
|
||||
categories = this.findAll('.display:not(:first-child)')
|
||||
}
|
||||
filterMulti(categories, this.get('filter').toLowerCase())
|
||||
}, { init: false })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
<ui-display title='{{data.category}}'>
|
||||
{{#if data.busy}}
|
||||
<ui-section>
|
||||
Crafting... <i class='fa-spin fa fa-spinner'></i>
|
||||
</ui-section>
|
||||
{{else}}
|
||||
<ui-section>
|
||||
<ui-button icon='arrow-left' action ='backwardCat'>
|
||||
{{data.prev_cat}}
|
||||
</ui-button>
|
||||
<ui-button icon='arrow-right' action='forwardCat'>
|
||||
{{data.next_cat}}
|
||||
</ui-button>
|
||||
{{#if data.display_craftable_only}}
|
||||
<ui-button icon='lock' action='toggle_recipes'>
|
||||
Showing Craftable Recipes
|
||||
</ui-button>
|
||||
{{else}}
|
||||
<ui-button icon='unlock' action='toggle_recipes'>
|
||||
Showing All Recipes
|
||||
</ui-button>
|
||||
{{/if}}
|
||||
{{#if config.fancy}}
|
||||
<ui-input value='{{filter}}' placeholder='Filter..'/>
|
||||
{{/if}}
|
||||
</ui-section>
|
||||
{{#each data.can_craft}}
|
||||
<ui-display title='{{name}}'>
|
||||
{{#if req_text}}
|
||||
<ui-section label='Requirements'>
|
||||
{{req_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if catalyst_text}}
|
||||
<ui-section label='Catalysts'>
|
||||
{{catalyst_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if tool_text}}
|
||||
<ui-section label='Tools'>
|
||||
{{tool_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
<ui-section>
|
||||
<ui-button icon='gears' action='make' params='{"recipe": "{{ref}}"}'>
|
||||
Craft
|
||||
</ui-button>
|
||||
</ui-section>
|
||||
</ui-display>
|
||||
{{/each}}
|
||||
{{^data.display_craftable_only}}
|
||||
{{#each data.cant_craft}}
|
||||
<ui-display title='{{name}}'>
|
||||
{{#if req_text}}
|
||||
<ui-section label='Requirements'>
|
||||
{{req_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if catalyst_text}}
|
||||
<ui-section label='Catalysts'>
|
||||
{{catalyst_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if tool_text}}
|
||||
<ui-section label='Tools'>
|
||||
{{tool_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
</ui-display>
|
||||
{{/each}}
|
||||
{{/data.display_craftable_only}}
|
||||
{{/if}}
|
||||
{{#if data.busy}}
|
||||
<ui-section>
|
||||
Crafting... <i class='fa-spin fa fa-spinner'></i>
|
||||
</ui-section>
|
||||
{{else}}
|
||||
<ui-section>
|
||||
<ui-button icon='arrow-left' action='backwardCat'>
|
||||
{{data.prev_cat}}
|
||||
</ui-button>
|
||||
<ui-button icon='arrow-right' action='forwardCat'>
|
||||
{{data.next_cat}}
|
||||
</ui-button>
|
||||
{{#if data.display_craftable_only}}
|
||||
<ui-button icon='lock' action='toggle_recipes'>
|
||||
Showing Craftable Recipes
|
||||
</ui-button>
|
||||
{{else}}
|
||||
<ui-button icon='unlock' action='toggle_recipes'>
|
||||
Showing All Recipes
|
||||
</ui-button>
|
||||
{{/if}}
|
||||
<ui-button icon='{{data.display_compact ? "check-square-o" : "square-o"}}' action='toggle_compact'>
|
||||
Compact
|
||||
</ui-button>
|
||||
{{#if config.fancy}}
|
||||
{{^data.display_compact}} {{! This doesn't work in compact mode, so let's hide it}}
|
||||
<ui-input value='{{filter}}' placeholder='Filter..'/>
|
||||
{{/data.display_compact}}
|
||||
{{/if}}
|
||||
</ui-section>
|
||||
{{#if data.display_compact}}
|
||||
<ui-display>
|
||||
{{#each data.can_craft}}
|
||||
<ui-section label='{{name}}'>
|
||||
<ui-button tooltip='{{tooltiptext(req_text, catalyst_text, tool_text)}}' tooltip-side='right' action='make' params='{"recipe": "{{ref}}"}' on-hover='hover' on-unhover='unhover' icon='gears'>
|
||||
Craft
|
||||
</ui-button>
|
||||
</ui-section>
|
||||
{{/each}}
|
||||
{{^data.display_craftable_only}}
|
||||
{{#each data.cant_craft}}
|
||||
<ui-section label='{{name}}'>
|
||||
<ui-button tooltip='{{tooltiptext(req_text, catalyst_text, tool_text)}}' tooltip-side='right' state='disabled' on-hover='hover' on-unhover='unhover' icon='gears'>
|
||||
Craft
|
||||
</ui-button>
|
||||
</ui-section>
|
||||
{{/each}}
|
||||
{{/data.display_craftable_only}}
|
||||
</ui-display>
|
||||
{{else}}
|
||||
{{#each data.can_craft}}
|
||||
<ui-display title='{{name}}'>
|
||||
{{#if req_text}}
|
||||
<ui-section label='Requirements'>
|
||||
{{req_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if catalyst_text}}
|
||||
<ui-section label='Catalysts'>
|
||||
{{catalyst_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if tool_text}}
|
||||
<ui-section label='Tools'>
|
||||
{{tool_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
<ui-section>
|
||||
<ui-button icon='gears' action='make' params='{"recipe": "{{ref}}"}'>
|
||||
Craft
|
||||
</ui-button>
|
||||
</ui-section>
|
||||
</ui-display>
|
||||
{{/each}}
|
||||
{{^data.display_craftable_only}}
|
||||
{{#each data.cant_craft}}
|
||||
<ui-display title='{{name}}'>
|
||||
{{#if req_text}}
|
||||
<ui-section label='Requirements'>
|
||||
{{req_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if catalyst_text}}
|
||||
<ui-section label='Catalysts'>
|
||||
{{catalyst_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
{{#if tool_text}}
|
||||
<ui-section label='Tools'>
|
||||
{{tool_text}}
|
||||
</ui-section>
|
||||
{{/if}}
|
||||
</ui-display>
|
||||
{{/each}}
|
||||
{{/data.display_craftable_only}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</ui-display>
|
||||
|
||||
Reference in New Issue
Block a user