Skip to content
View in the app

A better way to browse. Learn more.

LCPDFR.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Rage Native UI toggle TimerBar

Featured Replies

Is there any way to toggle a timerbar on and off without it duplicating?

public static void NewStart()
        {
            stop = false;
            SpeedoMeterMain();
        }

        public static void SpeedoMeterMain()
        {

            if(!stop)
            { 
                    Game.FrameRender += Process;
                    timerBarPool = new TimerBarPool();
                    SpeedText = new TextTimerBar("Speed", "0 km/h");
                    timerBarPool.Add(SpeedText);
                    ismade = true;
                
            }


        }

        public static void KillSpeedoMeter()
        {
            stop = true;
            timerBarPool.Remove(SpeedText);
            timerBarPool = null;
            SpeedText = null;
            
        }


        public static void Process(object sender, GraphicsEventArgs e)
        {
            if(stop) { return; }
            timerBarPool.Draw();
            SpeedText.Text = MathHelper.ConvertMetersPerSecondToKilometersPerHourRounded(Game.LocalPlayer.Character.Speed) + " km/h";


        }

I've been trying all kinds of methods but it just won't give in :p Any help is appreciated :)

Just swicthing the stop bool true/false should stop drawing the timerbar, no need to remove SpeedText from the pool and set the timerBarPool and SpeedText to null.

When you initialize the plugin create the timerbars and pool and if you want to have method to switch the stop bool, it could be something like this:
        public static void ToggleSpeedoMeter()
        {
            stop = !stop;
        }

The "!" symbol inverts a bool expression so if stop is true it will be false an viceversa.

That should work :smile:

  • Author

still no go sadly, Now it doesn't appear at all :)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rage;
using Gwen;
using RagePluginHook;
using System.Drawing;
using RAGENativeUI.Elements;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;

namespace KTools
{
    class SpeedoMeter
    {
        private static TimerBarPool timerBarPool;
        private static TextTimerBar SpeedText;
        private static bool stop;

        public static void ToggleSpeedoMeter()
        {
            stop = !stop;
            Game.LogTrivial("Toggle: " + stop.ToString());

        }

        public static void SpeedoMeterMain()
        {
                    Game.FrameRender += Process;
                    timerBarPool = new TimerBarPool();
                    SpeedText = new TextTimerBar("Speed", "0 km/h");
                    timerBarPool.Add(SpeedText);                         
            
        }


        public static void Process(object sender, GraphicsEventArgs e)
        {
            if (!stop) { return; }
            timerBarPool.Draw();
            SpeedText.Text = MathHelper.ConvertMetersPerSecondToKilometersPerHourRounded(Game.LocalPlayer.Character.Speed) + " km/h";
        }
      }
    }
[21/05/2016 00:38:55.416] Plugin "KTools" was loaded from "KTools.dll".
[21/05/2016 00:39:00.515] KTools: Toggle: True
[21/05/2016 00:39:01.717] KTools: Toggle: False
[21/05/2016 00:39:02.524] KTools: Toggle: True
[21/05/2016 00:39:03.525] KTools: Toggle: False

 

Nevermind, it would help if i added a call to SpeedoMeterMain() :p

So its the same problem all over with this, here's after toggling it 4 times (apologies for the pbrush quality :p)

It seems like it keeps adding new ones on top of it, thats why i tried to setting it to null and all that.

toggle.png

Edited by khorio

  • Author
Just now, alexguirre said:

Are you calling SpeedoMeterMain somewhere? This is what creates everything.

        public static void ToggleSpeedoMeter()
        {
            stop = !stop;
            SpeedoMeterMain();
        }

 

fixed that now :p

but still the same duplication

25 minutes ago, khorio said:

        public static void ToggleSpeedoMeter()
        {
            stop = !stop;
            SpeedoMeterMain();
        }

 

fixed that now :p

but still the same duplication

Because each time you toggle the speedometer you create a new timer bar, SpeedoMeterMain must be called only once when the plugin is loaded in your Main method or the first time you toggle the speedo meter.

Every time you call SpeedoMeterMain(); you attach a new event handler to Game.FrameRender, without detaching the old one, thus drawing the TimerBar multiple times in one frame. You can detach the event handler in KillSpeedoMeter();

	Game.FrameRender -= Process;
	

  • Author
On 5/20/2016 at 1:26 AM, alexguirre said:

Because each time you toggle the speedometer you create a new timer bar, SpeedoMeterMain must be called only once when the plugin is loaded in your Main method or the first time you toggle the speedo meter.

already fixed it, but thanks :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.