MediaWiki:Gadget-calc-cooking.js: Difference between revisions

From Idle Clans wiki
No edit summary
No edit summary
Line 69: Line 69:
// Button
// Button
var $calculateButton = utils.ui.buttonInput("Calculate");
var $calculateButton = utils.ui.buttonInput("Calculate");
// - Disable the button if no task is salected.
// - Disable the button if no task is selected.
if ($taskDropdown.getMenu().findSelectedItem() === null)
if ($taskDropdown.getMenu().findSelectedItem() === null)
$calculateButton.setDisabled(true);
$calculateButton.setDisabled(true);

Revision as of 19:26, 10 June 2024

$(function () {
	var CLAN_HOUSES = ["Tent", "Barn", "Windmill", "House", "Manor", "Castle"];
	var PERSONAL_HOUSES = ["Cardboard box", "Tent", "Van Down by the River", "Small cabin", "House"];
	var SKILL_CAPE = ["None", "Tier 1", "Tier 2", "Tier 3", "Tier 4"];
	var ENCHANTMENTS = ["None", "Common", "Rare", "Exceptional"];

	var utils = idleClans.util;
	var data = idleClans.data;

	function addDropdown($element, $dropdown, title, alignment) {
		alignment = alignment || "left";

		$element.append("<div class='calc-label-" + alignment + "'>" + title + "</div>");
		$element.append($dropdown.$element);
	}

	function addHeader($element, title) {
		$element.append("<div class='calc-header'>" + title + "</div>");
	}

	function addResultEntry($element, label, $result) {
		var $entry = $("<div class='calc-result-entry'></div>");
		$entry.append($("<div class='label'><span>" + label + "</span></div>"), $result);
		var $value = $("<div class='value'></div>");
		$value.append($result);
		$entry.append($value);

		$element.append($entry);
	}

	function addResultSpacer($element) {
		$element.append("<div class='calc-result-spacer'></div>");
	}

	function getDropdownValue($dropdown) {
		return $dropdown.getMenu().findSelectedItem().getData();
	}

	function createCalculator($element) {
		$element.addClass("idle-calculator");

		// XP
		var $clanHouseDropdown = utils.ui.dropdown(utils.tierify(CLAN_HOUSES, "None"), 0);
		var $personalHouseDropdown = utils.ui.dropdown(utils.tierify(PERSONAL_HOUSES, "None"), 0);
		var $dailyAdDropdown = utils.ui.dropdown(["None", "30%", "24/7 (10%)"], 0);

		// Speed
		var skillingItemOptions = utils.tierify(
			[ function(i) {return utils.getRefinedName("cooking pan", i)}, 7 ],
			"None");
		var $skillItemDropdown = utils.ui.dropdown(skillingItemOptions, 0);
		var $skillCapeDropdown = utils.ui.dropdown(SKILL_CAPE, 0);
		// - Enchantments
		var $amuletDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $earringDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $ringDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $braceletDropdown = utils.ui.dropdown(ENCHANTMENTS, 0);
		var $poakDropdown = utils.ui.dropdown(["No", "Yes"], 0);

		// Task
		var taskOptions = idleClans.data.tasks.COOKING.map(function (task) {
			return task.name;
		});
		// Add "Salect task" as the first option.
		taskOptions.splice(15, 0, {label: "==== Dishes ====", header: true});
		taskOptions.splice(11, 0, {label: "==== Meat ====", header: true});
		taskOptions.splice(0, 0, {label: "==== Fish ====", header: true});
		var $taskDropdown = utils.ui.dropdown(taskOptions, undefined, "Salect task");
		// Button
		var $calculateButton = utils.ui.buttonInput("Calculate");
		// - Disable the button if no task is selected.
		if ($taskDropdown.getMenu().findSelectedItem() === null)
			$calculateButton.setDisabled(true);
		// - Enable the button if a task is selected.
		$taskDropdown.on("labelChange", function () {
			$calculateButton.setDisabled(false);
		});