From 1c0ad653b29f5544de432b469a49d72cf3a19bd2 Mon Sep 17 00:00:00 2001 From: flashwave Date: Mon, 19 Sep 2016 20:07:02 +0200 Subject: [PATCH] add dialogue stuff --- resources/assets/less/yuuno/dialogue.less | 38 +++++++++++ resources/assets/less/yuuno/master.less | 1 + resources/assets/typescript/Sakura.ts | 5 ++ .../assets/typescript/Sakura/Dialogue.ts | 67 +++++++++++++++++++ .../typescript/Sakura/DialogueButton.ts | 9 +++ .../assets/typescript/Sakura/DialogueType.ts | 8 +++ .../assets/typescript/Sakura/Dictionary.ts | 57 ++++++++++++++++ .../assets/typescript/Sakura/KeyValuePair.ts | 8 +++ resources/views/yuuno/master.twig | 1 + resources/views/yuuno/user/profile.twig | 1 - 10 files changed, 194 insertions(+), 1 deletion(-) create mode 100644 resources/assets/less/yuuno/dialogue.less create mode 100644 resources/assets/typescript/Sakura/Dialogue.ts create mode 100644 resources/assets/typescript/Sakura/DialogueButton.ts create mode 100644 resources/assets/typescript/Sakura/DialogueType.ts create mode 100644 resources/assets/typescript/Sakura/Dictionary.ts create mode 100644 resources/assets/typescript/Sakura/KeyValuePair.ts diff --git a/resources/assets/less/yuuno/dialogue.less b/resources/assets/less/yuuno/dialogue.less new file mode 100644 index 0000000..bff33b4 --- /dev/null +++ b/resources/assets/less/yuuno/dialogue.less @@ -0,0 +1,38 @@ +.dialogues:not(:empty) { + background: fade(#000, 50%); + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + display: flex; + justify-content: center; + align-items: center; + z-index: 2147483648; // fuck it +} + +.dialogue { + font-family: "Open Sans", sans-serif; + display: inline-block; + background: #9475b2; + box-shadow: 0 0 5px #9475B2; + padding: 10px; + margin: 10px; + min-width: 200px; + + &__buttons { + text-align: right; + } + + &__button { + font-family: "Open Sans", sans-serif; + background: #8364a1; + border: 0 solid transparent; + padding: 2px 4px; + cursor: pointer; + + &:last-child { + font-weight: 700; + } + } +} diff --git a/resources/assets/less/yuuno/master.less b/resources/assets/less/yuuno/master.less index 77779d0..9d66658 100644 --- a/resources/assets/less/yuuno/master.less +++ b/resources/assets/less/yuuno/master.less @@ -8,6 +8,7 @@ @import "alert"; @import "dropdown"; @import "np"; +@import "dialogue"; /* * Animation Keyframes diff --git a/resources/assets/typescript/Sakura.ts b/resources/assets/typescript/Sakura.ts index c9ceeed..0f826b1 100644 --- a/resources/assets/typescript/Sakura.ts +++ b/resources/assets/typescript/Sakura.ts @@ -3,6 +3,10 @@ /// /// /// +/// +/// +/// +/// /// /// /// @@ -13,5 +17,6 @@ /// /// /// +/// /// /// diff --git a/resources/assets/typescript/Sakura/Dialogue.ts b/resources/assets/typescript/Sakura/Dialogue.ts new file mode 100644 index 0000000..ad61501 --- /dev/null +++ b/resources/assets/typescript/Sakura/Dialogue.ts @@ -0,0 +1,67 @@ +namespace Sakura +{ + export class Dialogue + { + public Text: string; + private Type: DialogueType = DialogueType.Info; + private Callbacks: Dictionary = new Dictionary(); + public static Container: string = "dialogues"; + + public SetType(type: DialogueType): void + { + this.Type = type; + } + + public AddCallback(button: DialogueButton, func: Function): void + { + if (this.Callbacks.Keys.indexOf(button) >= 0) { + this.Callbacks.Remove(button); + } + + this.Callbacks.Add(button, func); + } + + public Display(): void + { + var modifiers: string[] = [], + buttons: DialogueButton[] = []; + + switch (this.Type) { + case DialogueType.Confirm: + modifiers.push('confirm'); + buttons.push(DialogueButton.No); + buttons.push(DialogueButton.Yes); + break; + + default: + modifiers.push('info'); + buttons.push(DialogueButton.Ok); + } + + var container: HTMLDivElement = DOM.Create('div', DOM.BEM('dialogue', null, modifiers)), + text: HTMLDivElement = DOM.Create('div', DOM.BEM('dialogue', 'text')), + buttonCont: HTMLDivElement = DOM.Create('div', DOM.BEM('dialogue', 'buttons')); + + DOM.Append(text, DOM.Text(this.Text)); + DOM.Append(container, text); + + for (var btnId in buttons) { + var btnType: DialogueButton = buttons[btnId], + btnText: string = DialogueButton[btnType], + button: HTMLButtonElement = DOM.Create('button', DOM.BEM('dialogue', 'button')); + + DOM.Append(button, DOM.Text(btnText)); + button.setAttribute('data-type', btnType.toString()); + button.addEventListener("click", (ev: any) => { + (this.Callbacks.Get(+ev.target.attributes['data-type'].value)).Value.call(this); + }); + + DOM.Append(buttonCont, button); + } + + DOM.Append(container, buttonCont); + + DOM.Append(DOM.ID('dialogues'), container); + } + } +} diff --git a/resources/assets/typescript/Sakura/DialogueButton.ts b/resources/assets/typescript/Sakura/DialogueButton.ts new file mode 100644 index 0000000..8494386 --- /dev/null +++ b/resources/assets/typescript/Sakura/DialogueButton.ts @@ -0,0 +1,9 @@ +namespace Sakura +{ + export enum DialogueButton + { + Yes, + No, + Ok + } +} diff --git a/resources/assets/typescript/Sakura/DialogueType.ts b/resources/assets/typescript/Sakura/DialogueType.ts new file mode 100644 index 0000000..f292faf --- /dev/null +++ b/resources/assets/typescript/Sakura/DialogueType.ts @@ -0,0 +1,8 @@ +namespace Sakura +{ + export enum DialogueType + { + Info, + Confirm + } +} diff --git a/resources/assets/typescript/Sakura/Dictionary.ts b/resources/assets/typescript/Sakura/Dictionary.ts new file mode 100644 index 0000000..473827b --- /dev/null +++ b/resources/assets/typescript/Sakura/Dictionary.ts @@ -0,0 +1,57 @@ +namespace Sakura +{ + export class Dictionary + { + public Keys: TKey[] = []; + public Values: TValue[] = []; + + public Add(key: TKey, value: TValue): void + { + if (this.Keys.indexOf(key) !== -1) { + return; + } + + this.Keys.push(key); + this.Values.push(value); + } + + public Remove(key: TKey): void + { + var index: number = this.Keys.indexOf(key); + + if (index >= 0) { + this.Keys.splice(index, 1); + this.Values.splice(index, 1); + } + } + + public Reset(): void + { + this.Keys = []; + this.Values = []; + } + + public Get(key: TKey): KeyValuePair + { + var index: number = this.Keys.indexOf(key); + + if (index >= 0) { + var pair: KeyValuePair = new KeyValuePair(); + pair.Key = this.Keys[index]; + pair.Value = this.Values[index]; + return pair; + } + + return null; + } + + public Update(key: TKey, value: TValue): void + { + var index: number = this.Keys.indexOf(key); + + if (index >= 0) { + this.Values[index] = value; + } + } + } +} diff --git a/resources/assets/typescript/Sakura/KeyValuePair.ts b/resources/assets/typescript/Sakura/KeyValuePair.ts new file mode 100644 index 0000000..7a67247 --- /dev/null +++ b/resources/assets/typescript/Sakura/KeyValuePair.ts @@ -0,0 +1,8 @@ +namespace Sakura +{ + export class KeyValuePair + { + public Key: TKey; + public Value: TValue; + } +} diff --git a/resources/views/yuuno/master.twig b/resources/views/yuuno/master.twig index f580e82..78ea48e 100644 --- a/resources/views/yuuno/master.twig +++ b/resources/views/yuuno/master.twig @@ -64,6 +64,7 @@
+
{% if profile is defined ? profile.background : (user.permission(constant('Sakura\\Perms\\Site::CHANGE_BACKGROUND')) and (user.backgroundSitewide or showBG) and user.background) %}
{% endif %} diff --git a/resources/views/yuuno/user/profile.twig b/resources/views/yuuno/user/profile.twig index aaf28da..e6b3018 100644 --- a/resources/views/yuuno/user/profile.twig +++ b/resources/views/yuuno/user/profile.twig @@ -86,7 +86,6 @@ state = Sakura.DOM.ID('np-state'), by = Sakura.DOM.ID('np-by'); - console.log(data); artist.href = data.artist_url; artist.textContent = data.artist; track.href = data.track_url;