Rinart73 Posted August 5, 2018 Share Posted August 5, 2018 0.17.1-0.18.3 GitHub Modders community progressed a lot in the last few years. From making direct changes in files to a structured mod folders that inject their code into vanilla files with just one line. But even this way can't save us from mods being incompatible with each other just because they touch the same file. I remember that a long time ago someone tried to make a global API for modding. I'm aiming for the smaller goal and just want to present you this mod. "Mod Helper - Craft Orders" allows you to add and remove Orders in the UI without overriding the "initUI" function. It also allows you to add AIActions, their icons and brings some useful vanilla local functions like "checkCaptain" and "removeSpecialOrders". As of version 1.1.0 it also clears CraftOrders.AIAction and order icon when a player enters the ship and before ship jumps out of the sector, thus solving some coding problems. But it needs to be on server side too now. Installation Unpack mod archive into "Avorion" folder Add following line in the end of the file "data\scripts\entity\craftorders.lua". All other mods lines should be added after this one if not pcall(require, "mods.ModHelper_CraftOrders.scripts.entity.craftorders") then print("[ModHelper_CraftOrders][ERROR]: failed to extend craftorders.lua!") end Changelog 1.1.0 Added: Now mod resets AIAction and order icon before the jump and when player enters the ship Added: Config file 1.0.1 Fixed: removeSpecialOrders now also removes custom orders if they're placed in your mod's "/scripts/entity/ai" folder Changed: Had to overwrite most of the default button functions because of new 'removeSpecialOrders' 1.0.0 Initial release Tips and Notes Mod changes how elements in the Orders Window are positioned. Now we have 3 columns and 12 rows (maximum). Since there will be other mods in 'craftorders', I advice to add prefixes to your non-local functions It's also advised you to not replace other predefined functions like 'initialize' completely. So instead of doing this: function CraftOrders.initialize() -- your code end do this: local old_initialize = CraftOrders.initialize function CraftOrders.initialize() if old_initialize then old_initialize() end -- your code end API Variables CraftOrders.window - window that contains all elements, in case you need to do something with it CraftOrders.ElementType - table that allows you to specify which element you want to create. Current options are: Empty (just reserve a space), Button, CheckBox CraftOrders.Elements - table that contains all UI elements. Each item is a table and each table has following items: title - name of a Button or CheckBox func - associated function. Will be called when user clicks elemens (Button) or toggles it on/off (CheckBox) type - element type. Nil means 'CraftOrders.ElementType.Button' rect - reserved space (Rect). Will be calculated during 'initUI' function. You can get it in 'initUICallback' element - created button or checkbox. Will be created during 'initUI' function. You can get it in 'initUICallback' [*]CraftOrders.AIAction - table that contains all AIActions - default and custom ones. Don't add elements to it manually! Use "CraftOrders.addAIAction" Functions function CraftOrders.checkCaptain () - local function, now accessible function CraftOrders.removeSpecialOrders () - local function, now accessible function CraftOrders.registerInitUICallback (function callback [, bool beforeUICreation ]) Allows you to register callback that will be executed at the start of initUI function (if you'll pass beforeUICreation = true) or at the end of it (beforeUICreation = false or nothing). You can use 'before' callback to remove or adjust other elements in the CraftOrders.Elements table. You should use 'after' callback to get your created elements or reserved Rects. function int CraftOrders.addElement (string title, function callback [, int elemType [, int width [, int height ] ] ]) Requests mod to add an element. title - checkbox or button title. Please don't apply '%_t', as it will be done automatically callback - callback that will be executed on button click or checkbox toggle elemType - one of the elements types from 'CraftOrders.ElementType' table (default is CraftOrders.ElementType.Button) width - element width from 1 to 3. 1 = 230px, 2 = 470px, 3 = 710px. Default: 1 height - element height from 1 to 12. 1 = 30px, 2 = 70px, 3 = 110px e.t.c. Default: 1 Returns: element id, that you will need to use in 'after' initUI callback [*]function CraftOrders.removeElement (string/int index) Allows you to remove element from CraftOrders.Elements by index or title. This function should be executed in 'before' initUI callback [*]function CraftOrders.addAIAction (string name, string iconpath) Adds new AIAction with icon. Mod example -- Init UI local repairButton = CraftOrders.addElement("Repair", "testmod_onRepairButtonPressed") local someCheckBox = CraftOrders.addElement("Some Checkbox", "testmod_onSomeCheckBoxChanged", CraftOrders.ElementType.CheckBox) -- and in case you need some other ui elements, you can just ask mod to reserve the space local customUIElement = CraftOrders.addElement("", "", CraftOrders.ElementType.Empty, 2, 2) CraftOrders.addAIAction("Repair", "data/textures/icons/pixel/repair.png") local function beforeInitUI() CraftOrders.removeElement("Idle") end CraftOrders.registerInitUICallback(beforeInitUI, true) local function afterInitUI() if not CraftOrders.Elements[repairButton] or not CraftOrders.Elements[someCheckBox] or not CraftOrders.Elements[customUIElement] then print("Your elements were either removed by other mod or didn't fit in the window") else repairButton = CraftOrders.Elements[repairButton].element someCheckBox = CraftOrders.Elements[someCheckBox].element -- now we can create custom ui local rect = CraftOrders.Elements[customUIElement].rect customUIElement = CraftOrders.window:createFrame(rect) end end CraftOrders.registerInitUICallback(afterInitUI) -- Callbacks function CraftOrders.testmod_onRepairButtonPressed() print("'Repair' button") if onClient() then invokeServerFunction("testmod_onRepairButtonPressed") ScriptUI():stopInteraction() return end if CraftOrders.checkCaptain() then CraftOrders.removeSpecialOrders() -- some stuff CraftOrders.setAIAction(CraftOrders.AIAction.Repair) end end function CraftOrders.testmod_onSomeCheckBoxChanged() print("Some checkbox value: " .. tostring(someCheckBox.checked)) end ModHelper_CraftOrders-1.0.0_0.17.1-0.18.2.zip ModHelper_CraftOrders-1.0.1_0.17.1-0.18.2.zip ModHelper_CraftOrders-1.1.0_0.17.1-0.18.2.zip Link to comment Share on other sites More sharing options...
Rinart73 Posted August 8, 2018 Author Share Posted August 8, 2018 1.0.1 - hotfix Fixed: removeSpecialOrders now also removes custom orders if they're placed in your mod's "/scripts/entity/ai" folder Changed: Had to overwrite most of the default button functions because of new 'removeSpecialOrders' Link to comment Share on other sites More sharing options...
Rinart73 Posted September 5, 2018 Author Share Posted September 5, 2018 1.1.0 Added: Now mod resets AIAction and order icon before the jump and when a player enters the ship Added: Config file This update is important because some mods (Complex Craft Orders for example) had problems with processing orders after players entered ship or ships jumping into other sector - now you can set up consecutive Jump Orders and they will work! Also, now mod IS NOT client-side only. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now