# \[Mod\] UnitFramePlus v1.2

**URL:** <https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565>\
**Category:** Current Mods\
**Created:** [May 25, 2018, 5:36am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565 "2018-05-25T05:36:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 5:36am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/1 "2018-05-25T05:36:37Z")

</div>

**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](https://steamcommunity.com/sharedfiles/filedetails/?id=1393964470).**  
Non-Steam smod (not guaranteed to be up to date): [unitframeplus.smod](https://discourse.stonehearth.net/uploads/short-url/efDyvjAZjeR7g32lCrRr8LjSTbC.smod) (61.1 KB)

![screenshot](https://us1.discourse-cdn.com/flex022/uploads/stonehearth/original/3X/8/8/881069f88b563da4021c179b67a0923db7e9d82c.png)

 ![change_jobs](https://us1.discourse-cdn.com/flex022/uploads/stonehearth/original/3X/4/2/42326ba85bf9e69f3890c373595eacb41f67d727.png)

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 5:37am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/2 "2018-05-25T05:37:32Z")

</div>

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. 😛 I’m a programmer, not a graphic designer.

---

<div class="post-metadata">

**Author:** ![max99x](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/max99x/32/40094_2.png) [@max99x](https://discourse.stonehearth.net/u/max99x)\
**Post date:** [May 25, 2018, 5:41am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/3 "2018-05-25T05:41:45Z")

</div>

> 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')`.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 6:03am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/4 "2018-05-25T06:03:17Z")

</div>

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:

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

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

---

<div class="post-metadata">

**Author:** ![max99x](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/max99x/32/40094_2.png) [@max99x](https://discourse.stonehearth.net/u/max99x)\
**Post date:** [May 25, 2018, 7:10am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/5 "2018-05-25T07:10:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 7:55am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/6 "2018-05-25T07:55:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![max99x](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/max99x/32/40094_2.png) [@max99x](https://discourse.stonehearth.net/u/max99x)\
**Post date:** [May 25, 2018, 7:57am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/7 "2018-05-25T07:57:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 8:22am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/8 "2018-05-25T08:22:08Z")

</div>

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:

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

yields something like this:

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

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 8:07pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/9 "2018-05-25T20:07:43Z")

</div>

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

```auto
"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.

---

<div class="post-metadata">

**Author:** ![Wharp](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/wharp/32/56716_2.png) [@Wharp](https://discourse.stonehearth.net/u/Wharp)\
**Post date:** [May 25, 2018, 8:12pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/10 "2018-05-25T20:12:00Z")

</div>

@paulthegreat Paul this is great.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 8:21pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/11 "2018-05-25T20:21:52Z")

</div>

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?).

---

<div class="post-metadata">

**Author:** ![Wharp](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/wharp/32/56716_2.png) [@Wharp](https://discourse.stonehearth.net/u/Wharp)\
**Post date:** [May 25, 2018, 8:22pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/12 "2018-05-25T20:22:31Z")

</div>

Omg yes that would be so convenient!

---

<div class="post-metadata">

**Author:** ![max99x](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/max99x/32/40094_2.png) [@max99x](https://discourse.stonehearth.net/u/max99x)\
**Post date:** [May 25, 2018, 8:35pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/13 "2018-05-25T20:35:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 25, 2018, 8:45pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/14 "2018-05-25T20:45:56Z")

</div>

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

```auto
_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:

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

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 26, 2018, 5:32am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/15 "2018-05-26T05:32:56Z")

</div>

@Wharp, re:

> [@paulthegreat](#):
>
> adding a “change job” button to the unit frame

It’s done.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 26, 2018, 7:19pm UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/16 "2018-05-26T19:19:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [May 27, 2018, 7:53am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/17 "2018-05-27T07:53:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [June 11, 2018, 7:16am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/18 "2018-06-11T07:16:33Z")

</div>

Updated to add “attack with parties” buttons as suggested here: [“Attack” button when selecting a hostile mob](https://discourse.stonehearth.net/t/attack-button-when-selecting-a-hostile-mob/35800)

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

---

<div class="post-metadata">

**Author:** ![Banto](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/banto/32/68768_2.png) [@Banto](https://discourse.stonehearth.net/u/Banto)\
**Post date:** [September 29, 2018, 10:42am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/19 "2018-09-29T10:42:39Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex022/uploads/stonehearth/original/3X/3/c/3c913eca784f399bb8d8b63fc29f92a72e5b000a.png)

---

<div class="post-metadata">

**Author:** ![paulthegreat](https://sea2.discourse-cdn.com/flex022/user_avatar/discourse.stonehearth.net/paulthegreat/32/62395_2.png) [@paulthegreat](https://discourse.stonehearth.net/u/paulthegreat)\
**Post date:** [October 3, 2018, 4:04am UTC](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565/20 "2018-10-03T04:04:05Z")

</div>

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).

[Next page](https://discourse.stonehearth.net/t/mod-unitframeplus-v1-2/35565.md?page=2)
