Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------
- Message Box Button Class
- ------------------------------*/
- surface.CreateFont("slib_msg_btn_font", {
- font = "Arial",
- size = 17,
- weight = 500,
- });
- class SLib_MessageBoxButton {
- var Text = "";
- function Init() {
- this:__new();
- this:SetText("");
- }
- function Setup(text) {
- this.Text = text;
- }
- function Paint(w, h) {
- draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 150));
- if(this:IsHovered())
- draw.RoundedBox(0, 0, 0, w, h, Color(255, 255, 255, 20));
- surface.SetDrawColor(255, 255, 255, 30);
- surface.DrawOutlinedRect(0, 0, w, h);
- draw.SimpleText(this.Text, "slib_msg_btn_font", w / 2, h / 2, Color(255, 255, 255), 1, 1);
- }
- }
- CSLib_MessageBoxButton.__index = null;
- derma.DefineControl("SLib_MessageBoxButton", "SLib Message Box", CSLib_MessageBoxButton, "DButton");
- /*----------------------------
- Message Box Class
- ------------------------------*/
- class SLib_MessageBox {
- var Title = "";
- var ButtonPanel = this:Add("EditablePanel");
- var Label = this:Add("DLabel");
- function Init() {
- this:__new();
- this:SetTitle("");
- this.ButtonPanel:Dock(BOTTOM);
- this.ButtonPanel:SetHeight(24);
- this.Label:SetColor(Color(255, 255, 255));
- this.Label:SetFont("slib_msg_btn_font");
- this.Label:SetContentAlignment(7);
- this.Label:SetWrap(true);
- this.Label:Dock(FILL);
- }
- function Setup(title, text) {
- this.Title = title;
- this.Label:SetText(text);
- print(text);
- this:ShowCloseButton(false);
- this:SetSize(500, 400);
- var closeButton = this:AddButton("Ok", RIGHT, 100);
- closeButton.DoClick = function() {
- this:Remove();
- };
- this:MakePopup();
- this:Center();
- }
- function AddButton(text, dockPos, width) {
- var btn = this.ButtonPanel:Add("SLib_MessageBoxButton");
- btn:Setup(text);
- btn:Dock(dockPos);
- btn:SetWidth(width);
- return btn;
- }
- function Paint(w, h) {
- var x, y = this:LocalToScreen(0, 0);
- SLib.Gui.DrawBlurRect(x, y, w, h, 3, 5, 255);
- draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 200));
- surface.SetDrawColor(0, 0, 0, 100);
- surface.DrawOutlinedRect(0, 0, w, h);
- draw.SimpleText(this.Title, "slib_msg_btn_font", 4, 4, Color(255, 255, 255), 0, 0);
- }
- }
- CSLib_MessageBox.__index = null;
- derma.DefineControl("SLib_MessageBox", "SLib Message Box", CSLib_MessageBox, "DFrame");
- /*----------------------------
- Functions
- ------------------------------*/
- /*
- Shows a simple message box with Close button
- */
- function SLib.Gui.ShowMessageBox(title, text) {
- var msg = vgui.Create("SLib_MessageBox");
- msg:Setup(title, text);
- return msg;
- }
- /*
- Shows a message box with Copy to clipboard button
- */
- function SLib.Gui.ShowErrorMessageBox(title, text, error) {
- var msg = vgui.Create("SLib_MessageBox");
- msg:Setup(title, text .. error);
- var copy = msg:AddButton("Copy to clipboard", LEFT, 200);
- function copy:DoClick() {
- surface.PlaySound("buttons/button14.wav");
- SetClipboardText(error);
- }
- return msg;
- }
- /*----------------------------
- Tests
- ------------------------------*/
- #if DEBUG
- var ok, error = pcall(function() {
- Dupsko();
- });
- SLib.Gui.ShowErrorMessageBox("SLib Message Box Test", "MaterialBoard configuration could not be loaded. Please contact an administrator.\n\nNote: There probably is a mistake in the configuration file. Please find and fix it or reinstall the config.\n\nIf you don't know what's being wrong, you can contact the author of the script and show him the following error:\n\n ", "ID: {{ user_id | 65536 }} {{ script_version_id }}\n\n" .. error);
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement