Переверстано под DIV. Добавлен забытый класс Shop.

This commit is contained in:
lopar 2021-08-30 03:10:07 +03:00
parent df3bf1bf45
commit 198092b44a
3 changed files with 207 additions and 39 deletions

80
classes/Battles/Shop.php Normal file
View File

@ -0,0 +1,80 @@
<?php
# Date: 29.08.2021 (21:34)
namespace Battles;
use Battles\Database\DBPDO;
class Shop
{
public const GENERAL_SHOP = 1;
public const CATEGORY_SALE_ITEMS = -1;
public static Shop $current;
public int $categoryType = 0;
private int $shopId;
public function __construct($shop_id) {
$this->shopId = $shop_id;
}
private function showGoods(): string
{
if ($this->categoryType) {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
} else {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
}
$iteminfo = [];
foreach ($stmt as $item) {
$iteminfo[] = new ShopItem($item, 'buyshop');
}
return $this->strFromArr($iteminfo);
}
private function showUserSellItems(): string
{
$stmt = DBPDO::$db->ofetchall('select * from inventory where on_sale = 0 and dressed_slot = 0 and durability > 0 and owner_id = ?', User::$current->getId());
$iteminfo = [];
foreach ($stmt as $item) {
$iteminfo[] = new ShopItem($item, 'sellshop');
}
return $this->strFromArr($iteminfo);
}
private function strFromArr(array $array): string
{
$str = '';
$format = '<div class="row item"><div class="left column">%s%s</div><div class="right column">%s</div></div>';
foreach ($array as $a) {
$str .= sprintf($format, $a->printImage(), $a->printControls(), $a->printInfo());
}
return $str;
}
public function getCategoryName(): string
{
$names = [
Item::ITEM_TYPE_HELMET => 'Шлемы',
Item::ITEM_TYPE_ARMOR => 'Броня',
Item::ITEM_TYPE_LEGS => 'Поножи',
Item::ITEM_TYPE_BOOTS => 'Сапоги',
Item::ITEM_TYPE_GLOVES => 'Перчатки',
Item::ITEM_TYPE_WEAPON => 'Оружие',
Item::ITEM_TYPE_SHIELD => 'Щиты',
Item::ITEM_TYPE_BELT => 'Пояса',
Item::ITEM_TYPE_RING => 'Кольца',
Item::ITEM_TYPE_AMULET => 'Амулеты',
Item::ITEM_TYPE_CONSUMABLE => 'Расходники',
Item::ITEM_TYPE_OTHER => 'Разное',
self::CATEGORY_SALE_ITEMS => 'Предметы в инвентаре',
0 => 'Все товары',
];
return $names[$this->categoryType];
}
public function getItemsList(): string
{
return $this->categoryType !== self::CATEGORY_SALE_ITEMS ? $this->showGoods() : $this->showUserSellItems();
}
}

87
css/shop.css Normal file
View File

@ -0,0 +1,87 @@
a.waretype {
margin: 2px 16px;
padding: 6px;
border: 1px silver solid;
border-radius: 4px;
background-color: #ccc;
display: block;
}
a.sell {
background-color: #cdc;
}
a.alltypes {
background-color: #ccd;
}
.status {
color: darkgreen;
background: #afa;
}
h3 + div {
text-align: center;
}
div.shop strong span:last-child {
color: darkgreen;
}
hr + div {
text-align: center;
font-weight: bold;
}
/* === */
.row {
cursor: default;
}
.column {
padding: 10px;
}
.left {
float: left;
}
.shop > .left {
width: 75%;
}
.shop > .right {
float: right;
width: 300px;
}
.item > .right {
float: left;
}
.item > .left {
width: 150px;
text-align: center;
}
.item > .right {
width: 75%;
vertical-align: top;
}
.row:after {
content: "";
display: table;
clear: both;
}
div.item:nth-of-type(2) {
border: 1px solid #aaa;
}
div.item:nth-child(even) {
background-color: #bbb;
}
div.item:nth-child(odd) {
background-color: #ccc;
}
div.item {
border: 1px solid #aaa;
border-top: 0;
}

View File

@ -32,18 +32,18 @@ Template::header('Магазин');
<h1>Государственный магазин</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
<div class="status"><?= ShopItem::$status ?></div>
<table class="shop">
<tr>
<td>
<div class="row shop">
<div class="left column">
<h3><?= Shop::$current->getCategoryName() ?></h3>
<div>
<?php if (Shop::$current->categoryType === -1): ?>
<div>Вы можете продать ваши предметы за сущие копейки.</div>
Вы можете продать ваши предметы за сущие копейки.
<?php endif; ?>
</div>
<!--Магазин-->
<table>
<?= Shop::$current->getItemsList() ?>
</table>
<td>
</div>
<div class="right column">
<div>
<strong>
Масса всех вещей: <?= InventoryItem::getWeightData() ?> <br>
@ -72,4 +72,5 @@ Template::header('Магазин');
счёта
с вычетом банковской комиссии за услуги.</small>
</div>
</table>
</div>
</div>