Jump to content

Blur Effect?


Zeklo

Recommended Posts

       So I've just started modding Don't Starve recently. Really enjoying doing so, until now I had no issue finding and creating code from the assets available to me. I, like most people, am trying to create a character. I was just wondering how I would be able to make a toggle-able blur effect just around the screen I am trying to make an item, glasses, get rid of this effect, for obvious reasons. Blur being the default until the glasses are put on.

 

I've read most of the go to tutorials so please don't route me there. It doesn't have to be copy pasta code, a simple push in the right direction would be appreciated.

Link to comment
Share on other sites

       So I've just started modding Don't Starve recently. Really enjoying doing so, until now I had no issue finding and creating code from the assets available to me. I, like most people, am trying to create a character. I was just wondering how I would be able to make a toggle-able blur effect just around the screen I am trying to make an item, glasses, get rid of this effect, for obvious reasons. Blur being the default until the glasses are put on.

 

I've read most of the go to tutorials so please don't route me there. It doesn't have to be copy pasta code, a simple push in the right direction would be appreciated.

 

fire, ice_over, blood_over, and heat_over effects all place a sort of colored fuzzy border over the screen

 

The images are in ...dont_starve\data\DLC0001\images\

in the fx and fx2 tex files if you want to look at them, but they (or something like them)

are probably useable for your purposes.

 

These are handled by various widgets

...dont_starve\data\DLC0001\scripts\widgets

...dont_starve\data\scripts\widgets

 

You might also try looking at the color cube manager (controls color palettes for different seasons)

Or the sanity.lua

...dont_starve\data\scripts\components\sanity.lua

 

which I believe controls the distortion around the edge of the screen when your character is low on sanity.

Link to comment
Share on other sites

So I got the textures all setup and most of the code, though when I put on the glasses it crashes due to variable "self" not being declared.

 

Give us the whole error, ideally with stack-traceback. Every component has a "self", we can't tell which one, or at which part of the file.

Link to comment
Share on other sites

Give us the whole error, ideally with stack-traceback. Every component has a "self", we can't tell which one, or at which part of the file.

 

...starve/data/../mods/Alex/scripts/prefabs/glasses.lua:21: variable 'self" is not declared

LUA ERROR stack traceback:

    =[C] in function 'error'

    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/strict.lua(23,1)

    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/Alex/scripts/prefabs/glasses.lua(21,1) in function 'onequipfn'

    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/equippable.lua(44,1) in function 'Equip'

    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/components/inventory.lua(729,1)

    =(tail call) ?

    C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/bufferedaction.lua(19,1) in function 'Do'

Link to comment
Share on other sites

The error is coming up because prefabs (like your glasses) use 'inst' when referring to themselves. Components, screens and other things use 'self'.

That would make sense! Thanks, that got that error fixed, I'm getting a couple more errors I'll post them if I can't figure it out on my own.

 

Also is there a way to give a magic bonus like how wickerbottom has a science bonus?

EDIT: nvm on the magic bonus thing I got that worked out.

 

EDIT2: OK I'm starting to thing I used the wrong portion of the heatover code. This is all the heatover code. The first portion is what displays the image is it not?

local Widget = require "widgets/widget"local Image = require "widgets/image"local HeatOver = Class(Widget, function(self, owner)    self.owner = owner    Widget._ctor(self, "HeatOver")    self:SetClickable(false)    self.img = self:AddChild(Image("images/fx2.xml", "heat_over.tex"))    self.img:SetEffect( "shaders/overheat.ksh" )    self.img:SetHAnchor(ANCHOR_MIDDLE)    self.img:SetVAnchor(ANCHOR_MIDDLE)    self.img:SetScaleMode(SCALEMODE_FILLSCREEN)        self.img:SetBlendMode(BLENDMODE.Additive)    self.img:SetUVScale(1.05, 1.0)    self:Hide()    self.laststep = 0        self.alpha_min = 1.0    self.alpha_min_target = 1.0    self.effectTime = 0.0    self.effectSize = 0.0    self.effectSize_target = 0.0    self.effectFrequency = 0.0    self.effectFrequency_target = 0.0    self.effectSpeed = 0.0    --self.effectSpeed_target = 0.0    self:Show()    self:StartUpdating()        self.inst:ListenForEvent("temperaturedelta", function(inst, data) self:OnHeatChange() end, self.owner)end)function HeatOver:OnHeatChange()    --if 0 then        local temp = self.owner.components.temperature:GetCurrent()    local num_steps = 4            local all_up_thresh = {65, 70, 75, 80}        local heat_sounds =    {        "dontstarve_DLC001/common/HUD_hot_level1",        "dontstarve_DLC001/common/HUD_hot_level2",        "dontstarve_DLC001/common/HUD_hot_level3",        "dontstarve_DLC001/common/HUD_hot_level4",    }    local heat_sounds_names =    {        "HUD_hot_level1",        "HUD_hot_level2",        "HUD_hot_level3",        "HUD_hot_level4",    }    --local all_down_thresh = {8, 3, -2, -7}        local up_thresh = all_up_thresh[self.laststep+1]    local down_thresh = all_up_thresh[self.laststep]    if up_thresh and temp > up_thresh and self.laststep < num_steps and (temp >= 65 or GetSeasonManager():IsSummer()) then         -- Check if the sound is playing so it doesn't get spammed when temp dances back and forth across the threshold        if not TheFrontEnd:GetSound():PlayingSound(heat_sounds_names[self.laststep+1]) then            TheFrontEnd:GetSound():PlaySound(heat_sounds[self.laststep+1], heat_sounds_names[self.laststep+1])        end        self.laststep = self.laststep + 1        if GetSeasonManager() and GetSeasonManager():IsSummer() then            GetSeasonManager():ApplySummerDSP(.5, self.laststep+1)        end    elseif down_thresh and temp < down_thresh and self.laststep > 0 then        self.laststep = self.laststep - 1        if GetSeasonManager() and GetSeasonManager():IsSummer() then            GetSeasonManager():ApplySummerDSP(.5, self.laststep+1)        end    end        if self.laststep == 0 then        self.alpha_min_target = 1    else        local alpha_mins =        {            .4, .3, .1, 0        }        self.alpha_min_target = alpha_mins[self.laststep]        local distortion_size =        {            0.01, 0.011, 0.012, 0.013            --0.01, 0.01, 0.01, 0.01        }        self.effectSize_target = distortion_size[self.laststep]        local distortion_frequency =        {            10, 13, 17, 20        }        self.effectFrequency_target = distortion_frequency[self.laststep]        local distortion_speed =        {            -- keep this value constant for now as both lerping and stepping it produce ugly artifacts            7, 7, 7, 7        }        self.effectSpeed = distortion_speed[self.laststep]        --self.effectSpeed_target = distortion_speed[self.laststep]        self:StartUpdating()    end    --endendfunction HeatOver:OnUpdate(dt)    local lspeed = dt    self.alpha_min = (1 - lspeed) * self.alpha_min + lspeed *self.alpha_min_target    self.img:SetAlphaRange(self.alpha_min,1)    if self.alpha_min >= .99 then        self:Hide()        self:StopUpdating()    else        self:Show()    end    self.effectTime = self.effectTime + dt    self.effectSize = (1 - lspeed) * self.effectSize + lspeed *self.effectSize_target    self.effectFrequency = (1 - lspeed) * self.effectFrequency + lspeed *self.effectFrequency_target    --self.effectSpeed = (1 - lspeed) * self.effectSpeed + lspeed *self.effectSpeed_target    self.img:SetEffectParams(self.effectTime, self.effectSize, self.effectFrequency, self.effectSpeed)endreturn HeatOver

EDIT3: Oh also my items name is missing and I can't seem to pin-point why. Thoughts? I hate to be so needy but you guys know a lot more than I do.

Link to comment
Share on other sites

For the missing name item, you need to add it's name to STRINGS.lua. You can do this easily enough by adding GLOBAL.STRINGS.NAMES.YOUR_ITEM_NAME_IN_ALL_CAPS to modmain.lua.

For the heat over question,

 

self.img = self:AddChild(Image("images/fx2.xml", "heat_over.tex"))

 

adds the heat_over image file to the widget. 'self:Show()' actually causes to to appear on the screen.

Link to comment
Share on other sites

For the missing name item, you need to add it's name to STRINGS.lua. You can do this easily enough by adding GLOBAL.STRINGS.NAMES.YOUR_ITEM_NAME_IN_ALL_CAPS to modmain.lua.

For the heat over question,

 

self.img = self:AddChild(Image("images/fx2.xml", "heat_over.tex"))

 

adds the heat_over image file to the widget. 'self:Show()' actually causes to to appear on the screen.

So my items now have names, thank you so much!

However not as lucky for my glasses overlay code.

nm3QnEo.png

All I did was put the code below into my item's onequip.

inst.img = inst:AddChild(Image("images/fx2.xml", "heat_over.tex"))    inst.img:SetHAnchor(ANCHOR_MIDDLE)    inst.img:SetVAnchor(ANCHOR_MIDDLE)    inst.img:SetScaleMode(SCALEMODE_FILLSCREEN)        inst.img:SetBlendMode(BLENDMODE.Additive)    inst.img:SetUVScale(1.05, 1.0)    inst:Hide()    inst.laststep = 0        inst.alpha_min = 1.0    inst.alpha_min_target = 1.0    inst.effectTime = 0.0    inst.effectSize = 0.0    inst.effectSize_target = 0.0    inst.effectFrequency = 0.0    inst.effectFrequency_target = 0.0    inst.effectSpeed = 0.0    --inst.effectSpeed_target = 0.0    inst:Show()    inst:StartUpdating()

Link to comment
Share on other sites

I think the problem is that you aren't allowed to add images to a prefab in such a way.

You should set up a custom widget with the glasses blur effect. I don't have access to Don't Starve atm, but I'll try and run through the process from memory.

Basically copy the heatover widget and rename all the functions to glassesblur or something and then attach it to the player hud. Search for heatover in playerhud.lua (it should be in the screens folder) to see how they add widgets to the hud. Its probably something like self:AddChild(etc). Don't overwrite the playerhud.lua file though! You can tweak it from modmain.lua with GLOBAL.GetPlayer().hud:AddChild(etc), or GetPlayer().hud.controls:AddChild(etc) if its added in the controls function of playerhud.lua, you'll need to check to which fucntion it was added (controls is a function of the hud). Remember to add a command to set it to Show().

 

Then you have should put equip and unequip functions in the glasses prefab (see the nightmare armour prefab for an example) and add a line in these which toggles the glass blur on or off (e.g. GetPlayer().hud.glassesblur:Show() and GetPlayer().hud.glassesblur:Hide() ).

Link to comment
Share on other sites

I think the problem is that you aren't allowed to add images to a prefab in such a way.

You should set up a custom widget with the glasses blur effect. I don't have access to Don't Starve atm, but I'll try and run through the process from memory.

Basically copy the heatover widget and rename all the functions to glassesblur or something and then attach it to the player hud. Search for heatover in playerhud.lua (it should be in the screens folder) to see how they add widgets to the hud. Its probably something like self:AddChild(etc). Don't overwrite the playerhud.lua file though! You can tweak it from modmain.lua with GLOBAL.GetPlayer().hud:AddChild(etc), or GetPlayer().hud.controls:AddChild(etc) if its added in the controls function of playerhud.lua, you'll need to check to which fucntion it was added (controls is a function of the hud). Remember to add a command to set it to Show().

 

Then you have should put equip and unequip functions in the glasses prefab (see the nightmare armour prefab for an example) and add a line in these which toggles the glass blur on or off (e.g. GetPlayer().hud.glassesblur:Show() and GetPlayer().hud.glassesblur:Hide() ).

O.O I have never messed with widgets or the hud but I'll see what I can do.

EDIT: So I'm guessing the part in the hud I need to use is this:

self.heatover = self.overlayroot:AddChild(HeatOver(owner))
Link to comment
Share on other sites

That looks like it.

 

I'd guess you need to use GLOBAL.GetPlayer().hud.overlayroot:AddChild(blur(GLOBAL.GetPlayer() )) to add your widget. Remember to import your widget into modmain.lua (or you can just write the widget in there if you like).

 

Have a look at other mods which add UI elements for more examples. Like Always On Status.

Link to comment
Share on other sites

That looks like it.

 

I'd guess you need to use GLOBAL.GetPlayer().hud.overlayroot:AddChild(blur(GLOBAL.GetPlayer() )) to add your widget. Remember to import your widget into modmain.lua (or you can just write the widget in there if you like).

 

Have a look at other mods which add UI elements for more examples. Like Always On Status.

 

I don't know all the terminology yet but if by import you mean this:

local BlurOver = require "widgets/blurover"

Then I've already done that. However I'm getting an index nil value crash error, something I can actually make sense of, shouldn't be that hard to pin point (I hope). Thank you very much for the help btw!

 

Yeah seems like it has something to do with the code you gave me. That's to be expected, seeing as it was a guess. Time to edit it and make it work! Either that or I'm guessing I didn't import it or something.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
×
  • Create New...