Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
font-weight: bold;
}

.wizard-step-complete {
color: @success_color;
}

.progress-bar {
min-height: 8px;
}
78 changes: 58 additions & 20 deletions data/resources/ui/setup_page.ui
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,67 @@
<property name="margin-top">24</property>
<property name="margin-bottom">24</property>
<child>
<object class="GtkLabel" id="step_title">
<property name="wrap">true</property>
<property name="halign">center</property>
<style>
<class name="title-1"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="step_description">
<property name="wrap">true</property>
<property name="justify">center</property>
<property name="halign">center</property>
</object>
</child>
<child>
<object class="GtkBox" id="content_box">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<object class="GtkBox" id="wizard_box">
<property name="orientation">horizontal</property>
<property name="spacing">24</property>
<property name="halign">fill</property>
<property name="hexpand">true</property>
<property name="valign">fill</property>
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<child>
<object class="GtkScrolledWindow" id="step_sidebar_scrolled">
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<property name="min-content-width">240</property>
<property name="max-content-width">280</property>
<property name="hexpand">false</property>
<property name="vexpand">true</property>
<property name="child">
<object class="GtkListBox" id="steps_list">
<property name="selection-mode">none</property>
<style>
<class name="boxed-list"/>
</style>
</object>
</property>
</object>
</child>
<child>
<object class="GtkBox" id="content_area_box">
<property name="orientation">vertical</property>
<property name="spacing">24</property>
<property name="halign">fill</property>
<property name="valign">fill</property>
<property name="hexpand">true</property>
<property name="vexpand">true</property>
<child>
<object class="GtkLabel" id="step_title">
<property name="wrap">true</property>
<property name="halign">center</property>
<style>
<class name="title-1"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="step_description">
<property name="wrap">true</property>
<property name="justify">center</property>
<property name="halign">center</property>
</object>
</child>
<child>
<object class="GtkBox" id="content_box">
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<property name="halign">fill</property>
<property name="hexpand">true</property>
<property name="valign">fill</property>
<property name="vexpand">true</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
Expand Down
78 changes: 78 additions & 0 deletions src/ui/setup_page.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::cell::Cell;
use std::collections::HashSet;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

Expand All @@ -22,6 +23,10 @@ mod imp {
#[template_child]
pub body_box: TemplateChild<gtk::Box>,
#[template_child]
pub steps_list: TemplateChild<gtk::ListBox>,
#[template_child]
pub content_area_box: TemplateChild<gtk::Box>,
#[template_child]
pub step_title: TemplateChild<gtk::Label>,
#[template_child]
pub step_description: TemplateChild<gtk::Label>,
Expand All @@ -36,6 +41,7 @@ mod imp {
pub current_step: Cell<usize>,
pub all_steps: RefCell<Vec<steps::SetupStep>>,
pub selected_mods: RefCell<Vec<usize>>,
pub completed_steps: RefCell<HashSet<&'static str>>,
pub cancel_flag: RefCell<Option<Arc<AtomicBool>>>,
pub is_error: Cell<bool>,
}
Expand Down Expand Up @@ -197,15 +203,79 @@ impl AdventureModsSetupPage {

let initial_step = obj.skip_completed_steps(0);
obj.imp().current_step.set(initial_step);
obj.refresh_step_sidebar();
obj.show_current_step();
obj
}

fn refresh_step_sidebar(&self) {
let imp = self.imp();

while let Some(child) = imp.steps_list.first_child() {
imp.steps_list.remove(&child);
}

let all_steps = imp.all_steps.borrow();
let current_step = imp.current_step.get();
let completed_steps = imp.completed_steps.borrow();
let game = imp.game.borrow().clone();

for (idx, step) in all_steps.iter().enumerate() {
let row_box = gtk::Box::builder()
.orientation(gtk::Orientation::Horizontal)
.spacing(12)
.margin_start(12)
.margin_end(12)
.margin_top(10)
.margin_bottom(10)
.build();

let check_icon = gtk::Image::builder()
.icon_name("emblem-ok-symbolic")
.pixel_size(16)
.visible(false)
.build();

let step_label = gtk::Label::builder()
.label(step.title)
.wrap(true)
.xalign(0.0)
.hexpand(true)
.build();

let is_completed = game
.as_ref()
.map(|g| common::is_step_complete(step.id, g))
.unwrap_or(false)
|| completed_steps.contains(step.id);

if is_completed {
check_icon.set_visible(true);
check_icon.add_css_class("wizard-step-complete");
}

if idx == current_step {
row_box.add_css_class("setup-step-current");
}

row_box.append(&check_icon);
row_box.append(&step_label);

let row = gtk::ListBoxRow::builder()
.activatable(false)
.selectable(false)
.child(&row_box)
.build();
imp.steps_list.append(&row);
}
}

fn show_current_step(&self) {
let imp = self.imp();
let step_idx = imp.current_step.get();
let all_steps = imp.all_steps.borrow();
imp.is_error.set(false);
self.refresh_step_sidebar();

// Cancel any in-flight operation
if let Some(flag) = imp.cancel_flag.borrow().as_ref() {
Expand All @@ -223,6 +293,11 @@ impl AdventureModsSetupPage {
} else {
gtk::Align::Fill
});
imp.content_area_box.set_valign(if centered_layout {
gtk::Align::Center
} else {
gtk::Align::Fill
});
imp.content_box.set_halign(if centered_layout {
gtk::Align::Center
} else {
Expand Down Expand Up @@ -862,6 +937,9 @@ impl AdventureModsSetupPage {
}
fn advance_step(&self) {
let imp = self.imp();
if let Some(current_step) = imp.all_steps.borrow().get(imp.current_step.get()) {
imp.completed_steps.borrow_mut().insert(current_step.id);
}
let next = imp.current_step.get() + 1;
let total = imp.all_steps.borrow().len();

Expand Down
Loading