[Mod] UnitFramePlus v1.2


#1

Background:
So I got tired of toggling my soldiers’ “job” activity all the time to maximize their utility out of combat, and now that I’ve been playing around with modding a bit I decided to try my hand at adding this feature.

Well, I did it. I’m calling the mod UnitFramePlus because I may add some other modifications to the unit frame here, but for now all it does is add a button next to the other combat buttons when you have a soldier or party selected; the button indicates the current status (highlighted sword means job enabled, highlighted backpack means job disabled) with an arrow indicating what pressing the button will switch to.

Features:

  • a button that toggles the “job” property of the selected citizen (or all members of the selected party)
  • a “change jobs” command button that opens the Change Job (Promotion Tree) window
  • five “attack with parties” buttons that allow you to attack a selected enemy entity with any of your four parties or all of them
  • the border around the unit frame is red when an enemy entity is selected

Licensing:
I’m too lazy to look up any official licenses, but the short of it is, do whatever you want with it! Copy it verbatim into you own mod called “UnitFramePluser and paulthegreat is dumb” if you want, I don’t care! (I mean, I care a little, but you’re free to do so.) Be forewarned if you’re offering me any assets to include in this mod that they’ll carry the same usability freedoms. I’ll try to keep the mod functional, but if I’m slacking by all means fork it and publish your own (or maybe I’m not slacking, but you’re simply capable of doing it better).

Found on the Steam Workshop.

screenshot


Change Job Button
"Attack" button when selecting a hostile mob
Paul the Great's modding vertex
Community Desktop Tuesday
Stockpile & Farm patrols
A wishlist of minor polishes and improvements for 1.0/1.1
#2

P.S.- I could really use a hint about how to observe changes to citizens from inside the unit frame!

And if anyone wants to make better icons for me, I’ll totally use them. :stuck_out_tongue: I’m a programmer, not a graphic designer.


#3

P.S.- I could really use a hint about how to observe changes to citizens from inside the unit frame!

You’ll need a trace. If you only care about changes to the selected citizen, you might already have it, since the frame widget traces the currently selected object. In unit_frame.js look at the components property. That specifies which components are traced. Once the component you need is on there, you can access it using something like this.get('model.componentname.propertyoncomponent').


#4

Is there a way to add components to my reopened class, or do I have to copy the whole components object from unit_frame.js and add the components I need to it? I’m currently doing this:

App.StonehearthUnitFrameView.reopen({ ... });

and I don’t know how to just add on to the components object without replacing the whole components object.


#5

I think you’d need to reference App.StonehearthUnitFrameView.prototype.components and transform it.


#6

Unfortunately, 'model.stonehearth:party.members' only seems to contain URIs (instead of the full entity objects like the ‘citizens’ component in StonehearthCitizensView), so I have to do traces on those URIs to get their 'stonehearth:work_order' properties, meaning I can’t list them in the components and therefore can’t observe when they change.


#7

The trace specification in components is recursive. E.g. look at how the unit frame traces stonehearth:buffs.


#8

I appreciate that you’re trying to help me, but I’m still having trouble. I’ve tried sticking a few things within the "stonehearth:party": { "members": {...} } component, but I’m not getting anything more than what I was already getting, which is an object containing entity id keys for objects that simply contain a property called “entity” with a value of the URI:

this.get("model.stonehearth:party.members")

yields something like this:

{
    2933: Object {
        entity: "object://game/2933"
        __proto__: Object
    }
    4551: Object {
        entity: "object://game/4551"
        __proto__: Object
    }
}

#9

Okay, I’ve ended up including this in my components

"stonehearth:party": {
            "members": {
                "*": {
                    "entity": {
                        "stonehearth:work_order": {
                            "work_order_statuses": {},
                            "work_order_refs": {}
                        }
                    }
                }
            }
        },

and it works for the most part.

However, I still can’t seem to figure out observing on those properties. Observing on “model.stonehearth:work_order” works fine for when I have a single hearthling selected, but if I have a party selected that doesn’t fire (it’s null), and none of my attempts to observe the party member version work: “model.stonehearth:party” (works only when selecting a party, not when a member of that party changes), “model.stonehearth:party.members”, “model.stonehearth:party.members.*”, “model.stonehearth:party.members.*.entity”, “model.stonehearth:party.members.*.entity.stonehearth:work_order”, “model.stonehearth:party.members.*.entity.stonehearth:work_order.work_order_statuses”, “model.stonehearth:party.members.*.entity.stonehearth:work_order.work_order_statuses.job”. None of those trigger the observer when a party member’s job work order status changes.


#10

@paulthegreat Paul this is great.


#11

Thanks, and it’s getting better! Once I figure out this observer issue… I’m actually coming up with other ideas, too, like adding a “change job” button to the unit frame (how many times do you get the alert that your hearthling leveled up to 2 or 3, and you click on it to jump to that hearthling, but then you have to go to the Citizens view with them selected in order to actually upgrade them?).


#12

Omg yes that would be so convenient!


#13

If you’re talking about the string that goes in the observe() Ember call, anything after "model" is ignored. If you observe "model" you should get notified when anything changes.


#14

Yeah, that’s what I was referring to. So you’re saying I could just do this:

_updateObserver: function(){
        var self = this;
        self._updateJobToggleButton(null);
    }.observes('model'), //.stonehearth:work_order', 'model.stonehearth:party', 'entity.stonehearth:work_order'),

and get the same result as with the rest of that comment in the code? That doesn’t seem to work for me. I was basing it off unit_frame.js:_updateUnitFrameWidth, which has the following observes line:

}.observes('model.uri', 'model.stonehearth:commands.commands', 'model.stonehearth:ai', 'model.stonehearth:unit_info', 'model.stonehearth:job'),

#15

@Wharp, re:

It’s done.


#16

I’m still looking for a way to observe changes to party member work order statuses. I’m about to try a complicated way of doing it similar to the way the StonehearthCitizensView does it with StonehearthCitizenTasksRowViews handling individual citizens from the overall citizens collection, so if you know how I can do it without all that, please let me know.


#17

Alright, the simpler method I found is to just cache the work order statuses when you have a party selected and Ember.run.later every 100ms to re-check them and see if they’ve changed. This only continues to check while a party is selected.


#18

Updated to add “attack with parties” buttons as suggested here: “Attack” button when selecting a hostile mob

Also tweaked job toggle button to position it better and allow it to work with non-military citizens.


#19

This mod adds an extra Change Jobs making it duplicated might need a relook at this thing ? :slight_smile:
Running the latest unstable release on steam


#20

Yeah, I didn’t want to have to override the html for the Citizens page, just to remove a button. :-\ I guess I can reopen the Ember view and “inherit” didInsertElement and have it remove that div there. The first Change Jobs button is the hard-coded one, the other three in that screenshot all come from the commands available to that citizen (e.g., archers also have their “select quiver” command show up there).