Example #1
0
/**
 * Click-to-drag a power (to the action bar)
 */
int MenuPowers::click(Point mouse) {
	int active_tab = (tab_control) ? tab_control->getActiveTab() : 0;

	for (unsigned i=0; i<power_cell.size(); i++) {
		if (slots[i] && isWithin(slots[i]->pos, mouse) && (power_cell[i].tab == active_tab)) {
			if (TOUCHSCREEN) {
				if (!slots[i]->in_focus) {
					slots[i]->in_focus = true;
					tablist.setCurrent(slots[i]);
					return 0;
				}
			}

			if (powerUnlockable(power_cell[i].id) && points_left > 0 && power_cell[i].requires_point) {
				// unlock power
				stats->powers_list.push_back(power_cell[i].id);
				stats->check_title = true;
				setUnlockedPowers();
				action_bar->addPower(power_cell[i].id, 0);
				return 0;
			}
			else if (requirementsMet(power_cell[i].id) && !powers->powers[power_cell[i].id].passive) {
				// pick up and drag power
				slots[i]->in_focus = false;
				return power_cell[i].id;
			}
			else
				return 0;
		}
	}
	return 0;
}
Example #2
0
/**
 * Upgrade power cell "pci" to the next level
 */
void MenuPowers::upgradePower(int pci, bool ignore_tab) {
	int i = getNextLevelCell(pci);
	if (i == -1)
		return;

	// if power was present in ActionBar, update it there
	action_bar->addPower(power_cell_upgrade[i].id, power_cell[pci].id);

	// if we have tab_control
	if (tab_control) {
		int active_tab = tab_control->getActiveTab();
		if (power_cell[pci].tab == active_tab || ignore_tab) {
			replaceCellWithUpgrade(pci, i);
			stats->powers_list.push_back(power_cell_upgrade[i].id);
			stats->check_title = true;
		}
	}
	// if have don't have tabs
	else {
		replaceCellWithUpgrade(pci, i);
		stats->powers_list.push_back(power_cell_upgrade[i].id);
		stats->check_title = true;
	}
	setUnlockedPowers();
}
Example #3
0
/**
 * Replace data in power_cell[cell_index] by data in upgrades
 */
void MenuPowers::upgradePower(short power_cell_index) {
	short i = nextLevel(power_cell_index);
	if (i == -1)
		return;

	// if power was present in ActionBar, update it there
	action_bar->addPower(power_cell_upgrade[i].id, power_cell[power_cell_index].id);

	// if we have tab_control
	if (tab_control) {
		int active_tab = tab_control->getActiveTab();
		if (power_cell[power_cell_index].tab == active_tab) {
			replacePowerCellDataByUpgrade(power_cell_index, i);
			stats->powers_list.push_back(power_cell_upgrade[i].id);
			stats->check_title = true;
		}
	}
	// if have don't have tabs
	else {
		replacePowerCellDataByUpgrade(power_cell_index, i);
		stats->powers_list.push_back(power_cell_upgrade[i].id);
		stats->check_title = true;
	}
	setUnlockedPowers();
}
Example #4
0
void MenuPowers::setUnlockedPowers() {
	std::vector<int> power_ids;
	bool unlocked_cleared = false;

	// only clear/repopulate power_cell_unlocked if the size of the hero's powers_list has changed
	if (prev_powers_list_size != stats->powers_list.size() || power_cell_unlocked.empty()) {
		prev_powers_list_size = stats->powers_list.size();
		power_cell_unlocked.clear();
		unlocked_cleared = true;
	}

	for (size_t i=0; i<power_cell.size(); ++i) {
		if (std::find(stats->powers_list.begin(), stats->powers_list.end(), power_cell[i].id) != stats->powers_list.end()) {
			if (!unlocked_cleared)
				continue;

			// base power
			if (std::find(power_ids.begin(), power_ids.end(), power_cell[i].id) == power_ids.end()) {
				power_ids.push_back(power_cell_base[i].id);
				power_cell_unlocked.push_back(power_cell_base[i]);
			}
			if (power_cell[i].id == power_cell_base[i].id)
				continue;

			//upgrades
			for (size_t j=0; j<power_cell[i].upgrades.size(); ++j) {
				if (std::find(power_ids.begin(), power_ids.end(), power_cell[i].upgrades[j]) == power_ids.end()) {
					int id = getCellByPowerIndex(power_cell[i].upgrades[j], power_cell_upgrade);
					if (id != -1) {
						power_ids.push_back(power_cell[i].upgrades[j]);
						power_cell_unlocked.push_back(power_cell_upgrade[id]);

						if (power_cell[i].id == power_cell[i].upgrades[j])
							break;
					}
					else {
						break;
					}
				}
			}
		}
		else {
			// power is unlocked, but not in the player's powers_list
			int pci = getCellByPowerIndex(power_cell[i].id, power_cell_all);
			if (checkUnlocked(pci)) {
				stats->powers_list.push_back(power_cell[i].id);
			}
		}
	}

	// the hero's powers_list may have grown, so we need to re-check unlocked powers
	if (prev_powers_list_size != stats->powers_list.size()) {
		setUnlockedPowers();
	}
}
Example #5
0
/**
 * Click-to-drag a power (to the action bar)
 */
int MenuPowers::click(const Point& mouse) {
	int active_tab = (tab_control) ? tab_control->getActiveTab() : 0;

	for (size_t i=0; i<power_cell.size(); i++) {
		if (slots[i] && isWithinRect(slots[i]->pos, mouse) && (power_cell[i].tab == active_tab)) {
			if (TOUCHSCREEN) {
				if (!slots[i]->in_focus) {
					slots[i]->in_focus = true;
					if (!tabs.empty()) {
						tablist_pow[active_tab].setCurrent(slots[i]);
					}
					else {
						tablist.setCurrent(slots[i]);
					}
					return 0;
				}
			}

			int cell_index = getCellByPowerIndex(power_cell[i].id, power_cell_all);
			if (checkUnlock(cell_index) && points_left > 0 && power_cell[i].requires_point) {
				// unlock power
				stats->powers_list.push_back(power_cell[i].id);
				stats->check_title = true;
				setUnlockedPowers();
				action_bar->addPower(power_cell[i].id, 0);
				return 0;
			}
			else if (checkUnlocked(cell_index) && !powers->powers[power_cell[i].id].passive) {
				// pick up and drag power
				slots[i]->defocus();
				if (!tabs.empty()) {
					tablist_pow[active_tab].setCurrent(NULL);
				}
				else {
					tablist.setCurrent(NULL);
				}
				return power_cell[i].id;
			}
			else
				return 0;
		}
	}

	// nothing selected, defocus everything
	defocusTabLists();

	return 0;
}
Example #6
0
/**
 * Apply power upgrades on savegame loading
 */
void MenuPowers::applyPowerUpgrades() {
	for (unsigned i = 0; i < power_cell.size(); i++) {
		if (!power_cell[i].upgrades.empty()) {
			std::vector<short>::iterator it;
			for (it = power_cell[i].upgrades.end(); it != power_cell[i].upgrades.begin(); ) {
				--it;
				std::vector<int>::iterator upgrade_it;
				upgrade_it = std::find(stats->powers_list.begin(), stats->powers_list.end(), *it);
				if (upgrade_it != stats->powers_list.end()) {
					short upgrade_index = id_by_powerIndex(static_cast<short>(*upgrade_it), power_cell_upgrade);
					if (upgrade_index != -1)
						replacePowerCellDataByUpgrade(static_cast<short>(i), upgrade_index);
					break;
				}
			}
		}
	}
	setUnlockedPowers();
}
Example #7
0
/**
 * Apply power upgrades on savegame loading
 */
void MenuPowers::applyPowerUpgrades() {
	for (size_t i=0; i<power_cell.size(); i++) {
		if (!power_cell[i].upgrades.empty()) {
			std::vector<int>::iterator it;
			for (it = power_cell[i].upgrades.end(); it != power_cell[i].upgrades.begin(); ) {
				--it;
				std::vector<int>::iterator upgrade_it;
				upgrade_it = std::find(stats->powers_list.begin(), stats->powers_list.end(), *it);
				if (upgrade_it != stats->powers_list.end()) {
					int upgrade_index = getCellByPowerIndex((*upgrade_it), power_cell_upgrade);
					if (upgrade_index != -1)
						replaceCellWithUpgrade(static_cast<int>(i), upgrade_index);
					break;
				}
			}
		}
	}
	setUnlockedPowers();
}
Example #8
0
void MenuPowers::logic() {
	setUnlockedPowers();

	for (size_t i=0; i<power_cell_unlocked.size(); i++) {
		if (static_cast<size_t>(power_cell_unlocked[i].id) < powers->powers.size() && powers->powers[power_cell_unlocked[i].id].passive) {
			bool unlocked_power = std::find(stats->powers_list.begin(), stats->powers_list.end(), power_cell_unlocked[i].id) != stats->powers_list.end();
			std::vector<int>::iterator it = std::find(stats->powers_passive.begin(), stats->powers_passive.end(), power_cell_unlocked[i].id);

			int cell_index = getCellByPowerIndex(power_cell_unlocked[i].id, power_cell_all);
			bool is_current_upgrade_max = (getCellByPowerIndex(power_cell_unlocked[i].id, power_cell) != -1);

			if (it != stats->powers_passive.end()) {
				if (!is_current_upgrade_max || (!checkRequirements(cell_index) && power_cell_unlocked[i].passive_on)) {
					// passive power is activated, but does not meet requirements, so remove it
					stats->powers_passive.erase(it);
					stats->effects.removeEffectPassive(power_cell_unlocked[i].id);
					power_cell[i].passive_on = false;
					stats->refresh_stats = true;
				}
			}
			else if (is_current_upgrade_max && ((checkRequirements(cell_index) && !power_cell_unlocked[i].requires_point) || unlocked_power) && !power_cell_unlocked[i].passive_on) {
				// passive power has not been activated, so activate it here
				stats->powers_passive.push_back(power_cell_unlocked[i].id);
				power_cell_unlocked[i].passive_on = true;
				// for passives without special triggers, we need to trigger them here
				if (stats->effects.triggered_others)
					powers->activateSinglePassive(stats, power_cell_unlocked[i].id);
			}
		}
	}

	for (size_t i=0; i<power_cell.size(); i++) {
		//upgrade buttons logic
		if (upgradeButtons[i] != NULL) {
			upgradeButtons[i]->enabled = false;
			// enable button only if current level is unlocked and next level can be unlocked
			if (checkUpgrade(static_cast<int>(i))) {
				upgradeButtons[i]->enabled = true;
			}
			if ((!tab_control || power_cell[i].tab == tab_control->getActiveTab()) && upgradeButtons[i]->checkClick()) {
				upgradePower(static_cast<int>(i));
			}

			// automatically apply upgrades when requires_point = false
			if (upgradeButtons[i]->enabled) {
				int next_index;
				int prev_index = -1;
				while ((next_index = getNextLevelCell(static_cast<int>(i))) != -1) {
					if (prev_index == next_index) {
						// this should never happen, but if it ever does, it would be an infinite loop
						break;
					}

					if (!power_cell_upgrade[next_index].requires_point && checkUpgrade(static_cast<int>(i))) {
						upgradePower(static_cast<int>(i), true);
					}
					else {
						break;
					}

					prev_index = next_index;
				}
			}
		}
	}

	points_left = (stats->level * stats->power_points_per_level) - getPointsUsed();
	if (points_left > 0) {
		newPowerNotification = true;
	}

	if (!visible) return;

	tablist.logic();
	if (!tabs.empty()) {
		for (size_t i=0; i<tabs.size(); i++) {
			if (tab_control && tab_control->getActiveTab() == static_cast<int>(i)) {
				tablist.setNextTabList(&tablist_pow[i]);
			}
			tablist_pow[i].logic();
		}
	}

	if (closeButton->checkClick()) {
		visible = false;
		snd->play(sfx_close);
	}

	if (tab_control) {
		// make shure keyboard navigation leads us to correct tab
		for (size_t i=0; i<slots.size(); i++) {
			if (power_cell[i].tab == tab_control->getActiveTab())
				continue;

			if (slots[i] && slots[i]->in_focus)
				slots[i]->defocus();
		}

		tab_control->logic();
	}
}