Advertisement
Guest User

ui_faction

a guest
Mar 27th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. class "ui_faction" (CUIScriptWnd)
  2.  
  3. function ui_faction:__init() super()
  4.   self:InitControls()
  5. end
  6.  
  7. function ui_faction:InitControls()
  8.   self:Init(0, 0, device().width, device().height)
  9.  
  10.   self.overlay = CUIStatic()
  11.   self.overlay:SetAutoDelete(true)
  12.     -- replace x, y with position of overlay texture (position on hud)
  13.     -- and w, h with overlay texture's width and height, respectively
  14.     -- you can use device().width instead of w if you want to set screen's
  15.     -- width as a texture width
  16.   self.overlay:Init(510, 673, 60, 60)
  17.   self.overlay:InitTexture("ui\\ui_faction_empty")
  18.   self.overlay:SetStretchTexture(true) -- to stretch texture based on w, h
  19.   self.overlay:Show(false)
  20.   self:AttachChild(self.overlay)
  21.  
  22.   self.hud_stage = "no"
  23. end
  24.  
  25. --initialize and display overlay textures
  26. function ui_faction:display_texture(idx)
  27.     if self.hud_stage ~= idx then
  28.         self.overlay:InitTexture("ui\\ui_faction_" .. idx)
  29.         self.overlay:Show(true)
  30.         self.hud_stage = idx
  31.     end
  32. end
  33.  
  34. function ui_faction:Update()
  35.     CUIScriptWnd.Update(self)
  36.     local faction = "none"
  37.     if db.actor then
  38.         if has_alife_info("ui_car_body") then
  39.             if treasure_manager and treasure_manager.npc_community_loot then
  40.                 faction = treasure_manager.npc_community_loot
  41.             else
  42.                 faction = "none"
  43.             end
  44.         elseif db.actor:is_talking() then
  45.             if xr_motivator and xr_motivator.npc_talks then
  46.                 faction = xr_motivator.npc_community_trade or "none"
  47.             else
  48.                 faction = "none"
  49.             end
  50.         else
  51.             faction = "none"
  52.         end
  53.     end
  54.     if faction == "stalker" then
  55.       self:display_texture("stalker")
  56.     elseif faction == "trader" then
  57.       self:display_texture("stalker")
  58.     elseif faction == "bandit" then
  59.       self:display_texture("bandit")
  60.     elseif faction == "military" then
  61.       self:display_texture("military")
  62.     elseif faction == "dolg" then
  63.       self:display_texture("dolg")
  64.     elseif faction == "freedom" then
  65.       self:display_texture("freedom")
  66.     elseif faction == "ecolog" then
  67.       self:display_texture("ecolog")
  68.     elseif faction == "killer" then
  69.       self:display_texture("killer")
  70.     elseif faction == "monolith" then
  71.       self:display_texture("monolith")
  72.     elseif faction == "csky" then
  73.       self:display_texture("csky")
  74.     else
  75.       self:display_texture("empty")
  76.     end
  77. end
  78.  
  79. local HUD = nil
  80.  
  81. function add_custom_inv()
  82.   if HUD == nil then
  83.     HUD = ui_faction()
  84.     get_hud():AddDialogToRender(HUD)
  85.   end
  86. end
  87.  
  88. function remove_custom_inv()
  89.   if HUD ~= nil then
  90.     get_hud():RemoveDialogToRender(HUD)
  91.     HUD = nil
  92.   end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement