Compare commits

..

7 Commits
master ... ui

Author SHA1 Message Date
Sheldon Lee
bd9e09e53f Implemented type flexibility for UI. 2020-07-12 02:39:17 +01:00
Sheldon Lee
305c090e31 In progress for more type flexibilty for UI. 2020-07-11 02:08:17 +01:00
Sheldon Lee
3df203c588 Can now add lines to ui and draw. 2020-07-09 23:58:17 +01:00
Sheldon Lee
41db31e121 Started in ui. 2020-07-09 01:26:08 +01:00
Sheldon Lee
41ee67b718 Updated Session. 2020-07-09 01:26:01 +01:00
Sheldon Lee
90f6067556 Updated session. 2020-07-08 18:54:20 +01:00
Sheldon Lee
5cf60f5692 Started on ui. 2020-07-08 00:30:37 +01:00
5 changed files with 126 additions and 27 deletions

7
game.c
View File

@ -4,6 +4,7 @@
#include "grid.h" #include "grid.h"
#include "vect.h" #include "vect.h"
#include "log.h" #include "log.h"
#include "ui.h"
static Grid* grid = 0; static Grid* grid = 0;
@ -47,6 +48,9 @@ void initGame()
int height = 0; int height = 0;
// stdscr is screen created by initscr() // stdscr is screen created by initscr()
getmaxyx(stdscr, height, width); getmaxyx(stdscr, height, width);
addLine("x:", &cursor.x, 1, UI_INT);
addLine("y:", &cursor.y, 1, UI_INT);
grid = initGrid(width, height); grid = initGrid(width, height);
//randomizeGrid(grid); //randomizeGrid(grid);
@ -143,9 +147,6 @@ void drawLastPressed(char ch)
void drawCurPos() void drawCurPos()
{ {
attron(COLOR_PAIR(2));
mvprintw(1, 0, "curpos: %i, %i", cursor.x, cursor.y);
attroff(COLOR_PAIR(2));
attron(COLOR_PAIR(3)); attron(COLOR_PAIR(3));
mvaddch(cursor.y, cursor.x, ' '); mvaddch(cursor.y, cursor.x, ' ');
attroff(COLOR_PAIR(3)); attroff(COLOR_PAIR(3));

7
main.c
View File

@ -8,6 +8,7 @@
// game // game
#include "game.h" #include "game.h"
#include "log.h" #include "log.h"
#include "ui.h"
int main() int main()
@ -15,8 +16,8 @@ int main()
// framerate of the game // framerate of the game
const int FRAME_RATE = 30; const int FRAME_RATE = 30;
const float FRAME_TIME = 1.f/(float)FRAME_RATE; const float FRAME_TIME = 1.f/(float)FRAME_RATE;
startLog("log.txt");
startLog("log.txt");
initGame(); initGame();
float t = 0; float t = 0;
@ -27,8 +28,9 @@ int main()
handleInput(ch); handleInput(ch);
drawGame(); drawGame();
drawLastPressed(ch); //drawLastPressed(ch);
drawCurPos(); drawCurPos();
drawUI();
refresh(); refresh();
@ -38,6 +40,7 @@ int main()
t = (float) (clock()-start_t) / (float) CLOCKS_PER_SEC; t = (float) (clock()-start_t) / (float) CLOCKS_PER_SEC;
} }
endUI();
endGame(); endGame();
endLog(); endLog();
return 0; return 0;

View File

@ -180,12 +180,12 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 21 - ((20 * winheight(0) + 24) / 49) let s:l = 25 - ((24 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
21 25
normal! 05| normal! 08|
tabnext tabnext
edit grid.c edit grid.c
set splitbelow splitright set splitbelow splitright
@ -322,7 +322,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 24) / 49) let s:l = 1 - ((0 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -464,7 +464,7 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 10 - ((9 * winheight(0) + 24) / 49) let s:l = 10 - ((9 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
@ -481,6 +481,7 @@ set winheight=1
set winminwidth=0 set winminwidth=0
set winwidth=1 set winwidth=1
argglobal argglobal
1argu
if bufexists("game.c") | buffer game.c | else | edit game.c | endif if bufexists("game.c") | buffer game.c | else | edit game.c | endif
setlocal keymap= setlocal keymap=
setlocal noarabic setlocal noarabic
@ -606,12 +607,12 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 45 - ((42 * winheight(0) + 24) / 49) let s:l = 45 - ((44 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
45 45
normal! 05| normal! 0
tabnext tabnext
edit game.h edit game.h
set splitbelow splitright set splitbelow splitright
@ -748,14 +749,14 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 13 - ((12 * winheight(0) + 24) / 49) let s:l = 13 - ((12 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
13 13
normal! 035| normal! 0
tabnext tabnext
edit vect.c edit ui.c
set splitbelow splitright set splitbelow splitright
set nosplitbelow set nosplitbelow
set nosplitright set nosplitright
@ -765,7 +766,8 @@ set winheight=1
set winminwidth=0 set winminwidth=0
set winwidth=1 set winwidth=1
argglobal argglobal
3argu 5argu
if bufexists("ui.c") | buffer ui.c | else | edit ui.c | endif
setlocal keymap= setlocal keymap=
setlocal noarabic setlocal noarabic
setlocal autoindent setlocal autoindent
@ -890,14 +892,14 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 1 - ((0 * winheight(0) + 24) / 49) let s:l = 1 - ((0 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
1 1
normal! 0 normal! 0
tabnext tabnext
edit vect.h edit ui.h
set splitbelow splitright set splitbelow splitright
set nosplitbelow set nosplitbelow
set nosplitright set nosplitright
@ -907,7 +909,7 @@ set winheight=1
set winminwidth=0 set winminwidth=0
set winwidth=1 set winwidth=1
argglobal argglobal
5argu if bufexists("ui.h") | buffer ui.h | else | edit ui.h | endif
setlocal keymap= setlocal keymap=
setlocal noarabic setlocal noarabic
setlocal autoindent setlocal autoindent
@ -1032,11 +1034,11 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 3 - ((2 * winheight(0) + 24) / 49) let s:l = 6 - ((5 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
3 6
normal! 0 normal! 0
tabnext tabnext
edit makefile edit makefile
@ -1174,28 +1176,30 @@ setlocal nowinfixwidth
setlocal wrap setlocal wrap
setlocal wrapmargin=0 setlocal wrapmargin=0
silent! normal! zE silent! normal! zE
let s:l = 3 - ((2 * winheight(0) + 24) / 49) let s:l = 3 - ((2 * winheight(0) + 27) / 55)
if s:l < 1 | let s:l = 1 | endif if s:l < 1 | let s:l = 1 | endif
exe s:l exe s:l
normal! zt normal! zt
3 3
normal! 0 normal! 0
tabnext 1 tabnext 6
set stal=1 set stal=1
badd +1 grid.c badd +1 grid.c
badd +0 main.c badd +0 main.c
badd +1 vect.c badd +1 vect.c
badd +1 grid.h badd +1 grid.h
badd +1 vect.h badd +2 vect.h
badd +1 makefile badd +1 makefile
badd +1 game.c
badd +3 game.h
badd +17 ~/.vimrc badd +17 ~/.vimrc
badd +1 ~/.vimrs badd +1 ~/.vimrs
badd +12 session.vim badd +12 session.vim
badd +0 gamestate.h\ gamestate.c badd +1 gamestate.h\ gamestate.c
badd +3 game.h
badd +0 game.c
badd +1 gamestate.c badd +1 gamestate.c
badd +1 gamestate.h badd +1 gamestate.h
badd +0 ui.c
badd +0 ui.h
if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0 if exists('s:wipebuf') && len(win_findbuf(s:wipebuf)) == 0
silent exe 'bwipe ' . s:wipebuf silent exe 'bwipe ' . s:wipebuf
endif endif
@ -1207,6 +1211,7 @@ if filereadable(s:sx)
exe "source " . fnameescape(s:sx) exe "source " . fnameescape(s:sx)
endif endif
let &so = s:so_save | let &siso = s:siso_save let &so = s:so_save | let &siso = s:siso_save
nohlsearch
doautoall SessionLoadPost doautoall SessionLoadPost
unlet SessionLoad unlet SessionLoad
" vim: set ft=vim : " vim: set ft=vim :

70
ui.c Normal file
View File

@ -0,0 +1,70 @@
#include <stddef.h>
#include <stdlib.h>
#include <ncurses.h>
#include "ui.h"
#include "log.h"
typedef struct {
char* msg;
void* var;
size_t size;
ui_type type;
}Line;
static unsigned int ln_count = 0;
static Line* lines = NULL;
// declaration of locally used
static void startUI();
static void drawLine(Line*, int offset);
void addLine(char* msg, void* var, int size, ui_type type)
{
if (!lines) startUI();
else lines = realloc(lines, sizeof(Line) * ++ln_count);
Line line = { msg, var, size, type};
lines[ln_count-1] = line;
}
void drawUI()
{
if (!lines) return;
attron(COLOR_PAIR(2));
for (int i = 0; i < ln_count; i++) {
drawLine(&lines[i], i);
}
attroff(COLOR_PAIR(2));
}
void endUI()
{
free(lines);
}
// static definition
static void startUI()
{
lines = (Line*)malloc(sizeof(Line) * ++ln_count);
}
static void drawLine(Line* line, int offset)
{
switch (line->type) {
case UI_INT:
mvprintw(offset, 0, "%s %i", line->msg, *((int*)line->var) );
break;
case UI_FLOAT:
mvprintw(offset, 0, "%s %f", line->msg, *((float*)line->var) );
break;
case UI_CHAR:
mvprintw(offset, 0, "%s %c", line->msg, *((char*)line->var) );
break;
case UI_STRING:
mvprintw(offset, 0, "%s %s", line->msg, ((char*)line->var) );
break;
}
}

20
ui.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef UI_H
#define UI_H
#define ui_type uint8_t
#define UI_NULL 0
#define UI_INT 1
#define UI_FLOAT 2
#define UI_CHAR 3
#define UI_STRING 4
//void startUI();
void addLine(char* msg, void* var, int size, ui_type type);
void drawUI();
void endUI();
#endif