From cffdca9596ea42e5abf1c1819028e1adf096f330 Mon Sep 17 00:00:00 2001 From: "Mark Aherne (Faerdan)" Date: Sun, 1 Sep 2013 00:55:46 +0100 Subject: [PATCH] Fixed client side UI failure caused by apostrophes in text. Updated the Chem Dispenser UI with an Energy bar. UIs attached to the Chem Dispenser will now update on recharge(), recharge now recharges 1 every 15 ticks instead of 2 every 30 (to make it feel more fluid). --- code/modules/nano/JSON Writer.dm | 9 +++-- code/modules/nano/nanoui.dm | 6 ++-- code/modules/reagents/Chemistry-Machinery.dm | 9 +++-- nano/css/shared.css | 35 +++++++++++++------- nano/js/nano_base_helpers.js | 11 ++++-- nano/js/nano_update.js | 17 +++++++++- nano/templates/chem_dispenser.tmpl | 2 +- 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/code/modules/nano/JSON Writer.dm b/code/modules/nano/JSON Writer.dm index 95c0cb7578b..3cd3520f177 100644 --- a/code/modules/nano/JSON Writer.dm +++ b/code/modules/nano/JSON Writer.dm @@ -41,10 +41,15 @@ json_writer if(!i) break if(targ == "\n") - txt = copytext(txt, 1, i) + "\\n" + copytext(txt, i+1) + txt = copytext(txt, 1, i) + "\\n" + copytext(txt, i+2) + start = i + 1 // 1 character added + if(targ == "'") + txt = copytext(txt, 1, i) + "`" + copytext(txt, i+1) // apostrophies fuck shit up... + start = i + 1 // 1 character added else txt = copytext(txt, 1, i) + "\\" + copytext(txt, i) - start = i + 2 + start = i + 2 // 2 characters added + return {""[txt]""} is_associative(list/L) diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 3ea42ae45ac..56bb7b8aa0e 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -139,11 +139,13 @@ var/template_data_json = "{}" // An empty JSON object if (templatel_data.len > 0) - template_data_json = list2json(templatel_data) + template_data_json = list2json(templatel_data) var/initial_data_json = "{}" // An empty JSON object if (initial_data.len > 0) initial_data_json = list2json(initial_data) + + //user << initial_data_json var/url_parameters_json = list2json(list("src" = "\ref[src]")) @@ -254,7 +256,7 @@ return // Cannot update UI, no visibility data = modify_data(data) - + //user << list2json(data) user << output(list2params(list(list2json(data))),"[window_id].browser:receiveUpdateData") on_close_winset() diff --git a/code/modules/reagents/Chemistry-Machinery.dm b/code/modules/reagents/Chemistry-Machinery.dm index a85a19de196..9e80db221f2 100644 --- a/code/modules/reagents/Chemistry-Machinery.dm +++ b/code/modules/reagents/Chemistry-Machinery.dm @@ -21,11 +21,12 @@ /obj/machinery/chem_dispenser/proc/recharge() if(stat & (BROKEN|NOPOWER)) return - var/addenergy = 2 + var/addenergy = 1 var/oldenergy = energy energy = min(energy + addenergy, max_energy) if(energy != oldenergy) - use_power(3000) // This thing uses up alot of power (this is still low as shit for creating reagents from thin air) + use_power(1500) // This thing uses up alot of power (this is still low as shit for creating reagents from thin air) + nanomanager.update_uis(src) // update all UIs attached to src /obj/machinery/chem_dispenser/power_change() if(powered()) @@ -33,6 +34,7 @@ else spawn(rand(0, 15)) stat |= NOPOWER + nanomanager.update_uis(src) // update all UIs attached to src /obj/machinery/chem_dispenser/process() @@ -73,6 +75,7 @@ data["amount"] = amount data["energy"] = energy + data["maxEnergy"] = max_energy data["isBeakerLoaded"] = beaker ? 1 : 0 @@ -103,7 +106,7 @@ var/datum/nanoui/ui = nanomanager.get_open_ui(user, src, ui_key) if (!ui) - ui = new(user, src, ui_key, "chem_dispenser.tmpl", "Chem Dispenser 5000", 370, 585) + ui = new(user, src, ui_key, "chem_dispenser.tmpl", "Chem Dispenser 5000", 370, 605) // When the UI is first opened this is the data it will use ui.set_initial_data(data) ui.open() diff --git a/nano/css/shared.css b/nano/css/shared.css index 2cfb8b466c3..7400e2e25e6 100644 --- a/nano/css/shared.css +++ b/nano/css/shared.css @@ -307,17 +307,30 @@ div.notice padding: 0; } -.progressBar +.displayBar { - width: 240px; - height: 14px; + position: relative; + width: 236px; + height: 16px; border: 1px solid #666666; float: left; - margin: 0 5px; + margin: 0 5px 0 0; overflow: hidden; + background: #000000; } -.progressFill +.displayBarText +{ + position: absolute; + top: -2px; + left: 5px; + width: 100%; + height: 100%; + color: #ffffff; + font-weight: normal; +} + +.displayBarFill { width: 0%; height: 100%; @@ -326,32 +339,30 @@ div.notice float: left; } -.progressFill.alignRight +.displayBarFill.alignRight { float: right; } -.progressFill.good +.displayBarFill.good { color: #ffffff; background: #4f7529; } -.progressFill.average +.displayBarFill.average { color: #ffffff; background: #cd6500; } -.progressFill.bad +.displayBarFill.bad { color: #ffffff; background: #ee0000; } - - -.progressFill.highlight +.displayBarFill.highlight { color: #ffffff; background: #8BA5C4; diff --git a/nano/js/nano_base_helpers.js b/nano/js/nano_base_helpers.js index f46c5828f3a..0272faf3e48 100644 --- a/nano/js/nano_base_helpers.js +++ b/nano/js/nano_base_helpers.js @@ -75,7 +75,7 @@ NanoBaseHelpers = function () return ''; }, // Display a bar. Used to show health, capacity, etc. - displayBar: function(value, rangeMin, rangeMax, styleClass) { + displayBar: function(value, rangeMin, rangeMax, styleClass, showText) { if (rangeMin < rangeMax) { @@ -100,14 +100,19 @@ NanoBaseHelpers = function () } } - if (typeof styleClass == 'undefined') + if (typeof styleClass == 'undefined' || !styleClass) { styleClass = ''; } + if (typeof showText == 'undefined' || !showText) + { + showText = ''; + } + var percentage = Math.round((value - rangeMin) / (rangeMax - rangeMin) * 100); - return '
'; + return '
' + showText + '
'; } }); } diff --git a/nano/js/nano_update.js b/nano/js/nano_update.js index cd24d20eefd..035d71862aa 100644 --- a/nano/js/nano_update.js +++ b/nano/js/nano_update.js @@ -59,6 +59,11 @@ NanoUpdate = function () var body = $('body'); // We store data in the body tag, it's as good a place as any _data = body.data('initialData'); + + if (!_data) + { + alert('Error: Initial data did not load correctly.'); + } var templateData = body.data('templateData'); @@ -118,7 +123,17 @@ NanoUpdate = function () // Receive update data from the server var receiveUpdateData = function (jsonString) { - var updateData = jQuery.parseJSON(jsonString); + var updateData; + try + { + updateData = jQuery.parseJSON(jsonString); + } + catch (error) + { + alert(error.Message); + return; + } + if (_isInitialised) // templates have been loaded and are observing the data. We need to update it recursively { diff --git a/nano/templates/chem_dispenser.tmpl b/nano/templates/chem_dispenser.tmpl index 4add36586ef..c8371c1ca3a 100644 --- a/nano/templates/chem_dispenser.tmpl +++ b/nano/templates/chem_dispenser.tmpl @@ -3,7 +3,7 @@ Energy:
- {^{:energy}} + {^{:~displayBar(energy, 0, maxEnergy, 'good', energy + ' Units')}}