Download the latest version from the widget database
Wind Speed Display
Moderator: Moderators
Wind Speed Display
Wind Speed Display
Download the latest version from the widget database
As this is my first widget, please slam me with critique regarding the code.
Download the latest version from the widget database
Last edited by Jazcash on 23 Dec 2012, 22:30, edited 8 times in total.
Re: Wind Speed Display
Very nice - I like it :)
I got
Linux files and dirs are case sensitive, so I had to replace the path in line 41 with "LuaUI/Fonts/FreeSansBold.otf", and it worked.
I looked at other widgets, and they all use exactly this case sensitive path.
It has a bug in case of Tundra with min=max wind --> always red.
I don't get that nice windmill icon you have :( Maybe it is some transparency/opaque setting of mine? any idea?
Not your widgets fault: in BA max. 25 E of a windmill is used, even if wind is stronger. Is there a way to find out such max-settings of a game? Is it possible for a map to change that? IMO the green should be at min(max(map), max(game)).
I got
Code: Select all
[f=0000862] Loading: LuaUI/Widgets/gui_windSpeed.lua
[f=0000862] [Font] Error: Failed creating font: Couldn't find font 'luaui/fonts/FreeSansBold.otf'.
[f=0000863] false
[f=0000863] Error in DrawScreen(): [string "LuaUI/Widgets/gui_windSpeed.lua"]:78: attempt to index upvalue 'Myfont' (a nil value)
[f=0000863] Removed widget: Wind Speed
I looked at other widgets, and they all use exactly this case sensitive path.
It has a bug in case of Tundra with min=max wind --> always red.
I don't get that nice windmill icon you have :( Maybe it is some transparency/opaque setting of mine? any idea?
Not your widgets fault: in BA max. 25 E of a windmill is used, even if wind is stronger. Is there a way to find out such max-settings of a game? Is it possible for a map to change that? IMO the green should be at min(max(map), max(game)).
- Attachments
-
- opaque icon
- screen00029.png (1.11 KiB) Viewed 2676 times
Re: Wind Speed Display
Theres no need for any font handling whatsoever:
Only in tweak mode is easy, just add 'Tweak' to the callins:
Given someone has problems with the texture, I'd remove the texture options and go with:
You'll also want to put add
Right after you've used the texture, otherwise it stays set and can interfere with other widgets.
Code: Select all
gl.Text(format('%.1f', wind), iconWidth + 13, 15, MyFontSize)
Code: Select all
function widget:TweakMousePress(mx, my, mButton)
function widget:TweakMouseMove(mx, my, dx, dy, mButton)
Code: Select all
gl.Texture('LuaUI/Images/Windicon.png')
Code: Select all
gl.Texture(false)
Re: Wind Speed Display
Works - I see a windmill :)Niobium wrote:Given someone has problems with the texture, I'd remove the texture options and go with:Code: Select all
gl.Texture('LuaUI/Images/Windicon.png')
Re: Wind Speed Display
I'll fix this, perhaps so it's just 100% green, or maybe set it grey or white or something to represent that it doesn't change?dansan wrote:It has a bug in case of Tundra with min=max wind --> always red.
Not sure if there is a way to fetch a game's max windmill energy usage but I guess it wouldn't be too hard to setup an array for the top 5 games or something with their max windmill energy hard-coded. It'd just require changing if a game changes it.dansan wrote:Not your widgets fault: in BA max. 25 E of a windmill is used, even if wind is stronger. Is there a way to find out such max-settings of a game? Is it possible for a map to change that? IMO the green should be at min(max(map), max(game)).
I did do it this way originally, but changed it when I struggled finding good examples of using other fonts with it. Looks like I don't need to though, silly meNiobium wrote:Theres no need for any font handling whatsoever:Code: Select all
gl.Text(format('%.1f', wind), iconWidth + 13, 15, MyFontSize)
Simple enough!Niobium wrote:Only in tweak mode is easy, just add 'Tweak' to the callins:Code: Select all
function widget:TweakMousePress(mx, my, mButton) function widget:TweakMouseMove(mx, my, dx, dy, mButton)
Alright, I didn't account for how other OSs handle files and directories and such.Niobium wrote:Given someone has problems with the texture, I'd remove the texture options and go with:Code: Select all
gl.Texture('LuaUI/Images/Windicon.png')
AlrightyNiobium wrote:You'll also want to put addRight after you've used the texture, otherwise it stays set and can interfere with other widgets.Code: Select all
gl.Texture(false)
Thanks Niobium and dansan! I'll release the next version with these changes once I've figured out how rotate images around a point of origin in OpenGL, seeing as there's no point of origin functionality at all, I can see it being difficult
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Wind Speed Display
I think the rotation happens around the axis origin. So you can move the object so that the origin is at your desired rotation point, then rotate and then move to the final position.
EDIT:
Dunno if its really desired to have it rotating. Might be annoying to have a permanently rotating GUI element, no? Who gave you that shitty idea?
EDIT:
Dunno if its really desired to have it rotating. Might be annoying to have a permanently rotating GUI element, no? Who gave you that shitty idea?
Re: Wind Speed Display
I already thought of that, and was gonna make it a configurable optionvery_bad_soldier wrote: EDIT:
Dunno if its really desired to have it rotating. Might be annoying to have a permanently rotating GUI element, no? Who gave you that shitty idea?
Then again, I think it might be more trouble that it's worth...
Re: Wind Speed Display
Updated!
Changelog:
The blade rotation may be ugly. For me, I can see some artifacting (right word?). Not sure if this can be prevented.
Anyway you can turn off rotation by just changing the configRotation variable to 0, it's right at the bottom of my global variables. I'll perhaps had a nice GUI way to turn it on and off at some point.
Changelog:
Code: Select all
- No longer includes a font file
- Only moveable in tweak-mode
- Colour is green instead of red on maps where min and max wind are equal
- Blades on the windmill rotate according to the wind percentage
- Is hidden until the game begins
Anyway you can turn off rotation by just changing the configRotation variable to 0, it's right at the bottom of my global variables. I'll perhaps had a nice GUI way to turn it on and off at some point.
Re: Wind Speed Display
you read Spring.GetWind and in DrawScreen() which is very often but wind only changes slowly.
So read it in GameFrame() instead and calculate color there too.
If you increase rotation variable in DrawScreen the windmill will spin faster the more FPS you have.
Use Update (dt) instead.
Neither will not make a difference in speed for this widget but for more complex things it might and since you asked for critique
So read it in GameFrame() instead and calculate color there too.
If you increase rotation variable in DrawScreen the windmill will spin faster the more FPS you have.
Use Update (dt) instead.
Neither will not make a difference in speed for this widget but for more complex things it might and since you asked for critique
Re: Wind Speed Display
Just been speaking with vbs about this too, I'll see what I can do, thanks!knorke wrote:you read Spring.GetWind and in DrawScreen() which is very often but wind only changes slowly.
So read it in GameFrame() instead and calculate color there too.
If you increase rotation variable in DrawScreen the windmill will spin faster the more FPS you have.
Use Update (dt) instead.
Neither will not make a difference in speed for this widget but for more complex things it might and since you asked for critique
Re: Wind Speed Display
The image is a png and artifacting only seems to occur when the rotation isn't 0, 90, 180 or 270.
Edit: Now fixed, the blade image just added more white-space around it due to exceeding its size limit when rotating. Thanks to BD for pointing this out, silly I couldn't see it myself :D
Last edited by Jazcash on 08 Dec 2012, 17:49, edited 3 times in total.
Re: Wind Speed Display
I think it has become spring standard to allow move of widgets when you press the middle mouse button and drag it. I think that could be a nice option.
Tweak mode screws up ctrl key state.
Tweak mode screws up ctrl key state.
Re: Wind Speed Display
A few people told me they didn't like the fact it could be moved out of tweak mode as they sometimes usually move widgets that have this functionality by accident. I've never had this problem myself, might be due to my huge monitor but it would be nice to know what the majority think should be the default way to move a widget's position.Jools wrote:I think it has become spring standard to allow move of widgets when you press the middle mouse button and drag it. I think that could be a nice option.
Tweak mode screws up ctrl key state.
Although I don't have a problem with accidentally moving widgets, I still think all moving should be done in tweak mode anyway.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Wind Speed Display
Your texture dimensions need to be the power of 2. So resize the image (do not scale, resize the "canvas") and then grab the actually needed region by using texture coordinates.Jazcash wrote:Any ideas how to fix this artifacting?
Thats at least how I did it.
Re: Wind Speed Display
Already fixed before reading this, but thanks anywho!very_bad_soldier wrote:Your texture dimensions need to be the power of 2. So resize the image (do not scale, resize the "canvas") and then grab the actually needed region by using texture coordinates.Jazcash wrote:Any ideas how to fix this artifacting?
Thats at least how I did it.
Now fixed, the blade image just added more white-space around it due to exceeding its size limit when rotating. Thanks to BD for pointing this out, silly I couldn't see it myself :D
Re: Wind Speed Display
Wow - quick development! Looks very nice :)
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: Wind Speed Display
Hm I dont get that, it exceeds size limit when rotation?Jazcash wrote:Now fixed, the blade image just added more white-space around it due to exceeding its size limit when rotating.
Re: Wind Speed Display
I don't fully understand it either, which is naughty of me. This is what I think was the issue, or at least, may be related in some way...very_bad_soldier wrote:Hm I dont get that, it exceeds size limit when rotation?Jazcash wrote:Now fixed, the blade image just added more white-space around it due to exceeding its size limit when rotating.
It's amazing how little I care for why bugs occured once they're fixed xD
Anyway, it's looking almost bug free now. Next version will be released once I've added GUI options (with check-boxes). I'm guessing I have to code them myself or is there some sort of GUI element package out there I could use including things like slides, buttons, check-boxes and stuff?
Re: Wind Speed Display
This surely looks nice and clean comparing with other wind power display widgets!
Maybe change the color change red/green to relative effectiveness comparing with solar power?
It makes it more aperant on which windspeeds/ building winds is more effective to the average or newbie players.
Maybe change the color change red/green to relative effectiveness comparing with solar power?
It makes it more aperant on which windspeeds/ building winds is more effective to the average or newbie players.
Re: Wind Speed Display
Yep, already on my to-do list as a configurable option!Floris wrote: Maybe change the color change red/green to relative effectiveness comparing with solar power?
It makes it more aperant on which windspeeds/ building winds is more effective to the average or newbie players.