Advertisement
szymski

Untitled

Jan 30th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. /*----------------------------
  2. Message Box Button Class
  3. ------------------------------*/
  4.  
  5. surface.CreateFont("slib_msg_btn_font", {
  6. font = "Arial",
  7. size = 17,
  8. weight = 500,
  9. });
  10.  
  11. class SLib_MessageBoxButton {
  12.  
  13. var Text = "";
  14.  
  15. function Init() {
  16. this:__new();
  17. this:SetText("");
  18. }
  19.  
  20. function Setup(text) {
  21. this.Text = text;
  22. }
  23.  
  24. function Paint(w, h) {
  25. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 150));
  26.  
  27. if(this:IsHovered())
  28. draw.RoundedBox(0, 0, 0, w, h, Color(255, 255, 255, 20));
  29.  
  30. surface.SetDrawColor(255, 255, 255, 30);
  31. surface.DrawOutlinedRect(0, 0, w, h);
  32.  
  33. draw.SimpleText(this.Text, "slib_msg_btn_font", w / 2, h / 2, Color(255, 255, 255), 1, 1);
  34. }
  35.  
  36. }
  37.  
  38. CSLib_MessageBoxButton.__index = null;
  39. derma.DefineControl("SLib_MessageBoxButton", "SLib Message Box", CSLib_MessageBoxButton, "DButton");
  40.  
  41. /*----------------------------
  42. Message Box Class
  43. ------------------------------*/
  44.  
  45. class SLib_MessageBox {
  46.  
  47. var Title = "";
  48. var ButtonPanel = this:Add("EditablePanel");
  49. var Label = this:Add("DLabel");
  50.  
  51. function Init() {
  52. this:__new();
  53. this:SetTitle("");
  54.  
  55. this.ButtonPanel:Dock(BOTTOM);
  56. this.ButtonPanel:SetHeight(24);
  57.  
  58. this.Label:SetColor(Color(255, 255, 255));
  59. this.Label:SetFont("slib_msg_btn_font");
  60. this.Label:SetContentAlignment(7);
  61. this.Label:SetWrap(true);
  62. this.Label:Dock(FILL);
  63. }
  64.  
  65. function Setup(title, text) {
  66. this.Title = title;
  67. this.Label:SetText(text);
  68.  
  69. print(text);
  70.  
  71. this:ShowCloseButton(false);
  72. this:SetSize(500, 400);
  73.  
  74. var closeButton = this:AddButton("Ok", RIGHT, 100);
  75. closeButton.DoClick = function() {
  76. this:Remove();
  77. };
  78.  
  79. this:MakePopup();
  80. this:Center();
  81. }
  82.  
  83. function AddButton(text, dockPos, width) {
  84. var btn = this.ButtonPanel:Add("SLib_MessageBoxButton");
  85. btn:Setup(text);
  86. btn:Dock(dockPos);
  87. btn:SetWidth(width);
  88.  
  89. return btn;
  90. }
  91.  
  92. function Paint(w, h) {
  93. var x, y = this:LocalToScreen(0, 0);
  94. SLib.Gui.DrawBlurRect(x, y, w, h, 3, 5, 255);
  95.  
  96. draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 200));
  97.  
  98. surface.SetDrawColor(0, 0, 0, 100);
  99. surface.DrawOutlinedRect(0, 0, w, h);
  100.  
  101. draw.SimpleText(this.Title, "slib_msg_btn_font", 4, 4, Color(255, 255, 255), 0, 0);
  102. }
  103.  
  104. }
  105.  
  106. CSLib_MessageBox.__index = null;
  107. derma.DefineControl("SLib_MessageBox", "SLib Message Box", CSLib_MessageBox, "DFrame");
  108.  
  109. /*----------------------------
  110. Functions
  111. ------------------------------*/
  112.  
  113. /*
  114. Shows a simple message box with Close button
  115. */
  116. function SLib.Gui.ShowMessageBox(title, text) {
  117. var msg = vgui.Create("SLib_MessageBox");
  118. msg:Setup(title, text);
  119. return msg;
  120. }
  121.  
  122. /*
  123. Shows a message box with Copy to clipboard button
  124. */
  125. function SLib.Gui.ShowErrorMessageBox(title, text, error) {
  126. var msg = vgui.Create("SLib_MessageBox");
  127. msg:Setup(title, text .. error);
  128.  
  129. var copy = msg:AddButton("Copy to clipboard", LEFT, 200);
  130. function copy:DoClick() {
  131. surface.PlaySound("buttons/button14.wav");
  132. SetClipboardText(error);
  133. }
  134.  
  135. return msg;
  136. }
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. /*----------------------------
  144. Tests
  145. ------------------------------*/
  146.  
  147. #if DEBUG
  148.  
  149. var ok, error = pcall(function() {
  150.  
  151. Dupsko();
  152.  
  153. });
  154.  
  155. 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);
  156.  
  157. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement