Skip to content

Commit 340d045

Browse files
committed
add display size option
1 parent ced13f6 commit 340d045

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

crates/gui/src/league_app.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub struct LeagueApp {
88
pub histories: Arc<RwLock<Vec<GameHistoryQuery>>>,
99
pub filtered_histories: Arc<RwLock<Vec<GameHistoryQuery>>>,
1010
pub is_classic_mode: bool,
11+
pub max_game_count: u32,
12+
pub display_size: u32,
1113
}
1214

1315
/// functional implement block
@@ -19,6 +21,8 @@ impl LeagueApp {
1921
histories: Arc::new(RwLock::new(vec![])),
2022
filtered_histories: Arc::new(RwLock::new(vec![])),
2123
is_classic_mode: false,
24+
max_game_count: 20,
25+
display_size: 5,
2226
}
2327
}
2428

@@ -28,11 +32,12 @@ impl LeagueApp {
2832
let histories_task = self.histories.clone();
2933
let filtered_histories_task = self.filtered_histories.clone();
3034
let lcu_task = self.lcu_client.clone();
35+
let game_count = self.max_game_count;
3136
rt.block_on(async move {
3237
let mut histories = histories_task.write();
3338
let mut filtered_history = filtered_histories_task.write();
3439

35-
let expect_history = lcu_task.read().get_summoner_match_histories().await.unwrap();
40+
let expect_history = lcu_task.read().get_summoner_match_histories(game_count).await.unwrap();
3641

3742
if expect_history.is_empty() {
3843
log::debug!("No match history found currently");
@@ -70,8 +75,9 @@ impl eframe::App for LeagueApp {
7075
egui_extras::install_image_loaders(ctx);
7176
CentralPanel::default().show(ctx, |ui| {
7277
self.render_header_options(ui);
73-
self.render_match_history(ui);
74-
78+
egui::ScrollArea::vertical().show(ui, |ui| {
79+
self.render_match_history(ui);
80+
});
7581
});
7682

7783
}
@@ -81,24 +87,26 @@ impl eframe::App for LeagueApp {
8187
impl LeagueApp {
8288
pub fn render_header_options(&mut self, ui: &mut egui::Ui) {
8389
ui.horizontal(|ui| {
84-
if ui.button("Refresh Match History").highlight().clicked() {
90+
if ui.button("Refresh").highlight().clicked() {
8591
self.fetch_match_history().unwrap();
8692

8793
self.filter_by_mode();
8894
}
8995

90-
ui.checkbox(&mut self.is_classic_mode, "Filter Classic Mode");
96+
ui.checkbox(&mut self.is_classic_mode, "Classic Mode");
9197
ui.separator();
98+
99+
ui.add(egui::Slider::new(&mut self.display_size, 1..=self.max_game_count).text("Display Count"));
92100
});
93101
}
94102

95103
pub fn render_match_history(&self, ui: &mut egui::Ui) {
96104
ui.horizontal(|ui| {
97105
if self.is_classic_mode {
98-
Self::render_game_history(ui, &self.filtered_histories);
106+
self.render_game_history(ui, &self.filtered_histories);
99107
return;
100108
}
101-
Self::render_game_history(ui, &self.histories);
109+
self.render_game_history(ui, &self.histories);
102110
});
103111

104112
}
@@ -168,6 +176,7 @@ impl LeagueApp {
168176
ui.add(Image::new(spell2_url).fit_to_exact_size(Vec2::new(15., 15.)));
169177
});
170178
});
179+
ui.label(egui::RichText::new(game.get_date()));
171180
ui.label(egui::RichText::new(game.get_kda_result()).color(egui::Color32::DARK_BLUE));
172181
if game.get_win_status() {
173182
ui.label(egui::RichText::new("Win").color(egui::Color32::GREEN));
@@ -177,7 +186,7 @@ impl LeagueApp {
177186
});
178187
}
179188

180-
fn render_game_history(ui: &mut egui::Ui, histories: &Arc<RwLock<Vec<GameHistoryQuery>>>) {
189+
fn render_game_history(&self, ui: &mut egui::Ui, histories: &Arc<RwLock<Vec<GameHistoryQuery>>>) {
181190
ui.horizontal(|ui| {
182191
static PADDING: f32 = 4.;
183192
for (slot, history) in histories.read().iter().enumerate() {
@@ -192,7 +201,7 @@ impl LeagueApp {
192201
ui.add_space(PADDING);
193202

194203
for (index, game) in games.iter().enumerate() {
195-
if index == 5 {
204+
if index == self.display_size as usize {
196205
break;
197206
}
198207
Self::render_game(ui, game);

crates/lcu_api/src/lcu_client.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,20 @@ impl LcuClient {
9090
Ok(summoners)
9191
}
9292

93-
pub async fn get_summoner_match_history(&self, summoner: Summoner) -> Result<GameHistoryQuery, ModelError> {
93+
pub async fn get_summoner_match_history(&self, summoner: Summoner, game_count: u32) -> Result<GameHistoryQuery, ModelError> {
9494

95-
let url = format!("/lol-match-history/v1/products/lol/{}/matches{}", summoner.puuid, Self::index_range_query(0, 19));
95+
let url = format!("/lol-match-history/v1/products/lol/{}/matches{}", summoner.puuid, Self::index_range_query(0, game_count - 1));
9696
let history = self.get(&url)
9797
.await.map_err(|_| ModelError::HistoryNotFound)?;
9898

9999
Ok(history)
100100
}
101101

102-
pub async fn get_summoner_match_histories(&self) -> anyhow::Result<Vec<GameHistoryQuery>> {
102+
pub async fn get_summoner_match_histories(&self, game_count: u32) -> anyhow::Result<Vec<GameHistoryQuery>> {
103103
let summoners = self.get_team_summoners().await?;
104-
let mut histories = Vec::with_capacity(10);
104+
let mut histories = Vec::with_capacity(game_count as usize);
105105
for summoner in summoners {
106-
let history = self.get_summoner_match_history(summoner).await?;
106+
let history = self.get_summoner_match_history(summoner, game_count).await?;
107107
histories.push(history);
108108
}
109109
Ok(histories)

crates/league_model/src/common/game.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ impl Game {
6060
self.game_creation_date, self.game_mode, self.game_type)
6161
}
6262

63+
pub fn get_timestamp(&self) -> String {
64+
format!("{}", self.game_creation_date)
65+
}
66+
67+
pub fn get_date(&self) -> String {
68+
let mut timestamp = self.game_creation_date.clone();
69+
let _ = timestamp.split_off(10);
70+
timestamp
71+
}
72+
6373
pub fn get_name_title(&self) -> String {
6474
self.get_player().name_title()
6575
}

0 commit comments

Comments
 (0)