Переверстано под DIV. Добавлен забытый класс Shop.
This commit is contained in:
parent
df3bf1bf45
commit
198092b44a
80
classes/Battles/Shop.php
Normal file
80
classes/Battles/Shop.php
Normal 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
87
css/shop.css
Normal 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;
|
||||
}
|
79
shop.php
79
shop.php
@ -32,44 +32,45 @@ Template::header('Магазин');
|
||||
<h1>Государственный магазин</h1>
|
||||
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
|
||||
<div class="status"><?= ShopItem::$status ?></div>
|
||||
<table class="shop">
|
||||
<tr>
|
||||
<td>
|
||||
<h3><?= Shop::$current->getCategoryName() ?></h3>
|
||||
<div class="row shop">
|
||||
<div class="left column">
|
||||
<h3><?= Shop::$current->getCategoryName() ?></h3>
|
||||
<div>
|
||||
<?php if (Shop::$current->categoryType === -1): ?>
|
||||
<div>Вы можете продать ваши предметы за сущие копейки.</div>
|
||||
Вы можете продать ваши предметы за сущие копейки.
|
||||
<?php endif; ?>
|
||||
<!--Магазин-->
|
||||
<table>
|
||||
<?= Shop::$current->getItemsList() ?>
|
||||
</table>
|
||||
<td>
|
||||
<div>
|
||||
<strong>
|
||||
Масса всех вещей: <?= InventoryItem::getWeightData() ?> <br>
|
||||
Деньги: <?= User::$current->getMoney() ?>.
|
||||
</strong>
|
||||
</div>
|
||||
<hr>
|
||||
<div>Отделы магазина</div>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_WEAPON ?>&rnd=<?= mt_rand() ?>">Оружие</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_HELMET ?>&rnd=<?= mt_rand() ?>">Шлемы</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_ARMOR ?>&rnd=<?= mt_rand() ?>">Броня</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_LEGS ?>&rnd=<?= mt_rand() ?>">Поножи</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_BOOTS ?>&rnd=<?= mt_rand() ?>">Сапоги</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_GLOVES ?>&rnd=<?= mt_rand() ?>">Перчатки</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_SHIELD ?>&rnd=<?= mt_rand() ?>">Щиты</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_BELT ?>&rnd=<?= mt_rand() ?>">Пояса</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_RING ?>&rnd=<?= mt_rand() ?>">Кольца</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_AMULET ?>&rnd=<?= mt_rand() ?>">Амулеты</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_CONSUMABLE ?>&rnd=<?= mt_rand() ?>">Расходники</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_OTHER ?>&rnd=<?= mt_rand() ?>">Разное</a>
|
||||
<a class="waretype alltypes" href="?rnd=<?= mt_rand() ?>">Все товары</a>
|
||||
<a class="waretype sell" href="?otdel=sale&rnd=<?= mt_rand() ?>">Продать вещи</a>
|
||||
<div id="hint3" class="ahint"></div>
|
||||
<div>
|
||||
<small>Если у вас не хватит денег на покупку, деньги будут автоматически сняты с вашего банковского
|
||||
счёта
|
||||
с вычетом банковской комиссии за услуги.</small>
|
||||
</div>
|
||||
</table>
|
||||
</div>
|
||||
<!--Магазин-->
|
||||
<?= Shop::$current->getItemsList() ?>
|
||||
</div>
|
||||
<div class="right column">
|
||||
<div>
|
||||
<strong>
|
||||
Масса всех вещей: <?= InventoryItem::getWeightData() ?> <br>
|
||||
Деньги: <?= User::$current->getMoney() ?>.
|
||||
</strong>
|
||||
</div>
|
||||
<hr>
|
||||
<div>Отделы магазина</div>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_WEAPON ?>&rnd=<?= mt_rand() ?>">Оружие</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_HELMET ?>&rnd=<?= mt_rand() ?>">Шлемы</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_ARMOR ?>&rnd=<?= mt_rand() ?>">Броня</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_LEGS ?>&rnd=<?= mt_rand() ?>">Поножи</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_BOOTS ?>&rnd=<?= mt_rand() ?>">Сапоги</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_GLOVES ?>&rnd=<?= mt_rand() ?>">Перчатки</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_SHIELD ?>&rnd=<?= mt_rand() ?>">Щиты</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_BELT ?>&rnd=<?= mt_rand() ?>">Пояса</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_RING ?>&rnd=<?= mt_rand() ?>">Кольца</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_AMULET ?>&rnd=<?= mt_rand() ?>">Амулеты</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_CONSUMABLE ?>&rnd=<?= mt_rand() ?>">Расходники</a>
|
||||
<a class="waretype" href="?otdel=<?= Item::ITEM_TYPE_OTHER ?>&rnd=<?= mt_rand() ?>">Разное</a>
|
||||
<a class="waretype alltypes" href="?rnd=<?= mt_rand() ?>">Все товары</a>
|
||||
<a class="waretype sell" href="?otdel=sale&rnd=<?= mt_rand() ?>">Продать вещи</a>
|
||||
<div id="hint3" class="ahint"></div>
|
||||
<div>
|
||||
<small>Если у вас не хватит денег на покупку, деньги будут автоматически сняты с вашего банковского
|
||||
счёта
|
||||
с вычетом банковской комиссии за услуги.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user