Page 1 of 1

[Solved]Minimap interacts incorrectly with the slider

Posted: Thu Nov 22, 2018 9:43 pm
by WIZ4
Hi, I can’t sync the slider value with the minimap zoom. The values of the slider and the zoom of the minimap are the same. But as soon as I start using the slider to zoom in, the zoom suddenly changes dramatically. What is the reason?
slider.gif
slider.gif (746.26 KiB) Viewed 2745 times

Code: Select all

function slider_zoom()
	local frame = game.player.gui.center.add{ type = "frame", name = "frame", direction="vertical"} 
	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
	frame.add{type="slider", name="slider",orientation=horizontal, minimum_value=0.49,maximum_value=0.50,value=0.50}	
	frame.add{type = "label", name = "slider_value_number", caption = "slider value = "..frame.slider.slider_value}
	frame.add{type = "label", name = "minimap_zoom", caption = "minimap zoom = "..frame.minimap.zoom}
end

Code: Select all

script.on_event(defines.events.on_gui_value_changed, function(event)
		if name == "slider" then 
		player.gui.center.frame.minimap.zoom = event.element.slider_value
		player.gui.center.frame.slider_value_number.caption = "slider value = "..event.element.slider_value
		player.gui.center.frame.minimap_zoom.caption = "minimap zoom = "..player.gui.center.frame.minimap.zoom
	end
end)

Re: Minimap interacts incorrectly with the slider

Posted: Thu Nov 22, 2018 9:59 pm
by eradicator

Code: Select all

	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
add() does not take zoom as an argument. You have to change the zoom level after creation. Otherwise the map is created with standard value of..something like 0.15? And when you use the slider it gets set to 0.5 for the first time.

Re: Minimap interacts incorrectly with the slider

Posted: Thu Nov 22, 2018 10:08 pm
by WIZ4
eradicator wrote: Thu Nov 22, 2018 9:59 pm

Code: Select all

	frame.add{type = "minimap", name = "minimap", position = {0,0},surface_index=game.surfaces.nauvis.index,zoom=0.50}
add() does not take zoom as an argument. You have to change the zoom level after creation. Otherwise the map is created with standard value of..something like 0.15? And when you use the slider it gets set to 0.5 for the first time.
It worked, thanks. So is this a bug or should it be?

Re: Minimap interacts incorrectly with the slider

Posted: Thu Nov 22, 2018 11:08 pm
by Bilka
WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.









conclusion

Re: Minimap interacts incorrectly with the slider

Posted: Fri Nov 23, 2018 12:40 pm
by eradicator
Bilka wrote: Thu Nov 22, 2018 11:08 pm
WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.
After further investigation:
Both 0.16 and 0.17 preview doc state that it should work.
It actually "works" but is broken.
The bug is as follows:
add() sets the r/w "zoom" parameter for the minimap gui element to zoom*1, i.e. if you read map.zoom right after creation it will appear to have worked, but the value that is actually applied to the minimap is zoom/32. Can be easily verified by setting the map to it's own zoom value:

Code: Select all


/c c = game.player.gui.center

/c c.clear() c.add{type='minimap',name='map'}

/c c.map.zoom = c.map.zoom --should not change anything but does!
zoom32.jpg
zoom32.jpg (198.4 KiB) Viewed 2701 times

Re: Minimap interacts incorrectly with the slider

Posted: Fri Nov 23, 2018 1:04 pm
by Bilka
eradicator wrote: Fri Nov 23, 2018 12:40 pm
Bilka wrote: Thu Nov 22, 2018 11:08 pm
WIZ4 wrote: Thu Nov 22, 2018 10:08 pm So is this a bug or should it be?
Does the documentation state that it should work? No.
After further investigation:
Both 0.16 and 0.17 preview doc state that it should work.
Derp, I looked at the wrong thing...
eradicator wrote: Fri Nov 23, 2018 12:40 pm It actually "works" but is broken.
The bug is as follows:
... snip ...
I can confirm this. The issue seems to be that when the minimap is created, the scale of what is rendered is set to zoom / 32. But, zoom is still 0.75, and when you set it normally, the division is not done.

Re: Minimap interacts incorrectly with the slider

Posted: Fri Nov 23, 2018 1:36 pm
by eradicator
Bilka wrote: Fri Nov 23, 2018 1:04 pm I can confirm this. The issue seems to be that when the minimap is created, the scale of what is rendered is set to zoom / 32. But, zoom is still 0.75, and when you set it normally, the division is not done.
So who's gonna post the bug report? Or are you gonna fix it without one :D.

Re: Minimap interacts incorrectly with the slider

Posted: Fri Nov 23, 2018 1:44 pm
by Bilka
eradicator wrote: Fri Nov 23, 2018 1:36 pm So who's gonna post the bug report? Or are you gonna fix it without one :D.
I fixed it without one :)

Re: [Solved]Minimap interacts incorrectly with the slider

Posted: Fri Nov 23, 2018 8:16 pm
by WIZ4
Wow! Well done, guys!