Unbind crosshair from mousescrollbutton - Page 3

Unbind crosshair from mousescrollbutton

Please use this forum to set up matches and discuss played games.

Moderator: Moderators

User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Unbind crosshair from mousescrollbutton

Post by BrainDamage »

Thanks to SirMaverick for helping me to write this

Code: Select all

function widget:GetInfo() 
    return { 
        name = "Crosshair toggle", 
        desc = "Makes mid click toggle crosshair scroll mode", 
        author = "You", 
        date = "Today", 
        license = "WTFPL",
        layer = -1000, 
        enabled = true 
    } 
end 

local active
local hold
local time
local GetCameraState = Spring.GetCameraState
local SetCameraState =  Spring.SetCameraState
local GetModKeyState = Spring.GetModKeyState
local GetConfigInt = Spring.GetConfigInt
local GetConfigString = Spring.GetConfigString
local GetMouseState = Spring.GetMouseState
local IsAboveMiniMap = Spring.IsAboveMiniMap
local WarpMouse = Spring.WarpMouse
local SetMouseCursor = Spring.SetMouseCursor
local glColor = gl.Color
local glBeginEnd = gl.BeginEnd
local glEnable = gl.Enable
local glDisable = gl.Disable
local glLineWidth = gl.LineWidth
local GL_LINES = GL.LINES
local glVertex = gl.Vertex
local tan = math.tan
local camera
local scrollSpeed
local camTime
local vsx, vsy
local mx, my
local overHeadFov
local crossSize
local holdTime = 0.3

function widget:Initialize()
  scrollSpeed = GetConfigInt("OverheadScrollSpeed",0)
  middleClickScrollSpeed = tonumber(GetConfigString("MiddleClickScrollSpeed",0))
  overHeadFov = GetConfigInt("OverheadFOV", 45)
  crossSize = GetConfigInt("CrossSize",0)
  camTime = 0 --? camera's movement "smoothness"
  active = false
  hold = false
  vsx, vsy = widgetHandler:GetViewSizes()
  mx, my = GetMouseState()
end

function widget:ViewResize(viewSizeX, viewSizeY)
  vsx = viewSizeX
  vsy = viewSizeY
end

function widget:MousePress(x, y, button)
  camera = GetCameraState()
  if (camera.name ~=   "ta")    then
    active = false
    return false
  end
  time = Spring.GetTimer()
  if button ~= 2 or IsAboveMiniMap(x,y) then
    return false
  else
    if not active then
      hold = true
    end
    return true
  end
end


function widget:MouseRelease(x, y, button)
  camera = GetCameraState()
  if (camera.name ~=   "ta")    then
    active = false
  end
  if button ~= 2 then
    return false
  end

  if Spring.DiffTimers(Spring.GetTimer(), time) < holdTime or active then
    active = not active
    if not active then
      hold = false
    end
    return true
  end
  if hold then
    hold = false
    return true
  end
  return false
end

local function CrossHairMove( dx, dy )
  camera = GetCameraState()
  if (camera.name ~=   "ta")    then
    return false
  end
  if camera.flipped then
    dx = -dx
    dy = -dy
 end
 local _,_,shift = GetModKeyState()
 local speedMultiplier = 0.1
 if shift then
   speedMultiplier = speedMultiplier * 4
 end
 dx = dx * 100 * middleClickScrollSpeed
 dy = dy * 100 * middleClickScrollSpeed
 -- the following number is wrong if  we're in the mid of a camera transition, but I think no one sane would use it in such case 
 -- and the logic would be too complicated to replicate there
 local halfFov = overHeadFov * 0.008726646
 local tanHalfFov = tan(halfFov)
 local pixelsize =  tanHalfFov * 2/vsy * camera.height * 2
 camera.px = camera.px + dx * pixelsize * speedMultiplier * scrollSpeed
 camera.pz = camera.pz + dy * pixelsize * speedMultiplier * scrollSpeed
  -- move camera 
  SetCameraState(camera, camTime)
end

local function DrawCrosshair()
  if crossSize > 0 then
    glColor(1.0, 1.0, 1.0, 0.5)
    glLineWidth(1.49)
    glBeginEnd(GL_LINES, function() 
      glVertex(vsx/2 - crossSize, vsy/2)
      glVertex(vsx/2 + crossSize, vsy/2)
      glVertex(vsx/2, vsy/2 - crossSize)
      glVertex(vsx/2, vsy/2 + crossSize)
    end)
    glLineWidth(1.0)
  end
end

function widget:DrawScreen()
  if active then
    DrawCrosshair()
    SetMouseCursor( "none" ) -- set no mouse cursor
  end
end

function widget:Update()
  local x, y = GetMouseState()
  if active or hold then
    -- spring origins for mouse are bottom right, therefore y coordinate is reversed
    CrossHairMove( mx - x,  y - my )
    -- center mouse 
    WarpMouse(vsx/2, vsy/2)
    x = vsx / 2
    y = vsy / 2
  end
  mx = x
  my = y
end
add this to spring, and you've got old functionality back
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Unbind crosshair from mousescrollbutton

Post by SirMaverick »

lurker wrote:Notepad, wordpad, nope
Yes for WinXP. Licho said win7 does not have it anymore.
Brain Damage wrote:add this to spring, and you've got old functionality back
160 lines to replace 10 lines :)
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Unbind crosshair from mousescrollbutton

Post by lurker »

I tried some apps earlier today in XP, but I can't recall which ones.

Nothing here has it on Vista.
User avatar
Licho
Zero-K Developer
Posts: 3803
Joined: 19 May 2006, 19:13

Re: Unbind crosshair from mousescrollbutton

Post by Licho »

Engine settings option IS worthless!

Its for newbies, not pros. Newbies run into problems when they randomly enter "switch scrolling". Not me.

Please please please, I beg you, disable this thing or make it widget, I hate losing people just because they enter scrolling mode and cant disable menu then!
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Unbind crosshair from mousescrollbutton

Post by SirMaverick »

Licho wrote:Engine settings option IS worthless!

Its for newbies, not pros.
Worthless? It's absolutely not possible that a mod changes that option by default? The mod you are developing does this with many other options that you considered not optimal for new players. Why shouldn't it be possible for this option?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unbind crosshair from mousescrollbutton

Post by hoijui »

because the mouse handler only reads the config value once, at initialization, which is before the mod gets initialized.

we could make the mouse listener listen to the config value though, so it would be changeable any time (no bog deal there).
then a widget or a gadget could change it, so it could be a mod default, spring setting, and in game changeable through a widget or /set MouseDragScrollThreshold 0.0. The problem then would only be, to not make these things "overwrite" each other ;-).

Does anyone have something against that way of doing it?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Unbind crosshair from mousescrollbutton

Post by Tobi »

Licho wrote:Engine settings option IS worthless!

Its for newbies, not pros. Newbies run into problems when they randomly enter "switch scrolling". Not me.

Please please please, I beg you, disable this thing or make it widget, I hate losing people just because they enter scrolling mode and cant disable menu then!
Why? (Hint: nothing was said about it's default value.)

Engine setting would be fine although widget works too. (But forces everyone who wants to use such scrolling to break LockLuaUI protection for games that fail to include this widget.)
hoijui wrote:we could make the mouse listener listen to the config value though, so it would be changeable any time (no bog deal there).
then a widget or a gadget could change it, so it could be a mod default, spring setting, and in game changeable through a widget or /set MouseDragScrollThreshold 0.0. The problem then would only be, to not make these things "overwrite" each other ;-).

Does anyone have something against that way of doing it?
That would be good.

(Although I consider game X changing my settings for both game X and game Y bad practice, but that needs better support engine side.)
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: Unbind crosshair from mousescrollbutton

Post by jK »

hoijui wrote:The problem then would only be, to not make these things "overwrite" each other ;-).
You can save the old (positive) value as a negative value and vice versa, this way you wouldn't lose any data.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unbind crosshair from mousescrollbutton

Post by hoijui »

yeah Tobi, i came up with the same (did not think about that when i wrote the post). a first, simple way would be, to allow changing a setting, but marking it as do-not-save-to-file. it is not the nicest solution though, and we already discussed a general overhaul of the config system once, which would probably include something like local configs (eg, only for one game, or for one map or whatever). This would also solve the problem.
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Unbind crosshair from mousescrollbutton

Post by SirMaverick »

hoijui wrote:a first, simple way would be, to allow changing a setting, but marking it as do-not-save-to-file.
+1
I don't understand why every change has to be written to file immediately. Why not just at shutdown?
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unbind crosshair from mousescrollbutton

Post by hoijui »

it is at shutdown. hmm.. you think about the widget/gadget resetting it at game end?
guess that would work, yeah :-)
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Unbind crosshair from mousescrollbutton

Post by zwzsg »

hoijui wrote:it is at shutdown.
Sure? Because I had a widget that set my water to bump mapped, causing an insta-crash, and I can tell you the setting was saved.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unbind crosshair from mousescrollbutton

Post by hoijui »

oops.. you are right, its done on each change.
hmm, so it wold need the do-not-save option then (short termly).
SirMaverick
Posts: 834
Joined: 19 May 2009, 21:10

Re: Unbind crosshair from mousescrollbutton

Post by SirMaverick »

No, also during game. For example CA changes inputtextgeo to align input text to its own chat window. It's updated about every 2 seconds and written to file every time. That's not necessary.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Unbind crosshair from mousescrollbutton

Post by zwzsg »

Well, saving as soon as changed can also be useful, for when Spring doesn't end properly for reasons unrelated to settings. I suppose it also makes the code much simpler, and therefore less buggy and more maintanable. Reading current settings with Spring.GetConfigInt(..) would get very messy if Spring.SetConfigInt action was postponed to game end.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Unbind crosshair from mousescrollbutton

Post by hoijui »

no, it would not be more messy. the only pro of saving it directly is indeed that it is preserved after a crash (as much as i can see).
User avatar
BrainDamage
Lobby Developer
Posts: 1164
Joined: 25 Sep 2006, 13:56

Re: Unbind crosshair from mousescrollbutton

Post by BrainDamage »

zwzsg wrote:Well, saving as soon as changed can also be useful, for when Spring doesn't end properly for reasons unrelated to settings. I suppose it also makes the code much simpler, and therefore less buggy and more maintanable. Reading current settings with Spring.GetConfigInt(..) would get very messy if Spring.SetConfigInt action was postponed to game end.
no, the idea is that get&set write to ram instead to disk directly, and everything gets flushed to disk upon a specific command or game close
therefore if you set an option, get will read the temporary set value
from a game script point of view, it shouldn't really change much/at all
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Unbind crosshair from mousescrollbutton

Post by zwzsg »

no, it would not be more messy.
Oh ok then. You're coder, I'm not.
The only pro of saving it directly is indeed that it is preserved after a crash (as much as i can see).
That's not a pro, that's a big cons! (assuming setting change and crash are linked)
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Unbind crosshair from mousescrollbutton

Post by lurker »

More poking around on XP, I'm getting scrolling in an edit control but nowhere else, certainly not a standard means of navigating. But that's what the wheel is for.


And why would you assume that, zwzsg?
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Unbind crosshair from mousescrollbutton

Post by Tobi »

I think saving when it's changed is most important to prevent conflicts between settings changed in lobby (unitsync) and by engine.

(Or conflicts between multiple lobby clients or multiple engines running, you get the point.)

If either of them doesn't save immediately then changes by one will be overwritten by the other if they exit in the wrong order.

(Edit: saving isn't the key point here, more reloading unchanged values before saving any changed values. Still, chance for unresolvable conflicts (i.e. data loss) increases when settings aren't written for a longer time. Also data loss due to crashes unrelated to the particular setting being saved would be a bug IMO.)

I do agree though that it would be good to change the code a bit so that for e.g. the water renderer the setting is only written after the water renderer has been succesfully changed.
Post Reply

Return to “Ingame Community”