-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 34138a2
Showing
6 changed files
with
372 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
local mq = require('mq') | ||
local ImGui = require('ImGui') | ||
RGMercConfig = require('rgmercs.utils.rgmercs_config') | ||
RGMercConfig:LoadSettings() | ||
|
||
local RGMercsLogger = require("rgmercs.utils.rgmercs_logger") | ||
local RGMercUtils = require("rgmercs.utils.rgmercs_utils") | ||
|
||
-- Initialize class-based moduldes | ||
local RGMercModules = require("rgmercs.utils.rgmercs_modules").load() | ||
|
||
-- ImGui Variables | ||
local openGUI = true | ||
local shouldDrawGUI = true | ||
local BgOpacity = tonumber(RGMercConfig:getSettings().BgOpacity) | ||
|
||
local curState = "Idle..." | ||
|
||
-- Icon Rendering | ||
local animItems = mq.FindTextureAnimation("A_DragItem") | ||
local animBox = mq.FindTextureAnimation("A_RecessedBox") | ||
|
||
-- Constants | ||
local ICON_WIDTH = 40 | ||
local ICON_HEIGHT = 40 | ||
local COUNT_X_OFFSET = 39 | ||
local COUNT_Y_OFFSET = 23 | ||
local EQ_ICON_OFFSET = 500 | ||
|
||
local terminate = false | ||
|
||
local function display_item_on_cursor() | ||
if mq.TLO.Cursor() then | ||
local cursor_item = mq.TLO.Cursor -- this will be an MQ item, so don't forget to use () on the members! | ||
local mouse_x, mouse_y = ImGui.GetMousePos() | ||
local window_x, window_y = ImGui.GetWindowPos() | ||
local icon_x = mouse_x - window_x + 10 | ||
local icon_y = mouse_y - window_y + 10 | ||
local stack_x = icon_x + COUNT_X_OFFSET | ||
local stack_y = icon_y + COUNT_Y_OFFSET | ||
local text_size = ImGui.CalcTextSize(tostring(cursor_item.Stack())) | ||
ImGui.SetCursorPos(icon_x, icon_y) | ||
animItems:SetTextureCell(cursor_item.Icon() - EQ_ICON_OFFSET) | ||
ImGui.DrawTextureAnimation(animItems, ICON_WIDTH, ICON_HEIGHT) | ||
if cursor_item.Stackable() then | ||
ImGui.SetCursorPos(stack_x, stack_y) | ||
ImGui.DrawTextureAnimation(animBox, text_size, ImGui.GetTextLineHeight()) | ||
ImGui.SetCursorPos(stack_x - text_size, stack_y) | ||
ImGui.TextUnformatted(tostring(cursor_item.Stack())) | ||
end | ||
end | ||
end | ||
|
||
local function renderModulesTabs() | ||
if not RGMercConfig:settingsLoaded() then return end | ||
for name, _ in pairs(RGMercModules:getModuleList()) do | ||
ImGui.TableNextColumn() | ||
if ImGui.BeginTabItem(name) then | ||
RGMercModules:execModule(name, "Render") | ||
ImGui.EndTabItem() | ||
end | ||
end | ||
end | ||
|
||
local function RGMercsGUI() | ||
if openGUI then | ||
openGUI, shouldDrawGUI = ImGui.Begin('RGMercs', openGUI) | ||
if mq.TLO.MacroQuest.GameState() ~= "INGAME" then return end | ||
|
||
ImGui.SetNextWindowBgAlpha(BgOpacity) | ||
|
||
if shouldDrawGUI then | ||
local pressed | ||
ImGui.PushStyleColor(ImGuiCol.Text, 1.0, 1.0, 1.0, 1) | ||
ImGui.Text("RGMercs running for " .. RGMercConfig.CurLoadedChar) | ||
|
||
if ImGui.BeginTabBar("RGMercsTabs") then | ||
ImGui.SetItemDefaultFocus() | ||
if ImGui.BeginTabItem("RGMercsMain") then | ||
ImGui.Text(curState) | ||
ImGui.EndTabItem() | ||
end | ||
|
||
renderModulesTabs() | ||
|
||
ImGui.EndTabBar(); | ||
end | ||
ImGui.PopStyleColor(1) | ||
|
||
ImGui.NewLine() | ||
ImGui.NewLine() | ||
ImGui.Separator() | ||
|
||
BgOpacity, pressed = ImGui.SliderFloat("BG Opacity", BgOpacity, 0, 1.0, "%.1f", 0.1) | ||
if pressed then | ||
RGMercConfig:getSettings().BgOpacity = tostring(BgOpacity) | ||
RGMercConfig:SaveSettings(true) | ||
end | ||
|
||
display_item_on_cursor() | ||
end | ||
|
||
ImGui.End() | ||
end | ||
end | ||
|
||
mq.imgui.init('RGMercsUI', RGMercsGUI) | ||
mq.bind('/rgmercsui', function() | ||
openGUI = not openGUI | ||
end) | ||
|
||
local function Main() | ||
curState = "Idle..." | ||
|
||
if mq.TLO.MacroQuest.GameState() ~= "INGAME" then return end | ||
|
||
if RGMercConfig.CurLoadedChar ~= mq.TLO.Me.CleanName() then | ||
RGMercConfig:LoadSettings() | ||
end | ||
|
||
RGMercModules:execAll("GiveTime") | ||
end | ||
|
||
-- Global Messaging callback | ||
---@diagnostic disable-next-line: unused-local | ||
local script_actor = RGMercUtils.Actors.register(function(message) | ||
if message()["from"] == RGMercConfig.CurLoadedChar then return end | ||
if message()["script"] ~= RGMercUtils.ScriptName then return end | ||
|
||
RGMercsLogger.log_error("\ayGot Event from(\am%s\ay) module(\at%s\ay) event(\at%s\ay)", message()["from"], | ||
message()["module"], | ||
message()["event"]) | ||
|
||
if message()["module"] then | ||
if message()["module"] == "main" then | ||
RGMercConfig:LoadSettings() | ||
else | ||
RGMercModules:getModuleList()[message()["module"]]:LoadSettings() | ||
end | ||
end | ||
end) | ||
|
||
while not terminate do | ||
Main() | ||
mq.doevents() | ||
mq.delay(10) | ||
end | ||
|
||
RGMercModules:execAll("Shutdown") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
-- Sample Basic Class Module | ||
local mq = require('mq') | ||
local RGMercsLogger = require("rgmercs.utils.rgmercs_logger") | ||
local RGMercUtils = require("rgmercs.utils.rgmercs_utils") | ||
|
||
local Module = { _version = '0.1a', name = "Basic", author = 'Derple' } | ||
Module.__index = Module | ||
|
||
local function getConfigFileName() | ||
local server = mq.TLO.EverQuest.Server() | ||
server = server:gsub(" ", "") | ||
return mq.configDir .. '/rgmercs/PCConfigs/' .. 'basic_' .. server .. "_" .. RGMercConfig.CurLoadedChar .. '.lua' | ||
end | ||
|
||
function Module:SaveSettings(doBroadcast) | ||
mq.pickle(getConfigFileName(), self.settings) | ||
|
||
if doBroadcast then | ||
RGMercUtils.BroadcastUpdate(self.name, "SaveSettings") | ||
end | ||
end | ||
|
||
function Module:LoadSettings() | ||
RGMercsLogger.log("Basic Combat Module Loading Settings for: %s.", RGMercConfig.CurLoadedChar) | ||
local settings_pickle_path = getConfigFileName() | ||
|
||
local config, err = loadfile(settings_pickle_path) | ||
if err or not config then | ||
RGMercsLogger.log_error("\ay[Basic]: Unable to load global settings file(%s), creating a new one!", | ||
settings_pickle_path) | ||
self.settings = {} | ||
self.settings.MyCheckbox = false | ||
self:SaveSettings(true) | ||
else | ||
self.settings = config() | ||
end | ||
end | ||
|
||
function Module.New() | ||
RGMercsLogger.log("Basic Combat Module Loaded.") | ||
local newModule = setmetatable({ settings = {} }, Module) | ||
|
||
newModule:LoadSettings() | ||
|
||
return newModule | ||
end | ||
|
||
function Module:Render() | ||
ImGui.Text("Basic Combat Modules") | ||
local pressed | ||
self.settings.MyCheckbox, pressed = ImGui.Checkbox("I am a Checkbox", self.settings.MyCheckbox) | ||
if pressed then | ||
self:SaveSettings() | ||
end | ||
end | ||
|
||
function Module:GiveTime() | ||
-- Main Module logic goes here. | ||
end | ||
|
||
function Module:Shutdown() | ||
RGMercsLogger.log("Basic Combat Module UnLoaded.") | ||
end | ||
|
||
return Module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
local mq = require('mq') | ||
local RGMercUtils = require("rgmercs.utils.rgmercs_utils") | ||
local RGMercsLogger = require("rgmercs.utils.rgmercs_logger") | ||
|
||
local Config = { _version = '0.1a', author = 'Derple' } | ||
Config.__index = Config | ||
Config.settings_pickle_path = mq.configDir .. '/rgmercs/' .. 'rgmercs.lua' | ||
Config.settings = {} | ||
Config.CurLoadedChar = mq.TLO.Me.CleanName() | ||
|
||
function Config:SaveSettings(doBroadcast) | ||
mq.pickle(self.settings_pickle_path, self.settings) | ||
|
||
if doBroadcast then | ||
RGMercUtils.BroadcastUpdate("main", "SaveSettings") | ||
end | ||
end | ||
|
||
function Config:LoadSettings() | ||
RGMercsLogger.log("\ayLoading Main Settings for %s!", self.CurLoadedChar) | ||
|
||
local config, err = loadfile(self.settings_pickle_path) | ||
if err or not config then | ||
RGMercsLogger.log_error("\ayUnable to load global settings file(%s), creating a new one!", | ||
self.settings_pickle_path) | ||
self.settings = {} | ||
|
||
self:SaveSettings(true) | ||
else | ||
self.settings = config() | ||
end | ||
|
||
self.settings = self.settings or {} | ||
|
||
if not self.settings[self.CurLoadedChar] then | ||
self.settings[self.CurLoadedChar] = self.settings[self.CurLoadedChar] or {} | ||
self.settings[self.CurLoadedChar].BgOpacity = 1.0 | ||
self:SaveSettings(true) | ||
end | ||
|
||
return true | ||
end | ||
|
||
function Config:getSettings() | ||
return self.settings[self.CurLoadedChar] | ||
end | ||
|
||
function Config:settingsLoaded() | ||
return self.settings and self.settings[self.CurLoadedChar] | ||
end | ||
|
||
return Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- @type Mq | ||
local mq = require('mq') | ||
|
||
local actions = {} | ||
|
||
local logLeader = '\ar[\agRGMercs\ar]\aw >>>' | ||
|
||
--- @type number | ||
local logLevel = 2 | ||
|
||
function actions.get_log_level() return logLevel end | ||
|
||
function actions.set_log_level(level) logLevel = level end | ||
|
||
function actions.log_error(output, ...) | ||
if (logLevel < 0) then | ||
return | ||
end | ||
|
||
if (... ~= nil) then output = string.format(output, ...) end | ||
mq.parse(string.format('/mqlog [%s] %s', mq.TLO.Me.Name(), output)) | ||
printf('%s \ar %s', logLeader, output) | ||
end | ||
|
||
function actions.log(output, ...) | ||
if (logLevel < 1) then | ||
return | ||
end | ||
|
||
if (... ~= nil) then output = string.format(output, ...) end | ||
mq.parse(string.format('/mqlog [%s] %s', mq.TLO.Me.Name(), output)) | ||
printf('%s \aw %s', logLeader, output) | ||
end | ||
|
||
function actions.log2(output, ...) | ||
if (logLevel < 2) then | ||
return | ||
end | ||
|
||
if (... ~= nil) then output = string.format(output, ...) end | ||
mq.parse(string.format('/mqlog [%s] %s', mq.TLO.Me.Name(), output)) | ||
printf('%s \ao %s', logLeader, output) | ||
end | ||
|
||
function actions.debug_log(output, ...) | ||
if (logLevel < 3) then | ||
return | ||
end | ||
|
||
if (... ~= nil) then output = string.format(output, ...) end | ||
mq.cmd(string.format('/mqlog [%s] %s', mq.TLO.Me.Name(), output)) | ||
printf('%s \ag %s', logLeader, output) | ||
end | ||
|
||
function actions.output_test_logs() | ||
actions.log_error("Test Error") | ||
actions.log("Test Warning") | ||
actions.log2("Test Normal") | ||
actions.debug_log("Test Debug") | ||
end | ||
|
||
return actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
local Modules = { _version = '0.1a', author = 'Derple' } | ||
Modules.__index = Modules | ||
|
||
---@return any | ||
function Modules.load() | ||
local newModules = setmetatable({ | ||
modules = { | ||
Basic = require("modules.basic").New() | ||
} | ||
}, Modules) | ||
|
||
return newModules | ||
end | ||
|
||
function Modules:getModuleList() | ||
return self.modules | ||
end | ||
|
||
function Modules:execModule(m, fn, ...) | ||
for name, module in pairs(self.modules) do | ||
if name == m then | ||
module[fn](module, ...) | ||
return | ||
end | ||
end | ||
end | ||
|
||
function Modules:execAll(fn, ...) | ||
for _, m in pairs(self.modules) do | ||
m[fn](m, ...) | ||
end | ||
end | ||
|
||
return Modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local Utils = { _version = '0.1a', author = 'Derple' } | ||
Utils.__index = Utils | ||
Utils.Actors = require('actors') | ||
Utils.ScriptName = "RGMercs" | ||
|
||
function Utils.BroadcastUpdate(module, event) | ||
Utils.Actors.send({ from = RGMercConfig.CurLoadedChar, script = Utils.ScriptName, module = module, event = event }) | ||
end | ||
|
||
return Utils |