Some refactoring to help fix bug

This commit is contained in:
Jackzie 2024-09-25 11:50:18 -05:00
parent 9bfb1e4787
commit 9352c5b7d0
6 changed files with 30 additions and 17 deletions

View file

@ -138,6 +138,7 @@ public any Native_SpawnSchematic(Handle plugin, int numParams) {
return true;
}
enum struct PropSelectorIterator {
ArrayList _list;
int _index;
@ -335,10 +336,17 @@ enum struct PropSelector {
return -1;
}
}
enum itemMenuFlag {
// Do not change flags
IMF_NoChange = -1,
IMF_None = 0,
// Delete underlying item buffer when done using it (for temp buffers, such as search results)
IMF_DeleteAfterUse = 1
}
enum struct PlayerPropData {
ArrayList categoryStack;
ArrayList itemBuffer;
bool clearListBuffer;
int bufferFlags; // itemMenuFlag, IMF_*
int lastCategoryIndex;
int lastItemIndex;
// When did the user last interact with prop spawner? (Shows hints after long inactivity)
@ -359,7 +367,7 @@ enum struct PlayerPropData {
void Reset() {
if(this.Selector.IsActive()) this.Selector.Cancel();
this.chatPrompt = Prompt_None;
this.clearListBuffer = false;
this.bufferFlags = IMF_None;
this.lastCategoryIndex = 0;
this.lastItemIndex = 0;
this.lastActiveTime = 0;
@ -389,18 +397,20 @@ enum struct PlayerPropData {
ShowCategoryList(client, ROOT_CATEGORY);
}
// Sets the list buffer
void SetItemBuffer(ArrayList list, bool cleanupAfterUse = false) {
// Sets the list buffer, with optional flags. If no flags set, uses current flags
void SetItemBuffer(ArrayList list, int flags = IMF_NoChange) {
// Cleanup previous buffer if exist
this.itemBuffer = list;
this.clearListBuffer = cleanupAfterUse;
if(flags != IMF_NoChange) {
this.bufferFlags = flags;
}
}
void ClearItemBuffer() {
if(this.itemBuffer != null && this.clearListBuffer) {
if(this.itemBuffer != null && this.bufferFlags & IMF_DeleteAfterUse) {
PrintToServer("ClearItemBuffer(): arraylist deleted.");
delete this.itemBuffer;
}
this.clearListBuffer = false;
this.bufferFlags = IMF_None;
}
void PushCategory(CategoryData category) {
@ -443,7 +453,6 @@ enum struct PlayerPropData {
if(this.categoryStack != null) {
delete this.categoryStack;
}
this.clearListBuffer = false;
}
}
PlayerPropData g_PropData[MAXPLAYERS+1];

View file

@ -69,7 +69,7 @@ Action Command_Props(int client, int args) {
}
}
PrintToChat(client, "\x04[Editor]\x01 Check console");
} else if(StrEqual(arg, "search")) {
} else if(StrEqual(arg, "?q") || StrEqual(arg, "search")) {
if(args == 1) {
PrintToChat(client, "\x04[Editor]\x01 Enter your search query:");
g_PropData[client].chatPrompt = Prompt_Search;

View file

@ -344,12 +344,12 @@ int ManagerSelectorActionHandler(Menu menu, MenuAction action, int client, int p
Spawn_ShowManagerMainMenu(client);
} else if(StrEqual(info, "save_scene")) {
ArrayList items = g_PropData[client].Selector.End();
g_PropData[client].SetItemBuffer(items, true);
g_PropData[client].SetItemBuffer(items, IMF_DeleteAfterUse);
g_PropData[client].chatPrompt = Prompt_SaveScene;
SendEditorMessage(client, "Enter name for scene:");
} else if(StrEqual(info, "save_collection")) {
ArrayList items = g_PropData[client].Selector.End();
g_PropData[client].SetItemBuffer(items, true);
g_PropData[client].SetItemBuffer(items, IMF_DeleteAfterUse);
g_PropData[client].chatPrompt = Prompt_SaveCollection;
SendEditorMessage(client, "Enter name for collection:");
} else {

View file

@ -109,7 +109,9 @@ void ShowCategoryList(int client, CategoryData category) {
int index = g_PropData[client].lastCategoryIndex / 7 * 7;
menu.DisplayAt(client, index, MENU_TIME_FOREVER);
}
void _showItemMenu(int client, ArrayList items, const char[] title = "", bool clearArray = false, const char[] classnameOverride = "") {
void _showItemMenu(int client, ArrayList items, const char[] title = "", int flags = IMF_None, const char[] classnameOverride = "") {
if(items == null) {
// Use previous list buffer
items = g_PropData[client].itemBuffer;
@ -120,7 +122,7 @@ void _showItemMenu(int client, ArrayList items, const char[] title = "", bool cl
}
} else {
// Populate the buffer with this list
g_PropData[client].SetItemBuffer(items, clearArray);
g_PropData[client].SetItemBuffer(items, flags);
// Reset the index, so we start on the first item
g_PropData[client].lastItemIndex = 0;
strcopy(g_PropData[client].classnameOverride, 32, classnameOverride);
@ -168,7 +170,7 @@ void ShowCategoryItemMenu(int client, CategoryData category) {
* @param classnameOverride Override the classname to spawn as
*/
void ShowItemMenu(int client, ArrayList items = null, const char[] title = "", const char[] classnameOverride = "") {
_showItemMenu(client, items, title, false, classnameOverride);
_showItemMenu(client, items, title, IMF_NoChange, classnameOverride);
}
/**
* Show a list of items, deleting the arraylist on completion
@ -181,7 +183,7 @@ void ShowTempItemMenu(int client, ArrayList items, const char[] title = "", cons
if(items == null) {
LogError("ShowTempItemMenu: Given null item list");
}
_showItemMenu(client, items, title, true, classnameOverride);
_showItemMenu(client, items, title, IMF_DeleteAfterUse, classnameOverride);
}
void Spawn_ShowFavorites(int client) {

View file

@ -389,7 +389,7 @@ public Action OnClientSayCommand(int client, const char[] command, const char[]
void DoSearch(int client, const char[] query) {
ArrayList results = SearchItems(query);
if(results.Length == 0) {
CPrintToChat(client, "\x04[Editor]\x01 No results found. :(");
CPrintToChat(client, "\x04[Editor]\x01 No results found for \x05%s\x01 :(", query);
} else {
char title[64];
Format(title, sizeof(title), "Results for \"%s\"", query);
@ -464,6 +464,9 @@ bool _searchItems(ArrayList results, ArrayList items, const char[] query) {
for(int i = 0; i < items.Length; i++) {
items.GetArray(i, item);
int searchIndex = StrContains(item.name, query, false);
// Search model if name doesn't match
// item.model: models/...., we cut out models/ part
if(searchIndex == -1) searchIndex = StrContains(item.model[7], query, false);
if(searchIndex > -1) {
search.FromItemData(item);
search.index = searchIndex;

View file

@ -31,7 +31,6 @@ ConVar enabledBlacklist;
#include <editor/editor.sp>
#include <editor/props/base.sp>
#include <editor/natives.sp>
#include <editor>
public Plugin myinfo = {
name = "L4D2 Hats & Editor",