Skip to content

Instantly share code, notes, and snippets.

@Fireboyd78
Created February 8, 2024 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fireboyd78/281bca0246922c8619e80ceaa8350a49 to your computer and use it in GitHub Desktop.
Save Fireboyd78/281bca0246922c8619e80ceaa8350a49 to your computer and use it in GitHub Desktop.
PZ ContainerTags - Right-click and drag to move the icon around
--[[
Modded script for PZ ContainerTags mod:
- https://steamcommunity.com/sharedfiles/filedetails/?id=3066276504
- Original code belongs to Dismellion
Edited on 2/7/2024 by Dr. Spoonman/Fireboyd78:
- Added the ability to move the icon by holding down the right-mouse button and dragging.
- Refer to comments below for more information.
TODO: Save config options somewhere?
]]--
CTagsPanel = ISPanel:derive("CTagsPanel");
function CTagsPanel:initialise()
ISPanel.initialise(self)
end
function CTagsPanel:prerender()
end
function CTagsPanel:createChildren()
local hO = self.y;
self.tagsBtn = ISButton:new(0, 0, 40, 35, "", self, CTagsPanel.onOptionMouseDownHandler);
if CTags.mode == 2 then
self.tagsBtn:setImage(getTexture("media/textures/note_faction.png"));
else
self.tagsBtn:setImage(getTexture("media/textures/note.png"));
end
self.tagsBtn:initialise();
self.tagsBtn:instantiate();
self.tagsBtn:setDisplayBackground(false);
CTagsPanel.button = self.tagsBtn;
self.tagsBtn.borderColor = {r=1, g=1, b=1, a=0.1};
self.tagsBtn:ignoreWidthChange();
self.tagsBtn:ignoreHeightChange();
-- handle right-click and drag events
self.tagsBtn.onMouseDown = CTagsPanel.onOptionMouseDown
self.tagsBtn.onMouseMove = CTagsPanel.onOptionMouseMove
self.tagsBtn.onMouseMoveOutside = CTagsPanel.onOptionMouseMoveOutside
self.tagsBtn.onRightMouseDown = CTagsPanel.onOptionMouseRightDown
self.tagsBtn.onRightMouseUp = CTagsPanel.onOptionMouseRightUp
self.tagsBtn.onRightMouseUpOutside = CTagsPanel.onOptionMouseRightUpOutside
self.tagsBtn.moveWithMouse = true
self:addChild(self.tagsBtn);
end
function CTagsPanel.onOptionMouseDown(self, x, y)
if self.rightMouseDown == true then
-- don't let the user click the button if it's being dragged
return
end
ISButton.onMouseDown(self, x, y) -- return control to the button
end
--[[
use the right-mouse button as a means of dragging the panel (so as not to conflict with left-click events of the button)
]]--
function CTagsPanel.onOptionMouseRightDown(self, x, y)
ISPanel.onMouseDown(self, x, y)
self.rightMouseDown = true
end
function CTagsPanel.onOptionMouseRightUp(self, x, y)
ISPanel.onMouseUp(self, x, y)
self.rightMouseDown = false
end
function CTagsPanel.onOptionMouseRightUpOutside(self, x, y)
ISPanel.onMouseUpOutside(self, x, y)
self.rightMouseDown = false
end
function CTagsPanel.onOptionMouseMove(self, dx, dy)
if self.rightMouseDown == true then
ISPanel.onMouseMove(self, dx, dy) -- move the button
else
ISButton.onMouseMove(self, dx, dy) -- handle normally
end
end
function CTagsPanel.onOptionMouseMoveOutside(self, dx, dy)
if self.rightMouseDown == true then
ISPanel.onMouseMoveOutside(self, dx, dy) -- move the button (when cursor is outside)
else
ISButton.onMouseMoveOutside(self, dx, dy) -- handle normally
end
end
-- NB: there is no need to check for 'rightMouseDown' here because it's handled in the other code above ^^^
function CTagsPanel.onOptionMouseDownHandler(button, x, y)
local mode = CTags.mode or 1;
local button = CTagsPanel.button;
local iconOn = getTexture("media/textures/note.png");
local iconOff = getTexture("media/textures/note_off.png");
local iconFaction = getTexture("media/textures/note_faction.png");
if (getWorld():getGameMode() == "Multiplayer") then
-- Factions mode
if mode == 0 then
CTags.mode = 1;
button:setImage(iconOn)
end
if mode == 1 then
local faction = CTags:getFaction();
if faction then
CTags.mode = 2;
button:setImage(iconFaction)
else
CTags.mode = 0;
button:setImage(iconOff)
end
end
if mode == 2 then
CTags.mode = 0;
button:setImage(iconOff)
end
else
-- No factions in SP
if mode == 0 then
CTags.mode = 1;
button:setImage(iconOn)
end
if mode == 1 then
CTags.mode = 0;
button:setImage(iconOff)
end
end
end
function CTagsPanel.hide()
local window = CTagsPanel.window;
if not window then return end;
window:setVisible(false)
window:removeFromUIManager()
end
function CTagsPanel.make()
local player = getPlayer();
local playerNum = player:getPlayerNum()
local x = getPlayerScreenLeft(playerNum)
local y = getPlayerScreenTop(playerNum)
local panel = CTagsPanel:new(18, 670, 50, 50, player);
CTagsPanel.window = panel;
panel:initialise();
panel:addToUIManager();
return panel;
end
function CTagsPanel:new(x, y, w, h)
-- Don't store it, regenerate completely
if CTagsPanel.window then CTagsPanel:hide() end
local o = {};
o = ISPanel:new(x, y, w, h);
setmetatable(o, self);
self.__index = self;
o.x = x;
o.y = y;
o.background = true;
o.backgroundColor = {r=0, g=0, b=0, a=0};
o.borderColor = {r=0, g=0, b=0, a=0};
o.anchorLeft = true;
o.anchorRight = false;
o.anchorTop = true;
o.anchorBottom = false;
o.moveWithMouse = false;
o.screenW = getCore():getScreenWidth();
o.screenH = getCore():getScreenHeight();
o.player = getPlayer();
o.playerNumber = o.player:getPlayerNum();
o.core = getCore();
return o;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment