Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "base/internal/ui/reflexcore"
- --All credit for this to Reflex dev team, from OptionsMenu.lua
- local function uiKeyBind(bindCommand, x, y, w, bindState, optionalId, enabled)
- local h = 28;
- local c = 255;
- local k = nil;
- if enabled == false then
- c = UI_DISABLED_TEXT;
- else
- k = inputGrabRegion(x, y, w, h, optionalId);
- end
- nvgSave();
- -- Edit
- nvgBeginPath();
- nvgRoundedRect(x+1,y+1, w-2,h-2, 4-1);
- nvgFillBoxGradient(x+1, y+1+1.5, w-2, h-2, 3,4, Color(c,c,c,32), Color(32,32,32,32));
- nvgFill();
- local key = bindReverseLookup(bindCommand);
- if key == "(unbound)" then
- c = c / 2;
- else
- key = string.upper(key);
- end
- -- default border colour
- local bc = Color(0,0,0,48);
- -- modify when hovering
- bc.r = lerp(bc.r, UI_HOVER_BORDER_COLOR.r, k.hoverAmount);
- bc.g = lerp(bc.g, UI_HOVER_BORDER_COLOR.g, k.hoverAmount);
- bc.b = lerp(bc.b, UI_HOVER_BORDER_COLOR.b, k.hoverAmount);
- bc.a = lerp(bc.a, UI_HOVER_BORDER_COLOR.a, k.hoverAmount);
- -- modify when have focus
- if k.focus then
- local intensity = k.focusAmount;
- -- pulse
- intensity = intensity * (math.sin(OptionsMenu.keyBindPulseTimer) * 0.5 + 0.5);
- OptionsMenu.keyBindPulseTimer = OptionsMenu.keyBindPulseTimer + deltaTime * 16;
- bc.r = lerp(bc.r, 255, intensity);
- bc.g = lerp(bc.g, 255, intensity);
- bc.b = lerp(bc.b, 0, intensity);
- end
- -- border
- nvgBeginPath();
- nvgRoundedRect(x+0.5,y+0.5, w-1,h-1, 4-0.5);
- nvgStrokeColor(bc);
- nvgStroke();
- local tw = nvgTextWidth(key);
- if tw >= w - 5 then
- nvgScissor(x, y, w - 5, 100);
- end
- -- text
- nvgFontSize(20);
- nvgFontFace(FONT_TEXT);
- nvgFillColor(Color(c,c,c,64));
- nvgTextAlign(NVG_ALIGN_LEFT, NVG_ALIGN_MIDDLE);
- nvgText(x+h*0.3, y+h*0.5, key);
- nvgRestore();
- if k.nameKeyPressed ~= nil then
- if key ~= "(unbound)" then
- --consolePrint("unbind "..key);
- --Removed for destroying all binds on the key it's changing. #AFRO
- --consolePerformCommand("unbind "..key);
- --Adding this temp fix for now. #AFRO
- if bindState ~= nil then
- consolePerformCommand("bind "..bindState.." "..key.." \"\"");
- else
- consolePerformCommand("bind "..key.." \"\"");
- end
- end
- if bindState ~= nil then
- consolePerformCommand("bind "..bindState.." "..k.nameKeyPressed.." "..bindCommand);
- else
- consolePerformCommand("bind "..k.nameKeyPressed.." "..bindCommand);
- end
- end
- return k.nameKeyPressed;
- end
- Zoom =
- {
- canHide = false,
- canPosition = true;
- userData = {};
- transitionTimer = 0,
- transitionRun = false
- ,
- transition = function(self, direction)
- local transFov = direction == 0 and self.userData.zoomFov or self.userData.fov
- if self.transitionRun then
- -- using lerp to set r_fov over time for to create the transition.
- transFov = lerp(direction == 1 and self.userData.fov or self.userData.zoomFov
- , direction == 1 and self.userData.zoomFov or self.userData.fov
- , self.transitionTimer );
- self.transitionTimer = self.transitionTimer + (deltaTimeRaw / (self.userData.scaleSpeed));
- end
- --reseting everything if finished running transition.
- if self.transitionTimer >= 1 then
- self.transitionRun = false;
- self.transitionTimer = 0;
- self.zoomDirection = 0;
- end
- --return either transitioned Fov, or return your preset zoom fov / fov depending on direction.
- return self.transitionRun and "r_fov " .. transFov - transFov%1 or direction == 1 and "r_fov " .. self.userData.zoomFov or "r_fov " .. self.userData.fov ;
- end
- ,
- drawOptions = function (self, x , y)
- local padding = 10;
- local editboxH = 35;
- --Fov
- uiLabel("fov", x, y);
- local newFov = uiEditBox(self.userData.fov, x + nvgTextWidth("transition speed") + padding, y, 150, optionalId, true)
- -- Zoom fov
- y = y + editboxH + padding;
- uiLabel("zoom fov", x, y);
- local newZoomFov = uiEditBox(self.userData.zoomFov, x + nvgTextWidth("transition speed") + padding, y, 150, optionalId, true)
- -- Key bind
- y = y + editboxH + padding;
- uiLabel("key bind", x, y);
- local newZoomKey = uiKeyBind("ui_zoom_zoom 1", x + nvgTextWidth("transition speed") + padding, y, 150, "game", nil, true);
- --Transition Speed
- y = y + editboxH + padding;
- uiLabel("transition speed", x, y);
- self.userData.scaleSpeed = uiSlider(x + nvgTextWidth("transition speed") + padding, y, 150, 0, 0.5, self.userData.scaleSpeed);
- uiLabel(string.format("%2f", self.userData.scaleSpeed), x + nvgTextWidth("transition speed") + padding + 150 + padding, y);
- if newZoomKey then self.userData.zoomKey = tostring(newZoomKey) end;
- if tonumber(newFov) > tonumber(self.userData.zoomFov) then self.userData.fov = tonumber(newFov); end;
- if tonumber(newZoomFov) < tonumber(self.userData.fov) then self.userData.zoomFov = tonumber(newZoomFov); end;
- saveUserData(self.userData);
- end
- };
- registerWidget("Zoom");
- function Zoom:initialize()
- self.userData = loadUserData();
- CheckSetDefaultValue(self, "userData", "table", {});
- CheckSetDefaultValue(self.userData, "zoom", "boolean", false);
- CheckSetDefaultValue(self.userData, "zoomKey", "string", "mouse2");
- CheckSetDefaultValue(self.userData, "zoomFov", "number", 50);
- CheckSetDefaultValue(self.userData, "fov", "number", 110);
- CheckSetDefaultValue(self.userData, "scaleSpeed", "number", 0.1);
- widgetCreateConsoleVariable("zoom", "int", 0);
- end
- function Zoom:draw()
- if widgetGetConsoleVariable("zoom") == 1 then
- --set zoom direction mod to zoom in.
- self.zoomDirection = 1;
- if consoleGetVariable("r_fov") ~= self.userData.zoomFov then self.transitionRun = true; end;
- consolePerformCommand("bind game " .. self.userData.zoomKey .. " ui_zoom_zoom 0");
- elseif widgetGetConsoleVariable("zoom") == 0 then
- --set zoom direction mod to zoom out.
- self.zoomDirection = -1;
- if consoleGetVariable("r_fov") == self.userData.fov then self.transitionRun = false;
- else self.transitionRun = true;
- end;
- consolePerformCommand("bind game " .. self.userData.zoomKey .. " ui_zoom_zoom 1");
- end
- if self.zoomDirection == 1 then consolePerformCommand(self.transition(self, self.zoomDirection)); end;
- if self.zoomDirection == -1 then consolePerformCommand(self.transition(self, self.zoomDirection)); end;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement