Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.08 KB | None | 0 0
  1. local UIBUTTONNAME = "some_string"
  2. --[[local function UIOnSettlementSelected()
  3.     -- declaring ButtonParent as a local variable to be used within UIOnSettlementSelected()
  4.     local ButtonParent
  5.     -- defining existingElement as a CA_UI element with the string defined in UIBUTTONNAME
  6.     local existingElement = Util.getComponentWithName(UIBUTTONNAME)
  7.     -- if not not existingElement returns true - ie., already exists, then...
  8.     if not not existingElement then
  9.         --# assume existingElement: BUTTON
  10.        -- make the CA_UI visible
  11.         existingElement:SetVisible(true)
  12.        -- make the CA_UI 56x56 pixels
  13.         existingElement:Resize(56, 56)
  14.        -- move the CA_UI to (8, 1016), where (0, 0) is the top left corner
  15.         existingElement:MoveTo(8, 1016)
  16.     -- if the CA_UI doesn't already exist, then...
  17.     else
  18.         -- find the ButtonParent, the CA_UI upon which we'll place our new button
  19.         local ButtonParent = find_uicomponent(core:get_ui_root(), "layout") --, "info_panel_holder", "primary_info_panel_holder", "info_panel_background", "ProvinceInfoPopup", "parchment_banner"
  20.        -- define DetailsButton as a new button using a UIMF method
  21.         local DetailsButton = Button.new(UIBUTTONNAME, ButtonParent, "CIRCULAR", "ui/skins/default/icon_province_details.png")
  22.        -- resize the DetailsButton to 56x56 px
  23.         DetailsButton:Resize(56, 56)
  24.        -- move DetailsButton to(8, 1016)
  25.         DetailsButton:MoveTo(8, 1016)
  26.        -- when DetailsButton is clicked, trigger the function "CreatePanel()"
  27.         DetailsButton:RegisterForClick(function() CreatePanel() end)
  28.     end
  29. end]]
  30.  
  31.  
  32. function vandy()
  33.     --These four lines are explained in detail below in core:add_listener(PanelClosedUI
  34.     local ButtonParent = find_uicomponent(core:get_ui_root(), "layout")-- "bar_small_top", "TabGroup")
  35.     local testButton = Button.new("testButton", ButtonParent, "CIRCULAR", "ui/skins/default/browser_spell_tab_lore.png")
  36.     testButton:MoveTo(1800, 0)
  37.     testButton:RegisterForClick(function() CreatePanel() end)
  38.     --end four lines
  39.  
  40.  
  41.     core:add_listener(
  42.         "SettlementSelectedUI",
  43.         "SettlementSelected",
  44.         function(context)
  45.           return context:garrison_residence():faction():name() == cm:get_local_faction(true)
  46.        end,
  47.      function(context)
  48.           cm:callback(function()
  49.             --[[ local existingFrame = Util.getComponentWithName(UIPANELNAME)
  50.                 if not not existingFrame then
  51.                    --# assume existingFrame: FRAME
  52.                    existingFrame:Delete()
  53.                end]]
  54.                 UIOnSettlementSelected()
  55.             end, 0.1)
  56.         end,
  57.         true
  58.     )
  59.  
  60.     core:add_listener(
  61.         "PanelClosedUI",
  62.         "PanelClosedCampaign",
  63.         function(context)
  64.             return context.string == "technology_panel"
  65.         end,
  66.         function(context)
  67.             CreatePanel()
  68.             --Elements need a parent (something they are attached to). For example, a button needs a parent. In this case I don't want to create a frame for it because it will
  69.             --always be on screen. So I will get "layout" from core:get_ui_root (IE the UI root, the very top of the hierarchy, IE root has no parent, it is THE parent). Layout is
  70.             --essentially the frame for most of the UI elements such as the end turn button and the bar at the top with the income and other things on it.
  71.             --ButtonParent = find_uicomponent(core:get_ui_root(), "layout", "bar_small_top", "TabGroup")
  72.             --Here I am creating a new button called testButton, assigning to the ButtonParent (which is the above variable that contains the 'layout' information), defining it
  73.             --as a circular button and giving it the image icon_province_details.png
  74.             testButton = Button.new("testButton", ButtonParent, "CIRCULAR", "ui/skins/default/browser_spell_tab_lore.png")
  75.             --this moves the button to the specified coordinates. X and Y or horizontal and vertical (left to right, up to down). 0,0 is the top left of the screen. 2000, 0 is almost
  76.             --to the top right.
  77.             testButton:MoveTo(1800, 0)
  78.             testButton:RegisterForClick(function() CreatePanel() end)
  79.         end,
  80.         true
  81.        
  82.     )
  83.     function CreatePanel()
  84.         local uimfFrame = Frame.new("UIMFFrame");
  85.         uimfFrame:Resize(750, 400);
  86.         Util.centreComponentOnScreen(uimfFrame);
  87.         uimfFrame:SetTitle("UI Modding Framework")                  
  88.         uimfFrame:AddCloseButton();
  89.  
  90.     end
  91.     --[[creates a new frame with the name uimfFrame
  92.     local uimfFrame = Frame.new("UIMFFrame");
  93.     uimfFrame:Resize(750, 400);
  94.     --centers uimfFrame in the middle of the screen
  95.     Util.centreComponentOnScreen(uimfFrame);
  96.     uimfFrame:SetTitle("UI Modding Framework")  
  97.     --I mean.. it's a close button. It closes the thing.    
  98.     uimfFrame:AddCloseButton();
  99.  
  100.     --creates a container for elements such as buttons and text for layout
  101.     local mainContainer = Container.new(FlowLayout.VERTICAL);
  102.     --creates a second container that can be placed in the first container along with another container
  103.     --doing this allows you to easily organize multiple elements by splitting them up over various containers
  104.     local firstRow = Container.new(FlowLayout.HORIZONTAL);
  105.     --creates a new text button with the name customButton. uimfFrame is placed here to make customButton the
  106.     --child of uimfFrame, so that when uimfFrame is closed the button is closed/deleted. If uimfFrame is moved
  107.     --so is the Button
  108.     local customButton = TextButton.new("customButton", uimfFrame, "TEXT", "Create custom buttons")
  109.     local customText = Text.new("customText", uimfFrame, "NORMAL", "Create custom text")
  110.     --adds the elements to the declared firstRow container
  111.     firstRow:AddComponent(customButton);
  112.     firstRow:AddComponent(customText);
  113.     --asdds firstRow to mainContainer
  114.     mainContainer:AddComponent(firstRow);
  115.  
  116.     --centers mainContainer on uimfFrame
  117.     Util.centreComponentOnComponent(mainContainer, uimfFrame);]]
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement