more ui and ux improvements

This commit is contained in:
PoliEcho 2024-10-20 12:55:42 +02:00
parent b2dd352688
commit b48075fbc5
2 changed files with 30 additions and 14 deletions

View File

@ -15,8 +15,8 @@
MainWindow::MainWindow()
: m_button_spin("spin"), m_button_reset("reset money"),
m_button_quit("Quit"), slot_image0(), slot_image1(), slot_image2(),
m_label_money(), m_label_spins(), m_label_info(), m_label_bet("bet:"),
m_entry_bet(), m_timer_number(0) {
m_label_money(), m_label_spins(), m_label_info(), m_entry_bet(),
m_timer_number(0) {
set_title("Pupes Slots!");
m_grid_quit.set_margin(12);
@ -27,8 +27,15 @@ MainWindow::MainWindow()
money = 100;
spins = 0;
m_label_spins.set_label(std::to_string(spins));
m_label_money.set_label(std::to_string(money));
// bet entry
m_entry_bet.set_icon_from_icon_name("input-gaming");
m_entry_bet.set_placeholder_text("enter you bet");
// spins and money
m_label_spins.set_label("spins: " + std::to_string(spins));
m_label_spins.set_justify(Gtk::Justification::LEFT);
m_label_money.set_label("money: " + std::to_string(money));
m_label_money.set_justify(Gtk::Justification::LEFT);
// set image size
slot_image0.set_size_request(128, 128);
@ -44,13 +51,15 @@ MainWindow::MainWindow()
m_grid_main.attach(slot_image1, 1, 2);
m_grid_main.attach(slot_image2, 2, 2);
// info label
m_grid_main.attach(m_label_info, 1, 3);
// row 4 spin button, bet entry, reset button
m_grid_main.attach(m_button_spin, 0, 4);
m_grid_main.attach(m_label_bet, 1, 4);
m_grid_main.attach(m_entry_bet, 2, 4);
m_grid_main.attach(m_button_reset, 3, 4);
m_grid_main.attach(m_entry_bet, 1, 4);
m_grid_main.attach(m_button_reset, 2, 4);
// attach main grid to to level quit grid and add quit button
m_grid_quit.attach(m_grid_main, 0, 0);
m_grid_quit.attach(m_button_quit, 0, 1);
@ -92,7 +101,7 @@ void MainWindow::randomise_slots(bool save, Glib::ustring *slot_status) {
}
}
bool MainWindow::refresh_slots(int timer_number) {
bool MainWindow::refresh_slots(int timer_number, unsigned long long bet) {
std::cout << "This is timer " << timer_number;
@ -147,17 +156,24 @@ bool MainWindow::refresh_slots(int timer_number) {
void MainWindow::on_button_spin() {
if (can_spin) {
unsigned long long bet;
try {
bet = std::stoull(m_entry_bet.get_text());
} catch (...) {
std::cerr << "input a number\n";
return;
}
can_spin = false;
spins++;
m_label_spins.set_label(std::to_string(spins));
m_label_spins.set_label("spins: " + std::to_string(spins));
count_value = get_random_num(30, 50);
// Creation of a new object prevents long lines and shows us a little
// how slots work. We have 0 parameters and bool as a return value
// after calling sigc::bind.
sigc::slot<bool()> my_slot = sigc::bind(
sigc::mem_fun(*this, &MainWindow::refresh_slots), m_timer_number);
sigc::mem_fun(*this, &MainWindow::refresh_slots), m_timer_number, bet);
// This is where we connect the slot to the Glib::signal_timeout()
auto conn = Glib::signal_timeout().connect(my_slot, 300);

View File

@ -18,12 +18,12 @@ private:
// Signal handlers:
void on_button_quit();
void on_button_spin();
bool refresh_slots(int timer_number);
void randomise_slots(bool save_to_global, Glib::ustring *slot_status);
bool refresh_slots(int timer_number, unsigned long long bet);
void randomise_slots(bool save, Glib::ustring *slot_status);
// Child widgets:
Gtk::Grid m_grid_quit, m_grid_main;
Gtk::Label m_label_money, m_label_spins, m_label_info, m_label_bet;
Gtk::Label m_label_money, m_label_spins, m_label_info;
Gtk::Image slot_image0, slot_image1, slot_image2;
Gtk::Button m_button_spin, m_button_reset, m_button_quit;
Gtk::Entry m_entry_bet;