[Add] Shipyard information on manufacturer and purchase price etc.
This commit is contained in:
parent
1b4bea7b1f
commit
e6b28a1634
@ -67,7 +67,7 @@ void player_board(void) {
|
||||
0, "txtCargo", &gl_smallFont, &cDConsole,
|
||||
"SCreds:\n"
|
||||
"Cargo:\n");
|
||||
credits2str(cred, board_credits);
|
||||
credits2str(cred, board_credits, 2);
|
||||
snprintf(str, 128,
|
||||
"%s\n"
|
||||
"%s\n",
|
||||
@ -105,7 +105,7 @@ static void board_stealCreds(char* str) {
|
||||
credits += board_credits;
|
||||
board_credits = 0;
|
||||
board_update(); // Update the lack of credits.
|
||||
player_message("You manage to steal the ship's credits");
|
||||
player_message("You manage to steal the ship's Scred");
|
||||
}
|
||||
|
||||
// Failed to board.
|
||||
@ -129,7 +129,7 @@ static void board_update(void) {
|
||||
char str[128];
|
||||
char cred[10];
|
||||
|
||||
credits2str(cred, board_credits);
|
||||
credits2str(cred, board_credits, 2);
|
||||
|
||||
snprintf(str, 128,
|
||||
"%s\n"
|
||||
|
@ -4,13 +4,13 @@
|
||||
|
||||
// Convert credits to a usable string for displaying.
|
||||
// str must have 10 characters allocated.
|
||||
void credits2str(char* str, unsigned int credits) {
|
||||
void credits2str(char* str, unsigned int credits, int decimals) {
|
||||
if(credits >= 1000000000)
|
||||
snprintf(str, 10, "%.2fB", (double)credits / 1000000000.);
|
||||
snprintf(str, 10, "%.*fB", decimals, (double)credits / 1000000000.);
|
||||
else if(credits >= 1000000)
|
||||
snprintf(str, 10, "%2fM", (double)credits / 1000000.);
|
||||
snprintf(str, 10, "%*fM", decimals, (double)credits / 1000000.);
|
||||
else if(credits >= 1000)
|
||||
snprintf(str, 10, "%.2fK", (double)credits / 1000.);
|
||||
snprintf(str, 10, "%.*fK", decimals, (double)credits / 1000.);
|
||||
else snprintf(str, 10, "%d", credits);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void credits2str(char* str, unsigned int credits);
|
||||
void credits2str(char* str, unsigned int credits, int decimals);
|
||||
|
||||
|
48
src/land.c
48
src/land.c
@ -3,6 +3,7 @@
|
||||
#include "player.h"
|
||||
#include "rng.h"
|
||||
#include "music.h"
|
||||
#include "economy.h"
|
||||
#include "land.h"
|
||||
|
||||
// Global/main window.
|
||||
@ -21,7 +22,7 @@
|
||||
|
||||
// Shipyard.
|
||||
#define SHIPYARD_WIDTH 700
|
||||
#define SHIPYARD_HEIGHT 600
|
||||
#define SHIPYARD_HEIGHT 500
|
||||
#define SHIPYARD_XPOS (gl_screen.w-SHIPYARD_WIDTH)/2+100
|
||||
#define SHIPYARD_YPOS (gl_screen.h-SHIPYARD_HEIGHT)/2-25
|
||||
|
||||
@ -53,6 +54,7 @@ static void shipyard(void);
|
||||
static void shipyard_close(char* str);
|
||||
static void shipyard_update(char* str);
|
||||
static void shipyard_info(char* str);
|
||||
static void shipyard_buy(char* str);
|
||||
// Spaceport bar.
|
||||
static void spaceport_bar(void);
|
||||
static void spaceport_bar_close(char* str);
|
||||
@ -114,18 +116,29 @@ static void shipyard(void) {
|
||||
|
||||
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 20,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnBuyShip",
|
||||
"Buy", NULL);
|
||||
"Buy", shipyard_buy);
|
||||
|
||||
window_addButton(secondary_wid, -40-BUTTON_WIDTH, 40+BUTTON_HEIGHT,
|
||||
BUTTON_WIDTH, BUTTON_HEIGHT, "btnInfoShip",
|
||||
"Info", shipyard_info);
|
||||
|
||||
window_addRect(secondary_wid, 20+200+60, -50,
|
||||
window_addRect(secondary_wid, -40, -50,
|
||||
128, 96, "rctTarget", &cBlack, 0);
|
||||
|
||||
window_addImage(secondary_wid, 20+200+60, -50-96,
|
||||
window_addImage(secondary_wid, -40-128, -50-96,
|
||||
"imgTarget", NULL);
|
||||
|
||||
window_addText(secondary_wid, 40+200+40, -80,
|
||||
80, 96, 0, "txtSDesc", &gl_smallFont, &cDConsole,
|
||||
"Name:\n"
|
||||
"Class:\n"
|
||||
"Fabricator:\n"
|
||||
"\n"
|
||||
"Price:\n");
|
||||
|
||||
window_addText(secondary_wid, 40+200+40+80, -80,
|
||||
128, 96, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL);
|
||||
|
||||
|
||||
window_addText(secondary_wid, 20+200+40, -160,
|
||||
SHIPYARD_WIDTH-360, 200, 0, "txtDescription",
|
||||
@ -150,12 +163,28 @@ static void shipyard_update(char* str) {
|
||||
(void)str;
|
||||
char* shipname;
|
||||
Ship* ship;
|
||||
char buf[80], buf2[32];
|
||||
|
||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||
ship = ship_get(shipname);
|
||||
|
||||
window_modifyText(secondary_wid, "txtDescription", ship->description);
|
||||
window_modifyImage(secondary_wid, "imgTarget", ship->gfx_target);
|
||||
|
||||
credits2str(buf2, ship->price, 0);
|
||||
snprintf(buf, 80,
|
||||
"%s\n"
|
||||
"%s\n"
|
||||
"%s\n"
|
||||
"\n"
|
||||
"%s Scred\n",
|
||||
ship->name,
|
||||
ship_class(ship),
|
||||
ship->fabricator,
|
||||
buf2);
|
||||
|
||||
window_modifyText(secondary_wid, "txtDDesc", buf);
|
||||
|
||||
}
|
||||
|
||||
static void shipyard_info(char* str) {
|
||||
@ -166,6 +195,17 @@ static void shipyard_info(char* str) {
|
||||
ship_view(shipname);
|
||||
}
|
||||
|
||||
static void shipyard_buy(char* str) {
|
||||
(void)str;
|
||||
char* shipname;
|
||||
Ship* ship;
|
||||
|
||||
shipname = toolkit_getList(secondary_wid, "lstShipyard");
|
||||
ship = ship_get(shipname);
|
||||
|
||||
//Vec2 v;
|
||||
}
|
||||
|
||||
// Spaceport bar.
|
||||
static void spaceport_bar(void) {
|
||||
secondary_wid = window_create("SpacePort Bar", -1, -1, BAR_WIDTH, BAR_HEIGHT);
|
||||
|
@ -449,7 +449,7 @@ void player_render(void) {
|
||||
gl_print(NULL, gui.misc.x + 10, gui.misc.y - 10 - gl_defFont.h,
|
||||
&cConsole, "SCred:");
|
||||
|
||||
credits2str(str, credits);
|
||||
credits2str(str, credits, 2);
|
||||
|
||||
i = gl_printWidth(&gl_smallFont, "%s", str);
|
||||
gl_print(&gl_smallFont, gui.misc.x + gui.misc.w - 10 - i,
|
||||
|
@ -24,7 +24,6 @@
|
||||
static Ship* ship_stack = NULL;
|
||||
static int ships = 0;
|
||||
|
||||
static char* ship_class(Ship* s);
|
||||
static Ship* ship_parse(xmlNodePtr parent);
|
||||
static void ship_view_close(char* btn);
|
||||
|
||||
@ -56,7 +55,7 @@ char** ship_getAll(int* n) {
|
||||
return shipnames;
|
||||
}
|
||||
|
||||
static char* ship_class(Ship* s) {
|
||||
char* ship_class(Ship* s) {
|
||||
return ship_classes[s->class];
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,7 @@ typedef struct Ship_ {
|
||||
// Get.
|
||||
Ship* ship_get(const char* name);
|
||||
char** ship_getAll(int* n);
|
||||
char* ship_class(Ship* p);
|
||||
|
||||
// Load/quit.
|
||||
int ships_load(void);
|
||||
|
Loading…
Reference in New Issue
Block a user