Skip to content

Commit

Permalink
Updated with ability to drag bars around in the same style as xivparty
Browse files Browse the repository at this point in the history
  • Loading branch information
tirem committed Mar 21, 2023
1 parent a89754b commit 893ad82
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 60 deletions.
81 changes: 56 additions & 25 deletions xivbar/config.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require('common')
local imgui = require('imgui')
local chat = require('chat');

local showConfig = false;
local configInitialized = false;

-- find all our layouts and strip _alliance and file extensions
-- return a list of all sub directories
Expand All @@ -12,6 +14,27 @@ local function get_theme_paths()
end

local function DrawConfigMenu()
if (configInitialized == false) then
imgui.SetNextWindowPos({gTheme_options.screen_x + gTheme_options.offset_x, gTheme_options.screen_y + gTheme_options.offset_y});
imgui.SetNextWindowSize({1,1});
configInitialized = true;
end

imgui.PushStyleColor(ImGuiCol_WindowBg, {1,1,0,1});
imgui.PushStyleVar(ImGuiStyleVar_WindowBorderSize, 3);
imgui.Begin(("xivbar: move bar"), true, bit.bor(ImGuiWindowFlags_NoSavedSettings, ImGuiWindowFlags_NoDecoration))
local posX, posY = imgui.GetWindowPos();
posX = posX - gTheme_options.screen_x;;
posY = posY - gTheme_options.screen_y;
if (settings.Bars.OffsetX ~= posX or settings.Bars.OffsetY ~= posY) then
settings.Bars.OffsetX = posX;
settings.Bars.OffsetY = posY;
OnSettingsUpdated();
end
imgui.End();
imgui.PopStyleColor(1);
imgui.PopStyleVar(1);

if(imgui.Begin(("xivbar config"), true, ImGuiWindowFlags_AlwaysAutoResize)) then

-- Use tabs for this config menu
Expand All @@ -22,7 +45,7 @@ local function DrawConfigMenu()

if (imgui.Checkbox('Compact Bar', { settings.Theme.Compact })) then
settings.Theme.Compact = not settings.Theme.Compact;
UpdateSettings();
OnSettingsUpdated();
end
imgui.ShowHelp('Use the compact images for this theme');

Expand All @@ -34,7 +57,7 @@ local function DrawConfigMenu()

if (imgui.Selectable(theme_paths[i], is_selected) and theme_paths[i] ~= settings.Theme.Name) then
settings.Theme.Name = theme_paths[i];
UpdateSettings();
OnSettingsUpdated();
end

if (is_selected) then
Expand All @@ -49,58 +72,58 @@ local function DrawConfigMenu()
local fontName = { settings.Texts.Font };
if imgui.InputText('Font Name', fontName, 999) then
settings.Texts.Font = fontName[1];
UpdateSettings();
OnSettingsUpdated();
end
imgui.ShowHelp('Font to use for text');

-- Font Settings
local fontSize = { settings.Texts.Size };
if (imgui.SliderInt('Font Size', fontSize, 0, 32)) then
settings.Texts.Size = fontSize[1];
UpdateSettings();
OnSettingsUpdated();
end

-- Stroke Settings
local strokeWidth = { settings.Texts.Stroke.Width };
if (imgui.SliderInt('Stroke Width', strokeWidth, 0, 8)) then
settings.Texts.Stroke.Width = strokeWidth[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();

local fontRed = { settings.Texts.Color.Red };
if (imgui.SliderInt('Font Red', fontRed, 0, 255)) then
settings.Texts.Color.Red = fontRed[1];
UpdateSettings();
OnSettingsUpdated();
end
local fontGreen = { settings.Texts.Color.Green };
if (imgui.SliderInt('Font Green', fontGreen, 0, 255)) then
settings.Texts.Color.Green = fontGreen[1];
UpdateSettings();
OnSettingsUpdated();
end
local fontBlue = { settings.Texts.Color.Blue };
if (imgui.SliderInt('Font Blue', fontBlue, 0, 255)) then
settings.Texts.Color.Blue = fontBlue[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();

local strokeRed = { settings.Texts.Stroke.Red };
if (imgui.SliderInt('stroke Red', strokeRed, 0, 255)) then
settings.Texts.Stroke.Red = strokeRed[1];
UpdateSettings();
OnSettingsUpdated();
end
local strokeGreen = { settings.Texts.Stroke.Green };
if (imgui.SliderInt('stroke Green', strokeGreen, 0, 255)) then
settings.Texts.Stroke.Green = strokeGreen[1];
UpdateSettings();
OnSettingsUpdated();
end
local strokeBlue = { settings.Texts.Stroke.Blue };
if (imgui.SliderInt('stroke Blue', strokeBlue, 0, 255)) then
settings.Texts.Stroke.Blue = strokeBlue[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();
Expand All @@ -113,7 +136,7 @@ local function DrawConfigMenu()

if (imgui.Checkbox('Color HP Text', { settings.Theme.ColorHpText })) then
settings.Theme.ColorHpText = not settings.Theme.ColorHpText;
UpdateSettings();
OnSettingsUpdated();
end
imgui.ShowHelp('Color HP based on percent');

Expand All @@ -122,53 +145,53 @@ local function DrawConfigMenu()
local midHpR = { settings.Texts.HpMid.Red };
if (imgui.SliderInt('75% HP Red', midHpR, 0, 255)) then
settings.Texts.HpMid.Red = midHpR[1];
UpdateSettings();
OnSettingsUpdated();
end
local midHpG = { settings.Texts.HpMid.Green };
if (imgui.SliderInt('75% HP Green', midHpG, 0, 255)) then
settings.Texts.HpMid.Green = midHpG[1];
UpdateSettings();
OnSettingsUpdated();
end
local midHpB = { settings.Texts.HpMid.Blue };
if (imgui.SliderInt('75% HP Blue', midHpB, 0, 255)) then
settings.Texts.HpMid.Blue = midHpB[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();

local lowHpR = { settings.Texts.HpLow.Red };
if (imgui.SliderInt('50% HP Red', lowHpR, 0, 255)) then
settings.Texts.FullTpColor.Red = lowHpR[1];
UpdateSettings();
OnSettingsUpdated();
end
local lowHpG = { settings.Texts.HpLow.Green };
if (imgui.SliderInt('50% HP Green', lowHpG, 0, 255)) then
settings.Texts.HpLow.Green = lowHpG[1];
UpdateSettings();
OnSettingsUpdated();
end
local lowHpB = { settings.Texts.HpLow.Blue };
if (imgui.SliderInt('50% HP Blue', lowHpB, 0, 255)) then
settings.Texts.HpLow.Blue = lowHpB[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();

local critHpR = { settings.Texts.HpCritical.Red };
if (imgui.SliderInt('25% HP Red', critHpR, 0, 255)) then
settings.Texts.HpCritical.Red = critHpR[1];
UpdateSettings();
OnSettingsUpdated();
end
local critHpG = { settings.Texts.HpCritical.Green };
if (imgui.SliderInt('25% HP Green', critHpG, 0, 255)) then
settings.Texts.HpCritical.Green = critHpG[1];
UpdateSettings();
OnSettingsUpdated();
end
local critHpB = { settings.Texts.HpCritical.Blue };
if (imgui.SliderInt('25% HP Blue', critHpB, 0, 255)) then
settings.Texts.HpCritical.Blue = critHpB[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();
Expand All @@ -180,7 +203,7 @@ local function DrawConfigMenu()
if imgui.BeginTabItem('TP Bar') then
if (imgui.Checkbox('Dim TP Text', { settings.Theme.DimTpBar })) then
settings.Theme.DimTpBar = not settings.Theme.DimTpBar;
UpdateSettings();
OnSettingsUpdated();
end
imgui.ShowHelp('Dim the TP bar when TP is below 1000');

Expand All @@ -190,17 +213,17 @@ local function DrawConfigMenu()
local fullTpRed = { settings.Texts.FullTpColor.Red };
if (imgui.SliderInt('Full TP Red', fullTpRed, 0, 255)) then
settings.Texts.FullTpColor.Red = fullTpRed[1];
UpdateSettings();
OnSettingsUpdated();
end
local fullTpGreen = { settings.Texts.FullTpColor.Green };
if (imgui.SliderInt('Full TP Green', fullTpGreen, 0, 255)) then
settings.Texts.FullTpColor.Green = fullTpGreen[1];
UpdateSettings();
OnSettingsUpdated();
end
local fullTpBlue = { settings.Texts.FullTpColor.Blue };
if (imgui.SliderInt('Full TP Blue', fullTpBlue, 0, 255)) then
settings.Texts.FullTpColor.Blue = fullTpBlue[1];
UpdateSettings();
OnSettingsUpdated();
end

imgui.Separator();
Expand All @@ -225,7 +248,15 @@ ashita.events.register('command', '__config_command_cb', function (e)
local command_args = e.command:lower():args()
if table.contains({'/xivbar', '/xb'}, command_args[1]) then
-- Toggle the config menu
configInitialized = false;
showConfig = not showConfig;
if (not showConfig) then
UpdateSettings();
else
print(chat.header(addon.name)..'Config opened (/xb or /xivbar)')
print(chat.header(addon.name)..'Retype the command to save and close')
print(chat.header(addon.name)..'To move bar click and drag the yellow box')
end
e.blocked = true;
end
end);
3 changes: 3 additions & 0 deletions xivbar/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ theme.apply = function (settings)
options.bar_offset = settings.Theme.Bar.Compact.Offset
end

options.screen_x = AshitaCore:GetConfigurationManager():GetFloat('boot', 'ffxi.registry', '0001', 1024) / 2 - (options.total_width / 2)
options.screen_y = AshitaCore:GetConfigurationManager():GetFloat('boot', 'ffxi.registry', '0002', 768) - 60

return options
end

Expand Down
2 changes: 2 additions & 0 deletions xivbar/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ end

-- hide ui
function ui:hide()
if (self.background == nil) then return; end;
self.background.visible = false
self.hp_bar.visible = false
self.hp_text:set_visible(false);
Expand All @@ -138,6 +139,7 @@ end

-- show ui
function ui:show()
if (self.background == nil) then return; end;
self.background.visible = true
self.hp_bar.visible = true
self.hp_text:set_visible(true);
Expand Down
Loading

0 comments on commit 893ad82

Please sign in to comment.