CQUI-Org / cqui

Civilization 6 - Chao's Quick UI. Reduce clicks and manage your empire faster!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Modular LaunchBar Icons, Pulldown and Partial Screen Hooks

astog opened this issue · comments

commented

Hey @chaorace, I have been working on a safe way to add launchbar icons, partial screen hooks and other menus to the Game UI without overwriting the same file.

My idea was basically to build into launchbar and partialscreenhooks a modular system, where modders can use LuaEvents to externally add icons, buttons or screen hooks. Below are the three main systems I created in my own remote branch. Let me know, if you want me to create a pull request to merge in these changes.

Launcher Bar

These are the icons above the world planner with Tech, Civic tree buttons, etc. To add icons call:

LuaEvents.LaunchBar_AddIcon(buttonInfo);

An example of buttonInfo:

local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas(iconName, iconSize);
local buttonInfo = {
  -- ICON TEXTURE
  IconTexture = {
    OffsetX = textureOffsetX;
    OffsetY = textureOffsetY;
    Sheet = textureSheet;
    Color = UI.GetColorValue(color1);
  };

  -- BASE TEXTURE (Treat it as Button Texture)
  BaseTexture = {
    OffsetX = 0;        -- Texture offset
    OffsetY = 147;
    Sheet = "LaunchBar_Hook_GreatPeopleButton";
    Color = UI.GetColorValue(color2);
    HoverOffsetX = 0;   -- Offset on hover
    HoverOffsetY = 0;
  };

  -- BUTTON INFO
  Callback = function() print("test") end;  -- Callback function
  Tooltip = "barbs...";
}

Below I added to icons:

Launch Bar Extras List

I added list for menus that don't require an icon. I replaced the show/hide for the world builder with the list toggle. The usage is really simple, below is an example:

LuaEvents.LaunchBar_AddExtra("Test1", {Text="Test1", Callback=function() print("Test1") end, Tooltip="Test1"})
LuaEvents.LaunchBar_AddExtra("Test2", {Text="Test2", Callback=function() print("Test2") end})

The first param is key, second param is table:

local extraButton:table = {
  Text = "Test1";     -- The text to display in the button
  Callback = Open;  -- The function to call when the button is clicked
  Tooltip = "test1";  -- Can be nil to disable tooltip
}

Result:

Partial Screen Hooks

These are the top right of the screen with trade overview, world score, etc hooks. The way to add to these is similar to Launch Bar buttons.

  LuaEvents.PartialScreenHooks_AddHook(hookInfo1);

hookInfo structure is identical to buttonInfo. Below is one usage:

local hookInfo1:table = {
    -- ICON TEXTURE
    IconTexture = {
      OffsetX = 0;
      OffsetY = 0;
      Sheet = "MapPins24.dds";
      Color = UI.GetColorValue("COLOR_PLAYER_GOLDENROD")
    };

    -- BUTTON TEXTURE
    BaseTexture = {
      OffsetX = 0;
      OffsetY = 0;
      Sheet = "LaunchBar_Hook_ButtonSmall";

      -- Offset to have when hovering
      HoverOffsetX = 0;
      HoverOffsetY = 40;
    };

    Callback = function() print("Damascus steel!") end;
    Tooltip = "ATTACK!";
  };

Usage Notes

Since this requires the LuaEvents to be created the safe way to call these would be not in Initialize() but in

Events.LoadScreenClose

Below is implementing Unit Report Screen Launchbar icon:

function OnLoadScreenClose()
  -- Add Icon to Launchbar
  local textureOffsetX, textureOffsetY, textureSheet = IconManager:FindIconAtlas("ICON_CIVIC_FUTURE_CIVIC" ,38);
  local reportsButtonInfo = {
    -- ICON TEXTURE
    IconTexture = {
      OffsetX = textureOffsetX;
      OffsetY = textureOffsetY;
      Sheet = textureSheet;
    };

    -- BUTTON TEXTURE
    BaseTexture = {
      OffsetX = 4;
      OffsetY = 245;
      Sheet = "LaunchBar_Hook_CultureButton";

      -- Offset to have when hovering
      HoverOffsetX = 4;
      HoverOffsetY = 5;
    };

    -- BUTTON INFO
    Callback = Open;
    Tooltip = Locale.Lookup("LOC_HUD_REPORTS_VIEW_REPORTS");
  }

  LuaEvents.LaunchBar_AddIcon(reportsButtonInfo);
end

and in Initialize()

Events.LoadScreenClose.Add( OnLoadScreenClose );

Yes, I quite like this. If you've found this to be relatively stable, please submit the PR so we can look into getting this merged before the summer patch fixes start rolling