Skip to content

Commit df62f2d

Browse files
committed
Implementing store w/ UI
1 parent 6a5e705 commit df62f2d

File tree

4 files changed

+84
-26
lines changed

4 files changed

+84
-26
lines changed

src/VGCore/SystemOS.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
use VGCore\command\Tutorial;
4545
use VGCore\command\Economy;
4646

47+
use VGCore\store\Store;
48+
use VGCore\store\ItemList as IL;
49+
4750
class SystemOS extends PluginBase {
4851

4952
// Base File for arranging everything in good order. This is how every good core should be done.
@@ -83,6 +86,7 @@ public function loadUI() {
8386
PacketPool::registerPacket(new ServerSettingsResponsePacket());
8487

8588
$this->createUIs(); // creates the forms in @var $uis [] int array.
89+
$this->createShopUI(); // creates the forms in @var $uis [] int array.
8690
}
8791

8892
public function loadFilter() {
@@ -161,6 +165,17 @@ public function createShopUI() { // Seperated because of the sheer size of this
161165
$ui->addButton($itemcategory);
162166
$ui->addButton($blockcategory);
163167
self::$uis['shopMainMenuUI'] = UIDriver::addUI($this, $ui);
168+
// Shop Item Menu
169+
$ui = new SimpleForm('§a§lITEMS', '§ePlease select an item to buy :');
170+
$woodensword = new Button('§c§lWooden Sword');
171+
$ui->addButton($woodensword);
172+
self::$uis['shopItemMenuUI'] = UIDriver::addUI($this, $ui);
173+
// WoodenSword Buy Menu
174+
$ui = new CustomForm('§c§lWooden Sword');
175+
$price = IL::$woodsword[2];
176+
$amount = new Slider('§ePlease select how many you want. Each costs [C]' . $price, 1, 100, 1);
177+
$ui->addElement($amount);
178+
self::$uis['shopWSwordUI'] = UIDriver::addUI($this, $ui);
164179
}
165180

166181
// >>> Section 2 - Chat Filter

src/VGCore/listener/GUIListener.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,47 @@ public function onUIDataReceiveEvent(UIDataReceiveEvent $event) {
173173
break;
174174
}
175175
case '§aGo to §lSHOP': {
176-
$player = $event->getPlayer();
177-
$player->sendMessage(Chat::YELLOW . "This is not available yet. Stay Tuned!");
176+
UIDriver::showUIbyID($event->getPlugin(), SystemOS::$uis['shopMainMenuUI'], $event->getPlayer());
177+
break;
178+
}
179+
}
180+
break;
181+
}
182+
case SystemOS::$uis['shopMainMenuUI']: {
183+
$data = $event->getData();
184+
$ui = UIDriver::getPluginUI($this->os, $id);
185+
$response = $ui->handle($data, $event->getPlayer());
186+
switch ($response) {
187+
case '§a§lITEMS': {
188+
UIDriver::showUIbyID($event->getPlugin(), SystemOS::$uis['shopItemMenuUI'], $event->getPlayer());
189+
break;
190+
}
191+
case '§a§lBLOCKS': {
192+
//
193+
break;
194+
}
195+
}
196+
break;
197+
}
198+
case SystemOS::$uis['shopItemMenuUI']: {
199+
$data = $event->getData();
200+
$ui = UIDriver::getPluginUI($this->os, $id);
201+
$response = $ui->handle($data, $event->getPlayer());
202+
switch ($response) {
203+
case '§c§lWooden Sword': {
204+
UIDriver::showUIbyID($event->getPlugin(), SystemOS::$uis['shopWSwordUI'], $event->getPlayer());
178205
break;
179206
}
180207
}
181208
break;
182209
}
210+
case SystemOS::$uis['shopWSwordUI']: {
211+
$data = $event->getData();
212+
$ui = UIDriver::getPluginUI($this->os, $id);
213+
$response = $ui->handle($data, $event->getPlayer());
214+
var_dump($response);
215+
break;
216+
}
183217
}
184218
}
185219

src/VGCore/store/ItemList.php

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,40 @@
55
class ItemList {
66

77
// natural
8-
public static $dirt = [3, 0];
9-
public static $cobblestone = [4, 0];
10-
public static $normalwood = [17, 0];
11-
public static $ironore = [15, 0];
12-
public static $goldore = [14, 0];
13-
public static $diamondore = [56, 0];
14-
public static $coalore = [16, 0];
8+
public static $dirt = [3, 0, 10];
9+
public static $cobblestone = [4, 0, 30];
10+
public static $normalwood = [17, 0, 20];
11+
public static $ironore = [15, 0, 250];
12+
public static $goldore = [14, 0, 125];
13+
public static $diamondore = [56, 0, 500];
14+
public static $coalore = [16, 0, 70];
1515

1616
// craft or smelt
17-
public static $glass = [20, 0];
18-
public static $chest = [54, 0];
19-
public static $craftingtable = [58, 0];
20-
public static $furnace = [61, 0];
17+
public static $glass = [20, 0, 50];
18+
public static $chest = [54, 0, 40];
19+
public static $craftingtable = [58, 0, 20];
20+
public static $furnace = [61, 0, 200];
2121

2222
// tools and weapons
23-
public static $ironshovel = [256, 0];
24-
public static $ironpickaxe = [257, 0];
25-
public static $ironaxe = [258, 0];
26-
public static $ironsword = [267, 0];
27-
public static $woodshovel = [269, 0];
28-
public static $woodpickaxe = [270, 0];
29-
public static $woodaxe = [271, 0];
30-
public static $woodsword = [268, 0];
31-
public static $stoneshovel = [273, 0];
32-
public static $stonepickaxe = [274, 0];
33-
public static $stoneaxe = [275, 0];
34-
public static $stonesword = [272, 0];
23+
public static $ironshovel = [256, 0, 290];
24+
public static $ironpickaxe = [257, 0, 790];
25+
public static $ironaxe = [258, 0, 540];
26+
public static $ironsword = [267, 0, 800];
27+
public static $woodshovel = [269, 0, 70];
28+
public static $woodpickaxe = [270, 0, 80];
29+
public static $woodaxe = [271, 0, 75];
30+
public static $woodsword = [268, 0, 85];
31+
public static $stoneshovel = [273, 0, 145];
32+
public static $stonepickaxe = [274, 0, 160];
33+
public static $stoneaxe = [275, 0, 150];
34+
public static $stonesword = [272, 0, 250];
35+
public static $goldshovel = [284, 0, 150];
36+
public static $goldpickaxe = [285, 0, 175];
37+
public static $goldaxe = [286, 0, 170];
38+
public static $goldsword = [283, 0, 300];
39+
public static $diamondshovel = [277, 0, 870];
40+
public static $diamondpickaxe = [278, 0, 2370];
41+
public static $diamondaxe = [279, 0, 1620];
42+
public static $diamondsword = [276, 0, 2400];
3543

3644
}

src/VGCore/store/Store.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ public function __construct(SystemOS $plugin, EconomySystem $economy) {
1818
$this->economy = $economy;
1919
}
2020

21-
public function buyItem(Player $player, int $amount, int $price, array $info) {
21+
public function buyItem(Player $player, int $amount, array $info) {
2222
$name = $player->getName();
2323
$check = $this->economy->accountValidate($name);
24+
$price = $info[2];
2425
$finalprice = $price * $amount;
2526
if ($check === true) {
2627
$coin = $this->economy->getCoin($player);

0 commit comments

Comments
 (0)