|
7 | 7 | * Original File by lil_Toady
|
8 | 8 | *
|
9 | 9 | **************************************]]
|
10 |
| -aInteriorForm = nil |
| 10 | +aInterior = { |
| 11 | + Form = nil, |
| 12 | + interiors = {} |
| 13 | +} |
11 | 14 |
|
12 |
| -function aPlayerInterior(player) |
13 |
| - if (aInteriorForm == nil) then |
| 15 | +function aInterior.Show(player) |
| 16 | + if (aInterior.Form == nil) then |
14 | 17 | local x, y = guiGetScreenSize()
|
15 |
| - aInteriorForm = guiCreateWindow(x / 2 - 110, y / 2 - 150, 220, 300, "Player Interior Management", false) |
16 |
| - aInteriorList = guiCreateGridList(0.03, 0.08, 0.94, 0.73, true, aInteriorForm) |
17 |
| - guiGridListAddColumn(aInteriorList, "World", 0.2) |
18 |
| - guiGridListAddColumn(aInteriorList, "Description", 0.75) |
19 |
| - aInteriorSelect = guiCreateButton(0.03, 0.82, 0.94, 0.075, "Select", true, aInteriorForm) |
20 |
| - aInteriorCancel = guiCreateButton(0.03, 0.90, 0.94, 0.075, "Cancel", true, aInteriorForm) |
21 |
| - |
22 |
| - local node = xmlLoadFile("conf\\interiors.xml") |
23 |
| - if (node) then |
24 |
| - local interiors = 0 |
25 |
| - while (xmlFindChild(node, "interior", interiors) ~= false) do |
26 |
| - local interior = xmlFindChild(node, "interior", interiors) |
27 |
| - local row = guiGridListAddRow(aInteriorList) |
28 |
| - guiGridListSetItemText(aInteriorList, row, 1, xmlNodeGetAttribute(interior, "world"), false, true) |
29 |
| - guiGridListSetItemText(aInteriorList, row, 2, xmlNodeGetAttribute(interior, "id"), false, false) |
30 |
| - interiors = interiors + 1 |
31 |
| - end |
32 |
| - end |
33 |
| - addEventHandler("onClientGUIDoubleClick", aInteriorForm, aClientInteriorDoubleClick) |
34 |
| - addEventHandler("onClientGUIClick", aInteriorForm, aClientInteriorClick) |
| 18 | + aInterior.Form = guiCreateWindow(x / 2 - 110, y / 2 - 150, 220, 300, "Player Interior Management", false) |
| 19 | + guiSetAlpha(aInterior.Form, 1) |
| 20 | + guiSetProperty(aInterior.Form, 'AlwaysOnTop', 'True') |
| 21 | + aInterior.List = guiCreateGridList(0.03, 0.17, 0.94, 0.65, true, aInterior.Form) |
| 22 | + guiGridListAddColumn(aInterior.List, "World", 0.2) |
| 23 | + guiGridListAddColumn(aInterior.List, "Description", 0.75) |
| 24 | + aInterior.Edit = guiCreateEdit(0.03, 0.08, 0.94, 0.08, '', true, aInterior.Form) |
| 25 | + aInterior.Select = guiCreateButton(0.03, 0.82, 0.94, 0.075, "Select", true, aInterior.Form) |
| 26 | + aInterior.Cancel = guiCreateButton(0.03, 0.90, 0.94, 0.075, "Cancel", true, aInterior.Form) |
| 27 | + |
| 28 | + aInterior.Load() |
| 29 | + aInterior.Refresh() |
| 30 | + |
| 31 | + addEventHandler("onClientGUIDoubleClick", aInterior.Form, aInterior.onDoubleClick) |
| 32 | + addEventHandler("onClientGUIClick", aInterior.Form, aInterior.onClick) |
| 33 | + addEventHandler("onClientGUIChanged", aInterior.Form, aInterior.onGUIChange) |
| 34 | + |
35 | 35 | --Register With Admin Form
|
36 |
| - aRegister("PlayerInterior", aInteriorForm, aPlayerInterior, aPlayerInteriorClose) |
| 36 | + aRegister("PlayerInterior", aInterior.Form, aInterior.Show, aInterior.Close) |
37 | 37 | end
|
38 |
| - aInteriorSelectPointer = player |
39 |
| - guiSetVisible(aInteriorForm, true) |
40 |
| - guiBringToFront(aInteriorForm) |
| 38 | + aInterior.SelectPointer = player |
| 39 | + guiSetVisible(aInterior.Form, true) |
| 40 | + guiBringToFront(aInterior.Form) |
41 | 41 | end
|
42 | 42 |
|
43 |
| -function aPlayerInteriorClose(destroy) |
44 |
| - if ((destroy) or (guiCheckBoxGetSelected(aPerformanceInterior))) then |
45 |
| - if (aInteriorForm) then |
46 |
| - removeEventHandler("onClientGUIDoubleClick", aInteriorForm, aClientInteriorDoubleClick) |
47 |
| - removeEventHandler("onClientGUIClick", aInteriorForm, aClientInteriorClick) |
48 |
| - destroyElement(aInteriorForm) |
49 |
| - aInteriorForm = nil |
| 43 | +function aInterior.Close(destroy) |
| 44 | + if (destroy) then |
| 45 | + aInterior.interiors = {} |
| 46 | + if (aInterior.Form) then |
| 47 | + removeEventHandler("onClientGUIDoubleClick", aInterior.Form, aInterior.onDoubleClick) |
| 48 | + removeEventHandler("onClientGUIClick", aInterior.Form, aInterior.onClick) |
| 49 | + destroyElement(aInterior.Form) |
| 50 | + aInterior.Form = nil |
50 | 51 | end
|
51 | 52 | else
|
52 |
| - guiSetVisible(aInteriorForm, false) |
| 53 | + guiSetVisible(aInterior.Form, false) |
53 | 54 | end
|
54 | 55 | end
|
55 | 56 |
|
56 |
| -function aClientInteriorDoubleClick(button) |
| 57 | +function aInterior.onDoubleClick(button) |
57 | 58 | if (button == "left") then
|
58 |
| - if (source == aInteriorList) then |
59 |
| - if (guiGridListGetSelectedItem(aInteriorList) ~= -1) then |
| 59 | + if (source == aInterior.List) then |
| 60 | + if (guiGridListGetSelectedItem(aInterior.List) ~= -1) then |
60 | 61 | triggerServerEvent(
|
61 | 62 | "aPlayer",
|
62 | 63 | getLocalPlayer(),
|
63 |
| - aInteriorSelectPointer, |
| 64 | + aInterior.SelectPointer, |
64 | 65 | "setinterior",
|
65 |
| - guiGridListGetItemText(aInteriorList, guiGridListGetSelectedItem(aInteriorList), 2) |
| 66 | + guiGridListGetItemText(aInterior.List, guiGridListGetSelectedItem(aInterior.List), 2) |
66 | 67 | )
|
67 |
| - aPlayerInteriorClose(false) |
| 68 | + aInterior.Close(false) |
68 | 69 | end
|
69 | 70 | end
|
70 | 71 | end
|
71 | 72 | end
|
72 | 73 |
|
73 |
| -function aClientInteriorClick(button) |
| 74 | +function aInterior.onGUIChange() |
| 75 | + aInterior.Refresh() |
| 76 | +end |
| 77 | + |
| 78 | +function aInterior.onClick(button) |
74 | 79 | if (button == "left") then
|
75 |
| - if (source == aInteriorSelect) then |
76 |
| - if (guiGridListGetSelectedItem(aInteriorList) ~= -1) then |
| 80 | + if (source == aInterior.Select) then |
| 81 | + if (guiGridListGetSelectedItem(aInterior.List) ~= -1) then |
77 | 82 | triggerServerEvent(
|
78 | 83 | "aPlayer",
|
79 | 84 | getLocalPlayer(),
|
80 |
| - aInteriorSelectPointer, |
| 85 | + aInterior.SelectPointer, |
81 | 86 | "setinterior",
|
82 |
| - guiGridListGetItemText(aInteriorList, guiGridListGetSelectedItem(aInteriorList), 2) |
| 87 | + guiGridListGetItemText(aInterior.List, guiGridListGetSelectedItem(aInterior.List), 2) |
83 | 88 | )
|
84 |
| - guiSetVisible(aInteriorForm, false) |
| 89 | + guiSetVisible(aInterior.Form, false) |
85 | 90 | end
|
86 |
| - elseif (source == aInteriorCancel) then |
87 |
| - aPlayerInteriorClose(false) |
| 91 | + elseif (source == aInterior.Cancel) then |
| 92 | + aInterior.Close(false) |
| 93 | + end |
| 94 | + end |
| 95 | +end |
| 96 | + |
| 97 | +function aInterior.Load() |
| 98 | + local table = {} |
| 99 | + local node = xmlLoadFile("conf\\interiors.xml") |
| 100 | + if (node) then |
| 101 | + local interiors = 0 |
| 102 | + while (xmlFindChild(node, "interior", interiors) ~= false) do |
| 103 | + local interior = xmlFindChild(node, "interior", interiors) |
| 104 | + local id = #table + 1 |
| 105 | + table[id] = {} |
| 106 | + table[id]["id"] = xmlNodeGetAttribute(interior, "id") |
| 107 | + table[id]["world"] = xmlNodeGetAttribute(interior, "world") |
| 108 | + interiors = interiors + 1 |
| 109 | + end |
| 110 | + end |
| 111 | + aInterior.interiors = table |
| 112 | +end |
| 113 | + |
| 114 | +function aInterior.Refresh() |
| 115 | + local filter = guiGetText(aInterior.Edit):lower() |
| 116 | + guiGridListClear(aInterior.List) |
| 117 | + for k, v in ipairs(aInterior.interiors) do |
| 118 | + if v.world:find(filter) or v.id:lower():find(filter) then |
| 119 | + local row = guiGridListAddRow(aInterior.List) |
| 120 | + guiGridListSetItemText(aInterior.List, row, 1, v.world, false, true) |
| 121 | + guiGridListSetItemText(aInterior.List, row, 2, v.id, false, false) |
88 | 122 | end
|
89 | 123 | end
|
90 | 124 | end
|
0 commit comments