Skip to content

Commit

Permalink
adding rightbar
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Mar 9, 2024
1 parent 804e5e5 commit e46997e
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/game_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "my_backtrace.hpp"
#include "my_game.hpp"
#include "my_wid_popups.hpp"
#include "my_wid_rightbar.hpp"

std::string gama_state_to_string(int state)
{
Expand Down Expand Up @@ -57,6 +58,7 @@ void Game::change_state(uint8_t new_state, const std::string &why)
wid_load_destroy();
wid_save_destroy();
wid_quit_destroy();
wid_rightbar_fini();
break;
case STATE_KEYBOARD_MENU :
case STATE_LOAD_MENU :
Expand Down
5 changes: 5 additions & 0 deletions src/my_level_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ typedef struct LevelData_ {
// No c++ types can be used here, to allow easy level replay
//////////////////////////////////////////////////////////////

//
// Level number
//
uint8_t num;

//
// Map scroll offset
//
Expand Down
3 changes: 2 additions & 1 deletion src/my_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define UI_FONT_WIDTH 8
#define UI_LOGGING_EMPTY_LINE "`" // Complete hack, char I use to force space
#define UI_MOUSE_DOUBLE_CLICK 500 // Double click time
#define UI_MOUSE_WHEEL_SCALE 1.2 // How much the wheel mouse moves.
#define UI_MOUSE_WHEEL_SCALE 2.0 // How much the wheel mouse moves.
#define UI_MOUSE_WHEEL_SCALE_MAX 10
#define UI_POPUP_TEXT_COLOR UI_TEXT_COLOR
#define UI_SCROLL_JOY_SCALE 1.0
Expand All @@ -31,6 +31,7 @@
#define UI_WID_POPUP_WIDTH_NORMAL 18
#define UI_WID_POPUP_WIDTH_WIDE 24
#define UI_WID_SAVE_SLOTS 10 // How many save game slots
#define UI_RIGHTBAR_WIDTH 18

//
// Do faster processing of events, like reading the keyboard and updating widgets.
Expand Down
20 changes: 20 additions & 0 deletions src/my_wid_rightbar.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright Neil McGill, [email protected]
//

#pragma once

void wid_rightbar_fini(void);
bool wid_rightbar_init(void);
bool wid_rightbar_ascii_create(void);

#include "my_wid.hpp"

//
// Global widgets.
//
extern Widp wid_rightbar_window;
extern Widp wid_map_mini;
extern Widp wid_rightbar;

extern bool is_mouse_over_rightbar(void);
85 changes: 85 additions & 0 deletions src/wid_rightbar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// Copyright Neil McGill, [email protected]
//

#include "my_game.hpp"
#include "my_sdl_event.hpp"
#include "my_string.hpp"
#include "my_thing.hpp"
#include "my_ui.hpp"
#include "my_wid_popup.hpp"
#include "my_wid_popups.hpp"
#include "my_wid_rightbar.hpp"

static bool wid_rightbar_create(void);

Widp wid_rightbar {};
Widp wid_map_mini {};

static WidPopup *wid_rightbar_popup;

void wid_rightbar_fini(void)
{
TRACE_AND_INDENT();
wid_destroy(&wid_rightbar);
wid_destroy(&wid_map_mini);

delete wid_rightbar_popup;
wid_rightbar_popup = nullptr;
}

bool wid_rightbar_init(void)
{
TRACE_AND_INDENT();
return wid_rightbar_create();
}

bool wid_rightbar_create(void)
{
wid_rightbar_fini();

auto level = game->level;
if (! level) {
return false;
}

return wid_rightbar_ascii_create();
}

bool is_mouse_over_rightbar(void)
{
if (! wid_rightbar) {
return false;
}

//
// If we are in the portion of the lower screen above the itembar
// then do not scroll
//
int x = sdl.mouse_x;
int y = sdl.mouse_y;
pixel_to_ascii(&x, &y);

static int tlx, tly, brx, bry, cached;
if (cached != TERM_HEIGHT) {
cached = TERM_HEIGHT;
}

wid_get_tl_x_tl_y_br_x_br_y(wid_rightbar, &tlx, &tly, &brx, &bry);

//
// Add some border
//
tlx -= 1;
brx++;
tly -= 1;
bry++;

if ((x >= tlx) && (x < brx) && (y >= tly)) {
// CON(" rightbar %d %d %d", tlx, brx, x);
return true;
}
// CON("NOT rightbar %d %d %d", tlx, brx, x);

return false;
}
74 changes: 74 additions & 0 deletions src/wid_rightbar_ascii.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//
// Copyright Neil McGill, [email protected]
//

#include "my_color_defs.hpp"
#include "my_game.hpp"
#include "my_level.hpp"
#include "my_level_data.hpp"
#include "my_ptrcheck.hpp"
#include "my_string.hpp"
#include "my_thing.hpp"
#include "my_ui.hpp"
#include "my_vector_bounds_check.hpp"
#include "my_wid_rightbar.hpp"

bool wid_rightbar_ascii_create(void)
{
TRACE_AND_INDENT();
DBG2("Remake rightbar");

auto level = game->level;
if (! level) {
return false;
}

int width = UI_RIGHTBAR_WIDTH;
int y_at = 0;

{
TRACE_AND_INDENT();
point tl = make_point(TERM_WIDTH - width, 0);
point br = make_point(TERM_WIDTH - 1, TERM_HEIGHT - 1);

wid_rightbar = wid_new_square_window("wid rightbar");
wid_set_ignore_scroll_events(wid_rightbar, true);
wid_set_pos(wid_rightbar, tl, br);
wid_set_style(wid_rightbar, UI_WID_STYLE_SOLID_NONE);
wid_set_shape_none(wid_rightbar);
wid_lower(wid_rightbar);
}

{
TRACE_AND_INDENT();
auto w = wid_new_square_button(wid_rightbar, "level no");
point tl = make_point(0, y_at);
point br = make_point(width - 1, y_at);
auto s = dynprintf("Level %u", level->data->num);
wid_set_pos(w, tl, br);
wid_set_text(w, s);
wid_set_style(w, UI_WID_STYLE_NORMAL);
wid_set_shape_none(w);
myfree(s);
}

{
y_at++;
TRACE_AND_INDENT();
auto w = wid_new_plain(wid_rightbar, "Seed");
point tl = make_point(0, y_at);
point br = make_point(width - 1, y_at);

auto s = dynprintf("%%fg=gray$%s", game->seed_name.c_str());
wid_set_pos(w, tl, br);
wid_set_text(w, s);
wid_set_shape_none(w);
myfree(s);
}

wid_update(wid_rightbar);

DBG2("Remade rightbar");

return true;
}

0 comments on commit e46997e

Please sign in to comment.