Files

114 lines
8.2 KiB
Lua

-- All frames and state belong to this addon. No Blizzard function/global replacement.
local model, panel, opener, status, captureAge, history, log, searchBox, guidBox;
local kind="creature";local cachedKind,cachedQuery,cachedResults;local selectedEntry;local resultButtons={};local nearbyButtons={};local page=1;
local function text(parent,font,x,y,width)
local t=parent:CreateFontString(nil,"OVERLAY",font);t:SetPoint("TOPLEFT",x,y);t:SetWidth(width);t:SetJustifyH("LEFT");return t;
end
local function act(fn)
local ok,why=pcall(fn);
if not ok then
model:Note("Action refused");status:SetText(tostring(why):gsub("^.-:%d+: ",""));
end
end
local function button(parent,label,x,y,width,callback)
local b=CreateFrame("Button",nil,parent,"UIPanelButtonTemplate");b:SetSize(width,24);b:SetPoint("TOPLEFT",x,y);b:SetText(label);b:SetScript("OnClick",function()act(callback);end);return b;
end
local function refresh()
if not model or not panel then return;end
local allowed=model:Allowed();opener:SetShown(allowed);
if not allowed then panel:Hide();return;end
status:SetText(model.message);
local age=math.max(0,model.api.now()-(model.capture.captured or 0));
captureAge:SetText((model.guid and (model.kind.." GUID "..model.guid.."\n") or "No GUID selected\n")..(model:Row() and ("Row captured "..age.."s ago") or "Selected row not in loaded capture").."\nHost refresh: every 15s; reload to load it");
local query=searchBox:GetText();
if cachedKind~=kind or cachedQuery~=query then cachedResults=model:Search(kind,query);cachedKind=kind;cachedQuery=query;end
local results=cachedResults;
if (page-1)*10>=#results then page=1;end
for i,b in ipairs(resultButtons) do
local row=results[(page-1)*10+i];b.row=row;b:SetShown(row~=nil);
if row then b:SetText(row.entry.." "..row.name);end
end
for i,b in ipairs(nearbyButtons) do
local row=model.nearby[i];b.row=row;b:SetShown(row~=nil);
if row then b:SetText(row.kind.." GUID "..row.guid.." (entry "..row.entry..")");end
end
local lines={};local ops=model.saved.operations;
for i=math.max(1,#ops-7),#ops do local o=ops[i];lines[#lines+1]=i..". "..o.kind.." "..o.table.." GUID "..o.guid;end
history:SetText(table.concat(lines,"\n"));
lines={};for i=math.max(1,#model.saved.log-5),#model.saved.log do lines[#lines+1]=model.saved.log[i];end
log:SetText(table.concat(lines,"\n"));
end
local function build()
panel=CreateFrame("Frame",nil,UIParent,"BasicFrameTemplateWithInset");panel:SetSize(850,700);panel:SetPoint("CENTER");
panel:SetFrameStrata("DIALOG");panel:SetToplevel(true);panel:EnableMouse(true);panel:EnableMouseWheel(true);
panel:SetMovable(true);panel:RegisterForDrag("LeftButton");panel:SetScript("OnDragStart",panel.StartMoving);panel:SetScript("OnDragStop",panel.StopMovingOrSizing);
panel.TitleText:SetText("LOCAL Spawn Editor");panel:Hide();
opener=CreateFrame("Button",nil,UIParent,"UIPanelButtonTemplate");opener:SetSize(100,25);opener:SetPoint("TOP",0,-45);opener:SetText("LOCAL Editor");opener:Hide();
opener:SetScript("OnClick",function()if model:Allowed() then panel:SetShown(not panel:IsShown());refresh();end end);
button(panel,"Creatures",15,-40,150,function()kind="creature";page=1;refresh();end);
button(panel,"Gameobjects",175,-40,150,function()kind="gameobject";page=1;refresh();end);
searchBox=CreateFrame("EditBox",nil,panel,"InputBoxTemplate");searchBox:SetSize(305,25);searchBox:SetPoint("TOPLEFT",25,-75);searchBox:SetAutoFocus(false);
searchBox:SetScript("OnTextChanged",function()page=1;refresh();end);searchBox:SetScript("OnEscapePressed",searchBox.ClearFocus);
text(panel,"GameFontHighlightSmall",20,-104,320):SetText("Search template entry or name");
for i=1,10 do
local b=button(panel,"",15,-125-(i-1)*26,350,function()end);resultButtons[i]=b;
b:SetScript("OnClick",function()if b.row then selectedEntry=b.row.entry;model:Note("Selected template "..kind.." "..selectedEntry);end end);
end
button(panel,"Previous",15,-390,110,function()page=math.max(1,page-1);refresh();end);
button(panel,"Next",135,-390,110,function()page=page+1;refresh();end);
button(panel,"Add at my position",15,-425,225,function()model:Add(kind,selectedEntry);end);
button(panel,"Nearby",250,-425,115,function()model:Nearby(kind);end);
for i=1,6 do
local b=button(panel,"",15,-458-(i-1)*25,350,function()end);nearbyButtons[i]=b;
b:SetScript("OnClick",function()act(function()
if b.row then
if model.pending and model.pending.kind==b.row.kind and model.pending.candidates[b.row.guid] then model:ChooseAdded(b.row.guid);
else model:Select(b.row.kind,b.row.guid);end
guidBox:SetText(b.row.guid);
end
end);end);
end
button(panel,"Cancel unresolved add",15,-620,225,function()model.pending=nil;model:Note("Unresolved add cleared; inspect nearby spawns before continuing");end);
guidBox=CreateFrame("EditBox",nil,panel,"InputBoxTemplate");guidBox:SetSize(155,25);guidBox:SetPoint("TOPLEFT",405,-40);guidBox:SetAutoFocus(false);guidBox:SetNumeric(true);
button(panel,"Select GUID",575,-40,125,function()model:Select(kind,guidBox:GetText());end);
button(panel,"Use target",710,-40,120,function()
local guid=UnitGUID("target") or "";local low=guid:match("^Creature%-.+%-([0-9A-Fa-f]+)$");
if not low then error("Target a creature, or choose a nearby gameobject");end
local id=tonumber(low,16);if not id or id>4294967295 then error("Target GUID is outside Source range; use Nearby");end
guidBox:SetText(string.format("%.0f",id));model:Select("creature",guidBox:GetText());model.api.send(".npc info");
end);
captureAge=text(panel,"GameFontHighlight",400,-78,420);
button(panel,"Move to my position + facing",400,-145,330,function()model:Move();end);
local confirmGuid;
button(panel,"Delete (capture row first)",400,-180,330,function()
model:CapturedRow();local key=model.kind..":"..model.guid;
if confirmGuid~=key then confirmGuid=key;model:Note("Click Delete again to confirm GUID "..model.guid);return;end
confirmGuid=nil;model:Delete();
end);
button(panel,"Refresh captured rows",400,-220,205,function()model:Require();ReloadUI();end);
button(panel,"Export session",615,-220,170,function()model:Require();model:Note("Session exported by UI reload");ReloadUI();end);
text(panel,"GameFontNormal",400,-260,420):SetText("Undo list (host helper; SQL is never applied here)");
history=text(panel,"GameFontHighlightSmall",400,-285,420);history:SetHeight(145);history:SetJustifyV("TOP");
text(panel,"GameFontHighlightSmall",400,-430,420):SetText("Export, then select the operation number with spawn_undo.py --entry N --snapshots SESSION/snapshots. Review SQL outside the game.");
text(panel,"GameFontNormal",400,-485,420):SetText("Session log");
log=text(panel,"GameFontHighlightSmall",400,-510,420);log:SetHeight(115);log:SetJustifyV("TOP");
status=text(panel,"GameFontHighlightSmall",20,-660,810);
local elapsed=0;panel:SetScript("OnUpdate",function(_,dt)elapsed=elapsed+dt;if elapsed>=1 then elapsed=0;refresh();end end);
end
local events=CreateFrame("Frame");events:RegisterEvent("ADDON_LOADED");events:RegisterEvent("PLAYER_ENTERING_WORLD");events:RegisterEvent("CHAT_MSG_SYSTEM");
events:SetScript("OnEvent",function(_,event,arg)
if event=="ADDON_LOADED" and arg=="OctoEditor" then
model=OctoEditorCore.New(OctoEditorCapture or {},OctoEditorUndo,{
now=function()return time();end,player=function()return UnitName("player");end,
combat=function()return InCombatLockdown();end,clearTarget=function()ClearTarget();end,
send=function(command)SendChatMessage(command,"SAY");end,
later=function(delay,callback)C_Timer.After(delay,callback);end,
});
OctoEditorUndo=model.saved;build();model.changed=refresh;
elseif event=="PLAYER_ENTERING_WORLD" and model then
if model.capture.localOnly and string.upper(UnitName("player") or "")==string.upper(model.capture.character or "EDITOR") then
C_Timer.After(1,function()model.api.send(".account");end);
end
elseif event=="CHAT_MSG_SYSTEM" and model then model:System(arg);refresh();end
end);