Skip to content

Commit 7a9a5d1

Browse files
Add favorites (#242)
* Add favorites * Bump version * Fix scripts not showing star * Favorite toggle styling * Make favorite icon yellow on hover --------- Co-authored-by: Jiří Pihrt <[email protected]>
1 parent c3a976b commit 7a9a5d1

File tree

9 files changed

+70
-8
lines changed

9 files changed

+70
-8
lines changed

rlbot_gui/gui.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from rlbot_gui.match_runner.custom_maps import find_all_custom_maps
3535
from rlbot_gui.type_translation.packet_translation import convert_packet_to_dict
3636
from rlbot_gui.persistence.settings import load_settings, BOT_FOLDER_SETTINGS_KEY, MATCH_SETTINGS_KEY, \
37-
LAUNCHER_SETTINGS_KEY, TEAM_SETTINGS_KEY, load_launcher_settings, launcher_preferences_from_map
37+
LAUNCHER_SETTINGS_KEY, TEAM_SETTINGS_KEY, FAVORITES_KEY, load_launcher_settings, launcher_preferences_from_map
3838
from rlbot import gateway_util
3939

4040
#### LOAD JUST TO EXPOSE STORY_MODE
@@ -230,6 +230,19 @@ def save_team_settings(blue_bots, orange_bots):
230230
settings.setValue(TEAM_SETTINGS_KEY, {"blue_team": blue_bots, "orange_team": orange_bots})
231231

232232

233+
@eel.expose
234+
def get_favorite_runnables():
235+
settings = load_settings()
236+
favorite_runnables = settings.value(FAVORITES_KEY, type=list)
237+
return favorite_runnables if favorite_runnables else []
238+
239+
240+
@eel.expose
241+
def save_favorite_runnables(runnables):
242+
settings = load_settings()
243+
settings.setValue(FAVORITES_KEY, runnables)
244+
245+
233246
@eel.expose
234247
def pick_location(is_folder, filter="Config files (*.cfg)"):
235248
"""

rlbot_gui/gui/js/bot-card-vue.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ export default {
88
props: {
99
bot: Object,
1010
disabled: Boolean,
11+
favorited: Boolean,
1112
draggable: {
1213
type: Boolean,
1314
default: true,
1415
},
1516
},
1617
template: /*html*/`
1718
<draggable v-model="draggableModel" :options="draggableOptions" style="display: inline;">
18-
<runnable-card :runnable="bot" v-bind="[$props,$attrs]" :class="{draggable: draggable}" @click="$emit('click')">
19+
<runnable-card :runnable="bot" v-bind="[$props,$attrs]" :class="{draggable: draggable}" :favorited="favorited" @click="$emit('click')">
1920
</draggable>
2021
`,
2122
computed: {

rlbot_gui/gui/js/bot-pool-vue.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
'script-card': ScriptCard,
1111
'script-dependencies': ScriptDependencies,
1212
},
13-
props: ['bots', 'scripts', 'display-human'],
13+
props: ['bots', 'scripts', 'display-human', 'favorites'],
1414
template: /*html*/`
1515
<div class="p-1">
1616
<b-form inline class="mb-2">
@@ -33,15 +33,15 @@ export default {
3333
</b-form>
3434
3535
<div class="overflow-auto">
36-
<bot-card v-for="bot in bots" :bot="bot" v-show="passesFilter(bot)" @click="$emit('bot-clicked', bot)"/>
36+
<bot-card v-for="bot in bots" :bot="bot" v-show="passesFilter(bot)" @click="$emit('bot-clicked', bot)" :favorited="favorites.includes(bot.path)" />
3737
3838
<span v-if="displayedBotsCount + displayedScriptsCount === 0">
3939
No bots available for this category.
4040
</span>
4141
4242
<div v-if="displayedScriptsCount > 0" class="scripts-header">Scripts</div>
4343
44-
<script-card v-for="script in scripts" :script="script" v-show="passesFilter(script)"/>
44+
<script-card v-for="script in scripts" :script="script" v-show="passesFilter(script)" :favorited="favorites.includes(script.path)"/>
4545
4646
<script-dependencies :bots="bots" :scripts="scripts"
4747
v-if="secondaryCategorySelected.displayScriptDependencies"
@@ -84,6 +84,10 @@ export default {
8484
if (runnable.type === 'script' && !category.displayScriptDependencies && runnable.enabled)
8585
return true;
8686

87+
if (category && category.favorites) {
88+
return this.favorites.includes(runnable.path)
89+
}
90+
8791
let allowedTag = runnable.type === 'script' ? category.scripts : category.bots;
8892
if (allowedTag) {
8993
if (allowedTag === '*') {

rlbot_gui/gui/js/categories.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,12 @@ export default {
7070
},
7171
],
7272
},
73+
favorites: {
74+
name: "Favorites",
75+
categories: [
76+
{
77+
favorites: true,
78+
},
79+
],
80+
},
7381
};

rlbot_gui/gui/js/main-vue.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default {
137137
@bot-clicked="addToTeam($event, teamSelection)"
138138
ref="botPool"
139139
:display-human="displayHumanInBotPool"
140+
:favorites="favoritesPool"
140141
class="noscroll-flex"
141142
/>
142143
@@ -255,6 +256,17 @@ export default {
255256
</b-toast>
256257
257258
<b-modal id="bot-info-modal" size="xl" :title="activeBot.name" v-if="activeBot && activeBot.info" hide-footer centered>
259+
<template #modal-title="{ close }">
260+
<div class="d-flex align-items-center">
261+
{{activeBot.name}}
262+
<b-button v-if="activeBot.path" variant="outline-primary" class="icon-button" @click="toggleFavoriteRunnable(activeBot)"
263+
v-b-tooltip.hover title="Toggle bot as favorite"
264+
>
265+
<b-icon v-if="favoritesPool.includes(activeBot.path)" icon="star-fill" variant="warning" />
266+
<b-icon v-else icon="star" />
267+
</b-button>
268+
</div>
269+
</template>
258270
259271
<img v-if="activeBot.logo" class="bot-logo" v-bind:src="activeBot.logo">
260272
<p><span class="bot-info-key">Developers:</span> {{activeBot.info.developer}}</p>
@@ -471,6 +483,7 @@ export default {
471483
showBotpackUpdateSnackbar: false,
472484
appearancePath: '',
473485
recommendations: null,
486+
favoritesPool: [],
474487
downloadModalTitle: "Downloading Bot Pack",
475488
}
476489
},
@@ -743,6 +756,10 @@ export default {
743756
eel.get_match_options()(this.matchOptionsReceived)
744757
},
745758

759+
favoriteRunnablesReceived: function (runnables) {
760+
this.favoritesPool = runnables;
761+
},
762+
746763
botpackUpdateChecked: function (isBotpackUpToDate) {
747764
this.showBotpackUpdateSnackbar = !isBotpackUpToDate;
748765
this.isBotpackUpToDate = isBotpackUpToDate;
@@ -791,6 +808,16 @@ export default {
791808
bots.forEach(this.handleBotAddedToTeam);
792809
this.$bvModal.hide('recommendations-modal');
793810
},
811+
toggleFavoriteRunnable: async function(runnable) {
812+
let i = this.favoritesPool.indexOf(runnable.path);
813+
if (i >= 0) {
814+
this.favoritesPool.splice(i, 1);
815+
} else {
816+
this.favoritesPool.push(runnable.path);
817+
}
818+
await eel.save_favorite_runnables(this.favoritesPool)();
819+
},
820+
794821
startup: function() {
795822
if (this.$route.path != "/") {
796823
return
@@ -799,6 +826,7 @@ export default {
799826
eel.get_match_options()(this.matchOptionsReceived);
800827
eel.get_match_settings()(this.matchSettingsReceived);
801828
eel.get_team_settings()(this.teamSettingsReceived);
829+
eel.get_favorite_runnables()(this.favoriteRunnablesReceived);
802830

803831
eel.get_language_support()((support) => {
804832
this.languageSupport = support;

rlbot_gui/gui/js/runnable-card-vue.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
disabled: Boolean,
66
removable: Boolean,
77
hidewarning: Boolean,
8+
favorited: Boolean,
89
},
910
template: /*html*/`
1011
<b-card class="bot-card" @click="disabled || $emit('click')" :class="{disabled: disabled}">
@@ -19,6 +20,8 @@ export default {
1920
</span>
2021
</span>
2122
</slot>
23+
24+
<b-icon v-if="favorited" icon="star-fill" variant="warning" style="margin-left: 0.33em"></b-icon>
2225
2326
<b-button size="sm" class="icon-button warning-icon" v-if="runnable.warn && !hidewarning" variant="outline-warning"
2427
@click.stop="$store.commit('setActiveBot', runnable)" v-b-modal.language-warning-modal>

rlbot_gui/gui/js/script-card-vue.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import RunnableCard from './runnable-card-vue.js'
22

33
export default {
44
name: 'script-card',
5-
props: ['script', 'disabled'],
5+
props: {
6+
script: Object,
7+
disabled: Boolean,
8+
favorited: Boolean,
9+
},
610
components: {
711
'runnable-card': RunnableCard,
812
},
913
template: `
10-
<runnable-card :runnable="script" class="script-card" :disabled="disabled">
14+
<runnable-card :runnable="script" class="script-card" :disabled="disabled" :favorited="favorited">
1115
<b-form inline>
1216
<b-form-checkbox v-model="script.enabled" class="script-switch" switch :disabled="disabled">
1317
<img :src="script.logo">

rlbot_gui/persistence/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
MATCH_SETTINGS_KEY = 'match_settings'
66
LAUNCHER_SETTINGS_KEY = 'launcher_settings'
77
TEAM_SETTINGS_KEY = 'team_settings'
8+
FAVORITES_KEY = 'favorite_runnables'
89

910

1011
def load_settings() -> QSettings:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import setuptools
22

3-
__version__ = '0.0.160'
3+
__version__ = '0.0.161'
44

55
with open("README.md", "r") as readme_file:
66
long_description = readme_file.read()

0 commit comments

Comments
 (0)