From 01bc6a86511c5315bf9263bee97a0fbc85869304 Mon Sep 17 00:00:00 2001 From: Exxion Date: Wed, 10 Oct 2018 08:23:20 -0400 Subject: [PATCH] Adds XGM panel (#20045) * Refactor * XGM Panel * Icon --- code/ZAS/XGM.dm | 88 ++++++++++++++++++++++++++++++------ code/modules/admin/admin.dm | 2 + code/modules/admin/topic.dm | 3 ++ nano/templates/XGM_data.tmpl | 49 ++++++++++++++++++++ 4 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 nano/templates/XGM_data.tmpl diff --git a/code/ZAS/XGM.dm b/code/ZAS/XGM.dm index 799ede260f9..b8a88fe413f 100644 --- a/code/ZAS/XGM.dm +++ b/code/ZAS/XGM.dm @@ -22,19 +22,81 @@ for(var/p in subtypesof(/datum/gas)) var/datum/gas/gas = new p() - if(gas.id in gases) + if(!add(gas)) stack_trace("Duplicate gas id '[gas.id]' in from typepath '[p]'") - continue - gases[gas.id] = gas - name[gas.id] = gas.name - short_name[gas.id] = gas.short_name || gas.name - specific_heat[gas.id] = gas.specific_heat - molar_mass[gas.id] = gas.molar_mass - flags[gas.id] = gas.flags - if(gas.tile_overlay) - tile_overlay[gas.id] = image('icons/effects/tile_effects.dmi', gas.tile_overlay, FLY_LAYER) - if(gas.overlay_limit) - overlay_limit[gas.id] = gas.overlay_limit +/datum/xgm_data/proc/add(var/datum/gas/gas) + if(gases[gas.id]) + return FALSE + return update(gas) - return 1 +/datum/xgm_data/proc/update(var/datum/gas/gas) + gases[gas.id] = gas + name[gas.id] = gas.name + short_name[gas.id] = gas.short_name || gas.name + specific_heat[gas.id] = gas.specific_heat + molar_mass[gas.id] = gas.molar_mass + flags[gas.id] = gas.flags + if(gas.tile_overlay) + tile_overlay[gas.id] = image('icons/effects/tile_effects.dmi', gas.tile_overlay, FLY_LAYER) + if(gas.overlay_limit) + overlay_limit[gas.id] = gas.overlay_limit + return TRUE + +/datum/xgm_data/proc/update_id(var/id) + if(gases[id]) + return update(gases[id]) + return FALSE + +/datum/xgm_data/proc/update_all() + for(var/id in gases) + update_id(id) + + +/datum/xgm_data/ui_interact(mob/user, ui_key = "main", var/datum/nanoui/ui = null, var/force_open = NANOUI_FOCUS) + var/list/data = list() + var/list/data_gases = list() + for(var/g in gases) + var/list/L = list() + L["id"] = g + L["name"] = name[g] + data_gases[++data_gases.len] = L //We have to use this syntax because += will concatenate the lists instead. + data["gases"] = data_gases + + //Everything below this point is taken directly from an example implementation, other than the args to create the new UI. + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + + if (!ui) + // The ui does not exist, so we'll create a new one. + ui = new(user, src, ui_key, "XGM_data.tmpl", "XGM Panel", 550, 410, ignore_distance = TRUE) + // When the UI is first opened this is the data it will use. + ui.set_initial_data(data) + // Open the new ui window. + ui.open() + // Auto update every Master Controller tick. + ui.set_auto_update(1) + +/datum/xgm_data/Topic(href, href_list) + if(..()) + return TRUE + if(!check_rights(R_VAREDIT)) //Can't do anything useful with this without +VAREDIT anyway + return FALSE + + if(href_list["edit"]) + usr.client.debug_variables(gases[href_list["edit"]]) + return TRUE + + if(href_list["update"]) + update_id(href_list["update"]) + return TRUE + + if(href_list["create"]) + var/id = input("Enter new gasid") as text|null + if(!isnull(id)) + if(gases[id]) + alert("That gasid is already used.", "Duplicate gasid") + else + var/datum/gas/G = new() + G.id = id + add(G) + return TRUE diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index fac59ff8a30..f47456e595f 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -714,6 +714,8 @@ var/global/floorIsLava = 0
Edit ZAS Settings
Choose a default ZAS setting
+ XGM Panel
+
"} if(wages_enabled) diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 7b493600152..c318a7a6f43 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -4110,6 +4110,9 @@ if(href_list["vsc"] == "default") zas_settings.SetDefault(usr) + else if(href_list["xgm_panel"]) + XGM.ui_interact(usr) + else if(href_list["toglang"]) if(check_rights(R_SPAWN)) var/mob/M = locate(href_list["toglang"]) diff --git a/nano/templates/XGM_data.tmpl b/nano/templates/XGM_data.tmpl new file mode 100644 index 00000000000..c5d0ea600b4 --- /dev/null +++ b/nano/templates/XGM_data.tmpl @@ -0,0 +1,49 @@ +
+
+ After editing a gas, press its update button to apply the changes. +
+
+
+ DO NOT change the id var on any gas. It will fuck everything up. +
+
+
+ When you create a new gas, it will be initialized with default values for all vars except id. Edit and update it as usual to set the values you want. +
+
+
+ To add your new gas (or any other gas, for that matter) to a gas_mixture: +
+
+
+ 1. +
+
+ VV the gas_mixture. +
+
+
+
+ 2. +
+
+ Add a string equal to the gas's id to the gas_mixture's gas list, and associate it with the desired number of moles. +
+
+
+
+ {{for data.gases}} +
+
+ {{>value.name}} +
+
+ {{:helper.link('Edit', 'pencil', {'edit' : value.id})}} + {{:helper.link('Update', 'refresh', {'update' : value.id})}} +
+
+ {{/for}} +
+ {{:helper.link('Create New', 'plus', {'create' : 1})}} +
+