Exemplo n.º 1
0
static bool handle_io_spells_known(GameState* gs, ActionQueue& queued_actions,
		const BBox& bbox, SpellsKnown& spells, int ind_low, int ind_high) {
	const int spell_n = spells.amount();
	int mx = gs->mouse_x(), my = gs->mouse_y();
	int spellidx = ind_low;

	int x = bbox.x1, ex = bbox.x2;
	for (int y = bbox.y1; y < bbox.y2; y += TILE_SIZE) {
		if (spellidx >= spell_n)
			break;

		BBox entry_box(x, y, ex - 2, y + TILE_SIZE);
		if (entry_box.contains(mx, my) && gs->mouse_left_click()) {
			queued_actions.push_back(
					game_action(gs, gs->local_player(), GameAction::CHOSE_SPELL,
							spellidx));
			return true;
		}
		spellidx++;
	}
	return false;
}
Exemplo n.º 2
0
bool StoreContent::handle_io(GameState* gs, ActionQueue& queued_actions) {
	PlayerInst* p = gs->local_player();
	StoreInventory& inv = store_inventory();
	int mx = gs->mouse_x(), my = gs->mouse_y();
	bool within_inventory = bbox.contains(mx, my);

	/* Buy an item (left click) */
	if (gs->mouse_left_click() && within_inventory) {

		int slot = get_itemslotn(inv, bbox, mx, my);
		if (slot >= 0 && slot < INVENTORY_SIZE && inv.get(slot).amount > 0) {
			if (p->gold() >= inv.get(slot).cost) {
				queued_actions.push_back(
						game_action(gs, p, GameAction::PURCHASE_FROM_STORE,
								store_object->id, NONE, NONE, slot));
			} else {
				gs->game_chat().add_message("You cannot afford it!",
						COL_PALE_RED);
			}
			return true;
		}
	}
	return false;
}