Exemple #1
0
void Shop::renderShop() {
	if (shopOpen) {
		//Render the background
		lib->loop_portion(start, end, [&](Point p) {
			lib->rendertile(0x125, p);
		});
		//Render the close button
		if (lib->mouseLoc() == start) //Highlight if mouse is over close button
			tl_color(0x000000FF);
		lib->rendertile(static_cast<int>('x'), start);
		tl_color(0xFFFFFFFF);

		//If close button is hit, close the shop
		if (tl_buttonwentdown(1) && lib->mouseLoc() == start)
			shopOpen = false;
		
		tl_scale(2);
		lib->renderText(Point(start.x() + 6, start.y() + 3), "Well Hello There, Stranger!"); //Compensate start point with scale
		lib->renderText(Point(start.x() + 10, end.y() + 12), "Gold Amount: " + to_string(shopGold));
		tl_scale(1);

		//Render icon slots
		unsigned int idx = 0;
		Point iconStart = start + Point(5, 5);
		Point iconEnd = end + Point(-5, -5);
		lib->loop_portion(iconStart, end + Point(-5, -5), [&](Point p) {
			lib->rendertile(0x13D, p);
			if (lib->mouseLoc() == p && storeItems[idx].getLoc() != Point(-1, -1)) {
				tl_color(0xFF000040);
				lib->rendertile(0x13D, p);
			}
			tl_color(0xFFFFFFFF);
			if (storeItems[idx].getLoc() != Point(-1, -1))
				lib->rendertile(storeItems[idx].getPickupDef().getTile(), p);
			idx++;
		});

		if (lib->mouseLoc() >= iconStart && lib->mouseLoc() <= iconEnd - Point(1, 1)) {
			//Render item mouse over
			Pickup p = storeItems[idxFromPoint(lib->mouseLoc() - iconStart)];
			Point loc = lib->mouseLoc() - iconStart;

			if (p.getLoc() != Point(-1, -1)) {
				if (p.getPickupDef().getType() != 0)
					log->renderMouseOver(p.getPickupDef().getName(), p.getPickupDef().getDESC(), "Uses left: " + to_string(p.getUsesLeft()), "Cost: " + to_string(p.getPickupDef().getPrice()));
				else
					log->renderMouseOver(p.getPickupDef().getName(), p.getPickupDef().getDESC(), "Cost: " + to_string(p.getPickupDef().getPrice()), "");
			}
			//Buy item
			if (tl_buttonwentdown(1))
				buy(loc);
		}
		else if (lib->mouseLoc() >= Point(lib->res().x() - 3, 3) && lib->mouseLoc() <= Point(lib->res().x() - 2, 9)) {
			if (tl_buttonwentdown(1)) {
				Pickup p = invLog->sellItem(lib->mouseLoc());
				sell(p);
			}
		}
	}
}
void GameEngine::onMouseOver() {

	//Render inventory item information
	if (lib.mouseLoc().x() > lib.res().x() - 4) {
		Pickup item = invLog.getItemAtLoc(lib.mouseLoc());

		if (item.getLoc() != Point(-1, -1)) {
			if (item.getPickupDef().getType() != 0)
				log.renderMouseOver(item.getPickupDef().getName(), item.getPickupDef().getDESC(), "Uses left: " + to_string(item.getUsesLeft()), "");
			else
				log.renderMouseOver(item.getPickupDef().getName(), item.getPickupDef().getDESC(), "", "");
		}
	}

	//Render world information
	else {
		Point relMouseLoc = screenOrientation - lib.res() / 2 + lib.mouseLoc();

		if (relMouseLoc.x() > 0 && relMouseLoc.y() > 0 && relMouseLoc.x() <= worldSize - 1 && relMouseLoc.y() <= worldSize - 1 && !shop.isShopping()) {
			if (!map[relMouseLoc.x()][relMouseLoc.y()].isVisible()) {
				Pickup* p = map[relMouseLoc.x()][relMouseLoc.y()].getPickup();
				Actor* a = map[relMouseLoc.x()][relMouseLoc.y()].getActor();

				if (a != NULL)
					log.renderMouseOver(a->getActorDef().getDESC(), "HP: " + to_string(a->getHP()), "ATK: " + a->getActorDef().actorATK().to_str(), "DEF: " + to_string(a->getActorDef().getDEF()));
				else if (p != NULL) {
					if (p->getPickupDef().getType() != 0)
						log.renderMouseOver(p->getPickupDef().getName(), p->getPickupDef().getDESC(), "Uses left: " + to_string(p->getUsesLeft()), "");
					else
						log.renderMouseOver(p->getPickupDef().getName(), p->getPickupDef().getDESC(), "", "");
				}
			}
		}
	}
	tl_scale(1);
}