Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UIBUTTONNAME = "some_string"
- --[[local function UIOnSettlementSelected()
- -- declaring ButtonParent as a local variable to be used within UIOnSettlementSelected()
- local ButtonParent
- -- defining existingElement as a CA_UI element with the string defined in UIBUTTONNAME
- local existingElement = Util.getComponentWithName(UIBUTTONNAME)
- -- if not not existingElement returns true - ie., already exists, then...
- if not not existingElement then
- --# assume existingElement: BUTTON
- -- make the CA_UI visible
- existingElement:SetVisible(true)
- -- make the CA_UI 56x56 pixels
- existingElement:Resize(56, 56)
- -- move the CA_UI to (8, 1016), where (0, 0) is the top left corner
- existingElement:MoveTo(8, 1016)
- -- if the CA_UI doesn't already exist, then...
- else
- -- find the ButtonParent, the CA_UI upon which we'll place our new button
- local ButtonParent = find_uicomponent(core:get_ui_root(), "layout") --, "info_panel_holder", "primary_info_panel_holder", "info_panel_background", "ProvinceInfoPopup", "parchment_banner"
- -- define DetailsButton as a new button using a UIMF method
- local DetailsButton = Button.new(UIBUTTONNAME, ButtonParent, "CIRCULAR", "ui/skins/default/icon_province_details.png")
- -- resize the DetailsButton to 56x56 px
- DetailsButton:Resize(56, 56)
- -- move DetailsButton to(8, 1016)
- DetailsButton:MoveTo(8, 1016)
- -- when DetailsButton is clicked, trigger the function "CreatePanel()"
- DetailsButton:RegisterForClick(function() CreatePanel() end)
- end
- end]]
- function vandy()
- --These four lines are explained in detail below in core:add_listener(PanelClosedUI
- local ButtonParent = find_uicomponent(core:get_ui_root(), "layout")-- "bar_small_top", "TabGroup")
- local testButton = Button.new("testButton", ButtonParent, "CIRCULAR", "ui/skins/default/browser_spell_tab_lore.png")
- testButton:MoveTo(1800, 0)
- testButton:RegisterForClick(function() CreatePanel() end)
- --end four lines
- core:add_listener(
- "SettlementSelectedUI",
- "SettlementSelected",
- function(context)
- return context:garrison_residence():faction():name() == cm:get_local_faction(true)
- end,
- function(context)
- cm:callback(function()
- --[[ local existingFrame = Util.getComponentWithName(UIPANELNAME)
- if not not existingFrame then
- --# assume existingFrame: FRAME
- existingFrame:Delete()
- end]]
- UIOnSettlementSelected()
- end, 0.1)
- end,
- true
- )
- core:add_listener(
- "PanelClosedUI",
- "PanelClosedCampaign",
- function(context)
- return context.string == "technology_panel"
- end,
- function(context)
- CreatePanel()
- --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
- --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
- --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.
- --ButtonParent = find_uicomponent(core:get_ui_root(), "layout", "bar_small_top", "TabGroup")
- --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
- --as a circular button and giving it the image icon_province_details.png
- testButton = Button.new("testButton", ButtonParent, "CIRCULAR", "ui/skins/default/browser_spell_tab_lore.png")
- --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
- --to the top right.
- testButton:MoveTo(1800, 0)
- testButton:RegisterForClick(function() CreatePanel() end)
- end,
- true
- )
- function CreatePanel()
- local uimfFrame = Frame.new("UIMFFrame");
- uimfFrame:Resize(750, 400);
- Util.centreComponentOnScreen(uimfFrame);
- uimfFrame:SetTitle("UI Modding Framework")
- uimfFrame:AddCloseButton();
- end
- --[[creates a new frame with the name uimfFrame
- local uimfFrame = Frame.new("UIMFFrame");
- uimfFrame:Resize(750, 400);
- --centers uimfFrame in the middle of the screen
- Util.centreComponentOnScreen(uimfFrame);
- uimfFrame:SetTitle("UI Modding Framework")
- --I mean.. it's a close button. It closes the thing.
- uimfFrame:AddCloseButton();
- --creates a container for elements such as buttons and text for layout
- local mainContainer = Container.new(FlowLayout.VERTICAL);
- --creates a second container that can be placed in the first container along with another container
- --doing this allows you to easily organize multiple elements by splitting them up over various containers
- local firstRow = Container.new(FlowLayout.HORIZONTAL);
- --creates a new text button with the name customButton. uimfFrame is placed here to make customButton the
- --child of uimfFrame, so that when uimfFrame is closed the button is closed/deleted. If uimfFrame is moved
- --so is the Button
- local customButton = TextButton.new("customButton", uimfFrame, "TEXT", "Create custom buttons")
- local customText = Text.new("customText", uimfFrame, "NORMAL", "Create custom text")
- --adds the elements to the declared firstRow container
- firstRow:AddComponent(customButton);
- firstRow:AddComponent(customText);
- --asdds firstRow to mainContainer
- mainContainer:AddComponent(firstRow);
- --centers mainContainer on uimfFrame
- Util.centreComponentOnComponent(mainContainer, uimfFrame);]]
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement