The client UI and possibly how to help it with PlayerItemHeldEvent

Discussion in 'Resources' started by Pandarr, Jun 14, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Pandarr

    I'm guessing a poll of plugin devs would lean towards them feeling the UI for users isn't terribly useful. A poll of users would probably reiterate that. I may have a solution, in certain cases.

    1. Item shops are a hassle. /command /command /command...
    Proposal - Utilize the number keys. How? Catch PlayerItemHeldEvent and use .getNewSlot(). The idea is that a user goes to a shop and types /shop on. A text menu is presented.

    Code:
    1.  Sell
    2.  Buy
    3.  Exit
    
    By pressing the number on their keyboard they change inventory slots but it also lets us capture keyboard data in a sense. You could have "3. Exit" do /shop off for them. Heck you could even do /shop on when they got close enough to the sign/chest/etc depending on the nature of your plugin.

    2. RPG mods. I'm currently working on an RPG mod and was looking through current ones to see what people are doing, what users are wanting, etc. One thing I noticed was the RPG mods seem to replace items like snowballs for spell casting, either explicitly or via a /command. This led me to thinking, "Why not have users cast spells similar to Magicka?" If you set up a scheduled task, you could push/pop users itemheld changes to a stack, popping itemheld changes after a few ticks. Pressing, "1 3 1" within a small amount of ticks would cast a fireball, "1 4 1" would cast a blizzard. However "1 3 1" within more ticks would do nothing.

    One issue is that you can't differentiate between the scroll wheel and a keypress. That's why I would recommend not utilizing fully adjacent numbers for ability casting.

    Anyway, just an idea. Maybe it can be enhanced by some fancier code and better ideas. Maybe it's a total wash and won't work (I haven't done a POC yet). It seems like it could work though and be helpful in certain situations.

    Also, sorry if this is an already implemented idea. There's a lot of plugins and I haven't used them all.
     
    rmsy likes this.
  2. Offline

    Tagette

    nice idea, not sure how functional it would be
     
  3. Offline

    Pandarr

    Here's a working demo of a shopping scenario. The biggest hitch is that if the user is already on slot 1, and presses 1 again, the event doesn't trigger (it shouldn't). Anyway... if you want to take a peek... just use /pocshop and it'll display 3 options. You can press 1, 2, or 3 and it'll give you feedback. However if you're already on 1 and press 1 again, nothing happens. Oh well...

    Jar

    "Good enough to get it working" source
     
  4. Offline

    totokaka

    SMART!!
    but Pandarr in the code you use /pocshop not /shop
     
  5. Offline

    4am

    What happens when a player's inventory is empty?
     
  6. Hey, that's an awesome idea. It could be a really fast and smart way to handle user-input.
    What makes it uncomfortable for users to use is the thing when you already selected the slot and that you can quickly choose something wrong when scrolling.

    My idea to improve this is to make the player "confirm" his selection by clicking anywhere or something specific.
    You could write the options on a sign, then the player scrolls or jumps to the inventory-slot and punches the sign.

    I'm going to modify your example and test how that would work, if you don't mind.
    Great idea!

    Edit: This would apparently not work with the RPG-spells idea, but for that purpose only changing slot would fit enough IMO.
     
  7. Offline

    garbagemule

    Like I told you on IRC, this idea is absolutely amazing. There are quite a few immediate issues, such as the scroll wheel as you mention yourself, as well as the fact that the chatbox has to be "paused" or "frozen" for the player with the menu while they are making a choice. I think the former is difficult to resolve, but the latter could probably be sorted out.

    I linked you this on IRC, but I figure if anyone else has any ideas or suggestions for improvements, they might as well chip in here on the forums. Note that the menu listing skips the key corresponding to the slot that is currently selected.

    https://github.com/garbagemule/Selector

    Now, the .jar has a sample method. Load it up on a test-server, type /menu, use the number keys to select a menu item, and watch the output in the server console.

    The API-part consists of the "handler" class (and also the main plugin class), Selector, the SelectorMenu, as well as the SelectorListener. The idea is that the API user creates a SelectorMenu using the constructors and setters, and then extends SelectorListener and implements its onPlayerChoice method, like such:

    Code:java
    1. // Create a new SelectorMenu.
    2. SelectorMenu menu = new SelectorMenu();
    3. menu.setName("menuName");
    4. menu.setHeadline("This is a test menu");
    5. menu.addAll("Menu item #1", "Menu item #2", "Some other item", "Lol");
    6. Selector.showMenu(player, menu);
    7.  
    8. // Implementing the listener
    9. public class PluginNameSelectorListener extends SelectorListener
    10. {
    11. public void onPlayerChoice(Player p, SelectorMenu menu, String choice)
    12. {
    13. if (!menu.getName().equals("menuName"))
    14. return;
    15.  
    16. if (choice.equals("fatgoat"))
    17. p.damage(100);
    18. }
    19. }

    Obviously, the SelectorMenu objects can be stored as a static fields for ease-of-use, so the only thing the API user has to do in their events is Selector.showMenu(p, shopMenu) or Selector.showMenu(p, arenaMenu).

    What the player actually sees, if his currently held item is in the third item slot (slot id 2):
    This is a test menu
    [1] Menu item #1
    [2] Menu item #2
    [4] Some other item
    [5] Lol

    Notice how the player won't have to move off of the current item slot to choose any of the menu items.
     
  8. Finished my little example. I used the example of @Pandarr as a basement, but not much of the original code stayed ;)

    Download as an attachment. Source is included in the jar.
    New command is /pocsign. After typing it, left-click any sign. It should show you the 3 options. Select the correct inventory-slot and left-click again. Feedback should be displayed at the 4th line of the sign.

    This could be used as a signshop that is based on a menu, however you are always limited to the space of a sign.
     
  9. Offline

    garbagemule

    @Bone008 - Great idea! It is a little messy, but it works really well!

    My personal needs with regards to MobArena require a more personalized "space" of options, meaning a block that is public makes it difficult for big crowds to use it at the same time. Therefore, I'm attempting to expand on the chat-box idea. Currently, I'm working on making a queue of chat events, and every time a player is presented with a menu, their chat box "freezes" in the sense that all chat-messages are "delayed" until after they have chosen an option. This makes it ideal for crowded places, and it also provides up to 8 menu items (and possibly more, if I can get a type of "page" functionality going).

    I'm struggling with firing off chat events, though :(
     
  10. @garbagemule Obviously it's not designed to work on a real server, so neither Pandarr nor me cared about perfect handling or multiple players.
    If the purpose requires a non-block method, "freezing" the chat would be pretty helpful.
    However, how do you want to technically prevent messages from being sent to a speficic player?
    You could cancel all onPlayerChat-events and broadcast them to every player but the freezed one, but I don't see a way to capture stuff sent by other plugins or the server etc.
     
  11. Offline

    garbagemule

    @Bone008 - I've got it working fairly well now. I have implemented a custom auto-discarding queue, and it basically captures the x previous chat events. I'm not sure if it's possible to capture plugin or server broadcasts, but I think PlayerChatEvents are a great start. If I can make this somewhat fool-proof, I might use it in MobArena for arena selection :3

    Edit: Chat-handling should be fairly decent now. I still haven't tested with more players than myself, though. Here's the jar. The plugin keeps a queue of the 20 last chat-messages, and every time a player enters a menu, the whole chatbox is cleared (this can be disabled by removing lines 71 and 72 in SelectorMenu.java), and then the menu is presented. Upon choosing a menu option, the chat is "restored" by printing all the current messages in the chat-queue (only to that player, though).

    Now to find out if there's a way to intercept ALL text in the chatbox... Probably not without messing with n.m.s :/
     
  12. Offline

    Shamebot

    Throwing the idea of using the 1.6 map item as display into the discussion.
     
  13. Nice idea, but not really useful if you get user input from a changing inventory slot ...
    Remember, a map must be held in your hands in order to see its contents ;)
    Only thing you could do is always putting the map at the new slot, a pretty dirty way though and it would mess up the player's inventory.

    @garbagemule Nice way to capture the chat-messages. I don't think you can capture messages from other plugins, not even with obfuscated code, since player.sendMessage(...) sends the Packet3Chat without any detours. Unless you can capture packets ...
     
  14. Offline

    Shamebot

    @Bone008 Or save the content of the quick slot bar, set the all to a map item, let the user select the number he wants and restore the items.
     
  15. Offline

    4am

    Chat plugins like HeroChat send custom events when players chat but yes, for sendMessage() it would be cool if an event would fire. Sounds like a simple pull request, who's up for it? :)
     
Thread Status:
Not open for further replies.

Share This Page