Skip to content

Commit

Permalink
add lib
Browse files Browse the repository at this point in the history
  • Loading branch information
RarkHopper committed Feb 1, 2022
1 parent 06a4383 commit d61de8c
Show file tree
Hide file tree
Showing 21 changed files with 1,025 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI;

use pocketmine\form\Form as PmForm;

abstract class Form implements PmForm {
private string $title;

public const TYPE_SIMPLE_FORM = "form";
public const TYPE_CUSTOM_FORM = "custom_form";
public const TYPE_MODAL_FORM = "modal";

public function __construct(string $title) {
$this->title = $title;
$this->onCreation();
}

public function getTitle(): string {
return $this->title;
}

public function setTitle(string $title): void {
$this->title = $title;
}

abstract protected function getType(): string;

abstract protected function serializeBody(): array;

public function jsonSerialize(): array {
$body = $this->serializeBody();
$body["title"] = $this->title;
$body["type"] = $this->getType();
return $body;
}

protected function onCreation(): void {}
}
53 changes: 53 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Button.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

use Closure;
use brokiem\snpc\libs\EasyUI\icon\ButtonIcon;
use brokiem\snpc\libs\EasyUI\utils\Submittable;
use JsonSerializable;

class Button implements JsonSerializable {
use Submittable;

private string $text;
private ?ButtonIcon $icon;

public function __construct(string $text, ?ButtonIcon $icon = null, ?Closure $listener = null) {
$this->text = $text;
$this->icon = $icon;
$this->setSubmitListener($listener);
}

public function hasIcon(): bool {
return $this->icon !== null;
}

public function getIcon(): ?ButtonIcon {
return $this->icon;
}

public function setIcon(?ButtonIcon $icon): void {
$this->icon = $icon;
}

public function jsonSerialize(): array {
$data = [
"text" => $this->text
];

if($this->hasIcon()) {
$data["image"] = $this->icon->jsonSerialize();
}

return $data;
}
}
25 changes: 25 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Dropdown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

class Dropdown extends Selector {

public function getType(): string {
return Element::TYPE_DROPDOWN;
}

public function serializeBody(): array {
return [
"options" => $this->getOptionsTexts(),
"default" => $this->getDefaultIndex()
];
}
}
53 changes: 53 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Element.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

use JsonSerializable;

/**
* Element is exclusive for the elements of CustomForms
*/
abstract class Element implements JsonSerializable {

private ?string $headerText;

public const TYPE_DROPDOWN = "dropdown";
public const TYPE_INPUT = "input";
public const TYPE_LABEL = "label";
public const TYPE_SLIDER = "slider";
public const TYPE_STEP_SLIDER = "step_slider";
public const TYPE_TOGGLE = "toggle";

public function __construct(?string $headerText) {
$this->headerText = $headerText;
}

public function getHeaderText(): ?string {
return $this->headerText;
}

public function setHeaderText(?string $headerText): void {
$this->headerText = $headerText;
}

abstract public function getType(): string;

abstract public function serializeBody(): array;

abstract public function assignResult($result): void;

public function jsonSerialize(): array {
return array_merge($this->serializeBody(), [
"type" => $this->getType(),
"text" => $this->headerText ?? ""
]);
}
}
47 changes: 47 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Input.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);


namespace brokiem\snpc\libs\EasyUI\element;


class Input extends Element {
private ?string $defaultText;
private ?string $placeholder;
private ?string $submittedText = null;

public function __construct(?string $headerText, ?string $defaultText = null, ?string $placeholder = null) {
$this->defaultText = $defaultText;
$this->placeholder = $placeholder;
parent::__construct($headerText);
}

/**
* @return string|null
*/
public function getSubmittedText(): ?string {
return $this->submittedText;
}

public function getType(): string {
return Element::TYPE_INPUT;
}

public function assignResult($result): void {
$this->submittedText = $result;
}

public function serializeBody(): array {
return [
"default" => $this->defaultText ?? "",
"placeholder" => $this->placeholder ?? ""
];
}
}
30 changes: 30 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Label.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

class Label extends Element {

public function __construct(string $headerText) {
parent::__construct($headerText);
}

public function getType(): string {
return Element::TYPE_LABEL;
}

public function assignResult($result): void {
return;
}

public function serializeBody(): array {
return [];
}
}
31 changes: 31 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/ModalOption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

use brokiem\snpc\libs\EasyUI\utils\Submittable;

class ModalOption {
use Submittable;

private string $text;

public function __construct(string $text) {
$this->text = $text;
}

public function getText(): string {
return $this->text;
}

public function setText(string $text): void {
$this->text = $text;
}
}
34 changes: 34 additions & 0 deletions src/brokiem/snpc/libs/EasyUI/element/Option.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace brokiem\snpc\libs\EasyUI\element;

class Option {

private string $id;
private string $text;

public function __construct(string $id, string $text) {
$this->id = $id;
$this->text = $text;
}

public function getId(): string {
return $this->id;
}

public function getText(): string {
return $this->text;
}

public function setText(string $text): void {
$this->text = $text;
}
}
Loading

0 comments on commit d61de8c

Please sign in to comment.